04 Mar, 2016

1 commit

  • commit 3dfb7d8cdbc7ea0c2970450e60818bb3eefbad69 upstream.

    It looks like smack and yama weren't aware that the ptrace mode
    can have flags ORed into it - PTRACE_MODE_NOAUDIT until now, but
    only for /proc/$pid/stat, and with the PTRACE_MODE_*CREDS patch,
    all modes have flags ORed into them.

    Signed-off-by: Jann Horn
    Acked-by: Kees Cook
    Acked-by: Casey Schaufler
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: Andy Shevchenko
    Cc: Andy Lutomirski
    Cc: Al Viro
    Cc: "Eric W. Biederman"
    Cc: Willy Tarreau
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Jann Horn
     

26 Feb, 2016

1 commit

  • commit caaee6234d05a58c5b4d05e7bf766131b810a657 upstream.

    By checking the effective credentials instead of the real UID / permitted
    capabilities, ensure that the calling process actually intended to use its
    credentials.

    To ensure that all ptrace checks use the correct caller credentials (e.g.
    in case out-of-tree code or newly added code omits the PTRACE_MODE_*CREDS
    flag), use two new flags and require one of them to be set.

    The problem was that when a privileged task had temporarily dropped its
    privileges, e.g. by calling setreuid(0, user_uid), with the intent to
    perform following syscalls with the credentials of a user, it still passed
    ptrace access checks that the user would not be able to pass.

    While an attacker should not be able to convince the privileged task to
    perform a ptrace() syscall, this is a problem because the ptrace access
    check is reused for things in procfs.

    In particular, the following somewhat interesting procfs entries only rely
    on ptrace access checks:

    /proc/$pid/stat - uses the check for determining whether pointers
    should be visible, useful for bypassing ASLR
    /proc/$pid/maps - also useful for bypassing ASLR
    /proc/$pid/cwd - useful for gaining access to restricted
    directories that contain files with lax permissions, e.g. in
    this scenario:
    lrwxrwxrwx root root /proc/13020/cwd -> /root/foobar
    drwx------ root root /root
    drwxr-xr-x root root /root/foobar
    -rw-r--r-- root root /root/foobar/secret

    Therefore, on a system where a root-owned mode 6755 binary changes its
    effective credentials as described and then dumps a user-specified file,
    this could be used by an attacker to reveal the memory layout of root's
    processes or reveal the contents of files he is not allowed to access
    (through /proc/$pid/cwd).

    [akpm@linux-foundation.org: fix warning]
    Signed-off-by: Jann Horn
    Acked-by: Kees Cook
    Cc: Casey Schaufler
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: Andy Shevchenko
    Cc: Andy Lutomirski
    Cc: Al Viro
    Cc: "Eric W. Biederman"
    Cc: Willy Tarreau
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Jann Horn
     

18 Feb, 2016

1 commit

  • commit 613317bd212c585c20796c10afe5daaa95d4b0a1 upstream.

    This patch fixes vulnerability CVE-2016-2085. The problem exists
    because the vm_verify_hmac() function includes a use of memcmp().
    Unfortunately, this allows timing side channel attacks; specifically
    a MAC forgery complexity drop from 2^128 to 2^12. This patch changes
    the memcmp() to the cryptographically safe crypto_memneq().

    Reported-by: Xiaofei Rex Guo
    Signed-off-by: Ryan Ware
    Signed-off-by: Mimi Zohar
    Signed-off-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Ryan Ware
     

01 Feb, 2016

1 commit

  • commit 23567fd052a9abb6d67fe8e7a9ccdd9800a540f2 upstream.

    This fixes CVE-2016-0728.

    If a thread is asked to join as a session keyring the keyring that's already
    set as its session, we leak a keyring reference.

    This can be tested with the following program:

    #include
    #include
    #include
    #include

    int main(int argc, const char *argv[])
    {
    int i = 0;
    key_serial_t serial;

    serial = keyctl(KEYCTL_JOIN_SESSION_KEYRING,
    "leaked-keyring");
    if (serial < 0) {
    perror("keyctl");
    return -1;
    }

    if (keyctl(KEYCTL_SETPERM, serial,
    KEY_POS_ALL | KEY_USR_ALL) < 0) {
    perror("keyctl");
    return -1;
    }

    for (i = 0; i < 100; i++) {
    serial = keyctl(KEYCTL_JOIN_SESSION_KEYRING,
    "leaked-keyring");
    if (serial < 0) {
    perror("keyctl");
    return -1;
    }
    }

    return 0;
    }

    If, after the program has run, there something like the following line in
    /proc/keys:

    3f3d898f I--Q--- 100 perm 3f3f0000 0 0 keyring leaked-keyring: empty

    with a usage count of 100 * the number of times the program has been run,
    then the kernel is malfunctioning. If leaked-keyring has zero usages or
    has been garbage collected, then the problem is fixed.

    Reported-by: Yevgeny Pats
    Signed-off-by: David Howells
    Acked-by: Don Zickus
    Acked-by: Prarit Bhargava
    Acked-by: Jarod Wilson
    Signed-off-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Yevgeny Pats
     

19 Dec, 2015

1 commit

  • This fixes CVE-2015-7550.

    There's a race between keyctl_read() and keyctl_revoke(). If the revoke
    happens between keyctl_read() checking the validity of a key and the key's
    semaphore being taken, then the key type read method will see a revoked key.

    This causes a problem for the user-defined key type because it assumes in
    its read method that there will always be a payload in a non-revoked key
    and doesn't check for a NULL pointer.

    Fix this by making keyctl_read() check the validity of a key after taking
    semaphore instead of before.

    I think the bug was introduced with the original keyrings code.

    This was discovered by a multithreaded test program generated by syzkaller
    (http://github.com/google/syzkaller). Here's a cleaned up version:

    #include
    #include
    #include
    void *thr0(void *arg)
    {
    key_serial_t key = (unsigned long)arg;
    keyctl_revoke(key);
    return 0;
    }
    void *thr1(void *arg)
    {
    key_serial_t key = (unsigned long)arg;
    char buffer[16];
    keyctl_read(key, buffer, 16);
    return 0;
    }
    int main()
    {
    key_serial_t key = add_key("user", "%", "foo", 3, KEY_SPEC_USER_KEYRING);
    pthread_t th[5];
    pthread_create(&th[0], 0, thr0, (void *)(unsigned long)key);
    pthread_create(&th[1], 0, thr1, (void *)(unsigned long)key);
    pthread_create(&th[2], 0, thr0, (void *)(unsigned long)key);
    pthread_create(&th[3], 0, thr1, (void *)(unsigned long)key);
    pthread_join(th[0], 0);
    pthread_join(th[1], 0);
    pthread_join(th[2], 0);
    pthread_join(th[3], 0);
    return 0;
    }

    Build as:

    cc -o keyctl-race keyctl-race.c -lkeyutils -lpthread

    Run as:

    while keyctl-race; do :; done

    as it may need several iterations to crash the kernel. The crash can be
    summarised as:

    BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
    IP: [] user_read+0x56/0xa3
    ...
    Call Trace:
    [] keyctl_read_key+0xb6/0xd7
    [] SyS_keyctl+0x83/0xe0
    [] entry_SYSCALL_64_fastpath+0x12/0x6f

    Reported-by: Dmitry Vyukov
    Signed-off-by: David Howells
    Tested-by: Dmitry Vyukov
    Cc: stable@vger.kernel.org
    Signed-off-by: James Morris

    David Howells
     

26 Nov, 2015

1 commit


25 Nov, 2015

2 commits

  • If a user key gets negatively instantiated, an error code is cached in the
    payload area. A negatively instantiated key may be then be positively
    instantiated by updating it with valid data. However, the ->update key
    type method must be aware that the error code may be there.

    The following may be used to trigger the bug in the user key type:

    keyctl request2 user user "" @u
    keyctl add user user "a" @u

    which manifests itself as:

    BUG: unable to handle kernel paging request at 00000000ffffff8a
    IP: [] __call_rcu.constprop.76+0x1f/0x280 kernel/rcu/tree.c:3046
    PGD 7cc30067 PUD 0
    Oops: 0002 [#1] SMP
    Modules linked in:
    CPU: 3 PID: 2644 Comm: a.out Not tainted 4.3.0+ #49
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
    task: ffff88003ddea700 ti: ffff88003dd88000 task.ti: ffff88003dd88000
    RIP: 0010:[] [] __call_rcu.constprop.76+0x1f/0x280
    [] __call_rcu.constprop.76+0x1f/0x280 kernel/rcu/tree.c:3046
    RSP: 0018:ffff88003dd8bdb0 EFLAGS: 00010246
    RAX: 00000000ffffff82 RBX: 0000000000000000 RCX: 0000000000000001
    RDX: ffffffff81e3fe40 RSI: 0000000000000000 RDI: 00000000ffffff82
    RBP: ffff88003dd8bde0 R08: ffff88007d2d2da0 R09: 0000000000000000
    R10: 0000000000000000 R11: ffff88003e8073c0 R12: 00000000ffffff82
    R13: ffff88003dd8be68 R14: ffff88007d027600 R15: ffff88003ddea700
    FS: 0000000000b92880(0063) GS:ffff88007fd00000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
    CR2: 00000000ffffff8a CR3: 000000007cc5f000 CR4: 00000000000006e0
    Stack:
    ffff88003dd8bdf0 ffffffff81160a8a 0000000000000000 00000000ffffff82
    ffff88003dd8be68 ffff88007d027600 ffff88003dd8bdf0 ffffffff810a39e5
    ffff88003dd8be20 ffffffff812a31ab ffff88007d027600 ffff88007d027620
    Call Trace:
    [] kfree_call_rcu+0x15/0x20 kernel/rcu/tree.c:3136
    [] user_update+0x8b/0xb0 security/keys/user_defined.c:129
    [< inline >] __key_update security/keys/key.c:730
    [] key_create_or_update+0x291/0x440 security/keys/key.c:908
    [< inline >] SYSC_add_key security/keys/keyctl.c:125
    [] SyS_add_key+0x101/0x1e0 security/keys/keyctl.c:60
    [] entry_SYSCALL_64_fastpath+0x12/0x6a arch/x86/entry/entry_64.S:185

    Note the error code (-ENOKEY) in EDX.

    A similar bug can be tripped by:

    keyctl request2 trusted user "" @u
    keyctl add trusted user "a" @u

    This should also affect encrypted keys - but that has to be correctly
    parameterised or it will fail with EINVAL before getting to the bit that
    will crashes.

    Reported-by: Dmitry Vyukov
    Signed-off-by: David Howells
    Acked-by: Mimi Zohar
    Signed-off-by: James Morris

    David Howells
     
  • commit fa1aa143ac4a ("selinux: extended permissions for ioctls")
    introduced a bug into the handling of conditional rules, skipping the
    processing entirely when the caller does not provide an extended
    permissions (xperms) structure. Access checks from userspace using
    /sys/fs/selinux/access do not include such a structure since that
    interface does not presently expose extended permission information.
    As a result, conditional rules were being ignored entirely on userspace
    access requests, producing denials when access was allowed by
    conditional rules in the policy. Fix the bug by only skipping
    computation of extended permissions in this situation, not the entire
    conditional rules processing.

    Reported-by: Laurent Bigonville
    Signed-off-by: Stephen Smalley
    [PM: fixed long lines in patch description]
    Cc: stable@vger.kernel.org # 4.3
    Signed-off-by: Paul Moore

    Stephen Smalley
     

11 Nov, 2015

1 commit

  • Pull networking fixes from David Miller:

    1) Fix null deref in xt_TEE netfilter module, from Eric Dumazet.

    2) Several spots need to get to the original listner for SYN-ACK
    packets, most spots got this ok but some were not. Whilst covering
    the remaining cases, create a helper to do this. From Eric Dumazet.

    3) Missiing check of return value from alloc_netdev() in CAIF SPI code,
    from Rasmus Villemoes.

    4) Don't sleep while != TASK_RUNNING in macvtap, from Vlad Yasevich.

    5) Use after free in mvneta driver, from Justin Maggard.

    6) Fix race on dst->flags access in dst_release(), from Eric Dumazet.

    7) Add missing ZLIB_INFLATE dependency for new qed driver. From Arnd
    Bergmann.

    8) Fix multicast getsockopt deadlock, from WANG Cong.

    9) Fix deadlock in btusb, from Kuba Pawlak.

    10) Some ipv6_add_dev() failure paths were not cleaning up the SNMP6
    counter state. From Sabrina Dubroca.

    11) Fix packet_bind() race, which can cause lost notifications, from
    Francesco Ruggeri.

    12) Fix MAC restoration in qlcnic driver during bonding mode changes,
    from Jarod Wilson.

    13) Revert bridging forward delay change which broke libvirt and other
    userspace things, from Vlad Yasevich.

    * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: (65 commits)
    Revert "bridge: Allow forward delay to be cfgd when STP enabled"
    bpf_trace: Make dependent on PERF_EVENTS
    qed: select ZLIB_INFLATE
    net: fix a race in dst_release()
    net: mvneta: Fix memory use after free.
    net: Documentation: Fix default value tcp_limit_output_bytes
    macvtap: Resolve possible __might_sleep warning in macvtap_do_read()
    mvneta: add FIXED_PHY dependency
    net: caif: check return value of alloc_netdev
    net: hisilicon: NET_VENDOR_HISILICON should depend on HAS_DMA
    drivers: net: xgene: fix RGMII 10/100Mb mode
    netfilter: nft_meta: use skb_to_full_sk() helper
    net_sched: em_meta: use skb_to_full_sk() helper
    sched: cls_flow: use skb_to_full_sk() helper
    netfilter: xt_owner: use skb_to_full_sk() helper
    smack: use skb_to_full_sk() helper
    net: add skb_to_full_sk() helper and use it in selinux_netlbl_skbuff_setsid()
    bpf: doc: correct arch list for supported eBPF JIT
    dwc_eth_qos: Delete an unnecessary check before the function call "of_node_put"
    bonding: fix panic on non-ARPHRD_ETHER enslave failure
    ...

    Linus Torvalds
     

09 Nov, 2015

2 commits


07 Nov, 2015

1 commit

  • __GFP_WAIT was used to signal that the caller was in atomic context and
    could not sleep. Now it is possible to distinguish between true atomic
    context and callers that are not willing to sleep. The latter should
    clear __GFP_DIRECT_RECLAIM so kswapd will still wake. As clearing
    __GFP_WAIT behaves differently, there is a risk that people will clear the
    wrong flags. This patch renames __GFP_WAIT to __GFP_RECLAIM to clearly
    indicate what it does -- setting it allows all reclaim activity, clearing
    them prevents it.

    [akpm@linux-foundation.org: fix build]
    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Mel Gorman
    Acked-by: Michal Hocko
    Acked-by: Vlastimil Babka
    Acked-by: Johannes Weiner
    Cc: Christoph Lameter
    Acked-by: David Rientjes
    Cc: Vitaly Wool
    Cc: Rik van Riel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Mel Gorman
     

06 Nov, 2015

2 commits

  • Pull security subsystem update from James Morris:
    "This is mostly maintenance updates across the subsystem, with a
    notable update for TPM 2.0, and addition of Jarkko Sakkinen as a
    maintainer of that"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (40 commits)
    apparmor: clarify CRYPTO dependency
    selinux: Use a kmem_cache for allocation struct file_security_struct
    selinux: ioctl_has_perm should be static
    selinux: use sprintf return value
    selinux: use kstrdup() in security_get_bools()
    selinux: use kmemdup in security_sid_to_context_core()
    selinux: remove pointless cast in selinux_inode_setsecurity()
    selinux: introduce security_context_str_to_sid
    selinux: do not check open perm on ftruncate call
    selinux: change CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE default
    KEYS: Merge the type-specific data with the payload data
    KEYS: Provide a script to extract a module signature
    KEYS: Provide a script to extract the sys cert list from a vmlinux file
    keys: Be more consistent in selection of union members used
    certs: add .gitignore to stop git nagging about x509_certificate_list
    KEYS: use kvfree() in add_key
    Smack: limited capability for changing process label
    TPM: remove unnecessary little endian conversion
    vTPM: support little endian guests
    char: Drop owner assignment from i2c_driver
    ...

    Linus Torvalds
     
  • In commit e446f9dfe17b ("net: synack packets can be attached to request
    sockets"), I missed one remaining case of invalid skb->sk->sk_security
    access.

    Dmitry Vyukov got a KASan report pointing to it.

    Add selinux_skb_sk() helper that is responsible to get back to the
    listener if skb is attached to a request socket, instead of
    duplicating the logic.

    Fixes: ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener")
    Signed-off-by: Eric Dumazet
    Reported-by: Dmitry Vyukov
    Cc: Paul Moore
    Signed-off-by: David S. Miller

    Eric Dumazet
     

01 Nov, 2015

1 commit


23 Oct, 2015

1 commit


22 Oct, 2015

11 commits

  • James Morris
     
  • The crypto framework can be built as a loadable module, but the
    apparmor hash code can only be built-in, which then causes a
    link error:

    security/built-in.o: In function `aa_calc_profile_hash':
    integrity_audit.c:(.text+0x21610): undefined reference to `crypto_shash_update'
    security/built-in.o: In function `init_profile_hash':
    integrity_audit.c:(.init.text+0xb4c): undefined reference to `crypto_alloc_shash'

    This changes Apparmor to use 'select CRYPTO' like a lot of other
    subsystems do.

    Signed-off-by: Arnd Bergmann
    Acked-by: John Johansen
    Signed-off-by: James Morris

    Arnd Bergmann
     
  • The size of struct file_security_struct is 16byte at my setup.
    But, the real allocation size for per each file_security_struct
    is 64bytes in my setup that kmalloc min size is 64bytes
    because ARCH_DMA_MINALIGN is 64.

    This allocation is called every times at file allocation(alloc_file()).
    So, the total slack memory size(allocated size - request size)
    is increased exponentially.

    E.g) Min Kmalloc Size : 64bytes, Unit : bytes
    Allocated Size | Request Size | Slack Size | Allocation Count
    ---------------------------------------------------------------
    770048 | 192512 | 577536 | 12032

    At the result, this change reduce memory usage 42bytes per each
    file_security_struct

    Signed-off-by: Sangwoo
    Acked-by: Stephen Smalley
    [PM: removed extra subject prefix]
    Signed-off-by: Paul Moore

    Sangwoo
     
  • Fixes the following sparse warning:

    security/selinux/hooks.c:3242:5: warning: symbol 'ioctl_has_perm' was
    not declared. Should it be static?

    Signed-off-by: Geliang Tang
    Acked-by: Jeff Vander Stoep
    Acked-by: Stephen Smalley
    Signed-off-by: Paul Moore

    Geliang Tang
     
  • sprintf returns the number of characters printed (excluding '\0'), so
    we can use that and avoid duplicating the length computation.

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

    Rasmus Villemoes
     
  • This is much simpler.

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

    Rasmus Villemoes
     
  • Signed-off-by: Rasmus Villemoes
    Acked-by: Stephen Smalley
    Signed-off-by: Paul Moore

    Rasmus Villemoes
     
  • security_context_to_sid() expects a const char* argument, so there's
    no point in casting away the const qualifier of value.

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

    Rasmus Villemoes
     
  • There seems to be a little confusion as to whether the scontext_len
    parameter of security_context_to_sid() includes the nul-byte or
    not. Reading security_context_to_sid_core(), it seems that the
    expectation is that it does not (both the string copying and the test
    for scontext_len being zero hint at that).

    Introduce the helper security_context_str_to_sid() to do the strlen()
    call and fix all callers.

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

    Rasmus Villemoes
     
  • Use the ATTR_FILE attribute to distinguish between truncate()
    and ftruncate() system calls. The two other cases where
    do_truncate is called with a filp (and therefore ATTR_FILE is set)
    are for coredump files and for open(O_TRUNC). In both of those cases
    the open permission has already been checked during file open and
    therefore does not need to be repeated.

    Commit 95dbf739313f ("SELinux: check OPEN on truncate calls")
    fixed a major issue where domains were allowed to truncate files
    without the open permission. However, it introduced a new bug where
    a domain with the write permission can no longer ftruncate files
    without the open permission, even when they receive an already open
    file.

    Signed-off-by: Jeff Vander Stoep
    Acked-by: Stephen Smalley
    Signed-off-by: Paul Moore

    Jeff Vander Stoep
     
  • Change the SELinux checkreqprot default value to 0 so that SELinux
    performs access control checking on the actual memory protections
    used by the kernel and not those requested by the application.

    Signed-off-by: Paul Moore

    Paul Moore
     

21 Oct, 2015

4 commits


20 Oct, 2015

2 commits

  • James Morris
     
  • This feature introduces new kernel interface:

    - /relabel-self - for setting transition labels list

    This list is used to control smack label transition mechanism.
    List is set by, and per process. Process can transit to new label only if
    label is on the list. Only process with CAP_MAC_ADMIN capability can add
    labels to this list. With this list, process can change it's label without
    CAP_MAC_ADMIN but only once. After label changing, list is unset.

    Changes in v2:
    * use list_for_each_entry instead of _rcu during label write
    * added missing description in security/Smack.txt

    Changes in v3:
    * squashed into one commit

    Changes in v4:
    * switch from global list to per-task list
    * since the per-task list is accessed only by the task itself
    there is no need to use synchronization mechanisms on it

    Changes in v5:
    * change smackfs interface of relabel-self to the one used for onlycap
    multiple labels are accepted, separated by space, which
    replace the previous list upon write

    Signed-off-by: Zbigniew Jasinski
    Signed-off-by: Rafal Krypa
    Acked-by: Casey Schaufler

    Zbigniew Jasinski
     

19 Oct, 2015

3 commits

  • If request_key() is used to find a keyring, only do the search part - don't
    do the construction part if the keyring was not found by the search. We
    don't really want keyrings in the negative instantiated state since the
    rejected/negative instantiation error value in the payload is unioned with
    keyring metadata.

    Now the kernel gives an error:

    request_key("keyring", "#selinux,bdekeyring", "keyring", KEY_SPEC_USER_SESSION_KEYRING) = -1 EPERM (Operation not permitted)

    Signed-off-by: David Howells

    David Howells
     
  • Call tpm_seal_trusted() and tpm_unseal_trusted() for TPM 2.0 chips.
    We require explicit 'keyhandle=' option because there's no a fixed
    storage root key inside TPM2 chips.

    Signed-off-by: Jarkko Sakkinen
    Reviewed-by: Andreas Fuchs
    Tested-by: Mimi Zohar (on TPM 1.2)
    Tested-by: Chris J Arges
    Tested-by: Colin Ian King
    Tested-by: Kevin Strasser
    Signed-off-by: Peter Huewe

    Jarkko Sakkinen
     
  • Moved struct trusted_key_options to trustes-type.h so that the fields
    can be accessed from drivers/char/tpm.

    Signed-off-by: Jarkko Sakkinen
    Signed-off-by: Peter Huewe

    Jarkko Sakkinen
     

17 Oct, 2015

2 commits


16 Oct, 2015

1 commit

  • The following sequence of commands:

    i=`keyctl add user a a @s`
    keyctl request2 keyring foo bar @t
    keyctl unlink $i @s

    tries to invoke an upcall to instantiate a keyring if one doesn't already
    exist by that name within the user's keyring set. However, if the upcall
    fails, the code sets keyring->type_data.reject_error to -ENOKEY or some
    other error code. When the key is garbage collected, the key destroy
    function is called unconditionally and keyring_destroy() uses list_empty()
    on keyring->type_data.link - which is in a union with reject_error.
    Subsequently, the kernel tries to unlink the keyring from the keyring names
    list - which oopses like this:

    BUG: unable to handle kernel paging request at 00000000ffffff8a
    IP: [] keyring_destroy+0x3d/0x88
    ...
    Workqueue: events key_garbage_collector
    ...
    RIP: 0010:[] keyring_destroy+0x3d/0x88
    RSP: 0018:ffff88003e2f3d30 EFLAGS: 00010203
    RAX: 00000000ffffff82 RBX: ffff88003bf1a900 RCX: 0000000000000000
    RDX: 0000000000000000 RSI: 000000003bfc6901 RDI: ffffffff81a73a40
    RBP: ffff88003e2f3d38 R08: 0000000000000152 R09: 0000000000000000
    R10: ffff88003e2f3c18 R11: 000000000000865b R12: ffff88003bf1a900
    R13: 0000000000000000 R14: ffff88003bf1a908 R15: ffff88003e2f4000
    ...
    CR2: 00000000ffffff8a CR3: 000000003e3ec000 CR4: 00000000000006f0
    ...
    Call Trace:
    [] key_gc_unused_keys.constprop.1+0x5d/0x10f
    [] key_garbage_collector+0x1fa/0x351
    [] process_one_work+0x28e/0x547
    [] worker_thread+0x26e/0x361
    [] ? rescuer_thread+0x2a8/0x2a8
    [] kthread+0xf3/0xfb
    [] ? kthread_create_on_node+0x1c2/0x1c2
    [] ret_from_fork+0x3f/0x70
    [] ? kthread_create_on_node+0x1c2/0x1c2

    Note the value in RAX. This is a 32-bit representation of -ENOKEY.

    The solution is to only call ->destroy() if the key was successfully
    instantiated.

    Reported-by: Dmitry Vyukov
    Signed-off-by: David Howells
    Tested-by: Dmitry Vyukov

    David Howells
     

11 Oct, 2015

1 commit

  • selinux needs few changes to accommodate fact that SYNACK messages
    can be attached to a request socket, lacking sk_security pointer

    (Only syncookies are still attached to a TCP_LISTEN socket)

    Adds a new sk_listener() helper, and use it in selinux and sch_fq

    Fixes: ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener")
    Signed-off-by: Eric Dumazet
    Reported by: kernel test robot
    Cc: Paul Moore
    Cc: Stephen Smalley
    Cc: Eric Paris
    Acked-by: Paul Moore
    Signed-off-by: David S. Miller

    Eric Dumazet