10 Apr, 2012

22 commits

  • avc_add_callback now just used for registering reset functions
    in initcalls, and the callback functions just did reset operations.
    So, reducing the arguments to only one event is enough now.

    Signed-off-by: Wanlong Gao
    Signed-off-by: Eric Paris

    Wanlong Gao
     
  • avc_add_callback now only called from initcalls, so replace the
    weak GFP_ATOMIC to GFP_KERNEL, and mark this function __init
    to make a warning when not been called from initcalls.

    Signed-off-by: Wanlong Gao
    Signed-off-by: Eric Paris

    Wanlong Gao
     
  • We no longer need the distinction. We only need data after we decide to do an
    audit. So turn the "late" audit data into just "data" and remove what we
    currently have as "data".

    Signed-off-by: Eric Paris

    Eric Paris
     
  • It's just takin' up space.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • It isn't needed. If you don't set the type of the data associated with
    that type it is a pretty obvious programming bug. So why waste the cycles?

    Signed-off-by: Eric Paris

    Eric Paris
     
  • We did a lot of work to shrink the common_audit_data. Add a BUILD_BUG_ON
    so future programers (let's be honest, probably me) won't do something
    foolish like make it large again!

    Signed-off-by: Eric Paris

    Eric Paris
     
  • There are no legitimate users. Always use current and get back some stack
    space for the common_audit_data.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • apparmor is the only LSM that uses the common_audit_data tsk field.
    Instead of making all LSMs pay for the stack space move the aa usage into
    the apparmor_audit_data.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Just open code it so grep on the source code works better.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • selinux_inode_has_perm is a hot path. Instead of declaring the
    common_audit_data on the stack move it to a noinline function only used in
    the rare case we need to send an audit message.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Both callers could better be using file_has_perm() to get better audit
    results.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • We pay a rather large overhead initializing the common_audit_data.
    Since we only need this information if we actually emit an audit
    message there is little need to set it up in the hot path. This patch
    splits the functionality of avc_has_perm() into avc_has_perm_noaudit(),
    avc_audit_required() and slow_avc_audit(). But we take care of setting
    up to audit between required() and the actual audit call. Thus saving
    measurable time in a hot path.

    Signed-off-by: Stephen Smalley
    Signed-off-by: Eric Paris

    Eric Paris
     
  • We reset the bool names and values array to NULL, but do not reset the
    number of entries in these arrays to 0. If we error out and then get back
    into this function we will walk these NULL pointers based on the belief
    that they are non-zero length.

    Signed-off-by: Eric Paris
    cc: stable@kernel.org

    Eric Paris
     
  • I'm not really sure what the idea behind the sel_div function is, but it's
    useless. Since a and b are both unsigned, it's impossible for a % b < 0.
    That means that part of the function never does anything. Thus it's just a
    normal /. Just do that instead. I don't even understand what that operation
    was supposed to mean in the signed case however....

    If it was signed:
    sel_div(-2, 4) == ((-2 / 4) - ((-2 % 4) < 0))
    ((0) - ((-2) < 0))
    ((0) - (1))
    (-1)

    What actually happens:
    sel_div(-2, 4) == ((18446744073709551614 / 4) - ((18446744073709551614 % 4) < 0))
    ((4611686018427387903) - ((2 < 0))
    (4611686018427387903 - 0)
    ((unsigned int)4611686018427387903)
    (4294967295)

    Neither makes a whole ton of sense to me. So I'm getting rid of the
    function entirely.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • It's possible that the caller passed a NULL for scontext. However if this
    is a defered mapping we might still attempt to call *scontext=kstrdup().
    This is bad. Instead just return the len.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • We know that some yum operation is causing CAP_MAC_ADMIN failures. This
    implies that an RPM is laying down (or attempting to lay down) a file with
    an invalid label. The problem is that we don't have any information to
    track down the cause. This patch will cause such a failure to report the
    failed label in an SELINUX_ERR audit message. This is similar to the
    SELINUX_ERR reports on invalid transitions and things like that. It should
    help run down problems on what is trying to set invalid labels in the
    future.

    Resulting records look something like:
    type=AVC msg=audit(1319659241.138:71): avc: denied { mac_admin } for pid=2594 comm="chcon" capability=33 scontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=capability2
    type=SELINUX_ERR msg=audit(1319659241.138:71): op=setxattr invalid_context=unconfined_u:object_r:hello:s0
    type=SYSCALL msg=audit(1319659241.138:71): arch=c000003e syscall=188 success=no exit=-22 a0=a2c0e0 a1=390341b79b a2=a2d620 a3=1f items=1 ppid=2519 pid=2594 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="chcon" exe="/usr/bin/chcon" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
    type=CWD msg=audit(1319659241.138:71): cwd="/root" type=PATH msg=audit(1319659241.138:71): item=0 name="test" inode=785879 dev=fc:03 mode=0100644 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:admin_home_t:s0

    Signed-off-by: Eric Paris

    Eric Paris
     
  • dentry_open takes a file, rename it to file_open

    Signed-off-by: Eric Paris

    Eric Paris
     
  • In RH BZ 578841 we realized that the SELinux sandbox program was allowed to
    truncate files outside of the sandbox. The reason is because sandbox
    confinement is determined almost entirely by the 'open' permission. The idea
    was that if the sandbox was unable to open() files it would be unable to do
    harm to those files. This turns out to be false in light of syscalls like
    truncate() and chmod() which don't require a previous open() call. I looked
    at the syscalls that did not have an associated 'open' check and found that
    truncate(), did not have a seperate permission and even if it did have a
    separate permission such a permission owuld be inadequate for use by
    sandbox (since it owuld have to be granted so liberally as to be useless).
    This patch checks the OPEN permission on truncate. I think a better solution
    for sandbox is a whole new permission, but at least this fixes what we have
    today.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Because Fedora shipped userspace based on my development tree we now
    have policy version 27 in the wild defining only default user, role, and
    range. Thus to add default_type we need a policy.28.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • When new objects are created we have great and flexible rules to
    determine the type of the new object. We aren't quite as flexible or
    mature when it comes to determining the user, role, and range. This
    patch adds a new ability to specify the place a new objects user, role,
    and range should come from. For users and roles it can come from either
    the source or the target of the operation. aka for files the user can
    either come from the source (the running process and todays default) or
    it can come from the target (aka the parent directory of the new file)

    examples always are done with
    directory context: system_u:object_r:mnt_t:s0-s0:c0.c512
    process context: unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

    [no rule]
    unconfined_u:object_r:mnt_t:s0 test_none
    [default user source]
    unconfined_u:object_r:mnt_t:s0 test_user_source
    [default user target]
    system_u:object_r:mnt_t:s0 test_user_target
    [default role source]
    unconfined_u:unconfined_r:mnt_t:s0 test_role_source
    [default role target]
    unconfined_u:object_r:mnt_t:s0 test_role_target
    [default range source low]
    unconfined_u:object_r:mnt_t:s0 test_range_source_low
    [default range source high]
    unconfined_u:object_r:mnt_t:s0:c0.c1023 test_range_source_high
    [default range source low-high]
    unconfined_u:object_r:mnt_t:s0-s0:c0.c1023 test_range_source_low-high
    [default range target low]
    unconfined_u:object_r:mnt_t:s0 test_range_target_low
    [default range target high]
    unconfined_u:object_r:mnt_t:s0:c0.c512 test_range_target_high
    [default range target low-high]
    unconfined_u:object_r:mnt_t:s0-s0:c0.c512 test_range_target_low-high

    Signed-off-by: Eric Paris

    Eric Paris
     
  • There is no reason the DAC perms on reading the policy file need to be root
    only. There are selinux checks which should control this access.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • sesearch uses:
    lseek(3, 0, SEEK_SET) = -1 ESPIPE (Illegal seek)

    Make that work.

    Signed-off-by: Eric Paris

    Eric Paris
     

04 Apr, 2012

6 commits

  • It just bloats the audit data structure for no good reason, since the
    only time those fields are filled are just before calling the
    common_lsm_audit() function, which is also the only user of those
    fields.

    So just make them be the arguments to common_lsm_audit(), rather than
    bloating that structure that is passed around everywhere, and is
    initialized in hot paths.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • Instead of declaring the entire selinux_audit_data on the stack when we
    start an operation on declare it on the stack if we are going to use it.
    We know it's usefulness at the end of the security decision and can declare
    it there.

    Signed-off-by: Eric Paris
    Signed-off-by: Linus Torvalds

    Eric Paris
     
  • We don't use the argument, so remove it.

    Signed-off-by: Eric Paris
    Signed-off-by: Linus Torvalds

    Eric Paris
     
  • We do not use it. Remove it.

    Signed-off-by: Eric Paris
    Signed-off-by: Linus Torvalds

    Eric Paris
     
  • After shrinking the common_audit_data stack usage for private LSM data I'm
    not going to shrink the data union. To do this I'm going to move anything
    larger than 2 void * ptrs to it's own structure and require it to be declared
    separately on the calling stack. Thus hot paths which don't need more than
    a couple pointer don't have to declare space to hold large unneeded
    structures. I could get this down to one void * by dealing with the key
    struct and the struct path. We'll see if that is helpful after taking care of
    networking.

    Signed-off-by: Eric Paris
    Signed-off-by: Linus Torvalds

    Eric Paris
     
  • Linus found that the gigantic size of the common audit data caused a big
    perf hit on something as simple as running stat() in a loop. This patch
    requires LSMs to declare the LSM specific portion separately rather than
    doing it in a union. Thus each LSM can be responsible for shrinking their
    portion and don't have to pay a penalty just because other LSMs have a
    bigger space requirement.

    Signed-off-by: Eric Paris
    Signed-off-by: Linus Torvalds

    Eric Paris
     

01 Apr, 2012

5 commits

  • Pull second try at vfs part d#2 from Al Viro:
    "Miklos' first series (with do_lookup() rewrite split into edible
    chunks) + assorted bits and pieces.

    The 'untangling of do_lookup()' series is is a splitup of what used to
    be a monolithic patch from Miklos, so this series is basically "how do
    I convince myself that his patch is correct (or find a hole in it)".
    No holes found and I like the resulting cleanup, so in it went..."

    Changes from try 1: Fix a boot problem with selinux, and commit messages
    prettied up a bit.

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (24 commits)
    vfs: fix out-of-date dentry_unhash() comment
    vfs: split __lookup_hash
    untangling do_lookup() - take __lookup_hash()-calling case out of line.
    untangling do_lookup() - switch to calling __lookup_hash()
    untangling do_lookup() - merge d_alloc_and_lookup() callers
    untangling do_lookup() - merge failure exits in !dentry case
    untangling do_lookup() - massage !dentry case towards __lookup_hash()
    untangling do_lookup() - get rid of need_reval in !dentry case
    untangling do_lookup() - eliminate a loop.
    untangling do_lookup() - expand the area under ->i_mutex
    untangling do_lookup() - isolate !dentry stuff from the rest of it.
    vfs: move MAY_EXEC check from __lookup_hash()
    vfs: don't revalidate just looked up dentry
    vfs: fix d_need_lookup/d_revalidate order in do_lookup
    ext3: move headers to fs/ext3/
    migrate ext2_fs.h guts to fs/ext2/ext2.h
    new helper: ext2_image_size()
    get rid of pointless includes of ext2_fs.h
    ext2: No longer export ext2_fs.h to user space
    mtdchar: kill persistently held vfsmount
    ...

    Linus Torvalds
     
  • Signed-off-by: Al Viro

    Al Viro
     
  • Signed-off-by: Al Viro

    Al Viro
     
  • Now that all the slow-path code is gone from these functions, we can
    inline them into the main caller - avc_has_perm_flags().

    Now the compiler can see that 'avc' is allocated on the stack for this
    case, which helps register pressure a bit. It also actually shrinks the
    total stack frame, because the stack frame that avc_has_perm_flags()
    always needed (for that 'avc' allocation) is now sufficient for the
    inlined functions too.

    Inlining isn't bad - but mindless inlining of cold code (see the
    previous commit) is.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • The selinux AVC paths remain some of the hottest (and deepest) codepaths
    at filename lookup time, and we make it worse by having the slow path
    cases take up I$ and stack space even when they don't trigger. Gcc
    tends to always want to inline functions that are just called once -
    never mind that this might make for slower and worse code in the caller.

    So this tries to improve on it a bit by making the slow-path cases
    explicitly separate functions that are marked noinline, causing gcc to
    at least no longer allocate stack space for them unless they are
    actually called. It also seems to help register allocation a tiny bit,
    since gcc now doesn't take the slow case code into account.

    Uninlining the slow path may also allow us to inline the remaining hot
    path into the one caller that actually matters: avc_has_perm_flags().
    I'll have to look at that separately, but both avc_audit() and
    avc_has_perm_noaudit() are now small and lean enough that inlining them
    may make sense.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

30 Mar, 2012

1 commit

  • Pull x32 support for x86-64 from Ingo Molnar:
    "This tree introduces the X32 binary format and execution mode for x86:
    32-bit data space binaries using 64-bit instructions and 64-bit kernel
    syscalls.

    This allows applications whose working set fits into a 32 bits address
    space to make use of 64-bit instructions while using a 32-bit address
    space with shorter pointers, more compressed data structures, etc."

    Fix up trivial context conflicts in arch/x86/{Kconfig,vdso/vma.c}

    * 'x86-x32-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (71 commits)
    x32: Fix alignment fail in struct compat_siginfo
    x32: Fix stupid ia32/x32 inversion in the siginfo format
    x32: Add ptrace for x32
    x32: Switch to a 64-bit clock_t
    x32: Provide separate is_ia32_task() and is_x32_task() predicates
    x86, mtrr: Use explicit sizing and padding for the 64-bit ioctls
    x86/x32: Fix the binutils auto-detect
    x32: Warn and disable rather than error if binutils too old
    x32: Only clear TIF_X32 flag once
    x32: Make sure TS_COMPAT is cleared for x32 tasks
    fs: Remove missed ->fds_bits from cessation use of fd_set structs internally
    fs: Fix close_on_exec pointer in alloc_fdtable
    x32: Drop non-__vdso weak symbols from the x32 VDSO
    x32: Fix coding style violations in the x32 VDSO code
    x32: Add x32 VDSO support
    x32: Allow x32 to be configured
    x32: If configured, add x32 system calls to system call tables
    x32: Handle process creation
    x32: Signal-related system calls
    x86: Add #ifdef CONFIG_COMPAT to
    ...

    Linus Torvalds
     

29 Mar, 2012

2 commits

  • …m/linux/kernel/git/dhowells/linux-asm_system

    Pull "Disintegrate and delete asm/system.h" from David Howells:
    "Here are a bunch of patches to disintegrate asm/system.h into a set of
    separate bits to relieve the problem of circular inclusion
    dependencies.

    I've built all the working defconfigs from all the arches that I can
    and made sure that they don't break.

    The reason for these patches is that I recently encountered a circular
    dependency problem that came about when I produced some patches to
    optimise get_order() by rewriting it to use ilog2().

    This uses bitops - and on the SH arch asm/bitops.h drags in
    asm-generic/get_order.h by a circuituous route involving asm/system.h.

    The main difficulty seems to be asm/system.h. It holds a number of
    low level bits with no/few dependencies that are commonly used (eg.
    memory barriers) and a number of bits with more dependencies that
    aren't used in many places (eg. switch_to()).

    These patches break asm/system.h up into the following core pieces:

    (1) asm/barrier.h

    Move memory barriers here. This already done for MIPS and Alpha.

    (2) asm/switch_to.h

    Move switch_to() and related stuff here.

    (3) asm/exec.h

    Move arch_align_stack() here. Other process execution related bits
    could perhaps go here from asm/processor.h.

    (4) asm/cmpxchg.h

    Move xchg() and cmpxchg() here as they're full word atomic ops and
    frequently used by atomic_xchg() and atomic_cmpxchg().

    (5) asm/bug.h

    Move die() and related bits.

    (6) asm/auxvec.h

    Move AT_VECTOR_SIZE_ARCH here.

    Other arch headers are created as needed on a per-arch basis."

    Fixed up some conflicts from other header file cleanups and moving code
    around that has happened in the meantime, so David's testing is somewhat
    weakened by that. We'll find out anything that got broken and fix it..

    * tag 'split-asm_system_h-for-linus-20120328' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-asm_system: (38 commits)
    Delete all instances of asm/system.h
    Remove all #inclusions of asm/system.h
    Add #includes needed to permit the removal of asm/system.h
    Move all declarations of free_initmem() to linux/mm.h
    Disintegrate asm/system.h for OpenRISC
    Split arch_align_stack() out from asm-generic/system.h
    Split the switch_to() wrapper out of asm-generic/system.h
    Move the asm-generic/system.h xchg() implementation to asm-generic/cmpxchg.h
    Create asm-generic/barrier.h
    Make asm-generic/cmpxchg.h #include asm-generic/cmpxchg-local.h
    Disintegrate asm/system.h for Xtensa
    Disintegrate asm/system.h for Unicore32 [based on ver #3, changed by gxt]
    Disintegrate asm/system.h for Tile
    Disintegrate asm/system.h for Sparc
    Disintegrate asm/system.h for SH
    Disintegrate asm/system.h for Score
    Disintegrate asm/system.h for S390
    Disintegrate asm/system.h for PowerPC
    Disintegrate asm/system.h for PA-RISC
    Disintegrate asm/system.h for MN10300
    ...

    Linus Torvalds
     
  • Remove all #inclusions of asm/system.h preparatory to splitting and killing
    it. Performed with the following command:

    perl -p -i -e 's!^#\s*include\s*.*\n!!' `grep -Irl '^#\s*include\s*' *`

    Signed-off-by: David Howells

    David Howells
     

27 Mar, 2012

1 commit

  • Fix failure in aa_change_onexec api when the request is made from a confined
    task. This failure was caused by two problems

    The AA_MAY_ONEXEC perm was not being mapped correctly for this case.

    The executable name was being checked as second time instead of using the
    requested onexec profile name, which may not be the same as the exec
    profile name. This mistake can not be exploited to grant extra permission
    because of the above flaw where the ONEXEC permission was not being mapped
    so it will not be granted.

    BugLink: http://bugs.launchpad.net/bugs/963756

    Signed-off-by: John Johansen
    Signed-off-by: James Morris

    John Johansen
     

26 Mar, 2012

1 commit

  • selinux/xfrm.h needs to #include net/flow.h or else suffer:

    In file included from security/selinux/ss/services.c:69:0:
    security/selinux/include/xfrm.h: In function 'selinux_xfrm_notify_policyload':
    security/selinux/include/xfrm.h:53:14: error: 'flow_cache_genid' undeclared (first use in this function)
    security/selinux/include/xfrm.h:53:14: note: each undeclared identifier is reported only once for each function it appears in

    Signed-off-by: David Howells

    David Howells
     

24 Mar, 2012

2 commits

  • No functional changes. It is not sane to use UMH_KILLABLE with enum
    umh_wait, but obviously we do not want another argument in
    call_usermodehelper_* helpers. Kill this enum, use the plain int.

    Signed-off-by: Oleg Nesterov
    Cc: Tetsuo Handa
    Cc: Rusty Russell
    Cc: Tejun Heo
    Cc: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • A few call_usermodehelper() callers use the hardcoded constant instead of
    the proper UMH_WAIT_PROC, fix them.

    Reported-by: Tetsuo Handa
    Signed-off-by: Oleg Nesterov
    Cc: Lars Ellenberg
    Cc: Greg Kroah-Hartman
    Cc: Michal Januszewski
    Cc: Florian Tobias Schandinat
    Cc: Kentaro Takeda
    Cc: Tetsuo Handa
    Cc: James Morris
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov