05 Apr, 2014

1 commit

  • Pull file locking updates from Jeff Layton:
    "Highlights:

    - maintainership change for fs/locks.c. Willy's not interested in
    maintaining it these days, and is OK with Bruce and I taking it.
    - fix for open vs setlease race that Al ID'ed
    - cleanup and consolidation of file locking code
    - eliminate unneeded BUG() call
    - merge of file-private lock implementation"

    * 'locks-3.15' of git://git.samba.org/jlayton/linux:
    locks: make locks_mandatory_area check for file-private locks
    locks: fix locks_mandatory_locked to respect file-private locks
    locks: require that flock->l_pid be set to 0 for file-private locks
    locks: add new fcntl cmd values for handling file private locks
    locks: skip deadlock detection on FL_FILE_PVT locks
    locks: pass the cmd value to fcntl_getlk/getlk64
    locks: report l_pid as -1 for FL_FILE_PVT locks
    locks: make /proc/locks show IS_FILE_PVT locks as type "FLPVT"
    locks: rename locks_remove_flock to locks_remove_file
    locks: consolidate checks for compatible filp->f_mode values in setlk handlers
    locks: fix posix lock range overflow handling
    locks: eliminate BUG() call when there's an unexpected lock on file close
    locks: add __acquires and __releases annotations to locks_start and locks_stop
    locks: remove "inline" qualifier from fl_link manipulation functions
    locks: clean up comment typo
    locks: close potential race between setlease and open
    MAINTAINERS: update entry for fs/locks.c

    Linus Torvalds
     

04 Apr, 2014

1 commit

  • Pull security subsystem updates from James Morris:
    "Apart from reordering the SELinux mmap code to ensure DAC is called
    before MAC, these are minor maintenance updates"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (23 commits)
    selinux: correctly label /proc inodes in use before the policy is loaded
    selinux: put the mmap() DAC controls before the MAC controls
    selinux: fix the output of ./scripts/get_maintainer.pl for SELinux
    evm: enable key retention service automatically
    ima: skip memory allocation for empty files
    evm: EVM does not use MD5
    ima: return d_name.name if d_path fails
    integrity: fix checkpatch errors
    ima: fix erroneous removal of security.ima xattr
    security: integrity: Use a more current logging style
    MAINTAINERS: email updates and other misc. changes
    ima: reduce memory usage when a template containing the n field is used
    ima: restore the original behavior for sending data with ima template
    Integrity: Pass commname via get_task_comm()
    fs: move i_readcount
    ima: use static const char array definitions
    security: have cap_dentry_init_security return error
    ima: new helper: file_inode(file)
    kernel: Mark function as static in kernel/seccomp.c
    capability: Use current logging styles
    ...

    Linus Torvalds
     

31 Mar, 2014

1 commit

  • Due to some unfortunate history, POSIX locks have very strange and
    unhelpful semantics. The thing that usually catches people by surprise
    is that they are dropped whenever the process closes any file descriptor
    associated with the inode.

    This is extremely problematic for people developing file servers that
    need to implement byte-range locks. Developers often need a "lock
    management" facility to ensure that file descriptors are not closed
    until all of the locks associated with the inode are finished.

    Additionally, "classic" POSIX locks are owned by the process. Locks
    taken between threads within the same process won't conflict with one
    another, which renders them useless for synchronization between threads.

    This patchset adds a new type of lock that attempts to address these
    issues. These locks conflict with classic POSIX read/write locks, but
    have semantics that are more like BSD locks with respect to inheritance
    and behavior on close.

    This is implemented primarily by changing how fl_owner field is set for
    these locks. Instead of having them owned by the files_struct of the
    process, they are instead owned by the filp on which they were acquired.
    Thus, they are inherited across fork() and are only released when the
    last reference to a filp is put.

    These new semantics prevent them from being merged with classic POSIX
    locks, even if they are acquired by the same process. These locks will
    also conflict with classic POSIX locks even if they are acquired by
    the same process or on the same file descriptor.

    The new locks are managed using a new set of cmd values to the fcntl()
    syscall. The initial implementation of this converts these values to
    "classic" cmd values at a fairly high level, and the details are not
    exposed to the underlying filesystem. We may eventually want to push
    this handing out to the lower filesystem code but for now I don't
    see any need for it.

    Also, note that with this implementation the new cmd values are only
    available via fcntl64() on 32-bit arches. There's little need to
    add support for legacy apps on a new interface like this.

    Signed-off-by: Jeff Layton

    Jeff Layton
     

26 Mar, 2014

1 commit


20 Mar, 2014

2 commits

  • This patch is based on an earlier patch by Eric Paris, he describes
    the problem below:

    "If an inode is accessed before policy load it will get placed on a
    list of inodes to be initialized after policy load. After policy
    load we call inode_doinit() which calls inode_doinit_with_dentry()
    on all inodes accessed before policy load. In the case of inodes
    in procfs that means we'll end up at the bottom where it does:

    /* Default to the fs superblock SID. */
    isec->sid = sbsec->sid;

    if ((sbsec->flags & SE_SBPROC) && !S_ISLNK(inode->i_mode)) {
    if (opt_dentry) {
    isec->sclass = inode_mode_to_security_class(...)
    rc = selinux_proc_get_sid(opt_dentry,
    isec->sclass,
    &sid);
    if (rc)
    goto out_unlock;
    isec->sid = sid;
    }
    }

    Since opt_dentry is null, we'll never call selinux_proc_get_sid()
    and will leave the inode labeled with the label on the superblock.
    I believe a fix would be to mimic the behavior of xattrs. Look
    for an alias of the inode. If it can't be found, just leave the
    inode uninitialized (and pick it up later) if it can be found, we
    should be able to call selinux_proc_get_sid() ..."

    On a system exhibiting this problem, you will notice a lot of files in
    /proc with the generic "proc_t" type (at least the ones that were
    accessed early in the boot), for example:

    # ls -Z /proc/sys/kernel/shmmax | awk '{ print $4 " " $5 }'
    system_u:object_r:proc_t:s0 /proc/sys/kernel/shmmax

    However, with this patch in place we see the expected result:

    # ls -Z /proc/sys/kernel/shmmax | awk '{ print $4 " " $5 }'
    system_u:object_r:sysctl_kernel_t:s0 /proc/sys/kernel/shmmax

    Cc: Eric Paris
    Signed-off-by: Paul Moore
    Acked-by: Eric Paris

    Paul Moore
     
  • It turns out that doing the SELinux MAC checks for mmap() before the
    DAC checks was causing users and the SELinux policy folks headaches
    as users were seeing a lot of SELinux AVC denials for the
    memprotect:mmap_zero permission that would have also been denied by
    the normal DAC capability checks (CAP_SYS_RAWIO).

    Example:

    # cat mmap_test.c
    #include
    #include
    #include
    #include

    int main(int argc, char *argv[])
    {
    int rc;
    void *mem;

    mem = mmap(0x0, 4096,
    PROT_READ | PROT_WRITE,
    MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
    if (mem == MAP_FAILED)
    return errno;
    printf("mem = %p\n", mem);
    munmap(mem, 4096);

    return 0;
    }
    # gcc -g -O0 -o mmap_test mmap_test.c
    # ./mmap_test
    mem = (nil)
    # ausearch -m AVC | grep mmap_zero
    type=AVC msg=audit(...): avc: denied { mmap_zero }
    for pid=1025 comm="mmap_test"
    scontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
    tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
    tclass=memprotect

    This patch corrects things so that when the above example is run by a
    user without CAP_SYS_RAWIO the SELinux AVC is no longer generated as
    the DAC capability check fails before the SELinux permission check.

    Signed-off-by: Paul Moore
    Acked-by: Stephen Smalley

    Paul Moore
     

10 Mar, 2014

1 commit

  • security_xfrm_policy_alloc can be called in atomic context so the
    allocation should be done with GFP_ATOMIC. Add an argument to let the
    callers choose the appropriate way. In order to do so a gfp argument
    needs to be added to the method xfrm_policy_alloc_security in struct
    security_operations and to the internal function
    selinux_xfrm_alloc_user. After that switch to GFP_ATOMIC in the atomic
    callers and leave GFP_KERNEL as before for the rest.
    The path that needed the gfp argument addition is:
    security_xfrm_policy_alloc -> security_ops.xfrm_policy_alloc_security ->
    all users of xfrm_policy_alloc_security (e.g. selinux_xfrm_policy_alloc) ->
    selinux_xfrm_alloc_user (here the allocation used to be GFP_KERNEL only)

    Now adding a gfp argument to selinux_xfrm_alloc_user requires us to also
    add it to security_context_to_sid which is used inside and prior to this
    patch did only GFP_KERNEL allocation. So add gfp argument to
    security_context_to_sid and adjust all of its callers as well.

    CC: Paul Moore
    CC: Dave Jones
    CC: Steffen Klassert
    CC: Fan Du
    CC: David S. Miller
    CC: LSM list
    CC: SELinux list

    Signed-off-by: Nikolay Aleksandrov
    Acked-by: Paul Moore
    Signed-off-by: Steffen Klassert

    Nikolay Aleksandrov
     

06 Mar, 2014

1 commit

  • Conflicts:
    drivers/net/wireless/ath/ath9k/recv.c
    drivers/net/wireless/mwifiex/pcie.c
    net/ipv6/sit.c

    The SIT driver conflict consists of a bug fix being done by hand
    in 'net' (missing u64_stats_init()) whilst in 'net-next' a helper
    was created (netdev_alloc_pcpu_stats()) which takes care of this.

    The two wireless conflicts were overlapping changes.

    Signed-off-by: David S. Miller

    David S. Miller
     

24 Feb, 2014

1 commit


21 Feb, 2014

1 commit

  • When writing policy via /sys/fs/selinux/policy I wrote the type and class
    of filename trans rules in CPU endian instead of little endian. On
    x86_64 this works just fine, but it means that on big endian arch's like
    ppc64 and s390 userspace reads the policy and converts it from
    le32_to_cpu. So the values are all screwed up. Write the values in le
    format like it should have been to start.

    Signed-off-by: Eric Paris
    Acked-by: Stephen Smalley
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Eric Paris
     

12 Feb, 2014

1 commit

  • Inserting a entry into flowcache, or flushing flowcache should be based
    on per net scope. The reason to do so is flushing operation from fat
    netns crammed with flow entries will also making the slim netns with only
    a few flow cache entries go away in original implementation.

    Since flowcache is tightly coupled with IPsec, so it would be easier to
    put flow cache global parameters into xfrm namespace part. And one last
    thing needs to do is bumping flow cache genid, and flush flow cache should
    also be made in per net style.

    Signed-off-by: Fan Du
    Signed-off-by: Steffen Klassert

    Fan Du
     

10 Feb, 2014

1 commit


06 Feb, 2014

3 commits

  • The usage of strict_strto*() is not preferred, because
    strict_strto*() is obsolete. Thus, kstrto*() should be
    used.

    Signed-off-by: Jingoo Han
    Signed-off-by: James Morris

    Jingoo Han
     
  • Setting an empty security context (length=0) on a file will
    lead to incorrectly dereferencing the type and other fields
    of the security context structure, yielding a kernel BUG.
    As a zero-length security context is never valid, just reject
    all such security contexts whether coming from userspace
    via setxattr or coming from the filesystem upon a getxattr
    request by SELinux.

    Setting a security context value (empty or otherwise) unknown to
    SELinux in the first place is only possible for a root process
    (CAP_MAC_ADMIN), and, if running SELinux in enforcing mode, only
    if the corresponding SELinux mac_admin permission is also granted
    to the domain by policy. In Fedora policies, this is only allowed for
    specific domains such as livecd for setting down security contexts
    that are not defined in the build host policy.

    Reproducer:
    su
    setenforce 0
    touch foo
    setfattr -n security.selinux foo

    Caveat:
    Relabeling or removing foo after doing the above may not be possible
    without booting with SELinux disabled. Any subsequent access to foo
    after doing the above will also trigger the BUG.

    BUG output from Matthew Thode:
    [ 473.893141] ------------[ cut here ]------------
    [ 473.962110] kernel BUG at security/selinux/ss/services.c:654!
    [ 473.995314] invalid opcode: 0000 [#6] SMP
    [ 474.027196] Modules linked in:
    [ 474.058118] CPU: 0 PID: 8138 Comm: ls Tainted: G D I
    3.13.0-grsec #1
    [ 474.116637] Hardware name: Supermicro X8ST3/X8ST3, BIOS 2.0
    07/29/10
    [ 474.149768] task: ffff8805f50cd010 ti: ffff8805f50cd488 task.ti:
    ffff8805f50cd488
    [ 474.183707] RIP: 0010:[] []
    context_struct_compute_av+0xce/0x308
    [ 474.219954] RSP: 0018:ffff8805c0ac3c38 EFLAGS: 00010246
    [ 474.252253] RAX: 0000000000000000 RBX: ffff8805c0ac3d94 RCX:
    0000000000000100
    [ 474.287018] RDX: ffff8805e8aac000 RSI: 00000000ffffffff RDI:
    ffff8805e8aaa000
    [ 474.321199] RBP: ffff8805c0ac3cb8 R08: 0000000000000010 R09:
    0000000000000006
    [ 474.357446] R10: 0000000000000000 R11: ffff8805c567a000 R12:
    0000000000000006
    [ 474.419191] R13: ffff8805c2b74e88 R14: 00000000000001da R15:
    0000000000000000
    [ 474.453816] FS: 00007f2e75220800(0000) GS:ffff88061fc00000(0000)
    knlGS:0000000000000000
    [ 474.489254] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    [ 474.522215] CR2: 00007f2e74716090 CR3: 00000005c085e000 CR4:
    00000000000207f0
    [ 474.556058] Stack:
    [ 474.584325] ffff8805c0ac3c98 ffffffff811b549b ffff8805c0ac3c98
    ffff8805f1190a40
    [ 474.618913] ffff8805a6202f08 ffff8805c2b74e88 00068800d0464990
    ffff8805e8aac860
    [ 474.653955] ffff8805c0ac3cb8 000700068113833a ffff880606c75060
    ffff8805c0ac3d94
    [ 474.690461] Call Trace:
    [ 474.723779] [] ? lookup_fast+0x1cd/0x22a
    [ 474.778049] [] security_compute_av+0xf4/0x20b
    [ 474.811398] [] avc_compute_av+0x2a/0x179
    [ 474.843813] [] avc_has_perm+0x45/0xf4
    [ 474.875694] [] inode_has_perm+0x2a/0x31
    [ 474.907370] [] selinux_inode_getattr+0x3c/0x3e
    [ 474.938726] [] security_inode_getattr+0x1b/0x22
    [ 474.970036] [] vfs_getattr+0x19/0x2d
    [ 475.000618] [] vfs_fstatat+0x54/0x91
    [ 475.030402] [] vfs_lstat+0x19/0x1b
    [ 475.061097] [] SyS_newlstat+0x15/0x30
    [ 475.094595] [] ? __audit_syscall_entry+0xa1/0xc3
    [ 475.148405] [] system_call_fastpath+0x16/0x1b
    [ 475.179201] Code: 00 48 85 c0 48 89 45 b8 75 02 0f 0b 48 8b 45 a0 48
    8b 3d 45 d0 b6 00 8b 40 08 89 c6 ff ce e8 d1 b0 06 00 48 85 c0 49 89 c7
    75 02 0b 48 8b 45 b8 4c 8b 28 eb 1e 49 8d 7d 08 be 80 01 00 00 e8
    [ 475.255884] RIP []
    context_struct_compute_av+0xce/0x308
    [ 475.296120] RSP
    [ 475.328734] ---[ end trace f076482e9d754adc ]---

    Reported-by: Matthew Thode
    Signed-off-by: Stephen Smalley
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Stephen Smalley
     
  • The SELinux AF_NETLINK/NETLINK_SOCK_DIAG socket class was missing the
    SOCK_DIAG_BY_FAMILY definition which caused SELINUX_ERR messages when
    the ss tool was run.

    # ss
    Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
    u_str ESTAB 0 0 * 14189 * 14190
    u_str ESTAB 0 0 * 14145 * 14144
    u_str ESTAB 0 0 * 14151 * 14150
    {...}
    # ausearch -m SELINUX_ERR
    ----
    time->Thu Jan 23 11:11:16 2014
    type=SYSCALL msg=audit(1390493476.445:374):
    arch=c000003e syscall=44 success=yes exit=40
    a0=3 a1=7fff03aa11f0 a2=28 a3=0 items=0 ppid=1852 pid=1895
    auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0
    tty=pts0 ses=1 comm="ss" exe="/usr/sbin/ss"
    subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
    type=SELINUX_ERR msg=audit(1390493476.445:374):
    SELinux: unrecognized netlink message type=20 for sclass=32

    Signed-off-by: Paul Moore

    Paul Moore
     

05 Feb, 2014

1 commit

  • Linux 3.13

    Conflicts:
    security/selinux/hooks.c

    Trivial merge issue in selinux_inet_conn_request() likely due to me
    including patches that I sent to the stable folks in my next tree
    resulting in the patch hitting twice (I think). Thankfully it was an
    easy fix this time, but regardless, lesson learned, I will not do that
    again.

    Paul Moore
     

24 Jan, 2014

1 commit

  • Pull audit update from Eric Paris:
    "Again we stayed pretty well contained inside the audit system.
    Venturing out was fixing a couple of function prototypes which were
    inconsistent (didn't hurt anything, but we used the same value as an
    int, uint, u32, and I think even a long in a couple of places).

    We also made a couple of minor changes to when a couple of LSMs called
    the audit system. We hoped to add aarch64 audit support this go
    round, but it wasn't ready.

    I'm disappearing on vacation on Thursday. I should have internet
    access, but it'll be spotty. If anything goes wrong please be sure to
    cc rgb@redhat.com. He'll make fixing things his top priority"

    * git://git.infradead.org/users/eparis/audit: (50 commits)
    audit: whitespace fix in kernel-parameters.txt
    audit: fix location of __net_initdata for audit_net_ops
    audit: remove pr_info for every network namespace
    audit: Modify a set of system calls in audit class definitions
    audit: Convert int limit uses to u32
    audit: Use more current logging style
    audit: Use hex_byte_pack_upper
    audit: correct a type mismatch in audit_syscall_exit()
    audit: reorder AUDIT_TTY_SET arguments
    audit: rework AUDIT_TTY_SET to only grab spin_lock once
    audit: remove needless switch in AUDIT_SET
    audit: use define's for audit version
    audit: documentation of audit= kernel parameter
    audit: wait_for_auditd rework for readability
    audit: update MAINTAINERS
    audit: log task info on feature change
    audit: fix incorrect set of audit_sock
    audit: print error message when fail to create audit socket
    audit: fix dangling keywords in audit_log_set_loginuid() output
    audit: log on errors from filter user rules
    ...

    Linus Torvalds
     

22 Jan, 2014

1 commit

  • Pull security layer updates from James Morris:
    "Changes for this kernel include maintenance updates for Smack, SELinux
    (and several networking fixes), IMA and TPM"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (39 commits)
    SELinux: Fix memory leak upon loading policy
    tpm/tpm-sysfs: active_show() can be static
    tpm: tpm_tis: Fix compile problems with CONFIG_PM_SLEEP/CONFIG_PNP
    tpm: Make tpm-dev allocate a per-file structure
    tpm: Use the ops structure instead of a copy in tpm_vendor_specific
    tpm: Create a tpm_class_ops structure and use it in the drivers
    tpm: Pull all driver sysfs code into tpm-sysfs.c
    tpm: Move sysfs functions from tpm-interface to tpm-sysfs
    tpm: Pull everything related to /dev/tpmX into tpm-dev.c
    char: tpm: nuvoton: remove unused variable
    tpm: MAINTAINERS: Cleanup TPM Maintainers file
    tpm/tpm_i2c_atmel: fix coccinelle warnings
    tpm/tpm_ibmvtpm: fix unreachable code warning (smatch warning)
    tpm/tpm_i2c_stm_st33: Check return code of get_burstcount
    tpm/tpm_ppi: Check return value of acpi_get_name
    tpm/tpm_ppi: Do not compare strcmp(a,b) == -1
    ima: remove unneeded size_limit argument from ima_eventdigest_init_common()
    ima: update IMA-templates.txt documentation
    ima: pass HASH_ALGO__LAST as hash algo in ima_eventdigest_init()
    ima: change the default hash algorithm to SHA1 in ima_eventdigest_ng_init()
    ...

    Linus Torvalds
     

14 Jan, 2014

1 commit

  • Two of the conditions in selinux_audit_rule_match() should never happen and
    the third indicates a race that should be retried. Remove the calls to
    audit_log() (which call audit_log_start()) and deal with the errors in the
    caller, logging only once if the condition is met. Calling audit_log_start()
    in this location makes buffer allocation and locking more complicated in the
    calling tree (audit_filter_user()).

    Signed-off-by: Richard Guy Briggs
    Signed-off-by: Eric Paris

    Richard Guy Briggs
     

12 Jan, 2014

1 commit

  • While running stress tests on adding and deleting ftrace instances I hit
    this bug:

    BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
    IP: selinux_inode_permission+0x85/0x160
    PGD 63681067 PUD 7ddbe067 PMD 0
    Oops: 0000 [#1] PREEMPT
    CPU: 0 PID: 5634 Comm: ftrace-test-mki Not tainted 3.13.0-rc4-test-00033-gd2a6dde-dirty #20
    Hardware name: /DG965MQ, BIOS MQ96510J.86A.0372.2006.0605.1717 06/05/2006
    task: ffff880078375800 ti: ffff88007ddb0000 task.ti: ffff88007ddb0000
    RIP: 0010:[] [] selinux_inode_permission+0x85/0x160
    RSP: 0018:ffff88007ddb1c48 EFLAGS: 00010246
    RAX: 0000000000000000 RBX: 0000000000800000 RCX: ffff88006dd43840
    RDX: 0000000000000001 RSI: 0000000000000081 RDI: ffff88006ee46000
    RBP: ffff88007ddb1c88 R08: 0000000000000000 R09: ffff88007ddb1c54
    R10: 6e6576652f6f6f66 R11: 0000000000000003 R12: 0000000000000000
    R13: 0000000000000081 R14: ffff88006ee46000 R15: 0000000000000000
    FS: 00007f217b5b6700(0000) GS:ffffffff81e21000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033^M
    CR2: 0000000000000020 CR3: 000000006a0fe000 CR4: 00000000000007f0
    Call Trace:
    security_inode_permission+0x1c/0x30
    __inode_permission+0x41/0xa0
    inode_permission+0x18/0x50
    link_path_walk+0x66/0x920
    path_openat+0xa6/0x6c0
    do_filp_open+0x43/0xa0
    do_sys_open+0x146/0x240
    SyS_open+0x1e/0x20
    system_call_fastpath+0x16/0x1b
    Code: 84 a1 00 00 00 81 e3 00 20 00 00 89 d8 83 c8 02 40 f6 c6 04 0f 45 d8 40 f6 c6 08 74 71 80 cf 02 49 8b 46 38 4c 8d 4d cc 45 31 c0 b7 50 20 8b 70 1c 48 8b 41 70 89 d9 8b 78 04 e8 36 cf ff ff
    RIP selinux_inode_permission+0x85/0x160
    CR2: 0000000000000020

    Investigating, I found that the inode->i_security was NULL, and the
    dereference of it caused the oops.

    in selinux_inode_permission():

    isec = inode->i_security;

    rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, &avd);

    Note, the crash came from stressing the deletion and reading of debugfs
    files. I was not able to recreate this via normal files. But I'm not
    sure they are safe. It may just be that the race window is much harder
    to hit.

    What seems to have happened (and what I have traced), is the file is
    being opened at the same time the file or directory is being deleted.
    As the dentry and inode locks are not held during the path walk, nor is
    the inodes ref counts being incremented, there is nothing saving these
    structures from being discarded except for an rcu_read_lock().

    The rcu_read_lock() protects against freeing of the inode, but it does
    not protect freeing of the inode_security_struct. Now if the freeing of
    the i_security happens with a call_rcu(), and the i_security field of
    the inode is not changed (it gets freed as the inode gets freed) then
    there will be no issue here. (Linus Torvalds suggested not setting the
    field to NULL such that we do not need to check if it is NULL in the
    permission check).

    Note, this is a hack, but it fixes the problem at hand. A real fix is
    to restructure the destroy_inode() to call all the destructor handlers
    from the RCU callback. But that is a major job to do, and requires a
    lot of work. For now, we just band-aid this bug with this fix (it
    works), and work on a more maintainable solution in the future.

    Link: http://lkml.kernel.org/r/20140109101932.0508dec7@gandalf.local.home
    Link: http://lkml.kernel.org/r/20140109182756.17abaaa8@gandalf.local.home

    Cc: stable@vger.kernel.org
    Signed-off-by: Steven Rostedt
    Signed-off-by: Linus Torvalds

    Steven Rostedt
     

08 Jan, 2014

1 commit


07 Jan, 2014

1 commit

  • Hello.

    I got below leak with linux-3.10.0-54.0.1.el7.x86_64 .

    [ 681.903890] kmemleak: 5538 new suspected memory leaks (see /sys/kernel/debug/kmemleak)

    Below is a patch, but I don't know whether we need special handing for undoing
    ebitmap_set_bit() call.
    ----------
    >>From fe97527a90fe95e2239dfbaa7558f0ed559c0992 Mon Sep 17 00:00:00 2001
    From: Tetsuo Handa
    Date: Mon, 6 Jan 2014 16:30:21 +0900
    Subject: [PATCH] SELinux: Fix memory leak upon loading policy

    Commit 2463c26d "SELinux: put name based create rules in a hashtable" did not
    check return value from hashtab_insert() in filename_trans_read(). It leaks
    memory if hashtab_insert() returns error.

    unreferenced object 0xffff88005c9160d0 (size 8):
    comm "systemd", pid 1, jiffies 4294688674 (age 235.265s)
    hex dump (first 8 bytes):
    57 0b 00 00 6b 6b 6b a5 W...kkk.
    backtrace:
    [] kmemleak_alloc+0x4e/0xb0
    [] kmem_cache_alloc_trace+0x12e/0x360
    [] policydb_read+0xd1d/0xf70
    [] security_load_policy+0x6c/0x500
    [] sel_write_load+0xac/0x750
    [] vfs_write+0xc0/0x1f0
    [] SyS_write+0x4c/0xa0
    [] system_call_fastpath+0x16/0x1b
    [] 0xffffffffffffffff

    However, we should not return EEXIST error to the caller, or the systemd will
    show below message and the boot sequence freezes.

    systemd[1]: Failed to load SELinux policy. Freezing.

    Signed-off-by: Tetsuo Handa
    Acked-by: Eric Paris
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Tetsuo Handa
     

06 Jan, 2014

1 commit


24 Dec, 2013

2 commits

  • selinux_setprocattr() does ptrace_parent(p) under task_lock(p),
    but task_struct->alloc_lock doesn't pin ->parent or ->ptrace,
    this looks confusing and triggers the "suspicious RCU usage"
    warning because ptrace_parent() does rcu_dereference_check().

    And in theory this is wrong, spin_lock()->preempt_disable()
    doesn't necessarily imply rcu_read_lock() we need to access
    the ->parent.

    Reported-by: Evan McNabb
    Signed-off-by: Oleg Nesterov
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Oleg Nesterov
     
  • Fix a broken networking check. Return an error if peer recv fails. If
    secmark is active and the packet recv succeeds the peer recv error is
    ignored.

    Signed-off-by: Chad Hanson
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Chad Hanson
     

17 Dec, 2013

2 commits


16 Dec, 2013

2 commits

  • Pull SELinux fixes from James Morris.

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    selinux: process labeled IPsec TCP SYN-ACK packets properly in selinux_ip_postroute()
    selinux: look for IPsec labels on both inbound and outbound packets
    selinux: handle TCP SYN-ACK packets correctly in selinux_ip_postroute()
    selinux: handle TCP SYN-ACK packets correctly in selinux_ip_output()
    selinux: fix possible memory leak

    Linus Torvalds
     
  • This reverts commit 102aefdda4d8275ce7d7100bc16c88c74272b260.

    Tom London reports that it causes sync() to hang on Fedora rawhide:

    https://bugzilla.redhat.com/show_bug.cgi?id=1033965

    and Josh Boyer bisected it down to this commit. Reverting the commit in
    the rawhide kernel fixes the problem.

    Eric Paris root-caused it to incorrect subtype matching in that commit
    breaking fuse, and has a tentative patch, but by now we're better off
    retrying this in 3.14 rather than playing with it any more.

    Reported-by: Tom London
    Bisected-by: Josh Boyer
    Acked-by: Eric Paris
    Cc: James Morris
    Cc: Anand Avati
    Cc: Paul Moore
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

14 Dec, 2013

1 commit

  • Revert "selinux: consider filesystem subtype in policies"

    This reverts commit 102aefdda4d8275ce7d7100bc16c88c74272b260.

    Explanation from Eric Paris:

    SELinux policy can specify if it should use a filesystem's
    xattrs or not. In current policy we have a specification that
    fuse should not use xattrs but fuse.glusterfs should use
    xattrs. This patch has a bug in which non-glusterfs
    filesystems would match the rule saying fuse.glusterfs should
    use xattrs. If both fuse and the particular filesystem in
    question are not written to handle xattr calls during the mount
    command, they will deadlock.

    I have fixed the bug to do proper matching, however I believe a
    revert is still the correct solution. The reason I believe
    that is because the code still does not work. The s_subtype is
    not set until after the SELinux hook which attempts to match on
    the ".gluster" portion of the rule. So we cannot match on the
    rule in question. The code is useless.

    Signed-off-by: Paul Moore

    Paul Moore
     

13 Dec, 2013

5 commits

  • James Morris
     
  • Due to difficulty in arriving at the proper security label for
    TCP SYN-ACK packets in selinux_ip_postroute(), we need to check packets
    while/before they are undergoing XFRM transforms instead of waiting
    until afterwards so that we can determine the correct security label.

    Reported-by: Janak Desai
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Paul Moore
     
  • Previously selinux_skb_peerlbl_sid() would only check for labeled
    IPsec security labels on inbound packets, this patch enables it to
    check both inbound and outbound traffic for labeled IPsec security
    labels.

    Reported-by: Janak Desai
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Paul Moore
     
  • In selinux_ip_postroute() we perform access checks based on the
    packet's security label. For locally generated traffic we get the
    packet's security label from the associated socket; this works in all
    cases except for TCP SYN-ACK packets. In the case of SYN-ACK packet's
    the correct security label is stored in the connection's request_sock,
    not the server's socket. Unfortunately, at the point in time when
    selinux_ip_postroute() is called we can't query the request_sock
    directly, we need to recreate the label using the same logic that
    originally labeled the associated request_sock.

    See the inline comments for more explanation.

    Reported-by: Janak Desai
    Tested-by: Janak Desai
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Paul Moore
     
  • In selinux_ip_output() we always label packets based on the parent
    socket. While this approach works in almost all cases, it doesn't
    work in the case of TCP SYN-ACK packets when the correct label is not
    the label of the parent socket, but rather the label of the larval
    socket represented by the request_sock struct.

    Unfortunately, since the request_sock isn't queued on the parent
    socket until *after* the SYN-ACK packet is sent, we can't lookup the
    request_sock to determine the correct label for the packet; at this
    point in time the best we can do is simply pass/NF_ACCEPT the packet.
    It must be said that simply passing the packet without any explicit
    labeling action, while far from ideal, is not terrible as the SYN-ACK
    packet will inherit any IP option based labeling from the initial
    connection request so the label *should* be correct and all our
    access controls remain in place so we shouldn't have to worry about
    information leaks.

    Reported-by: Janak Desai
    Tested-by: Janak Desai
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore

    Paul Moore
     

12 Dec, 2013

1 commit


11 Dec, 2013

1 commit


10 Dec, 2013

1 commit


05 Dec, 2013

2 commits