13 Feb, 2019

1 commit

  • [ Upstream commit 5b841bfab695e3b8ae793172a9ff7990f99cc3e2 ]

    Function smack_key_permission() only issues smack requests for the
    following operations:
    - KEY_NEED_READ (issues MAY_READ)
    - KEY_NEED_WRITE (issues MAY_WRITE)
    - KEY_NEED_LINK (issues MAY_WRITE)
    - KEY_NEED_SETATTR (issues MAY_WRITE)
    A blank smack request is issued in all other cases, resulting in
    smack access being granted if there is any rule defined between
    subject and object, or denied with -EACCES otherwise.

    Request MAY_READ access for KEY_NEED_SEARCH and KEY_NEED_VIEW.
    Fix the logic in the unlikely case when both MAY_READ and
    MAY_WRITE are needed. Validate access permission field for valid
    contents.

    Signed-off-by: Zoran Markovic
    Signed-off-by: Casey Schaufler
    Cc: Casey Schaufler
    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Signed-off-by: Sasha Levin

    Zoran Markovic
     

14 Nov, 2018

1 commit

  • [ Upstream commit dcb569cf6ac99ca899b8109c128b6ae52477a015 ]

    This fixes a pair of problems in the Smack ptrace checks
    related to checking capabilities. In both cases, as reported
    by Lukasz Pawelczyk, the raw capability calls are used rather
    than the Smack wrapper that check addition restrictions.
    In one case, as reported by Jann Horn, the wrong task is being
    checked for capabilities.

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

    Casey Schaufler
     

16 Aug, 2018

1 commit


14 Aug, 2018

1 commit

  • Pull vfs open-related updates from Al Viro:

    - "do we need fput() or put_filp()" rules are gone - it's always fput()
    now. We keep track of that state where it belongs - in ->f_mode.

    - int *opened mess killed - in finish_open(), in ->atomic_open()
    instances and in fs/namei.c code around do_last()/lookup_open()/atomic_open().

    - alloc_file() wrappers with saner calling conventions are introduced
    (alloc_file_clone() and alloc_file_pseudo()); callers converted, with
    much simplification.

    - while we are at it, saner calling conventions for path_init() and
    link_path_walk(), simplifying things inside fs/namei.c (both on
    open-related paths and elsewhere).

    * 'work.open3' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (40 commits)
    few more cleanups of link_path_walk() callers
    allow link_path_walk() to take ERR_PTR()
    make path_init() unconditionally paired with terminate_walk()
    document alloc_file() changes
    make alloc_file() static
    do_shmat(): grab shp->shm_file earlier, switch to alloc_file_clone()
    new helper: alloc_file_clone()
    create_pipe_files(): switch the first allocation to alloc_file_pseudo()
    anon_inode_getfile(): switch to alloc_file_pseudo()
    hugetlb_file_setup(): switch to alloc_file_pseudo()
    ocxlflash_getfile(): switch to alloc_file_pseudo()
    cxl_getfile(): switch to alloc_file_pseudo()
    ... and switch shmem_file_setup() to alloc_file_pseudo()
    __shmem_file_setup(): reorder allocations
    new wrapper: alloc_file_pseudo()
    kill FILE_{CREATED,OPENED}
    switch atomic_open() and lookup_open() to returning 0 in all success cases
    document ->atomic_open() changes
    ->atomic_open(): return 0 in all success cases
    get rid of 'opened' in path_openat() and the helpers downstream
    ...

    Linus Torvalds
     

24 Jul, 2018

3 commits


12 Jul, 2018

1 commit


23 Jun, 2018

1 commit

  • 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

    Casey Schaufler
     

06 Jun, 2018

2 commits


05 May, 2018

1 commit


12 Apr, 2018

3 commits

  • There is a permission discrepancy when consulting msq ipc object
    metadata between /proc/sysvipc/msg (0444) and the MSG_STAT shmctl
    command. The later does permission checks for the object vs S_IRUGO.
    As such there can be cases where EACCESS is returned via syscall but the
    info is displayed anyways in the procfs files.

    While this might have security implications via info leaking (albeit no
    writing to the msq metadata), this behavior goes way back and showing
    all the objects regardless of the permissions was most likely an
    overlook - so we are stuck with it. Furthermore, modifying either the
    syscall or the procfs file can cause userspace programs to break (ie
    ipcs). Some applications require getting the procfs info (without root
    privileges) and can be rather slow in comparison with a syscall -- up to
    500x in some reported cases for shm.

    This patch introduces a new MSG_STAT_ANY command such that the msq ipc
    object permissions are ignored, and only audited instead. In addition,
    I've left the lsm security hook checks in place, as if some policy can
    block the call, then the user has no other choice than just parsing the
    procfs file.

    Link: http://lkml.kernel.org/r/20180215162458.10059-4-dave@stgolabs.net
    Signed-off-by: Davidlohr Bueso
    Reported-by: Robert Kettler
    Cc: Eric W. Biederman
    Cc: Kees Cook
    Cc: Manfred Spraul
    Cc: Michael Kerrisk
    Cc: Michal Hocko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Davidlohr Bueso
     
  • There is a permission discrepancy when consulting shm ipc object
    metadata between /proc/sysvipc/sem (0444) and the SEM_STAT semctl
    command. The later does permission checks for the object vs S_IRUGO.
    As such there can be cases where EACCESS is returned via syscall but the
    info is displayed anyways in the procfs files.

    While this might have security implications via info leaking (albeit no
    writing to the sma metadata), this behavior goes way back and showing
    all the objects regardless of the permissions was most likely an
    overlook - so we are stuck with it. Furthermore, modifying either the
    syscall or the procfs file can cause userspace programs to break (ie
    ipcs). Some applications require getting the procfs info (without root
    privileges) and can be rather slow in comparison with a syscall -- up to
    500x in some reported cases for shm.

    This patch introduces a new SEM_STAT_ANY command such that the sem ipc
    object permissions are ignored, and only audited instead. In addition,
    I've left the lsm security hook checks in place, as if some policy can
    block the call, then the user has no other choice than just parsing the
    procfs file.

    Link: http://lkml.kernel.org/r/20180215162458.10059-3-dave@stgolabs.net
    Signed-off-by: Davidlohr Bueso
    Reported-by: Robert Kettler
    Cc: Eric W. Biederman
    Cc: Kees Cook
    Cc: Manfred Spraul
    Cc: Michael Kerrisk
    Cc: Michal Hocko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Davidlohr Bueso
     
  • Patch series "sysvipc: introduce STAT_ANY commands", v2.

    The following patches adds the discussed (see [1]) new command for shm
    as well as for sems and msq as they are subject to the same
    discrepancies for ipc object permission checks between the syscall and
    via procfs. These new commands are justified in that (1) we are stuck
    with this semantics as changing syscall and procfs can break userland;
    and (2) some users can benefit from performance (for large amounts of
    shm segments, for example) from not having to parse the procfs
    interface.

    Once merged, I will submit the necesary manpage updates. But I'm thinking
    something like:

    : diff --git a/man2/shmctl.2 b/man2/shmctl.2
    : index 7bb503999941..bb00bbe21a57 100644
    : --- a/man2/shmctl.2
    : +++ b/man2/shmctl.2
    : @@ -41,6 +41,7 @@
    : .\" 2005-04-25, mtk -- noted aberrant Linux behavior w.r.t. new
    : .\" attaches to a segment that has already been marked for deletion.
    : .\" 2005-08-02, mtk: Added IPC_INFO, SHM_INFO, SHM_STAT descriptions.
    : +.\" 2018-02-13, dbueso: Added SHM_STAT_ANY description.
    : .\"
    : .TH SHMCTL 2 2017-09-15 "Linux" "Linux Programmer's Manual"
    : .SH NAME
    : @@ -242,6 +243,18 @@ However, the
    : argument is not a segment identifier, but instead an index into
    : the kernel's internal array that maintains information about
    : all shared memory segments on the system.
    : +.TP
    : +.BR SHM_STAT_ANY " (Linux-specific)"
    : +Return a
    : +.I shmid_ds
    : +structure as for
    : +.BR SHM_STAT .
    : +However, the
    : +.I shm_perm.mode
    : +is not checked for read access for
    : +.IR shmid ,
    : +resembing the behaviour of
    : +/proc/sysvipc/shm.
    : .PP
    : The caller can prevent or allow swapping of a shared
    : memory segment with the following \fIcmd\fP values:
    : @@ -287,7 +300,7 @@ operation returns the index of the highest used entry in the
    : kernel's internal array recording information about all
    : shared memory segments.
    : (This information can be used with repeated
    : -.B SHM_STAT
    : +.B SHM_STAT/SHM_STAT_ANY
    : operations to obtain information about all shared memory segments
    : on the system.)
    : A successful
    : @@ -328,7 +341,7 @@ isn't accessible.
    : \fIshmid\fP is not a valid identifier, or \fIcmd\fP
    : is not a valid command.
    : Or: for a
    : -.B SHM_STAT
    : +.B SHM_STAT/SHM_STAT_ANY
    : operation, the index value specified in
    : .I shmid
    : referred to an array slot that is currently unused.

    This patch (of 3):

    There is a permission discrepancy when consulting shm ipc object metadata
    between /proc/sysvipc/shm (0444) and the SHM_STAT shmctl command. The
    later does permission checks for the object vs S_IRUGO. As such there can
    be cases where EACCESS is returned via syscall but the info is displayed
    anyways in the procfs files.

    While this might have security implications via info leaking (albeit no
    writing to the shm metadata), this behavior goes way back and showing all
    the objects regardless of the permissions was most likely an overlook - so
    we are stuck with it. Furthermore, modifying either the syscall or the
    procfs file can cause userspace programs to break (ie ipcs). Some
    applications require getting the procfs info (without root privileges) and
    can be rather slow in comparison with a syscall -- up to 500x in some
    reported cases.

    This patch introduces a new SHM_STAT_ANY command such that the shm ipc
    object permissions are ignored, and only audited instead. In addition,
    I've left the lsm security hook checks in place, as if some policy can
    block the call, then the user has no other choice than just parsing the
    procfs file.

    [1] https://lkml.org/lkml/2017/12/19/220

    Link: http://lkml.kernel.org/r/20180215162458.10059-2-dave@stgolabs.net
    Signed-off-by: Davidlohr Bueso
    Acked-by: Michal Hocko
    Cc: Michael Kerrisk
    Cc: Manfred Spraul
    Cc: Eric W. Biederman
    Cc: Kees Cook
    Cc: Robert Kettler
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Davidlohr Bueso
     

08 Apr, 2018

3 commits

  • …morris/linux-security

    Pull integrity updates from James Morris:
    "A mixture of bug fixes, code cleanup, and continues to close
    IMA-measurement, IMA-appraisal, and IMA-audit gaps.

    Also note the addition of a new cred_getsecid LSM hook by Matthew
    Garrett:

    For IMA purposes, we want to be able to obtain the prepared secid
    in the bprm structure before the credentials are committed. Add a
    cred_getsecid hook that makes this possible.

    which is used by a new CREDS_CHECK target in IMA:

    In ima_bprm_check(), check with both the existing process
    credentials and the credentials that will be committed when the new
    process is started. This will not change behaviour unless the
    system policy is extended to include CREDS_CHECK targets -
    BPRM_CHECK will continue to check the same credentials that it did
    previously"

    * 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    ima: Fallback to the builtin hash algorithm
    ima: Add smackfs to the default appraise/measure list
    evm: check for remount ro in progress before writing
    ima: Improvements in ima_appraise_measurement()
    ima: Simplify ima_eventsig_init()
    integrity: Remove unused macro IMA_ACTION_RULE_FLAGS
    ima: drop vla in ima_audit_measurement()
    ima: Fix Kconfig to select TPM 2.0 CRB interface
    evm: Constify *integrity_status_msg[]
    evm: Move evm_hmac and evm_hash from evm_main.c to evm_crypto.c
    fuse: define the filesystem as untrusted
    ima: fail signature verification based on policy
    ima: clear IMA_HASH
    ima: re-evaluate files on privileged mounted filesystems
    ima: fail file signature verification on non-init mounted filesystems
    IMA: Support using new creds in appraisal policy
    security: Add a cred_getsecid hook

    Linus Torvalds
     
  • Pull smack update from James Morris:
    "One small change for Automotive Grade Linux"

    * 'next-smack' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    Smack: Handle CGROUP2 in the same way that CGROUP

    Linus Torvalds
     
  • Pull general security layer updates from James Morris:

    - Convert security hooks from list to hlist, a nice cleanup, saving
    about 50% of space, from Sargun Dhillon.

    - Only pass the cred, not the secid, to kill_pid_info_as_cred and
    security_task_kill (as the secid can be determined from the cred),
    from Stephen Smalley.

    - Close a potential race in kernel_read_file(), by making the file
    unwritable before calling the LSM check (vs after), from Kees Cook.

    * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    security: convert security hooks to use hlist
    exec: Set file unwritable before LSM check
    usb, signal, security: only pass the cred, not the secid, to kill_pid_info_as_cred and security_task_kill

    Linus Torvalds
     

28 Mar, 2018

1 commit

  • Rename the variables shp, sma, msq to isp. As that is how the code already
    refers to those variables.

    Collapse smack_of_shm, smack_of_sem, and smack_of_msq into smack_of_ipc,
    as the three functions had become completely identical.

    Collapse smack_shm_alloc_security, smack_sem_alloc_security and
    smack_msg_queue_alloc_security into smack_ipc_alloc_security as the three
    functions had become identical.

    Collapse smack_shm_free_security, smack_sem_free_security and
    smack_msg_queue_free_security into smack_ipc_free_security as the
    three functions had become identical.

    Requested-by: Casey Schaufler
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

27 Mar, 2018

1 commit


23 Mar, 2018

4 commits


07 Mar, 2018

1 commit

  • …ed and security_task_kill

    commit d178bc3a708f39cbfefc3fab37032d3f2511b4ec ("user namespace: usb:
    make usb urbs user namespace aware (v2)") changed kill_pid_info_as_uid
    to kill_pid_info_as_cred, saving and passing a cred structure instead of
    uids. Since the secid can be obtained from the cred, drop the secid fields
    from the usb_dev_state and async structures, and drop the secid argument to
    kill_pid_info_as_cred. Replace the secid argument to security_task_kill
    with the cred. Update SELinux, Smack, and AppArmor to use the cred, which
    avoids the need for Smack and AppArmor to use a secid at all in this hook.
    Further changes to Smack might still be required to take full advantage of
    this change, since it should now be possible to perform capability
    checking based on the supplied cred. The changes to Smack and AppArmor
    have only been compile-tested.

    Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
    Acked-by: Paul Moore <paul@paul-moore.com>
    Acked-by: Casey Schaufler <casey@schaufler-ca.com>
    Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Acked-by: John Johansen <john.johansen@canonical.com>
    Signed-off-by: James Morris <james.morris@microsoft.com>

    Stephen Smalley
     

01 Mar, 2018

1 commit


11 Jan, 2018

1 commit

  • Smack: Privilege check on key operations

    Operations on key objects are subjected to Smack policy
    even if the process is privileged. This is inconsistent
    with the general behavior of Smack and may cause issues
    with authentication by privileged daemons. This patch
    allows processes with CAP_MAC_OVERRIDE to access keys
    even if the Smack rules indicate otherwise.

    Reported-by: Jose Bollo
    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

28 Dec, 2017

1 commit


14 Nov, 2017

1 commit

  • Pull general security subsystem updates from James Morris:
    "TPM (from Jarkko):
    - essential clean up for tpm_crb so that ARM64 and x86 versions do
    not distract each other as much as before

    - /dev/tpm0 rejects now too short writes (shorter buffer than
    specified in the command header

    - use DMA-safe buffer in tpm_tis_spi

    - otherwise mostly minor fixes.

    Smack:
    - base support for overlafs

    Capabilities:
    - BPRM_FCAPS fixes, from Richard Guy Briggs:

    The audit subsystem is adding a BPRM_FCAPS record when auditing
    setuid application execution (SYSCALL execve). This is not expected
    as it was supposed to be limited to when the file system actually
    had capabilities in an extended attribute. It lists all
    capabilities making the event really ugly to parse what is
    happening. The PATH record correctly records the setuid bit and
    owner. Suppress the BPRM_FCAPS record on set*id.

    TOMOYO:
    - Y2038 timestamping fixes"

    * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (28 commits)
    MAINTAINERS: update the IMA, EVM, trusted-keys, encrypted-keys entries
    Smack: Base support for overlayfs
    MAINTAINERS: remove David Safford as maintainer for encrypted+trusted keys
    tomoyo: fix timestamping for y2038
    capabilities: audit log other surprising conditions
    capabilities: fix logic for effective root or real root
    capabilities: invert logic for clarity
    capabilities: remove a layer of conditional logic
    capabilities: move audit log decision to function
    capabilities: use intuitive names for id changes
    capabilities: use root_priveleged inline to clarify logic
    capabilities: rename has_cap to has_fcap
    capabilities: intuitive names for cap gain status
    capabilities: factor out cap_bprm_set_creds privileged root
    tpm, tpm_tis: use ARRAY_SIZE() to define TPM_HID_USR_IDX
    tpm: fix duplicate inline declaration specifier
    tpm: fix type of a local variables in tpm_tis_spi.c
    tpm: fix type of a local variable in tpm2_map_command()
    tpm: fix type of a local variable in tpm2_get_cc_attrs_tbl()
    tpm-dev-common: Reject too short writes
    ...

    Linus Torvalds
     

02 Nov, 2017

1 commit

  • Supply the Smack module hooks in support of overlayfs.
    Ensure that the Smack label of new files gets the correct
    value when a directory is transmuting. Original implementation
    by Romanini Daniele, with a few tweaks added.

    Signed-off-by: Romanini Daniele
    Signed-off-by: Casey Schaufler
    Signed-off-by: James Morris

    Casey Schaufler
     

04 Oct, 2017

1 commit

  • security_inode_getsecurity() provides the text string value
    of a security attribute. It does not provide a "secctx".
    The code in xattr_getsecurity() that calls security_inode_getsecurity()
    and then calls security_release_secctx() happened to work because
    SElinux and Smack treat the attribute and the secctx the same way.
    It fails for cap_inode_getsecurity(), because that module has no
    secctx that ever needs releasing. It turns out that Smack is the
    one that's doing things wrong by not allocating memory when instructed
    to do so by the "alloc" parameter.

    The fix is simple enough. Change the security_release_secctx() to
    kfree() because it isn't a secctx being returned by
    security_inode_getsecurity(). Change Smack to allocate the string when
    told to do so.

    Note: this also fixes memory leaks for LSMs which implement
    inode_getsecurity but not release_secctx, such as capabilities.

    Signed-off-by: Casey Schaufler
    Reported-by: Konstantin Khlebnikov
    Cc: stable@vger.kernel.org
    Signed-off-by: James Morris

    Casey Schaufler
     

08 Sep, 2017

1 commit

  • Pull secureexec update from Kees Cook:
    "This series has the ultimate goal of providing a sane stack rlimit
    when running set*id processes.

    To do this, the bprm_secureexec LSM hook is collapsed into the
    bprm_set_creds hook so the secureexec-ness of an exec can be
    determined early enough to make decisions about rlimits and the
    resulting memory layouts. Other logic acting on the secureexec-ness of
    an exec is similarly consolidated. Capabilities needed some special
    handling, but the refactoring removed other special handling, so that
    was a wash"

    * tag 'secureexec-v4.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
    exec: Consolidate pdeath_signal clearing
    exec: Use sane stack rlimit under secureexec
    exec: Consolidate dumpability logic
    smack: Remove redundant pdeath_signal clearing
    exec: Use secureexec for clearing pdeath_signal
    exec: Use secureexec for setting dumpability
    LSM: drop bprm_secureexec hook
    commoncap: Move cap_elevated calculation into bprm_set_creds
    commoncap: Refactor to remove bprm_secureexec hook
    smack: Refactor to remove bprm_secureexec hook
    selinux: Refactor to remove bprm_secureexec hook
    apparmor: Refactor to remove bprm_secureexec hook
    binfmt: Introduce secureexec flag
    exec: Correct comments about "point of no return"
    exec: Rename bprm->cred_prepared to called_set_creds

    Linus Torvalds
     

02 Aug, 2017

3 commits

  • This removes the redundant pdeath_signal clearing in Smack: the check in
    smack_bprm_committing_creds() matches the check in smack_bprm_set_creds()
    (which used to be in the now-removed smack_bprm_securexec() hook) and
    since secureexec is now being checked for clearing pdeath_signal, this
    is redundant to the common exec code.

    Signed-off-by: Kees Cook
    Acked-by: Serge Hallyn
    Reviewed-by: James Morris
    Reviewed-by: Casey Schaufler

    Kees Cook
     
  • The Smack bprm_secureexec hook can be merged with the bprm_set_creds
    hook since it's dealing with the same information, and all of the details
    are finalized during the first call to the bprm_set_creds hook via
    prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
    via bprm->called_set_creds).

    Here, the test can just happen at the end of the bprm_set_creds hook,
    and the bprm_secureexec hook can be dropped.

    Signed-off-by: Kees Cook
    Acked-by: Serge Hallyn
    Reviewed-by: James Morris
    Reviewed-by: Casey Schaufler

    Kees Cook
     
  • The cred_prepared bprm flag has a misleading name. It has nothing to do
    with the bprm_prepare_cred hook, and actually tracks if bprm_set_creds has
    been called. Rename this flag and improve its comment.

    Cc: David Howells
    Cc: Stephen Smalley
    Cc: Casey Schaufler
    Signed-off-by: Kees Cook
    Acked-by: John Johansen
    Acked-by: James Morris
    Acked-by: Paul Moore
    Acked-by: Serge Hallyn

    Kees Cook
     

01 Aug, 2017

1 commit


02 Jun, 2017

3 commits


10 May, 2017

1 commit

  • Pull misc vfs updates from Al Viro:
    "Assorted bits and pieces from various people. No common topic in this
    pile, sorry"

    * 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    fs/affs: add rename exchange
    fs/affs: add rename2 to prepare multiple methods
    Make stat/lstat/fstatat pass AT_NO_AUTOMOUNT to vfs_statx()
    fs: don't set *REFERENCED on single use objects
    fs: compat: Remove warning from COMPATIBLE_IOCTL
    remove pointless extern of atime_need_update_rcu()
    fs: completely ignore unknown open flags
    fs: add a VALID_OPEN_FLAGS
    fs: remove _submit_bh()
    fs: constify tree_descr arrays passed to simple_fill_super()
    fs: drop duplicate header percpu-rwsem.h
    fs/affs: bugfix: Write files greater than page size on OFS
    fs/affs: bugfix: enable writes on OFS disks
    fs/affs: remove node generation check
    fs/affs: import amigaffs.h
    fs/affs: bugfix: make symbolic links work again

    Linus Torvalds