09 Aug, 2016

3 commits

  • During a new file creation we need to make sure new file is created with the
    right label. New file is created in upper/ so effectively file should get
    label as if task had created file in upper/.

    We switched to mounter's creds for actual file creation. Also if there is a
    whiteout present, then file will be created in work/ dir first and then
    renamed in upper. In none of the cases file will be labeled as we want it to
    be.

    This patch introduces a new hook dentry_create_files_as(), which determines
    the label/context dentry will get if it had been created by task in upper
    and modify passed set of creds appropriately. Caller makes use of these new
    creds for file creation.

    Signed-off-by: Vivek Goyal
    Acked-by: Stephen Smalley
    [PM: fix whitespace issues found with checkpatch.pl]
    [PM: changes to use stat->mode in ovl_create_or_link()]
    Signed-off-by: Paul Moore

    Vivek Goyal
     
  • Provide a security hook which is called when xattrs of a file are being
    copied up. This hook is called once for each xattr and LSM can return
    0 if the security module wants the xattr to be copied up, 1 if the
    security module wants the xattr to be discarded on the copy, -EOPNOTSUPP
    if the security module does not handle/manage the xattr, or a -errno
    upon an error.

    Signed-off-by: David Howells
    Signed-off-by: Vivek Goyal
    Acked-by: Stephen Smalley
    [PM: whitespace cleanup for checkpatch.pl]
    Signed-off-by: Paul Moore

    Vivek Goyal
     
  • Provide a security hook to label new file correctly when a file is copied
    up from lower layer to upper layer of a overlay/union mount.

    This hook can prepare a new set of creds which are suitable for new file
    creation during copy up. Caller will use new creds to create file and then
    revert back to old creds and release new creds.

    Signed-off-by: Vivek Goyal
    Acked-by: Stephen Smalley
    [PM: whitespace cleanup to appease checkpatch.pl]
    Signed-off-by: Paul Moore

    Vivek Goyal
     

06 Aug, 2016

1 commit

  • Pull qstr constification updates from Al Viro:
    "Fairly self-contained bunch - surprising lot of places passes struct
    qstr * as an argument when const struct qstr * would suffice; it
    complicates analysis for no good reason.

    I'd prefer to feed that separately from the assorted fixes (those are
    in #for-linus and with somewhat trickier topology)"

    * 'work.const-qstr' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    qstr: constify instances in adfs
    qstr: constify instances in lustre
    qstr: constify instances in f2fs
    qstr: constify instances in ext2
    qstr: constify instances in vfat
    qstr: constify instances in procfs
    qstr: constify instances in fuse
    qstr constify instances in fs/dcache.c
    qstr: constify instances in nfs
    qstr: constify instances in ocfs2
    qstr: constify instances in autofs4
    qstr: constify instances in hfs
    qstr: constify instances in hfsplus
    qstr: constify instances in logfs
    qstr: constify dentry_init_security

    Linus Torvalds
     

21 Jul, 2016

1 commit


06 Jun, 2016

1 commit

  • Serge Hallyn pointed out that the current implementation of
    security_inode_getsecurity() works if there is only one hook
    provided for it, but will fail if there is more than one and
    the attribute requested isn't supplied by the first module.
    This isn't a problem today, since only SELinux and Smack
    provide this hook and there is (currently) no way to enable
    both of those modules at the same time. Serge, however, wants
    to introduce a capability attribute and an inode_getsecurity
    hook in the capability security module to handle it. This
    addresses that upcoming problem, will be required for "extreme
    stacking" and is just a better implementation.

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

    Casey Schaufler
     

20 May, 2016

1 commit

  • Pull security subsystem updates from James Morris:
    "Highlights:

    - A new LSM, "LoadPin", from Kees Cook is added, which allows forcing
    of modules and firmware to be loaded from a specific device (this
    is from ChromeOS, where the device as a whole is verified
    cryptographically via dm-verity).

    This is disabled by default but can be configured to be enabled by
    default (don't do this if you don't know what you're doing).

    - Keys: allow authentication data to be stored in an asymmetric key.
    Lots of general fixes and updates.

    - SELinux: add restrictions for loading of kernel modules via
    finit_module(). Distinguish non-init user namespace capability
    checks. Apply execstack check on thread stacks"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (48 commits)
    LSM: LoadPin: provide enablement CONFIG
    Yama: use atomic allocations when reporting
    seccomp: Fix comment typo
    ima: add support for creating files using the mknodat syscall
    ima: fix ima_inode_post_setattr
    vfs: forbid write access when reading a file into memory
    fs: fix over-zealous use of "const"
    selinux: apply execstack check on thread stacks
    selinux: distinguish non-init user namespace capability checks
    LSM: LoadPin for kernel file loading restrictions
    fs: define a string representation of the kernel_read_file_id enumeration
    Yama: consolidate error reporting
    string_helpers: add kstrdup_quotable_file
    string_helpers: add kstrdup_quotable_cmdline
    string_helpers: add kstrdup_quotable
    selinux: check ss_initialized before revalidating an inode label
    selinux: delay inode label lookup as long as possible
    selinux: don't revalidate an inode's label when explicitly setting it
    selinux: Change bool variable name to index.
    KEYS: Add KEYCTL_DH_COMPUTE command
    ...

    Linus Torvalds
     

18 May, 2016

1 commit

  • Pull 'struct path' constification update from Al Viro:
    "'struct path' is passed by reference to a bunch of Linux security
    methods; in theory, there's nothing to stop them from modifying the
    damn thing and LSM community being what it is, sooner or later some
    enterprising soul is going to decide that it's a good idea.

    Let's remove the temptation and constify all of those..."

    * 'work.const-path' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    constify ima_d_path()
    constify security_sb_pivotroot()
    constify security_path_chroot()
    constify security_path_{link,rename}
    apparmor: remove useless checks for NULL ->mnt
    constify security_path_{mkdir,mknod,symlink}
    constify security_path_{unlink,rmdir}
    apparmor: constify common_perm_...()
    apparmor: constify aa_path_link()
    apparmor: new helper - common_path_perm()
    constify chmod_common/security_path_chmod
    constify security_sb_mount()
    constify chown_common/security_path_chown
    tomoyo: constify assorted struct path *
    apparmor_path_truncate(): path->mnt is never NULL
    constify vfs_truncate()
    constify security_path_truncate()
    [apparmor] constify struct path * in a bunch of helpers

    Linus Torvalds
     

23 Apr, 2016

1 commit

  • security_settime() uses a timespec, which is not year 2038 safe
    on 32bit systems. Thus this patch introduces the security_settime64()
    function with timespec64 type. We also convert the cap_settime() helper
    function to use the 64bit types.

    This patch then moves security_settime() to the header file as an
    inline helper function so that existing users can be iteratively
    converted.

    None of the existing hooks is using the timespec argument and therefor
    the patch is not making any functional changes.

    Cc: Serge Hallyn ,
    Cc: James Morris ,
    Cc: "Serge E. Hallyn" ,
    Cc: Paul Moore
    Cc: Stephen Smalley
    Cc: Kees Cook
    Cc: Prarit Bhargava
    Cc: Richard Cochran
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Reviewed-by: James Morris
    Signed-off-by: Baolin Wang
    [jstultz: Reworded commit message]
    Signed-off-by: John Stultz

    Baolin Wang
     

21 Apr, 2016

1 commit

  • This LSM enforces that kernel-loaded files (modules, firmware, etc)
    must all come from the same filesystem, with the expectation that
    such a filesystem is backed by a read-only device such as dm-verity
    or CDROM. This allows systems that have a verified and/or unchangeable
    filesystem to enforce module and firmware loading restrictions without
    needing to sign the files individually.

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

    Kees Cook
     

11 Apr, 2016

1 commit

  • The skb_owned_by hook was added with the commit ca10b9e9a8ca
    ("selinux: add a skb_owned_by() hook") and later removed
    when said commit was reverted.

    Later on, when switching to list of hooks, a field named
    'skb_owned_by' was included into the security_hook_head struct,
    but without any users nor caller.

    This commit removes the said left-over field.

    Fixes: b1d9e6b0646d ("LSM: Switch to lists of hooks")
    Signed-off-by: Paolo Abeni
    Acked-by: Casey Schaufler
    Acked-by: Paul Moore
    Signed-off-by: James Morris

    Paolo Abeni
     

28 Mar, 2016

9 commits


21 Feb, 2016

4 commits

  • Replace copy_module_from_fd() with kernel_read_file_from_fd().

    Although none of the upstreamed LSMs define a kernel_module_from_file
    hook, IMA is called, based on policy, to prevent unsigned kernel modules
    from being loaded by the original kernel module syscall and to
    measure/appraise signed kernel modules.

    The security function security_kernel_module_from_file() was called prior
    to reading a kernel module. Preventing unsigned kernel modules from being
    loaded by the original kernel module syscall remains on the pre-read
    kernel_read_file() security hook. Instead of reading the kernel module
    twice, once for measuring/appraising and again for loading the kernel
    module, the signature validation is moved to the kernel_post_read_file()
    security hook.

    This patch removes the security_kernel_module_from_file() hook and security
    call.

    Signed-off-by: Mimi Zohar
    Acked-by: Kees Cook
    Acked-by: Luis R. Rodriguez
    Cc: Rusty Russell

    Mimi Zohar
     
  • The kernel_read_file security hook is called prior to reading the file
    into memory.

    Changelog v4+:
    - export security_kernel_read_file()

    Signed-off-by: Mimi Zohar
    Acked-by: Kees Cook
    Acked-by: Luis R. Rodriguez
    Acked-by: Casey Schaufler

    Mimi Zohar
     
  • Replace the fw_read_file_contents with kernel_file_read_from_path().

    Although none of the upstreamed LSMs define a kernel_fw_from_file hook,
    IMA is called by the security function to prevent unsigned firmware from
    being loaded and to measure/appraise signed firmware, based on policy.

    Instead of reading the firmware twice, once for measuring/appraising the
    firmware and again for reading the firmware contents into memory, the
    kernel_post_read_file() security hook calculates the file hash based on
    the in memory file buffer. The firmware is read once.

    This patch removes the LSM kernel_fw_from_file() hook and security call.

    Changelog v4+:
    - revert dropped buf->size assignment - reported by Sergey Senozhatsky
    v3:
    - remove kernel_fw_from_file hook
    - use kernel_file_read_from_path() - requested by Luis
    v2:
    - reordered and squashed firmware patches
    - fix MAX firmware size (Kees Cook)

    Signed-off-by: Mimi Zohar
    Acked-by: Kees Cook
    Acked-by: Luis R. Rodriguez

    Mimi Zohar
     
  • This patch defines a new IMA hook ima_post_read_file() for measuring
    and appraising files read by the kernel. The caller loads the file into
    memory before calling this function, which calculates the hash followed by
    the normal IMA policy based processing.

    Changelog v5:
    - fail ima_post_read_file() if either file or buf is NULL
    v3:
    - rename ima_hash_and_process_file() to ima_post_read_file()

    v1:
    - split patch

    Signed-off-by: Mimi Zohar
    Acked-by: Dmitry Kasatkin

    Mimi Zohar
     

19 Feb, 2016

2 commits

  • To differentiate between the kernel_read_file() callers, this patch
    defines a new enumeration named kernel_read_file_id and includes the
    caller identifier as an argument.

    Subsequent patches define READING_KEXEC_IMAGE, READING_KEXEC_INITRAMFS,
    READING_FIRMWARE, READING_MODULE, and READING_POLICY.

    Changelog v3:
    - Replace the IMA specific enumeration with a generic one.

    Signed-off-by: Mimi Zohar
    Acked-by: Kees Cook
    Acked-by: Luis R. Rodriguez
    Cc: Al Viro

    Mimi Zohar
     
  • For a while it was looked down upon to directly read files from Linux.
    These days there exists a few mechanisms in the kernel that do just
    this though to load a file into a local buffer. There are minor but
    important checks differences on each. This patch set is the first
    attempt at resolving some of these differences.

    This patch introduces a common function for reading files from the kernel
    with the corresponding security post-read hook and function.

    Changelog v4+:
    - export security_kernel_post_read_file() - Fengguang Wu
    v3:
    - additional bounds checking - Luis
    v2:
    - To simplify patch review, re-ordered patches

    Signed-off-by: Mimi Zohar
    Reviewed-by: Luis R. Rodriguez
    Acked-by: Kees Cook
    Cc: Al Viro

    Mimi Zohar
     

25 Dec, 2015

3 commits


09 Sep, 2015

1 commit

  • Pull security subsystem updates from James Morris:
    "Highlights:

    - PKCS#7 support added to support signed kexec, also utilized for
    module signing. See comments in 3f1e1bea.

    ** NOTE: this requires linking against the OpenSSL library, which
    must be installed, e.g. the openssl-devel on Fedora **

    - Smack
    - add IPv6 host labeling; ignore labels on kernel threads
    - support smack labeling mounts which use binary mount data

    - SELinux:
    - add ioctl whitelisting (see
    http://kernsec.org/files/lss2015/vanderstoep.pdf)
    - fix mprotect PROT_EXEC regression caused by mm change

    - Seccomp:
    - add ptrace options for suspend/resume"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (57 commits)
    PKCS#7: Add OIDs for sha224, sha284 and sha512 hash algos and use them
    Documentation/Changes: Now need OpenSSL devel packages for module signing
    scripts: add extract-cert and sign-file to .gitignore
    modsign: Handle signing key in source tree
    modsign: Use if_changed rule for extracting cert from module signing key
    Move certificate handling to its own directory
    sign-file: Fix warning about BIO_reset() return value
    PKCS#7: Add MODULE_LICENSE() to test module
    Smack - Fix build error with bringup unconfigured
    sign-file: Document dependency on OpenSSL devel libraries
    PKCS#7: Appropriately restrict authenticated attributes and content type
    KEYS: Add a name for PKEY_ID_PKCS7
    PKCS#7: Improve and export the X.509 ASN.1 time object decoder
    modsign: Use extract-cert to process CONFIG_SYSTEM_TRUSTED_KEYS
    extract-cert: Cope with multiple X.509 certificates in a single file
    sign-file: Generate CMS message as signature instead of PKCS#7
    PKCS#7: Support CMS messages also [RFC5652]
    X.509: Change recorded SKID & AKID to not include Subject or Issuer
    PKCS#7: Check content type and versions
    MAINTAINERS: The keyrings mailing list has moved
    ...

    Linus Torvalds
     

02 Sep, 2015

1 commit

  • Pull user namespace updates from Eric Biederman:
    "This finishes up the changes to ensure proc and sysfs do not start
    implementing executable files, as the there are application today that
    are only secure because such files do not exist.

    It akso fixes a long standing misfeature of /proc//mountinfo that
    did not show the proper source for files bind mounted from
    /proc//ns/*.

    It also straightens out the handling of clone flags related to user
    namespaces, fixing an unnecessary failure of unshare(CLONE_NEWUSER)
    when files such as /proc//environ are read while is calling
    unshare. This winds up fixing a minor bug in unshare flag handling
    that dates back to the first version of unshare in the kernel.

    Finally, this fixes a minor regression caused by the introduction of
    sysfs_create_mount_point, which broke someone's in house application,
    by restoring the size of /sys/fs/cgroup to 0 bytes. Apparently that
    application uses the directory size to determine if a tmpfs is mounted
    on /sys/fs/cgroup.

    The bind mount escape fixes are present in Al Viros for-next branch.
    and I expect them to come from there. The bind mount escape is the
    last of the user namespace related security bugs that I am aware of"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace:
    fs: Set the size of empty dirs to 0.
    userns,pidns: Force thread group sharing, not signal handler sharing.
    unshare: Unsharing a thread does not require unsharing a vm
    nsfs: Add a show_path method to fix mountinfo
    mnt: fs_fully_visible enforce noexec and nosuid if !SB_I_NOEXEC
    vfs: Commit to never having exectuables on proc and sysfs.

    Linus Torvalds
     

26 Aug, 2015

1 commit

  • While in most cases commit b1d9e6b064 ("LSM: Switch to lists of hooks")
    retained previous error returns, in three cases it altered them without
    any explanation in the commit message. Restore all of them - in the
    security_old_inode_init_security() case this led to reiserfs using
    uninitialized data, sooner or later crashing the system (the only other
    user of this function - ocfs2 - was unaffected afaict, since it passes
    pre-initialized structures).

    Signed-off-by: Jan Beulich
    Signed-off-by: Casey Schaufler
    Signed-off-by: James Morris

    Jan Beulich
     

28 Jul, 2015

1 commit

  • Now that minor LSMs can cleanly stack with major LSMs, remove the unneeded
    config for Yama to be made to explicitly stack. Just selecting the main
    Yama CONFIG will allow it to work, regardless of the major LSM. Since
    distros using Yama are already forcing it to stack, this is effectively
    a no-op change.

    Additionally add MAINTAINERS entry.

    Signed-off-by: Kees Cook
    Signed-off-by: James Morris

    Kees Cook
     

10 Jul, 2015

1 commit

  • Today proc and sysfs do not contain any executable files. Several
    applications today mount proc or sysfs without noexec and nosuid and
    then depend on there being no exectuables files on proc or sysfs.
    Having any executable files show on proc or sysfs would cause
    a user space visible regression, and most likely security problems.

    Therefore commit to never allowing executables on proc and sysfs by
    adding a new flag to mark them as filesystems without executables and
    enforce that flag.

    Test the flag where MNT_NOEXEC is tested today, so that the only user
    visible effect will be that exectuables will be treated as if the
    execute bit is cleared.

    The filesystems proc and sysfs do not currently incoporate any
    executable files so this does not result in any user visible effects.

    This makes it unnecessary to vet changes to proc and sysfs tightly for
    adding exectuable files or changes to chattr that would modify
    existing files, as no matter what the individual file say they will
    not be treated as exectuable files by the vfs.

    Not having to vet changes to closely is important as without this we
    are only one proc_create call (or another goof up in the
    implementation of notify_change) from having problematic executables
    on proc. Those mistakes are all too easy to make and would create
    a situation where there are security issues or the assumptions of
    some program having to be broken (and cause userspace regressions).

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

    Eric W. Biederman
     

28 Jun, 2015

1 commit

  • Pull security subsystem updates from James Morris:
    "The main change in this kernel is Casey's generalized LSM stacking
    work, which removes the hard-coding of Capabilities and Yama stacking,
    allowing multiple arbitrary "small" LSMs to be stacked with a default
    monolithic module (e.g. SELinux, Smack, AppArmor).

    See
    https://lwn.net/Articles/636056/

    This will allow smaller, simpler LSMs to be incorporated into the
    mainline kernel and arbitrarily stacked by users. Also, this is a
    useful cleanup of the LSM code in its own right"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (38 commits)
    tpm, tpm_crb: fix le64_to_cpu conversions in crb_acpi_add()
    vTPM: set virtual device before passing to ibmvtpm_reset_crq
    tpm_ibmvtpm: remove unneccessary message level.
    ima: update builtin policies
    ima: extend "mask" policy matching support
    ima: add support for new "euid" policy condition
    ima: fix ima_show_template_data_ascii()
    Smack: freeing an error pointer in smk_write_revoke_subj()
    selinux: fix setting of security labels on NFS
    selinux: Remove unused permission definitions
    selinux: enable genfscon labeling for sysfs and pstore files
    selinux: enable per-file labeling for debugfs files.
    selinux: update netlink socket classes
    signals: don't abuse __flush_signals() in selinux_bprm_committed_creds()
    selinux: Print 'sclass' as string when unrecognized netlink message occurs
    Smack: allow multiple labels in onlycap
    Smack: fix seq operations in smackfs
    ima: pass iint to ima_add_violation()
    ima: wrap event related data to the new ima_event_data structure
    integrity: add validity checks for 'path' parameter
    ...

    Linus Torvalds
     

12 May, 2015

3 commits

  • Instead of using a vector of security operations
    with explicit, special case stacking of the capability
    and yama hooks use lists of hooks with capability and
    yama hooks included as appropriate.

    The security_operations structure is no longer required.
    Instead, there is a union of the function pointers that
    allows all the hooks lists to use a common mechanism for
    list management while retaining typing. Each module
    supplies an array describing the hooks it provides instead
    of a sparsely populated security_operations structure.
    The description includes the element that gets put on
    the hook list, avoiding the issues surrounding individual
    element allocation.

    The method for registering security modules is changed to
    reflect the information available. The method for removing
    a module, currently only used by SELinux, has also changed.
    It should be generic now, however if there are potential
    race conditions based on ordering of hook removal that needs
    to be addressed by the calling module.

    The security hooks are called from the lists and the first
    failure is returned.

    Signed-off-by: Casey Schaufler
    Acked-by: John Johansen
    Acked-by: Kees Cook
    Acked-by: Paul Moore
    Acked-by: Stephen Smalley
    Acked-by: Tetsuo Handa
    Signed-off-by: James Morris

    Casey Schaufler
     
  • Introduce two macros around calling the functions in the
    security operations vector. The marco versions here do not
    change any behavior.

    Signed-off-by: Casey Schaufler
    Acked-by: John Johansen
    Acked-by: Kees Cook
    Acked-by: Paul Moore
    Acked-by: Stephen Smalley
    Acked-by: Tetsuo Handa
    Signed-off-by: James Morris

    Casey Schaufler
     
  • The security.h header file serves two purposes,
    interfaces for users of the security modules and
    interfaces for security modules. Users of the
    security modules don't need to know about what's
    in the security_operations structure, so pull it
    out into it's own header, lsm_hooks.h

    Signed-off-by: Casey Schaufler
    Acked-by: John Johansen
    Acked-by: Kees Cook
    Acked-by: Paul Moore
    Acked-by: Stephen Smalley
    Acked-by: Tetsuo Handa
    Signed-off-by: James Morris

    Casey Schaufler
     

11 May, 2015

2 commits

  • inode_follow_link now takes an inode and rcu flag as well as the
    dentry.

    inode is used in preference to d_backing_inode(dentry), particularly
    in RCU-walk mode.

    selinux_inode_follow_link() gets dentry_has_perm() and
    inode_has_perm() open-coded into it so that it can call
    avc_has_perm_flags() in way that is safe if LOOKUP_RCU is set.

    Calling avc_has_perm_flags() with rcu_read_lock() held means
    that when avc_has_perm_noaudit calls avc_compute_av(), the attempt
    to rcu_read_unlock() before calling security_compute_av() will not
    actually drop the RCU read-lock.

    However as security_compute_av() is completely in a read_lock()ed
    region, it should be safe with the RCU read-lock held.

    Signed-off-by: NeilBrown
    Signed-off-by: Al Viro

    NeilBrown
     
  • No ->inode_follow_link() methods use the nameidata arg, and
    it is about to become private to namei.c.
    So remove from all inode_follow_link() functions.

    Signed-off-by: NeilBrown
    Signed-off-by: Al Viro

    NeilBrown