26 Jan, 2019

1 commit

  • [ Upstream commit 2cbdcb882f97a45f7475c67ac6257bbc16277dfe ]

    If a superblock has the MS_SUBMOUNT flag set, we should always allow
    mounting it. These mounts are done automatically by the kernel either as
    part of mounting some parent mount (e.g. debugfs always mounts tracefs
    under "tracing" for compatibility) or they are mounted automatically as
    needed on subdirectory accesses (e.g. NFS crossmnt mounts). Since such
    automounts are either an implicit consequence of the parent mount (which
    is already checked) or they can happen during regular accesses (where it
    doesn't make sense to check against the current task's context), the
    mount permission check should be skipped for them.

    Without this patch, attempts to access contents of an automounted
    directory can cause unexpected SELinux denials.

    In the current kernel tree, the MS_SUBMOUNT flag is set only via
    vfs_submount(), which is called only from the following places:
    - AFS, when automounting special "symlinks" referencing other cells
    - CIFS, when automounting "referrals"
    - NFS, when automounting subtrees
    - debugfs, when automounting tracefs

    In all cases the submounts are meant to be transparent to the user and
    it makes sense that if mounting the master is allowed, then so should be
    the automounts. Note that CAP_SYS_ADMIN capability checking is already
    skipped for (SB_KERNMOUNT|SB_SUBMOUNT) in:
    - sget_userns() in fs/super.c:
    if (!(flags & (SB_KERNMOUNT|SB_SUBMOUNT)) &&
    !(type->fs_flags & FS_USERNS_MOUNT) &&
    !capable(CAP_SYS_ADMIN))
    return ERR_PTR(-EPERM);
    - sget() in fs/super.c:
    /* Ensure the requestor has permissions over the target filesystem */
    if (!(flags & (SB_KERNMOUNT|SB_SUBMOUNT)) && !ns_capable(user_ns, CAP_SYS_ADMIN))
    return ERR_PTR(-EPERM);

    Verified internally on patched RHEL 7.6 with a reproducer using
    NFS+httpd and selinux-tesuite.

    Fixes: 93faccbbfa95 ("fs: Better permission checking for submounts")
    Signed-off-by: Ondrej Mosnacek
    Signed-off-by: Paul Moore
    Signed-off-by: Sasha Levin

    Ondrej Mosnacek
     

23 Jan, 2019

3 commits

  • commit 5b0e7310a2a33c06edc7eb81ffc521af9b2c5610 upstream.

    levdatum->level can be NULL if we encounter an error while loading
    the policy during sens_read prior to initializing it. Make sure
    sens_destroy handles that case correctly.

    Reported-by: syzbot+6664500f0f18f07a5c0e@syzkaller.appspotmail.com
    Signed-off-by: Stephen Smalley
    Signed-off-by: Paul Moore
    Signed-off-by: Greg Kroah-Hartman

    Stephen Smalley
     
  • commit a5795fd38ee8194451ba3f281f075301a3696ce2 upstream.

    From: Casey Schaufler

    Check that the cred security blob has been set before trying
    to clean it up. There is a case during credential initialization
    that could result in this.

    Signed-off-by: Casey Schaufler
    Acked-by: John Johansen
    Signed-off-by: James Morris
    Reported-by: syzbot+69ca07954461f189e808@syzkaller.appspotmail.com
    Signed-off-by: Greg Kroah-Hartman

    James Morris
     
  • commit 9474f4e7cd71a633fa1ef93b7daefd44bbdfd482 upstream.

    It's possible that a pid has died before we take the rcu lock, in which
    case we can't walk the ancestry list as it may be detached. Instead, check
    for death first before doing the walk.

    Reported-by: syzbot+a9ac39bf55329e206219@syzkaller.appspotmail.com
    Fixes: 2d514487faf1 ("security: Yama LSM")
    Cc: stable@vger.kernel.org
    Suggested-by: Oleg Nesterov
    Signed-off-by: Kees Cook
    Signed-off-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     

13 Jan, 2019

1 commit

  • commit 5df275cd4cf51c86d49009f1397132f284ba515e upstream.

    Do the LE conversions before doing the Infiniband-related range checks.
    The incorrect checks are otherwise causing a failure to load any policy
    with an ibendportcon rule on BE systems. This can be reproduced by
    running (on e.g. ppc64):

    cat >my_module.cil <
    Cc: Eli Cohen
    Cc: James Morris
    Cc: Doug Ledford
    Cc: # 4.13+
    Fixes: a806f7a1616f ("selinux: Create policydb version for Infiniband support")
    Signed-off-by: Ondrej Mosnacek
    Acked-by: Stephen Smalley
    Signed-off-by: Paul Moore
    Signed-off-by: Greg Kroah-Hartman

    Ondrej Mosnacek
     

01 Dec, 2018

5 commits

  • commit e2598077dc6a26c9644393e5c21f22a90dbdccdb upstream.

    Intermittently security.ima is not being written for new files. This
    patch re-initializes the new slab iint->atomic_flags field before
    freeing it.

    Fixes: commit 0d73a55208e9 ("ima: re-introduce own integrity cache lock")
    Signed-off-by: Mimi Zohar
    Signed-off-by: James Morris
    Cc: Aditya Kali
    Signed-off-by: Greg Kroah-Hartman

    Mimi Zohar
     
  • commit 0d73a55208e94fc9fb6deaeea61438cd3280d4c0 upstream.

    Before IMA appraisal was introduced, IMA was using own integrity cache
    lock along with i_mutex. process_measurement and ima_file_free took
    the iint->mutex first and then the i_mutex, while setxattr, chmod and
    chown took the locks in reverse order. To resolve the potential deadlock,
    i_mutex was moved to protect entire IMA functionality and the redundant
    iint->mutex was eliminated.

    Solution was based on the assumption that filesystem code does not take
    i_mutex further. But when file is opened with O_DIRECT flag, direct-io
    implementation takes i_mutex and produces deadlock. Furthermore, certain
    other filesystem operations, such as llseek, also take i_mutex.

    More recently some filesystems have replaced their filesystem specific
    lock with the global i_rwsem to read a file. As a result, when IMA
    attempts to calculate the file hash, reading the file attempts to take
    the i_rwsem again.

    To resolve O_DIRECT related deadlock problem, this patch re-introduces
    iint->mutex. But to eliminate the original chmod() related deadlock
    problem, this patch eliminates the requirement for chmod hooks to take
    the iint->mutex by introducing additional atomic iint->attr_flags to
    indicate calling of the hooks. The allowed locking order is to take
    the iint->mutex first and then the i_rwsem.

    Original flags were cleared in chmod(), setxattr() or removwxattr()
    hooks and tested when file was closed or opened again. New atomic flags
    are set or cleared in those hooks and tested to clear iint->flags on
    close or on open.

    Atomic flags are following:
    * IMA_CHANGE_ATTR - indicates that chATTR() was called (chmod, chown,
    chgrp) and file attributes have changed. On file open, it causes IMA
    to clear iint->flags to re-evaluate policy and perform IMA functions
    again.
    * IMA_CHANGE_XATTR - indicates that setxattr or removexattr was called
    and extended attributes have changed. On file open, it causes IMA to
    clear iint->flags IMA_DONE_MASK to re-appraise.
    * IMA_UPDATE_XATTR - indicates that security.ima needs to be updated.
    It is cleared if file policy changes and no update is needed.
    * IMA_DIGSIG - indicates that file security.ima has signature and file
    security.ima must not update to file has on file close.
    * IMA_MUST_MEASURE - indicates the file is in the measurement policy.

    Fixes: Commit 6552321831dc ("xfs: remove i_iolock and use i_rwsem in
    the VFS inode instead")

    Signed-off-by: Dmitry Kasatkin
    Signed-off-by: Mimi Zohar
    Cc: Aditya Kali
    Signed-off-by: Greg Kroah-Hartman

    Dmitry Kasatkin
     
  • commit 50b977481fce90aa5fbda55e330b9d722733e358 upstream.

    The EVM signature includes the inode number and (optionally) the
    filesystem UUID, making it impractical to ship EVM signatures in
    packages. This patch adds a new portable format intended to allow
    distributions to include EVM signatures. It is identical to the existing
    format but hardcodes the inode and generation numbers to 0 and does not
    include the filesystem UUID even if the kernel is configured to do so.

    Removing the inode means that the metadata and signature from one file
    could be copied to another file without invalidating it. This is avoided
    by ensuring that an IMA xattr is present during EVM validation.

    Portable signatures are intended to be immutable - ie, they will never
    be transformed into HMACs.

    Based on earlier work by Dmitry Kasatkin and Mikhail Kurinnoi.

    Signed-off-by: Matthew Garrett
    Cc: Dmitry Kasatkin
    Cc: Mikhail Kurinnoi
    Signed-off-by: Mimi Zohar
    Cc: Aditya Kali
    Signed-off-by: Greg Kroah-Hartman

    Matthew Garrett
     
  • commit f3cc6b25dcc5616f0d5c720009b2ac66f97df2ff upstream.

    All files matching a "measure" rule must be included in the IMA
    measurement list, even when the file hash cannot be calculated.
    Similarly, all files matching an "audit" rule must be audited, even when
    the file hash can not be calculated.

    The file data hash field contained in the IMA measurement list template
    data will contain 0's instead of the actual file hash digest.

    Note:
    In general, adding, deleting or in anyway changing which files are
    included in the IMA measurement list is not a good idea, as it might
    result in not being able to unseal trusted keys sealed to a specific
    TPM PCR value. This patch not only adds file measurements that were
    not previously measured, but specifies that the file hash value for
    these files will be 0's.

    As the IMA measurement list ordering is not consistent from one boot
    to the next, it is unlikely that anyone is sealing keys based on the
    IMA measurement list. Remote attestation servers should be able to
    process these new measurement records, but might complain about
    these unknown records.

    Signed-off-by: Mimi Zohar
    Reviewed-by: Dmitry Kasatkin
    Cc: Aditya Kali
    Signed-off-by: Greg Kroah-Hartman

    Mimi Zohar
     
  • commit 4458bba09788e70e8fb39ad003f087cd9dfbd6ac upstream.

    syzbot is hitting warning at str_read() [1] because len parameter can
    become larger than KMALLOC_MAX_SIZE. We don't need to emit warning for
    this case.

    [1] https://syzkaller.appspot.com/bug?id=7f2f5aad79ea8663c296a2eedb81978401a908f0

    Signed-off-by: Tetsuo Handa
    Reported-by: syzbot
    Signed-off-by: Paul Moore
    Signed-off-by: Greg Kroah-Hartman

    Tetsuo Handa
     

27 Nov, 2018

1 commit

  • [ Upstream commit 250f2da49cb8e582215a65c03f50e8ddf5cd119c ]

    Syzkaller reported a OOB-read with the stacktrace below. This occurs
    inside __aa_lookupn_ns as `n` is not initialized. `n` is obtained from
    aa_splitn_fqname. In cases where `name` is invalid, aa_splitn_fqname
    returns without initializing `ns_name` and `ns_len`.

    Fix this by always initializing `ns_name` and `ns_len`.

    __dump_stack lib/dump_stack.c:77 [inline]
    dump_stack+0x1c4/0x2b4 lib/dump_stack.c:113
    print_address_description.cold.8+0x9/0x1ff mm/kasan/report.c:256
    kasan_report_error mm/kasan/report.c:354 [inline]
    kasan_report.cold.9+0x242/0x309 mm/kasan/report.c:412
    __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:430
    memcmp+0xe3/0x160 lib/string.c:861
    strnstr+0x4b/0x70 lib/string.c:934
    __aa_lookupn_ns+0xc1/0x570 security/apparmor/policy_ns.c:209
    aa_lookupn_ns+0x88/0x1e0 security/apparmor/policy_ns.c:240
    aa_fqlookupn_profile+0x1b9/0x1010 security/apparmor/policy.c:468
    fqlookupn_profile+0x80/0xc0 security/apparmor/label.c:1844
    aa_label_strn_parse+0xa3a/0x1230 security/apparmor/label.c:1908
    aa_label_parse+0x42/0x50 security/apparmor/label.c:1943
    aa_change_profile+0x513/0x3510 security/apparmor/domain.c:1362
    apparmor_setprocattr+0xaa4/0x1150 security/apparmor/lsm.c:658
    security_setprocattr+0x66/0xc0 security/security.c:1298
    proc_pid_attr_write+0x301/0x540 fs/proc/base.c:2555
    __vfs_write+0x119/0x9f0 fs/read_write.c:485
    vfs_write+0x1fc/0x560 fs/read_write.c:549
    ksys_write+0x101/0x260 fs/read_write.c:598
    __do_sys_write fs/read_write.c:610 [inline]
    __se_sys_write fs/read_write.c:607 [inline]
    __x64_sys_write+0x73/0xb0 fs/read_write.c:607
    do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
    entry_SYSCALL_64_after_hwframe+0x49/0xbe

    Fixes: 3b0aaf5866bf ("apparmor: add lib fn to find the "split" for fqnames")
    Reported-by: syzbot+61e4b490d9d2da591b50@syzkaller.appspotmail.com
    Signed-off-by: Zubin Mithra
    Reviewed-by: Kees Cook
    Signed-off-by: John Johansen
    Signed-off-by: Sasha Levin

    Zubin Mithra
     

14 Nov, 2018

1 commit


29 Sep, 2018

1 commit

  • commit 8c0f9f5b309d627182d5da72a69246f58bde1026 upstream.

    This changes UAPI, breaking iwd and libell:

    ell/key.c: In function 'kernel_dh_compute':
    ell/key.c:205:38: error: 'struct keyctl_dh_params' has no member named 'private'; did you mean 'dh_private'?
    struct keyctl_dh_params params = { .private = private,
    ^~~~~~~
    dh_private

    This reverts commit 8a2336e549d385bb0b46880435b411df8d8200e8.

    Fixes: 8a2336e549d3 ("uapi/linux/keyctl.h: don't use C++ reserved keyword as a struct member name")
    Signed-off-by: Lubomir Rintel
    Signed-off-by: David Howells
    cc: Randy Dunlap
    cc: Mat Martineau
    cc: Stephan Mueller
    cc: James Morris
    cc: "Serge E. Hallyn"
    cc: Mat Martineau
    cc: Andrew Morton
    cc: Linus Torvalds
    cc:
    Signed-off-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Lubomir Rintel
     

26 Sep, 2018

3 commits

  • [ Upstream commit 87ea58433208d17295e200d56be5e2a4fe4ce7d6 ]

    lsm_append() should return -ENOMEM if memory allocation failed.

    Fixes: d69dece5f5b6 ("LSM: Add /sys/kernel/security/lsm")
    Signed-off-by: Eric Biggers
    Signed-off-by: James Morris
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     
  • [ Upstream commit e2861fa71641c6414831d628a1f4f793b6562580 ]

    When EVM attempts to appraise a file signed with a crypto algorithm the
    kernel doesn't have support for, it will cause the kernel to trigger a
    module load. If the EVM policy includes appraisal of kernel modules this
    will in turn call back into EVM - since EVM is holding a lock until the
    crypto initialisation is complete, this triggers a deadlock. Add a
    CRYPTO_NOLOAD flag and skip module loading if it's set, and add that flag
    in the EVM case in order to fail gracefully with an error message
    instead of deadlocking.

    Signed-off-by: Matthew Garrett
    Acked-by: Herbert Xu
    Signed-off-by: Mimi Zohar
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Matthew Garrett
     
  • [ Upstream commit 129a99890936766f4b69b9da7ed88366313a9210 ]

    A socket which has sk_family set to PF_INET6 is able to receive not
    only IPv6 but also IPv4 traffic (IPv4-mapped IPv6 addresses).

    Prior to this patch, the smk_skb_to_addr_ipv6() could have been
    called for socket buffers containing IPv4 packets, in result such
    traffic was allowed.

    Signed-off-by: Piotr Sawicki
    Signed-off-by: Casey Schaufler
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Piotr Sawicki
     

15 Sep, 2018

1 commit

  • commit 8a2336e549d385bb0b46880435b411df8d8200e8 upstream.

    Since this header is in "include/uapi/linux/", apparently people want to
    use it in userspace programs -- even in C++ ones. However, the header
    uses a C++ reserved keyword ("private"), so change that to "dh_private"
    instead to allow the header file to be used in C++ userspace.

    Fixes https://bugzilla.kernel.org/show_bug.cgi?id=191051
    Link: http://lkml.kernel.org/r/0db6c314-1ef4-9bfa-1baa-7214dd2ee061@infradead.org
    Fixes: ddbb41148724 ("KEYS: Add KEYCTL_DH_COMPUTE command")
    Signed-off-by: Randy Dunlap
    Reviewed-by: Andrew Morton
    Cc: David Howells
    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: Mat Martineau
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Randy Dunlap
     

10 Sep, 2018

1 commit

  • commit 355139a8dba446cc11a424cddbf7afebc3041ba1 upstream.

    The code in cap_inode_getsecurity(), introduced by commit 8db6c34f1dbc
    ("Introduce v3 namespaced file capabilities"), should use
    d_find_any_alias() instead of d_find_alias() do handle unhashed dentry
    correctly. This is needed, for example, if execveat() is called with an
    open but unlinked overlayfs file, because overlayfs unhashes dentry on
    unlink.
    This is a regression of real life application, first reported at
    https://www.spinics.net/lists/linux-unionfs/msg05363.html

    Below reproducer and setup can reproduce the case.
    const char* exec="echo";
    const char *newargv[] = { "echo", "hello", NULL};
    const char *newenviron[] = { NULL };
    int fd, err;

    fd = open(exec, O_PATH);
    unlink(exec);
    err = syscall(322/*SYS_execveat*/, fd, "", newargv, newenviron,
    AT_EMPTY_PATH);
    if(err
    Acked-by: Amir Goldstein
    Acked-by: Serge E. Hallyn
    Fixes: 8db6c34f1dbc ("Introduce v3 namespaced file capabilities")
    Cc: # v4.14
    Signed-off-by: Eddie Horng
    Signed-off-by: Eric W. Biederman
    Signed-off-by: Greg Kroah-Hartman

    Eddie.Horng
     

24 Aug, 2018

1 commit

  • [ Upstream commit 7b4e88434c4e7982fb053c49657e1c8bbb8692d9 ]

    Smack: Mark inode instant in smack_task_to_inode

    /proc clean-up in commit 1bbc55131e59bd099fdc568d3aa0b42634dbd188
    resulted in smack_task_to_inode() being called before smack_d_instantiate.
    This resulted in the smk_inode value being ignored, even while present
    for files in /proc/self. Marking the inode as instant here fixes that.

    Signed-off-by: Casey Schaufler
    Signed-off-by: James Morris
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Casey Schaufler
     

03 Aug, 2018

1 commit

  • [ Upstream commit fd90bc559bfba743ae8de87ff23b92a5e4668062 ]

    Don't differentiate, for now, between kernel_read_file_id READING_FIRMWARE
    and READING_FIRMWARE_PREALLOC_BUFFER enumerations.

    Fixes: a098ecd firmware: support loading into a pre-allocated buffer (since 4.8)
    Signed-off-by: Mimi Zohar
    Cc: Luis R. Rodriguez
    Cc: David Howells
    Cc: Kees Cook
    Cc: Serge E. Hallyn
    Cc: Stephen Boyd
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Mimi Zohar
     

05 Jun, 2018

1 commit

  • commit efe3de79e0b52ca281ef6691480c8c68c82a4657 upstream.

    Call trace:
    [] dump_backtrace+0x0/0x428
    [] show_stack+0x28/0x38
    [] dump_stack+0xd4/0x124
    [] print_address_description+0x68/0x258
    [] kasan_report.part.2+0x228/0x2f0
    [] kasan_report+0x5c/0x70
    [] check_memory_region+0x12c/0x1c0
    [] memcpy+0x34/0x68
    [] xattr_getsecurity+0xe0/0x160
    [] vfs_getxattr+0xc8/0x120
    [] getxattr+0x100/0x2c8
    [] SyS_fgetxattr+0x64/0xa0
    [] el0_svc_naked+0x24/0x28

    If user get root access and calls security.selinux setxattr() with an
    embedded NUL on a file and then if some process performs a getxattr()
    on that file with a length greater than the actual length of the string,
    it would result in a panic.

    To fix this, add the actual length of the string to the security context
    instead of the length passed by the userspace process.

    Signed-off-by: Sachin Grover
    Cc: stable@vger.kernel.org
    Signed-off-by: Paul Moore
    Signed-off-by: Greg Kroah-Hartman

    Sachin Grover
     

30 May, 2018

3 commits

  • [ Upstream commit ab60368ab6a452466885ef4edf0cefd089465132 ]

    IMA requires having it's hash algorithm be compiled-in due to it's
    early use. The default IMA algorithm is protected by Kconfig to be
    compiled-in.

    The ima_hash kernel parameter allows to choose the hash algorithm. When
    the specified algorithm is not available or available as a module, IMA
    initialization fails, which leads to a kernel panic (mknodat syscall calls
    ima_post_path_mknod()). Therefore as fallback we force IMA to use
    the default builtin Kconfig hash algorithm.

    Fixed crash:

    $ grep CONFIG_CRYPTO_MD4 .config
    CONFIG_CRYPTO_MD4=m

    [ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.12.14-2.3-default root=UUID=74ae8202-9ca7-4e39-813b-22287ec52f7a video=1024x768-16 plymouth.ignore-serial-consoles console=ttyS0 console=tty resume=/dev/disk/by-path/pci-0000:00:07.0-part3 splash=silent showopts ima_hash=md4
    ...
    [ 1.545190] ima: Can not allocate md4 (reason: -2)
    ...
    [ 2.610120] BUG: unable to handle kernel NULL pointer dereference at (null)
    [ 2.611903] IP: ima_match_policy+0x23/0x390
    [ 2.612967] PGD 0 P4D 0
    [ 2.613080] Oops: 0000 [#1] SMP
    [ 2.613080] Modules linked in: autofs4
    [ 2.613080] Supported: Yes
    [ 2.613080] CPU: 0 PID: 1 Comm: systemd Not tainted 4.12.14-2.3-default #1
    [ 2.613080] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
    [ 2.613080] task: ffff88003e2d0040 task.stack: ffffc90000190000
    [ 2.613080] RIP: 0010:ima_match_policy+0x23/0x390
    [ 2.613080] RSP: 0018:ffffc90000193e88 EFLAGS: 00010296
    [ 2.613080] RAX: 0000000000000000 RBX: 000000000000000c RCX: 0000000000000004
    [ 2.613080] RDX: 0000000000000010 RSI: 0000000000000001 RDI: ffff880037071728
    [ 2.613080] RBP: 0000000000008000 R08: 0000000000000000 R09: 0000000000000000
    [ 2.613080] R10: 0000000000000008 R11: 61c8864680b583eb R12: 00005580ff10086f
    [ 2.613080] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000008000
    [ 2.613080] FS: 00007f5c1da08940(0000) GS:ffff88003fc00000(0000) knlGS:0000000000000000
    [ 2.613080] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    [ 2.613080] CR2: 0000000000000000 CR3: 0000000037002000 CR4: 00000000003406f0
    [ 2.613080] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    [ 2.613080] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    [ 2.613080] Call Trace:
    [ 2.613080] ? shmem_mknod+0xbf/0xd0
    [ 2.613080] ima_post_path_mknod+0x1c/0x40
    [ 2.613080] SyS_mknod+0x210/0x220
    [ 2.613080] entry_SYSCALL_64_fastpath+0x1a/0xa5
    [ 2.613080] RIP: 0033:0x7f5c1bfde570
    [ 2.613080] RSP: 002b:00007ffde1c90dc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000085
    [ 2.613080] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f5c1bfde570
    [ 2.613080] RDX: 0000000000000000 RSI: 0000000000008000 RDI: 00005580ff10086f
    [ 2.613080] RBP: 00007ffde1c91040 R08: 00005580ff10086f R09: 0000000000000000
    [ 2.613080] R10: 0000000000104000 R11: 0000000000000246 R12: 00005580ffb99660
    [ 2.613080] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000002
    [ 2.613080] Code: 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 41 57 41 56 44 8d 14 09 41 55 41 54 55 53 44 89 d3 09 cb 48 83 ec 38 48 8b 05 c5 03 29 01 8b 20 4c 39 e0 0f 84 d7 01 00 00 4c 89 44 24 08 89 54 24 20
    [ 2.613080] RIP: ima_match_policy+0x23/0x390 RSP: ffffc90000193e88
    [ 2.613080] CR2: 0000000000000000
    [ 2.613080] ---[ end trace 9a9f0a8a73079f6a ]---
    [ 2.673052] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009
    [ 2.673052]
    [ 2.675337] Kernel Offset: disabled
    [ 2.676405] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009

    Signed-off-by: Petr Vorel
    Signed-off-by: Mimi Zohar
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Petr Vorel
     
  • [ Upstream commit fac37c628fd5d68fd7298d9b57ae8601ee1b4723 ]

    TPM_CRB driver provides TPM CRB 2.0 support. If it is built as a
    module, the TPM chip is registered after IMA init. tpm_pcr_read() in
    IMA fails and displays the following message even though eventually
    there is a TPM chip on the system.

    ima: No TPM chip found, activating TPM-bypass! (rc=-19)

    Fix IMA Kconfig to select TPM_CRB so TPM_CRB driver is built in the kernel
    and initializes before IMA.

    Signed-off-by: Jiandi An
    Signed-off-by: Mimi Zohar
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Jiandi An
     
  • [ Upstream commit 120f3b11ef88fc38ce1d0ff9c9a4b37860ad3140 ]

    security/integrity/digsig.c has build errors on some $ARCH due to a
    missing header file, so add it.

    security/integrity/digsig.c:146:2: error: implicit declaration of function 'vfree' [-Werror=implicit-function-declaration]

    Reported-by: Michael Ellerman
    Signed-off-by: Randy Dunlap
    Cc: Mimi Zohar
    Cc: linux-integrity@vger.kernel.org
    Link: http://kisskb.ellerman.id.au/kisskb/head/13396/
    Signed-off-by: James Morris
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Randy Dunlap
     

29 Apr, 2018

1 commit

  • commit 1f5781725dcbb026438e77091c91a94f678c3522 upstream.

    syzbot is reporting NULL pointer dereference at xattr_getsecurity() [1],
    for cap_inode_getsecurity() is returning sizeof(struct vfs_cap_data) when
    memory allocation failed. Return -ENOMEM if memory allocation failed.

    [1] https://syzkaller.appspot.com/bug?id=a55ba438506fe68649a5f50d2d82d56b365e0107

    Signed-off-by: Tetsuo Handa
    Fixes: 8db6c34f1dbc8e06 ("Introduce v3 namespaced file capabilities")
    Reported-by: syzbot
    Cc: stable # 4.14+
    Acked-by: Serge E. Hallyn
    Acked-by: James Morris
    Signed-off-by: Eric W. Biederman
    Signed-off-by: Greg Kroah-Hartman

    Tetsuo Handa
     

19 Apr, 2018

3 commits

  • commit b5beb07ad32ab533027aa988d96a44965ec116f7 upstream.

    Resource auditing is using the peer field which is not available
    when the rlim data struct is used, because it is a different element
    of the same union. Accessing peer during resource auditing could
    cause garbage log entries or even oops the kernel.

    Move the rlim data block into the same struct as the peer field
    so they can be used together.

    CC:
    Fixes: 86b92cb782b3 ("apparmor: move resource checks to using labels")
    Signed-off-by: John Johansen
    Signed-off-by: Greg Kroah-Hartman

    John Johansen
     
  • commit 040d9e2bce0a5b321c402b79ee43a8e8d2fd3b06 upstream.

    The .ns_name should not be virtualized by the current ns view. It
    needs to report the ns base name as that is being used during startup
    as part of determining apparmor policy namespace support.

    BugLink: http://bugs.launchpad.net/bugs/1746463
    Fixes: d9f02d9c237aa ("apparmor: fix display of ns name")
    Cc: Stable
    Reported-by: Serge Hallyn
    Tested-by: Serge Hallyn
    Signed-off-by: John Johansen
    Signed-off-by: Greg Kroah-Hartman

    John Johansen
     
  • commit 98cf5bbff413eadf1b9cb195a7b80cc61c72a50e upstream.

    The existence test is not being properly logged as the signal mapping
    maps it to the last entry in the named signal table. This is done
    to help catch bugs by making the 0 mapped signal value invalid so
    that we can catch the signal value not being filled in.

    When fixing the off-by-one comparision logic the reporting of the
    existence test was broken, because the logic behind the mapped named
    table was hidden. Fix this by adding a define for the name lookup
    and using it.

    Cc: Stable
    Fixes: f7dc4c9a855a1 ("apparmor: fix off-by-one comparison on MAXMAPPED_SIG")
    Signed-off-by: John Johansen
    Signed-off-by: Greg Kroah-Hartman

    John Johansen
     

24 Mar, 2018

1 commit

  • [ Upstream commit 22ec1a2aea73b9dfe340dff7945bd85af4cc6280 ]

    As done for /proc/kcore in

    commit df04abfd181a ("fs/proc/kcore.c: Add bounce buffer for ktext data")

    this adds a bounce buffer when reading memory via /dev/mem. This
    is needed to allow kernel text memory to be read out when built with
    CONFIG_HARDENED_USERCOPY (which refuses to read out kernel text) and
    without CONFIG_STRICT_DEVMEM (which would have refused to read any RAM
    contents at all).

    Since this build configuration isn't common (most systems with
    CONFIG_HARDENED_USERCOPY also have CONFIG_STRICT_DEVMEM), this also tries
    to inform Kconfig about the recommended settings.

    This patch is modified from Brad Spengler/PaX Team's changes to /dev/mem
    code in the last public patch of grsecurity/PaX based on my understanding
    of the code. Changes or omissions from the original code are mine and
    don't reflect the original grsecurity/PaX code.

    Reported-by: Michael Holzheu
    Fixes: f5509cc18daa ("mm: Hardened usercopy")
    Signed-off-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     

19 Mar, 2018

1 commit

  • [ Upstream commit b7e27bc1d42e8e0cc58b602b529c25cd0071b336 ]

    Custom policies can require file signatures based on LSM labels. These
    files are normally created and only afterwards labeled, requiring them
    to be signed.

    Instead of requiring file signatures based on LSM labels, entire
    filesystems could require file signatures. In this case, we need the
    ability of writing new files without requiring file signatures.

    The definition of a "new" file was originally defined as any file with
    a length of zero. Subsequent patches redefined a "new" file to be based
    on the FILE_CREATE open flag. By combining the open flag with a file
    size of zero, this patch relaxes the file signature requirement.

    Fixes: 1ac202e978e1 ima: accept previously set IMA_NEW_FILE
    Signed-off-by: Mimi Zohar
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Mimi Zohar
     

25 Feb, 2018

2 commits

  • commit 4b14752ec4e0d87126e636384cf37c8dd9df157c upstream.

    We can't do anything reasonable in security_bounded_transition() if we
    don't have a policy loaded, and in fact we could run into problems
    with some of the code inside expecting a policy. Fix these problems
    like we do many others in security/selinux/ss/services.c by checking
    to see if the policy is loaded (ss_initialized) and returning quickly
    if it isn't.

    Reported-by: syzbot
    Signed-off-by: Paul Moore
    Acked-by: Stephen Smalley
    Reviewed-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Paul Moore
     
  • commit ef28df55ac27e1e5cd122e19fa311d886d47a756 upstream.

    The syzbot/syzkaller automated tests found a problem in
    security_context_to_sid_core() during early boot (before we load the
    SELinux policy) where we could potentially feed context strings without
    NUL terminators into the strcmp() function.

    We already guard against this during normal operation (after the SELinux
    policy has been loaded) by making a copy of the context strings and
    explicitly adding a NUL terminator to the end. The patch extends this
    protection to the early boot case (no loaded policy) by moving the context
    copy earlier in security_context_to_sid_core().

    Reported-by: syzbot
    Signed-off-by: Paul Moore
    Reviewed-By: William Roberts
    Signed-off-by: Greg Kroah-Hartman

    Paul Moore
     

04 Feb, 2018

1 commit

  • commit 36447456e1cca853188505f2a964dbbeacfc7a7a upstream.

    The switch to uuid_t invereted the logic of verfication that &entry->fsuuid
    is zero during parsing of "fsuuid=" rule. Instead of making sure the
    &entry->fsuuid field is not attempted to be overwritten, we bail out for
    perfectly correct rule.

    Fixes: 787d8c530af7 ("ima/policy: switch to use uuid_t")
    Signed-off-by: Mike Rapoport
    Signed-off-by: Mimi Zohar
    Signed-off-by: Greg Kroah-Hartman

    Mike Rapoport
     

17 Jan, 2018

2 commits

  • commit a237f762681e2a394ca67f21df2feb2b76a3609b upstream.

    When the config option for PTI was added a reference to documentation was
    added as well. But the documentation did not exist at that point. The final
    documentation has a different file name.

    Fix it up to point to the proper file.

    Fixes: 385ce0ea ("x86/mm/pti: Add Kconfig")
    Signed-off-by: W. Trevor King
    Signed-off-by: Thomas Gleixner
    Cc: Dave Hansen
    Cc: linux-mm@kvack.org
    Cc: linux-security-module@vger.kernel.org
    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/3009cc8ccbddcd897ec1e0cb6dda524929de0d14.1515799398.git.wking@tremily.us
    Signed-off-by: Greg Kroah-Hartman

    W. Trevor King
     
  • commit 0dda0b3fb255048a221f736c8a2a24c674da8bf3 upstream.

    Given a label with a profile stack of
    A//&B or A//&C ...

    A ptrace rule should be able to specify a generic trace pattern with
    a rule like

    ptrace trace A//&**,

    however this is failing because while the correct label match routine
    is called, it is being done post label decomposition so it is always
    being done against a profile instead of the stacked label.

    To fix this refactor the cross check to pass the full peer label in to
    the label_match.

    Fixes: 290f458a4f16 ("apparmor: allow ptrace checks to be finer grained than just capability")
    Reported-by: Matthew Garrett
    Tested-by: Matthew Garrett
    Signed-off-by: John Johansen
    Signed-off-by: Greg Kroah-Hartman

    John Johansen
     

10 Jan, 2018

1 commit

  • commit 5b9f57cf47b87f07210875d6a24776b4496b818d upstream.

    When the mount code was refactored for Labels it was not correctly
    updated to check whether policy supported mediation of the mount
    class. This causes a regression when the kernel feature set is
    reported as supporting mount and policy is pinned to a feature set
    that does not support mount mediation.

    BugLink: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=882697#41
    Fixes: 2ea3ffb7782a ("apparmor: add mount mediation")
    Reported-by: Fabian Grünbichler
    Signed-off-by: John Johansen
    Signed-off-by: Greg Kroah-Hartman

    John Johansen
     

05 Jan, 2018

1 commit

  • commit dc32b5c3e6e2ef29cef76d9ce1b92d394446150e upstream.

    If userspace attempted to set a "security.capability" xattr shorter than
    4 bytes (e.g. 'setfattr -n security.capability -v x file'), then
    cap_convert_nscap() read past the end of the buffer containing the xattr
    value because it accessed the ->magic_etc field without verifying that
    the xattr value is long enough to contain that field.

    Fix it by validating the xattr value size first.

    This bug was found using syzkaller with KASAN. The KASAN report was as
    follows (cleaned up slightly):

    BUG: KASAN: slab-out-of-bounds in cap_convert_nscap+0x514/0x630 security/commoncap.c:498
    Read of size 4 at addr ffff88002d8741c0 by task syz-executor1/2852

    CPU: 0 PID: 2852 Comm: syz-executor1 Not tainted 4.15.0-rc6-00200-gcc0aac99d977 #253
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-20171110_100015-anatol 04/01/2014
    Call Trace:
    __dump_stack lib/dump_stack.c:17 [inline]
    dump_stack+0xe3/0x195 lib/dump_stack.c:53
    print_address_description+0x73/0x260 mm/kasan/report.c:252
    kasan_report_error mm/kasan/report.c:351 [inline]
    kasan_report+0x235/0x350 mm/kasan/report.c:409
    cap_convert_nscap+0x514/0x630 security/commoncap.c:498
    setxattr+0x2bd/0x350 fs/xattr.c:446
    path_setxattr+0x168/0x1b0 fs/xattr.c:472
    SYSC_setxattr fs/xattr.c:487 [inline]
    SyS_setxattr+0x36/0x50 fs/xattr.c:483
    entry_SYSCALL_64_fastpath+0x18/0x85

    Fixes: 8db6c34f1dbc ("Introduce v3 namespaced file capabilities")
    Signed-off-by: Eric Biggers
    Reviewed-by: Serge Hallyn
    Signed-off-by: James Morris
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

03 Jan, 2018

1 commit

  • commit 385ce0ea4c078517fa51c261882c4e72fba53005 upstream.

    Finally allow CONFIG_PAGE_TABLE_ISOLATION to be enabled.

    PARAVIRT generally requires that the kernel not manage its own page tables.
    It also means that the hypervisor and kernel must agree wholeheartedly
    about what format the page tables are in and what they contain.
    PAGE_TABLE_ISOLATION, unfortunately, changes the rules and they
    can not be used together.

    I've seen conflicting feedback from maintainers lately about whether they
    want the Kconfig magic to go first or last in a patch series. It's going
    last here because the partially-applied series leads to kernels that can
    not boot in a bunch of cases. I did a run through the entire series with
    CONFIG_PAGE_TABLE_ISOLATION=y to look for build errors, though.

    [ tglx: Removed SMP and !PARAVIRT dependencies as they not longer exist ]

    Signed-off-by: Dave Hansen
    Signed-off-by: Thomas Gleixner
    Cc: Andy Lutomirski
    Cc: Boris Ostrovsky
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: David Laight
    Cc: Denys Vlasenko
    Cc: Eduardo Valentin
    Cc: Greg KH
    Cc: H. Peter Anvin
    Cc: Josh Poimboeuf
    Cc: Juergen Gross
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Will Deacon
    Cc: aliguori@amazon.com
    Cc: daniel.gruss@iaik.tugraz.at
    Cc: hughd@google.com
    Cc: keescook@google.com
    Cc: linux-mm@kvack.org
    Signed-off-by: Ingo Molnar
    Signed-off-by: Greg Kroah-Hartman

    Dave Hansen
     

14 Dec, 2017

2 commits

  • [ Upstream commit 4633307e5ed6128975595df43f796a10c41d11c1 ]

    Fixes: d07881d2edb0 ("apparmor: move new_null_profile to after profile lookup fns()")
    Reported-by: Seth Arnold
    Signed-off-by: John Johansen
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    John Johansen
     
  • commit 18026d866801d0c52e5550210563222bd6c7191d upstream.

    keyctl_restrict_keyring() allows through a NULL restriction when the
    "type" is non-NULL, which causes a NULL pointer dereference in
    asymmetric_lookup_restriction() when it calls strcmp() on the
    restriction string.

    But no key types actually use a "NULL restriction" to mean anything, so
    update keyctl_restrict_keyring() to reject it with EINVAL.

    Reported-by: syzbot
    Fixes: 97d3aa0f3134 ("KEYS: Add a lookup_restriction function for the asymmetric key type")
    Signed-off-by: Eric Biggers
    Signed-off-by: David Howells
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers