23 Jan, 2016

1 commit

  • parallel to mutex_{lock,unlock,trylock,is_locked,lock_nested},
    inode_foo(inode) being mutex_foo(&inode->i_mutex).

    Please, use those for access to ->i_mutex; over the coming cycle
    ->i_mutex will become rwsem, with ->lookup() done with it held
    only shared.

    Signed-off-by: Al Viro

    Al Viro
     

18 Jan, 2016

1 commit

  • Pull security subsystem updates from James Morris:

    - EVM gains support for loading an x509 cert from the kernel
    (EVM_LOAD_X509), into the EVM trusted kernel keyring.

    - Smack implements 'file receive' process-based permission checking for
    sockets, rather than just depending on inode checks.

    - Misc enhancments for TPM & TPM2.

    - Cleanups and bugfixes for SELinux, Keys, and IMA.

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (41 commits)
    selinux: Inode label revalidation performance fix
    KEYS: refcount bug fix
    ima: ima_write_policy() limit locking
    IMA: policy can be updated zero times
    selinux: rate-limit netlink message warnings in selinux_nlmsg_perm()
    selinux: export validatetrans decisions
    gfs2: Invalid security labels of inodes when they go invalid
    selinux: Revalidate invalid inode security labels
    security: Add hook to invalidate inode security labels
    selinux: Add accessor functions for inode->i_security
    security: Make inode argument of inode_getsecid non-const
    security: Make inode argument of inode_getsecurity non-const
    selinux: Remove unused variable in selinux_inode_init_security
    keys, trusted: seal with a TPM2 authorization policy
    keys, trusted: select hash algorithm for TPM2 chips
    keys, trusted: fix: *do not* allow duplicate key options
    tpm_ibmvtpm: properly handle interrupted packet receptions
    tpm_tis: Tighten IRQ auto-probing
    tpm_tis: Refactor the interrupt setup
    tpm_tis: Get rid of the duplicate IRQ probing code
    ...

    Linus Torvalds
     

09 Jan, 2016

1 commit

  • Commit 5d226df4 has introduced a performance regression of about
    10% in the UnixBench pipe benchmark. It turns out that the call
    to inode_security in selinux_file_permission can be moved below
    the zero-mask test and that inode_security_revalidate can be
    removed entirely, which brings us back to roughly the original
    performance.

    Signed-off-by: Andreas Gruenbacher
    Acked-by: Stephen Smalley
    Signed-off-by: Paul Moore

    Andreas Gruenbacher
     

04 Jan, 2016

1 commit

  • Nothing in there gives a damn about the buffer alignment - it
    just parses its contents. So the use of get_zeroed_page()
    doesn't buy us anything - might as well had been kmalloc(),
    which makes that code equivalent to open-coded memdup_user_nul()

    Signed-off-by: Al Viro

    Al Viro
     

25 Dec, 2015

8 commits


26 Nov, 2015

1 commit


25 Nov, 2015

1 commit

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

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

    Stephen Smalley
     

11 Nov, 2015

1 commit

  • Pull networking fixes from David Miller:

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

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

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

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

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

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

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

    8) Fix multicast getsockopt deadlock, from WANG Cong.

    9) Fix deadlock in btusb, from Kuba Pawlak.

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

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

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

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

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

    Linus Torvalds
     

09 Nov, 2015

1 commit


06 Nov, 2015

2 commits

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

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

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

    Dmitry Vyukov got a KASan report pointing to it.

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

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

    Eric Dumazet
     

22 Oct, 2015

9 commits

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

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

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

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

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

    Sangwoo
     
  • Fixes the following sparse warning:

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

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

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

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

    Rasmus Villemoes
     
  • This is much simpler.

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

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

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

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

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

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

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

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

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

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

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

    Signed-off-by: Paul Moore

    Paul Moore
     

17 Oct, 2015

2 commits


11 Oct, 2015

1 commit

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

    (Only syncookies are still attached to a TCP_LISTEN socket)

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

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

    Eric Dumazet
     

19 Sep, 2015

1 commit


11 Sep, 2015

1 commit

  • With two exceptions (drm/qxl and drm/radeon) all vm_operations_struct
    structs should be constant.

    Signed-off-by: Kirill A. Shutemov
    Reviewed-by: Oleg Nesterov
    Cc: "H. Peter Anvin"
    Cc: Andy Lutomirski
    Cc: Dave Hansen
    Cc: Ingo Molnar
    Cc: Minchan Kim
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kirill A. Shutemov
     

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
     

05 Sep, 2015

1 commit

  • Many file systems that implement the show_options hook fail to correctly
    escape their output which could lead to unescaped characters (e.g. new
    lines) leaking into /proc/mounts and /proc/[pid]/mountinfo files. This
    could lead to confusion, spoofed entries (resulting in things like
    systemd issuing false d-bus "mount" notifications), and who knows what
    else. This looks like it would only be the root user stepping on
    themselves, but it's possible weird things could happen in containers or
    in other situations with delegated mount privileges.

    Here's an example using overlay with setuid fusermount trusting the
    contents of /proc/mounts (via the /etc/mtab symlink). Imagine the use
    of "sudo" is something more sneaky:

    $ BASE="ovl"
    $ MNT="$BASE/mnt"
    $ LOW="$BASE/lower"
    $ UP="$BASE/upper"
    $ WORK="$BASE/work/ 0 0
    none /proc fuse.pwn user_id=1000"
    $ mkdir -p "$LOW" "$UP" "$WORK"
    $ sudo mount -t overlay -o "lowerdir=$LOW,upperdir=$UP,workdir=$WORK" none /mnt
    $ cat /proc/mounts
    none /root/ovl/mnt overlay rw,relatime,lowerdir=ovl/lower,upperdir=ovl/upper,workdir=ovl/work/ 0 0
    none /proc fuse.pwn user_id=1000 0 0
    $ fusermount -u /proc
    $ cat /proc/mounts
    cat: /proc/mounts: No such file or directory

    This fixes the problem by adding new seq_show_option and
    seq_show_option_n helpers, and updating the vulnerable show_option
    handlers to use them as needed. Some, like SELinux, need to be open
    coded due to unusual existing escape mechanisms.

    [akpm@linux-foundation.org: add lost chunk, per Kees]
    [keescook@chromium.org: seq_show_option should be using const parameters]
    Signed-off-by: Kees Cook
    Acked-by: Serge Hallyn
    Acked-by: Jan Kara
    Acked-by: Paul Moore
    Cc: J. R. Okajima
    Signed-off-by: Kees Cook
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     

15 Aug, 2015

1 commit


14 Jul, 2015

5 commits

  • Create a common helper function to determine the label for a new inode.
    This is then used by:

    - may_create()
    - selinux_dentry_init_security()
    - selinux_inode_init_security()

    This will change the behaviour of the functions slightly, bringing them
    all into line.

    Suggested-by: Stephen Smalley
    Signed-off-by: David Howells
    Acked-by: Stephen Smalley
    Signed-off-by: Paul Moore

    David Howells
     
  • Ensure that we catch any cases where tclass == 0.

    Signed-off-by: Stephen Smalley
    Signed-off-by: Paul Moore

    Stephen Smalley
     
  • Initialize the security class of sock security structures
    to the generic socket class. This is similar to what is
    already done in inode_alloc_security for files. Generally
    the sclass field will later by set by socket_post_create
    or sk_clone or sock_graft, but for protocol implementations
    that fail to call any of these for newly accepted sockets,
    we want some sane default that will yield a legitimate
    avc denied message with non-garbage values for class and
    permission.

    Signed-off-by: Stephen Smalley
    Signed-off-by: Paul Moore

    Stephen Smalley
     
  • The inode_free_security() function just took the superblock's isec_lock
    before checking and trying to remove the inode security struct from the
    linked list. In many cases, the list was empty and so the lock taking
    is wasteful as no useful work is done. On multi-socket systems with
    a large number of CPUs, there can also be a fair amount of spinlock
    contention on the isec_lock if many tasks are exiting at the same time.

    This patch changes the code to check the state of the list first before
    taking the lock and attempting to dequeue it. The list_del_init()
    can be called more than once on the same list with no harm as long
    as they are properly serialized. It should not be possible to have
    inode_free_security() called concurrently with list_add(). For better
    safety, however, we use list_empty_careful() here even though it is
    still not completely safe in case that happens.

    Signed-off-by: Waiman Long
    Acked-by: Stephen Smalley
    Signed-off-by: Paul Moore

    Waiman Long
     
  • Add extended permissions logic to selinux. Extended permissions
    provides additional permissions in 256 bit increments. Extend the
    generic ioctl permission check to use the extended permissions for
    per-command filtering. Source/target/class sets including the ioctl
    permission may additionally include a set of commands. Example:

    allowxperm : ioctl unpriv_app_socket_cmds
    auditallowxperm : ioctl priv_gpu_cmds

    Where unpriv_app_socket_cmds and priv_gpu_cmds are macros
    representing commonly granted sets of ioctl commands.

    When ioctl commands are omitted only the permissions are checked.
    This feature is intended to provide finer granularity for the ioctl
    permission that may be too imprecise. For example, the same driver
    may use ioctls to provide important and benign functionality such as
    driver version or socket type as well as dangerous capabilities such
    as debugging features, read/write/execute to physical memory or
    access to sensitive data. Per-command filtering provides a mechanism
    to reduce the attack surface of the kernel, and limit applications
    to the subset of commands required.

    The format of the policy binary has been modified to include ioctl
    commands, and the policy version number has been incremented to
    POLICYDB_VERSION_XPERMS_IOCTL=30 to account for the format
    change.

    The extended permissions logic is deliberately generic to allow
    components to be reused e.g. netlink filters

    Signed-off-by: Jeff Vander Stoep
    Acked-by: Nick Kralevich
    Signed-off-by: Paul Moore

    Jeff Vander Stoep