13 Dec, 2018

1 commit

  • Historically a lot of these existed because we did not have
    a distinction between what was modular code and what was providing
    support to modules via EXPORT_SYMBOL and friends. That changed
    when we forked out support for the latter into the export.h file.
    This means we should be able to reduce the usage of module.h
    in code that is obj-y Makefile or bool Kconfig.

    The advantage in removing such instances is that module.h itself
    sources about 15 other headers; adding significantly to what we feed
    cpp, and it can obscure what headers we are effectively using.

    Since module.h might have been the implicit source for init.h
    (for __init) and for export.h (for EXPORT_SYMBOL) we consider each
    instance for the presence of either and replace as needed.

    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: John Johansen
    Cc: Mimi Zohar
    Cc: Dmitry Kasatkin
    Cc: David Howells
    Cc: linux-security-module@vger.kernel.org
    Cc: linux-integrity@vger.kernel.org
    Cc: keyrings@vger.kernel.org
    Signed-off-by: Paul Gortmaker
    Signed-off-by: James Morris

    Paul Gortmaker
     

24 Oct, 2018

1 commit

  • Pull security subsystem updates from James Morris:
    "In this patchset, there are a couple of minor updates, as well as some
    reworking of the LSM initialization code from Kees Cook (these prepare
    the way for ordered stackable LSMs, but are a valuable cleanup on
    their own)"

    * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    LSM: Don't ignore initialization failures
    LSM: Provide init debugging infrastructure
    LSM: Record LSM name in struct lsm_info
    LSM: Convert security_initcall() into DEFINE_LSM()
    vmlinux.lds.h: Move LSM_TABLE into INIT_DATA
    LSM: Convert from initcall to struct lsm_info
    LSM: Remove initcall tracing
    LSM: Rename .security_initcall section to .lsm_info
    vmlinux.lds.h: Avoid copy/paste of security_init section
    LSM: Correctly announce start of LSM initialization
    security: fix LSM description location
    keys: Fix the use of the C++ keyword "private" in uapi/linux/keyctl.h
    seccomp: remove unnecessary unlikely()
    security: tomoyo: Fix obsolete function
    security/capabilities: remove check for -EINVAL

    Linus Torvalds
     

11 Oct, 2018

6 commits

  • LSM initialization failures have traditionally been ignored. We should
    at least WARN when something goes wrong.

    Signed-off-by: Kees Cook
    Reviewed-by: Casey Schaufler
    Reviewed-by: John Johansen
    Signed-off-by: James Morris

    Kees Cook
     
  • Booting with "lsm.debug" will report future details on how LSM ordering
    decisions are being made.

    Signed-off-by: Kees Cook
    Reviewed-by: Casey Schaufler
    Reviewed-by: John Johansen
    Reviewed-by: James Morris
    Signed-off-by: James Morris

    Kees Cook
     
  • In preparation for doing more interesting LSM init probing, this converts
    the existing initcall system into an explicit call into a function pointer
    from a section-collected struct lsm_info array.

    Signed-off-by: Kees Cook
    Reviewed-by: Casey Schaufler
    Reviewed-by: James Morris
    Reviewed-by: John Johansen
    Signed-off-by: James Morris

    Kees Cook
     
  • This partially reverts commit 58eacfffc417 ("init, tracing: instrument
    security and console initcall trace events") since security init calls
    are about to no longer resemble regular init calls.

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

    Kees Cook
     
  • In preparation for switching from initcall to just a regular set of
    pointers in a section, rename the internal section name.

    Signed-off-by: Kees Cook
    Reviewed-by: Casey Schaufler
    Reviewed-by: James Morris
    Reviewed-by: John Johansen
    Signed-off-by: James Morris

    Kees Cook
     
  • For a while now, the LSM core has said it was "initializED", rather than
    "initializING". This adjust the report to be more accurate (i.e. before
    this was reported before any LSMs had been initialized.)

    Signed-off-by: Kees Cook
    Reviewed-by: Casey Schaufler
    Reviewed-by: James Morris
    Reviewed-by: John Johansen
    Signed-off-by: James Morris

    Kees Cook
     

03 Oct, 2018

1 commit

  • Linus recently observed that if we did not worry about the padding
    member in struct siginfo it is only about 48 bytes, and 48 bytes is
    much nicer than 128 bytes for allocating on the stack and copying
    around in the kernel.

    The obvious thing of only adding the padding when userspace is
    including siginfo.h won't work as there are sigframe definitions in
    the kernel that embed struct siginfo.

    So split siginfo in two; kernel_siginfo and siginfo. Keeping the
    traditional name for the userspace definition. While the version that
    is used internally to the kernel and ultimately will not be padded to
    128 bytes is called kernel_siginfo.

    The definition of struct kernel_siginfo I have put in include/signal_types.h

    A set of buildtime checks has been added to verify the two structures have
    the same field offsets.

    To make it easy to verify the change kernel_siginfo retains the same
    size as siginfo. The reduction in size comes in a following change.

    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

23 Aug, 2018

1 commit

  • Allow the initcall tables to be emitted using relative references that
    are only half the size on 64-bit architectures and don't require fixups
    at runtime on relocatable kernels.

    Link: http://lkml.kernel.org/r/20180704083651.24360-5-ard.biesheuvel@linaro.org
    Acked-by: James Morris
    Acked-by: Sergey Senozhatsky
    Acked-by: Petr Mladek
    Acked-by: Michael Ellerman
    Acked-by: Ingo Molnar
    Signed-off-by: Ard Biesheuvel
    Cc: Arnd Bergmann
    Cc: Benjamin Herrenschmidt
    Cc: Bjorn Helgaas
    Cc: Catalin Marinas
    Cc: James Morris
    Cc: Jessica Yu
    Cc: Josh Poimboeuf
    Cc: Kees Cook
    Cc: Nicolas Pitre
    Cc: Paul Mackerras
    Cc: Russell King
    Cc: "Serge E. Hallyn"
    Cc: Steven Rostedt
    Cc: Thomas Garnier
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ard Biesheuvel
     

16 Aug, 2018

2 commits

  • …morris/linux-security

    Pull integrity updates from James Morris:
    "This adds support for EVM signatures based on larger digests, contains
    a new audit record AUDIT_INTEGRITY_POLICY_RULE to differentiate the
    IMA policy rules from the IMA-audit messages, addresses two deadlocks
    due to either loading or searching for crypto algorithms, and cleans
    up the audit messages"

    * 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    EVM: fix return value check in evm_write_xattrs()
    integrity: prevent deadlock during digsig verification.
    evm: Allow non-SHA1 digital signatures
    evm: Don't deadlock if a crypto algorithm is unavailable
    integrity: silence warning when CONFIG_SECURITYFS is not enabled
    ima: Differentiate auditing policy rules from "audit" actions
    ima: Do not audit if CONFIG_INTEGRITY_AUDIT is not set
    ima: Use audit_log_format() rather than audit_log_string()
    ima: Call audit_log_string() rather than logging it untrusted

    Linus Torvalds
     
  • Pull security subsystem updates from James Morris:

    - kstrdup() return value fix from Eric Biggers

    - Add new security_load_data hook to differentiate security checking of
    kernel-loaded binaries in the case of there being no associated file
    descriptor, from Mimi Zohar.

    - Add ability to IMA to specify a policy at build-time, rather than
    just via command line params or by loading a custom policy, from
    Mimi.

    - Allow IMA and LSMs to prevent sysfs firmware load fallback (e.g. if
    using signed firmware), from Mimi.

    - Allow IMA to deny loading of kexec kernel images, as they cannot be
    measured by IMA, from Mimi.

    * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    security: check for kstrdup() failure in lsm_append()
    security: export security_kernel_load_data function
    ima: based on policy warn about loading firmware (pre-allocated buffer)
    module: replace the existing LSM hook in init_module
    ima: add build time policy
    ima: based on policy require signed firmware (sysfs fallback)
    firmware: add call to LSM hook before firmware sysfs fallback
    ima: based on policy require signed kexec kernel images
    kexec: add call to LSM hook in original kexec_load syscall
    security: define new LSM hook named security_kernel_load_data
    MAINTAINERS: remove the outdated "LINUX SECURITY MODULE (LSM) FRAMEWORK" entry

    Linus Torvalds
     

18 Jul, 2018

3 commits

  • This patch aimed to prevent deadlock during digsig verification.The point
    of issue - user space utility modprobe and/or it's dependencies (ld-*.so,
    libz.so.*, libc-*.so and /lib/modules/ files) that could be used for
    kernel modules load during digsig verification and could be signed by
    digsig in the same time.

    First at all, look at crypto_alloc_tfm() work algorithm:
    crypto_alloc_tfm() will first attempt to locate an already loaded
    algorithm. If that fails and the kernel supports dynamically loadable
    modules, it will then attempt to load a module of the same name or alias.
    If that fails it will send a query to any loaded crypto manager to
    construct an algorithm on the fly.

    We have situation, when public_key_verify_signature() in case of RSA
    algorithm use alg_name to store internal information in order to construct
    an algorithm on the fly, but crypto_larval_lookup() will try to use
    alg_name in order to load kernel module with same name.

    1) we can't do anything with crypto module work, since it designed to work
    exactly in this way;
    2) we can't globally filter module requests for modprobe, since it
    designed to work with any requests.

    In this patch, I propose add an exception for "crypto-pkcs1pad(rsa,*)"
    module requests only in case of enabled integrity asymmetric keys support.
    Since we don't have any real "crypto-pkcs1pad(rsa,*)" kernel modules for
    sure, we are safe to fail such module request from crypto_larval_lookup().
    In this way we prevent modprobe execution during digsig verification and
    avoid possible deadlock if modprobe and/or it's dependencies also signed
    with digsig.

    Requested "crypto-pkcs1pad(rsa,*)" kernel module name formed by:
    1) "pkcs1pad(rsa,%s)" in public_key_verify_signature();
    2) "crypto-%s" / "crypto-%s-all" in crypto_larval_lookup().
    "crypto-pkcs1pad(rsa," part of request is a constant and unique and could
    be used as filter.

    Signed-off-by: Mikhail Kurinnoi
    Signed-off-by: Mimi Zohar

    include/linux/integrity.h | 13 +++++++++++++
    security/integrity/digsig_asymmetric.c | 23 +++++++++++++++++++++++
    security/security.c | 7 ++++++-
    3 files changed, 42 insertions(+), 1 deletion(-)

    Mikhail Kurinnoi
     
  • 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

    Eric Biggers
     
  • The firmware_loader can be built as a loadable module, which now
    fails when CONFIG_SECURITY is enabled, because a call to the
    security_kernel_load_data() function got added, and this is
    not exported to modules:

    ERROR: "security_kernel_load_data" [drivers/base/firmware_loader/firmware_class.ko] undefined!

    Add an EXPORT_SYMBOL_GPL() to make it available here.

    Fixes: 6e852651f28e ("firmware: add call to LSM hook before firmware sysfs fallback")
    Signed-off-by: Arnd Bergmann
    Signed-off-by: James Morris

    Arnd Bergmann
     

17 Jul, 2018

2 commits

  • The original kexec_load syscall can not verify file signatures, nor can
    the kexec image be measured. Based on policy, deny the kexec_load
    syscall.

    Signed-off-by: Mimi Zohar
    Cc: Eric Biederman
    Cc: Kees Cook
    Reviewed-by: Kees Cook
    Signed-off-by: James Morris

    Mimi Zohar
     
  • Differentiate between the kernel reading a file specified by userspace
    from the kernel loading a buffer containing data provided by userspace.
    This patch defines a new LSM hook named security_kernel_load_data().

    Signed-off-by: Mimi Zohar
    Cc: Eric Biederman
    Cc: Luis R. Rodriguez
    Cc: Kees Cook
    Cc: Casey Schaufler
    Acked-by: Serge Hallyn
    Acked-by: Kees Cook
    Signed-off-by: James Morris

    Mimi Zohar
     

12 Jul, 2018

2 commits


05 May, 2018

1 commit

  • Right now the LSM labels for socketpairs are always uninitialized,
    since there is no security hook for the socketpair() syscall. This
    patch adds the required hooks so LSMs can properly label socketpairs.
    This allows SO_PEERSEC to return useful information on those sockets.

    Note that the behavior of socketpair() can be emulated by creating a
    listener socket, connecting to it, and then discarding the initial
    listener socket. With this workaround, SO_PEERSEC would return the
    caller's security context. However, with socketpair(), the uninitialized
    context is returned unconditionally. This is unexpected and makes
    socketpair() less useful in situations where the security context is
    crucial to the application.

    With the new socketpair-hook this disparity can be solved by making
    socketpair() return the expected security context.

    Acked-by: Serge Hallyn
    Signed-off-by: Tom Gundersen
    Signed-off-by: David Herrmann
    Signed-off-by: James Morris

    David Herrmann
     

11 Apr, 2018

1 commit

  • Pull tracing updates from Steven Rostedt:
    "New features:

    - Tom Zanussi's extended histogram work.

    This adds the synthetic events to have histograms from multiple
    event data Adds triggers "onmatch" and "onmax" to call the
    synthetic events Several updates to the histogram code from this

    - Allow way to nest ring buffer calls in the same context

    - Allow absolute time stamps in ring buffer

    - Rewrite of filter code parsing based on Al Viro's suggestions

    - Setting of trace_clock to global if TSC is unstable (on boot)

    - Better OOM handling when allocating large ring buffers

    - Added initcall tracepoints (consolidated initcall_debug code with
    them)

    And other various fixes and clean ups"

    * tag 'trace-v4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (68 commits)
    init: Have initcall_debug still work without CONFIG_TRACEPOINTS
    init, tracing: Have printk come through the trace events for initcall_debug
    init, tracing: instrument security and console initcall trace events
    init, tracing: Add initcall trace events
    tracing: Add rcu dereference annotation for test func that touches filter->prog
    tracing: Add rcu dereference annotation for filter->prog
    tracing: Fixup logic inversion on setting trace_global_clock defaults
    tracing: Hide global trace clock from lockdep
    ring-buffer: Add set/clear_current_oom_origin() during allocations
    ring-buffer: Check if memory is available before allocation
    lockdep: Add print_irqtrace_events() to __warn
    vsprintf: Do not preprocess non-dereferenced pointers for bprintf (%px and %pK)
    tracing: Uninitialized variable in create_tracing_map_fields()
    tracing: Make sure variable string fields are NULL-terminated
    tracing: Add action comparisons when testing matching hist triggers
    tracing: Don't add flag strings when displaying variable references
    tracing: Fix display of hist trigger expressions containing timestamps
    ftrace: Drop a VLA in module_exists()
    tracing: Mention trace_clock=global when warning about unstable clocks
    tracing: Default to using trace_global_clock if sched_clock is unstable
    ...

    Linus Torvalds
     

08 Apr, 2018

2 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 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
     

07 Apr, 2018

1 commit

  • Pull SELinux updates from Paul Moore:
    "A bigger than usual pull request for SELinux, 13 patches (lucky!)
    along with a scary looking diffstat.

    Although if you look a bit closer, excluding the usual minor
    tweaks/fixes, there are really only two significant changes in this
    pull request: the addition of proper SELinux access controls for SCTP
    and the encapsulation of a lot of internal SELinux state.

    The SCTP changes are the result of a multi-month effort (maybe even a
    year or longer?) between the SELinux folks and the SCTP folks to add
    proper SELinux controls. A special thanks go to Richard for seeing
    this through and keeping the effort moving forward.

    The state encapsulation work is a bit of janitorial work that came out
    of some early work on SELinux namespacing. The question of namespacing
    is still an open one, but I believe there is some real value in the
    encapsulation work so we've split that out and are now sending that up
    to you"

    * tag 'selinux-pr-20180403' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux:
    selinux: wrap AVC state
    selinux: wrap selinuxfs state
    selinux: fix handling of uninitialized selinux state in get_bools/classes
    selinux: Update SELinux SCTP documentation
    selinux: Fix ltp test connect-syscall failure
    selinux: rename the {is,set}_enforcing() functions
    selinux: wrap global selinux state
    selinux: fix typo in selinux_netlbl_sctp_sk_clone declaration
    selinux: Add SCTP support
    sctp: Add LSM hooks
    sctp: Add ip option support
    security: Add support for SCTP security hooks
    netlabel: If PF_INET6, check sk_buff ip header version

    Linus Torvalds
     

06 Apr, 2018

1 commit


31 Mar, 2018

1 commit

  • This changes security_hook_heads to use hlist_heads instead of
    the circular doubly-linked list heads. This should cut down
    the size of the struct by about half.

    In addition, it allows mutation of the hooks at the tail of the
    callback list without having to modify the head. The longer-term
    purpose of this is to enable making the heads read only.

    Signed-off-by: Sargun Dhillon
    Reviewed-by: Tetsuo Handa
    Acked-by: Casey Schaufler
    Signed-off-by: James Morris

    Sargun Dhillon
     

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
     

23 Feb, 2018

1 commit


20 Oct, 2017

1 commit

  • Introduce several LSM hooks for the syscalls that will allow the
    userspace to access to eBPF object such as eBPF programs and eBPF maps.
    The security check is aimed to enforce a per object security protection
    for eBPF object so only processes with the right priviliges can
    read/write to a specific map or use a specific eBPF program. Besides
    that, a general security hook is added before the multiplexer of bpf
    syscall to check the cmd and the attribute used for the command. The
    actual security module can decide which command need to be checked and
    how the cmd should be checked.

    Signed-off-by: Chenbo Feng
    Acked-by: James Morris
    Signed-off-by: David S. Miller

    Chenbo Feng
     

13 Sep, 2017

1 commit

  • Pull selinux updates from Paul Moore:
    "A relatively quiet period for SELinux, 11 patches with only two/three
    having any substantive changes.

    These noteworthy changes include another tweak to the NNP/nosuid
    handling, per-file labeling for cgroups, and an object class fix for
    AF_UNIX/SOCK_RAW sockets; the rest of the changes are minor tweaks or
    administrative updates (Stephen's email update explains the file
    explosion in the diffstat).

    Everything passes the selinux-testsuite"

    [ Also a couple of small patches from the security tree from Tetsuo
    Handa for Tomoyo and LSM cleanup. The separation of security policy
    updates wasn't all that clean - Linus ]

    * tag 'selinux-pr-20170831' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux:
    selinux: constify nf_hook_ops
    selinux: allow per-file labeling for cgroupfs
    lsm_audit: update my email address
    selinux: update my email address
    MAINTAINERS: update the NetLabel and Labeled Networking information
    selinux: use GFP_NOWAIT in the AVC kmem_caches
    selinux: Generalize support for NNP/nosuid SELinux domain transitions
    selinux: genheaders should fail if too many permissions are defined
    selinux: update the selinux info in MAINTAINERS
    credits: update Paul Moore's info
    selinux: Assign proper class to PF_UNIX/SOCK_RAW sockets
    tomoyo: Update URLs in Documentation/admin-guide/LSM/tomoyo.rst
    LSM: Remove security_task_create() hook.

    Linus Torvalds
     

02 Aug, 2017

1 commit

  • This removes the bprm_secureexec hook since the logic has been folded into
    the bprm_set_creds hook for all LSMs now.

    Cc: Eric W. Biederman
    Signed-off-by: Kees Cook
    Reviewed-by: John Johansen
    Acked-by: James Morris
    Acked-by: Serge Hallyn

    Kees Cook
     

18 Jul, 2017

1 commit


10 Jun, 2017

1 commit

  • When an NFSv4 client performs a mount operation, it first mounts the
    NFSv4 root and then does path walk to the exported path and performs a
    submount on that, cloning the security mount options from the root's
    superblock to the submount's superblock in the process.

    Unless the NFS server has an explicit fsid=0 export with the
    "security_label" option, the NFSv4 root superblock will not have
    SBLABEL_MNT set, and neither will the submount superblock after cloning
    the security mount options. As a result, setxattr's of security labels
    over NFSv4.2 will fail. In a similar fashion, NFSv4.2 mounts mounted
    with the context= mount option will not show the correct labels because
    the nfs_server->caps flags of the cloned superblock will still have
    NFS_CAP_SECURITY_LABEL set.

    Allowing the NFSv4 client to enable or disable SECURITY_LSM_NATIVE_LABELS
    behavior will ensure that the SBLABEL_MNT flag has the correct value
    when the client traverses from an exported path without the
    "security_label" option to one with the "security_label" option and
    vice versa. Similarly, checking to see if SECURITY_LSM_NATIVE_LABELS is
    set upon return from security_sb_clone_mnt_opts() and clearing
    NFS_CAP_SECURITY_LABEL if necessary will allow the correct labels to
    be displayed for NFSv4.2 mounts mounted with the context= mount option.

    Resolves: https://github.com/SELinuxProject/selinux-kernel/issues/35

    Signed-off-by: Scott Mayhew
    Reviewed-by: Stephen Smalley
    Tested-by: Stephen Smalley
    Signed-off-by: Paul Moore

    Scott Mayhew
     

24 May, 2017

3 commits

  • Allocate and free a security context when creating and destroying a MAD
    agent. This context is used for controlling access to PKeys and sending
    and receiving SMPs.

    When sending or receiving a MAD check that the agent has permission to
    access the PKey for the Subnet Prefix of the port.

    During MAD and snoop agent registration for SMI QPs check that the
    calling process has permission to access the manage the subnet and
    register a callback with the LSM to be notified of policy changes. When
    notificaiton of a policy change occurs recheck permission and set a flag
    indicating sending and receiving SMPs is allowed.

    When sending and receiving MADs check that the agent has access to the
    SMI if it's on an SMI QP. Because security policy can change it's
    possible permission was allowed when creating the agent, but no longer
    is.

    Signed-off-by: Daniel Jurgens
    Acked-by: Doug Ledford
    [PM: remove the LSM hook init code]
    Signed-off-by: Paul Moore

    Daniel Jurgens
     
  • Add a generic notificaiton mechanism in the LSM. Interested consumers
    can register a callback with the LSM and security modules can produce
    events.

    Because access to Infiniband QPs are enforced in the setup phase of a
    connection security should be enforced again if the policy changes.
    Register infiniband devices for policy change notification and check all
    QPs on that device when the notification is received.

    Add a call to the notification mechanism from SELinux when the AVC
    cache changes or setenforce is cleared.

    Signed-off-by: Daniel Jurgens
    Acked-by: James Morris
    Acked-by: Doug Ledford
    Signed-off-by: Paul Moore

    Daniel Jurgens
     
  • Add new LSM hooks to allocate and free security contexts and check for
    permission to access a PKey.

    Allocate and free a security context when creating and destroying a QP.
    This context is used for controlling access to PKeys.

    When a request is made to modify a QP that changes the port, PKey index,
    or alternate path, check that the QP has permission for the PKey in the
    PKey table index on the subnet prefix of the port. If the QP is shared
    make sure all handles to the QP also have access.

    Store which port and PKey index a QP is using. After the reset to init
    transition the user can modify the port, PKey index and alternate path
    independently. So port and PKey settings changes can be a merge of the
    previous settings and the new ones.

    In order to maintain access control if there are PKey table or subnet
    prefix change keep a list of all QPs are using each PKey index on
    each port. If a change occurs all QPs using that device and port must
    have access enforced for the new cache settings.

    These changes add a transaction to the QP modify process. Association
    with the old port and PKey index must be maintained if the modify fails,
    and must be removed if it succeeds. Association with the new port and
    PKey index must be established prior to the modify and removed if the
    modify fails.

    1. When a QP is modified to a particular Port, PKey index or alternate
    path insert that QP into the appropriate lists.

    2. Check permission to access the new settings.

    3. If step 2 grants access attempt to modify the QP.

    4a. If steps 2 and 3 succeed remove any prior associations.

    4b. If ether fails remove the new setting associations.

    If a PKey table or subnet prefix changes walk the list of QPs and
    check that they have permission. If not send the QP to the error state
    and raise a fatal error event. If it's a shared QP make sure all the
    QPs that share the real_qp have permission as well. If the QP that
    owns a security structure is denied access the security structure is
    marked as such and the QP is added to an error_list. Once the moving
    the QP to error is complete the security structure mark is cleared.

    Maintaining the lists correctly turns QP destroy into a transaction.
    The hardware driver for the device frees the ib_qp structure, so while
    the destroy is in progress the ib_qp pointer in the ib_qp_security
    struct is undefined. When the destroy process begins the ib_qp_security
    structure is marked as destroying. This prevents any action from being
    taken on the QP pointer. After the QP is destroyed successfully it
    could still listed on an error_list wait for it to be processed by that
    flow before cleaning up the structure.

    If the destroy fails the QPs port and PKey settings are reinserted into
    the appropriate lists, the destroying flag is cleared, and access control
    is enforced, in case there were any cache changes during the destroy
    flow.

    To keep the security changes isolated a new file is used to hold security
    related functionality.

    Signed-off-by: Daniel Jurgens
    Acked-by: Doug Ledford
    [PM: merge fixup in ib_verbs.h and uverbs_cmd.c]
    Signed-off-by: Paul Moore

    Daniel Jurgens