17 Feb, 2016

1 commit

  • Before this commit, removing the access property of
    a file, aka, the extended attribute security.SMACK64
    was not effictive until the cache had been cleaned.

    This patch fixes that problem.

    Signed-off-by: José Bollo
    Acked-by: Casey Schaufler

    José Bollo
     

12 Feb, 2016

1 commit

  • Prior to the 4.2 kernel there no no harm in providing
    a security module hook that does nothing, as the default
    hook would get called if the module did not supply one.
    With the list based infrastructure an empty hook adds
    overhead. This patch removes the three Smack hooks that
    don't actually do anything.

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

21 Jan, 2016

1 commit

  • It looks like smack and yama weren't aware that the ptrace mode
    can have flags ORed into it - PTRACE_MODE_NOAUDIT until now, but
    only for /proc/$pid/stat, and with the PTRACE_MODE_*CREDS patch,
    all modes have flags ORed into them.

    Signed-off-by: Jann Horn
    Acked-by: Kees Cook
    Acked-by: Casey Schaufler
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: James Morris
    Cc: "Serge E. Hallyn"
    Cc: Andy Shevchenko
    Cc: Andy Lutomirski
    Cc: Al Viro
    Cc: "Eric W. Biederman"
    Cc: Willy Tarreau
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jann Horn
     

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
     

26 Dec, 2015

1 commit


25 Dec, 2015

2 commits


18 Dec, 2015

1 commit

  • Smack security handler for sendmsg() syscall
    is vulnerable to type confusion issue what
    can allow to privilege escalation into root
    or cause denial of service.

    A malicious attacker can create socket of one
    type for example AF_UNIX and pass is into
    sendmsg() function ensuring that this is
    AF_INET socket.

    Remedy
    Do not trust user supplied data.
    Proposed fix below.

    Signed-off-by: Roman Kubiak
    Signed-off-by: Mateusz Fruba
    Acked-by: Casey Schaufler

    Roman Kubiak
     

14 Dec, 2015

1 commit


10 Dec, 2015

1 commit

  • The existing file receive hook checks for access on
    the file inode even for UDS. This is not right, as
    the inode is not used by Smack to make access checks
    for sockets. This change checks for an appropriate
    access relationship between the receiving (current)
    process and the socket. If the process can't write
    to the socket's send label or the socket's receive
    label can't write to the process fail.

    This will allow the legitimate cases, where the
    socket sender and socket receiver can freely communicate.
    Only strangly set socket labels should cause a problem.

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

20 Oct, 2015

1 commit

  • This feature introduces new kernel interface:

    - /relabel-self - for setting transition labels list

    This list is used to control smack label transition mechanism.
    List is set by, and per process. Process can transit to new label only if
    label is on the list. Only process with CAP_MAC_ADMIN capability can add
    labels to this list. With this list, process can change it's label without
    CAP_MAC_ADMIN but only once. After label changing, list is unset.

    Changes in v2:
    * use list_for_each_entry instead of _rcu during label write
    * added missing description in security/Smack.txt

    Changes in v3:
    * squashed into one commit

    Changes in v4:
    * switch from global list to per-task list
    * since the per-task list is accessed only by the task itself
    there is no need to use synchronization mechanisms on it

    Changes in v5:
    * change smackfs interface of relabel-self to the one used for onlycap
    multiple labels are accepted, separated by space, which
    replace the previous list upon write

    Signed-off-by: Zbigniew Jasinski
    Signed-off-by: Rafal Krypa
    Acked-by: Casey Schaufler

    Zbigniew Jasinski
     

10 Oct, 2015

3 commits


13 Aug, 2015

1 commit


01 Aug, 2015

1 commit


28 Jul, 2015

1 commit

  • IPv6 appears to be (finally) coming of age with the
    influx of autonomous devices. In support of this, add
    the ability to associate a Smack label with IPv6 addresses.

    This patch also cleans up some of the conditional
    compilation associated with the introduction of
    secmark processing. It's now more obvious which bit
    of code goes with which feature.

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

23 Jul, 2015

1 commit


15 May, 2015

2 commits

  • This patch makes the following functions to use ERR_PTR() and related
    macros to pass the appropriate error code through returned pointers:

    smk_parse_smack()
    smk_import_entry()
    smk_fetch()

    It also makes all the other functions that use them to handle the
    error cases properly. This ways correct error codes from places
    where they happened can be propagated to the user space if necessary.

    Doing this it fixes a bug in onlycap and unconfined files
    handling. Previously their content was cleared on any error from
    smk_import_entry/smk_parse_smack, be it EINVAL (as originally intended)
    or ENOMEM. Right now it only reacts on EINVAL passing other codes
    properly to userspace.

    Comments have been updated accordingly.

    Signed-off-by: Lukasz Pawelczyk

    Lukasz Pawelczyk
     
  • The dmabuf fd can be shared between processes via unix domain
    socket. The file of dmabuf fd is came from anon_inode. The inode
    has no set and get xattr operations, so it can not be shared
    between processes with smack. This patch fixes just to ignore
    private inode including anon_inode for smack_file_receive.

    Signed-off-by: Seung-Woo Kim

    Seung-Woo Kim
     

12 May, 2015

2 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
     
  • Add a list header for each security hook. They aren't used until
    later in the patch series. They are grouped together in a structure
    so that there doesn't need to be an external address for each.

    Macro-ize the initialization of the security_operations
    for each security module in anticipation of changing out
    the security_operations structure.

    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
     

27 Apr, 2015

1 commit

  • Pull fourth vfs update from Al Viro:
    "d_inode() annotations from David Howells (sat in for-next since before
    the beginning of merge window) + four assorted fixes"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    RCU pathwalk breakage when running into a symlink overmounting something
    fix I_DIO_WAKEUP definition
    direct-io: only inc/dec inode->i_dio_count for file systems
    fs/9p: fix readdir()
    VFS: assorted d_backing_inode() annotations
    VFS: fs/inode.c helpers: d_inode() annotations
    VFS: fs/cachefiles: d_backing_inode() annotations
    VFS: fs library helpers: d_inode() annotations
    VFS: assorted weird filesystems: d_inode() annotations
    VFS: normal filesystems (and lustre): d_inode() annotations
    VFS: security/: d_inode() annotations
    VFS: security/: d_backing_inode() annotations
    VFS: net/: d_inode() annotations
    VFS: net/unix: d_backing_inode() annotations
    VFS: kernel/: d_inode() annotations
    VFS: audit: d_backing_inode() annotations
    VFS: Fix up some ->d_inode accesses in the chelsio driver
    VFS: Cachefiles should perform fs modifications on the top layer only
    VFS: AF_UNIX sockets should call mknod on the top layer only

    Linus Torvalds
     

16 Apr, 2015

2 commits

  • most of the ->d_inode uses there refer to the same inode IO would
    go to, i.e. d_backing_inode()

    Signed-off-by: David Howells
    Signed-off-by: Al Viro

    David Howells
     
  • Pull security subsystem updates from James Morris:
    "Highlights for this window:

    - improved AVC hashing for SELinux by John Brooks and Stephen Smalley

    - addition of an unconfined label to Smack

    - Smack documentation update

    - TPM driver updates"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (28 commits)
    lsm: copy comm before calling audit_log to avoid race in string printing
    tomoyo: Do not generate empty policy files
    tomoyo: Use if_changed when generating builtin-policy.h
    tomoyo: Use bin2c to generate builtin-policy.h
    selinux: increase avtab max buckets
    selinux: Use a better hash function for avtab
    selinux: convert avtab hash table to flex_array
    selinux: reconcile security_netlbl_secattr_to_sid() and mls_import_netlbl_cat()
    selinux: remove unnecessary pointer reassignment
    Smack: Updates for Smack documentation
    tpm/st33zp24/spi: Add missing device table for spi phy.
    tpm/st33zp24: Add proper wait for ordinal duration in case of irq mode
    smack: Fix gcc warning from unused smack_syslog_lock mutex in smackfs.c
    Smack: Allow an unconfined label in bringup mode
    Smack: getting the Smack security context of keys
    Smack: Assign smack_known_web as default smk_in label for kernel thread's socket
    tpm/tpm_infineon: Use struct dev_pm_ops for power management
    MAINTAINERS: Add Jason as designated reviewer for TPM
    tpm: Update KConfig text to include TPM2.0 FIFO chips
    tpm/st33zp24/dts/st33zp24-spi: Add dts documentation for st33zp24 spi phy
    ...

    Linus Torvalds
     

12 Apr, 2015

1 commit


24 Mar, 2015

3 commits

  • I have vehemently opposed adding a "permissive" mode to Smack
    for the simple reasons that it would be subject to massive abuse
    and that developers refuse to turn it off come product release.
    I still believe that this is true, and still refuse to add a
    general "permissive mode". So don't ask again.

    Bumjin Im suggested an approach that addresses most of the concerns,
    and I have implemented it here. I still believe that we'd be better
    off without this sort of thing, but it looks like this minimizes the
    abuse potential.

    Firstly, you have to configure Smack Bringup Mode. That allows
    for "release" software to be ammune from abuse. Second, only one
    label gets to be "permissive" at a time. You can use it for
    debugging, but that's about it.

    A label written to smackfs/unconfined is treated specially.
    If either the subject or object label of an access check
    matches the "unconfined" label, and the access would not
    have been allowed otherwise an audit record and a console
    message are generated. The audit record "request" string is
    marked with either "(US)" or "(UO)", to indicate that the
    request was granted because of an unconfined label. The
    fact that an inode was accessed by an unconfined label is
    remembered, and subsequent accesses to that "impure"
    object are noted in the log. The impurity is not stored in
    the filesystem, so a file mislabled as a side effect of
    using an unconfined label may still cause concern after
    a reboot.

    So, it's there, it's dangerous, but so many application
    developers seem incapable of living without it I have
    given in. I've tried to make it as safe as I can, but
    in the end it's still a chain saw.

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     
  • With this commit, the LSM Smack implements the LSM
    side part of the system call keyctl with the action
    code KEYCTL_GET_SECURITY.

    It is now possible to get the context of, for example,
    the user session key using the command "keyctl security @s".

    The original patch has been modified for merge.

    Signed-off-by: José Bollo
    Signed-off-by: Casey Schaufler

    José Bollo
     
  • This change fixes the bug associated with sockets owned by kernel threads. These
    sockets, created usually by network devices' drivers tasks, received smk_in
    label from the task that created them - the "floor" label in the most cases. The
    result was that they were not able to receive data packets because of missing
    smack rules. The main reason of the access deny is that the socket smk_in label
    is placed as the object during smk check, kernel thread's capabilities are
    omitted.

    Signed-off-by: Marcin Lis

    Marcin Lis
     

23 Feb, 2015

1 commit


12 Feb, 2015

1 commit


22 Jan, 2015

1 commit

  • We hit use after free on dereferncing pointer to task_smack struct in
    smk_of_task() called from smack_task_to_inode().

    task_security() macro uses task_cred_xxx() to get pointer to the task_smack.
    task_cred_xxx() could be used only for non-pointer members of task's
    credentials. It cannot be used for pointer members since what they point
    to may disapper after dropping RCU read lock.

    Mainly task_security() used this way:
    smk_of_task(task_security(p))

    Intead of this introduce function smk_of_task_struct() which
    takes task_struct as argument and returns pointer to smk_known struct
    and do this under RCU read lock.
    Bogus task_security() macro is not used anymore, so remove it.

    KASan's report for this:

    AddressSanitizer: use after free in smack_task_to_inode+0x50/0x70 at addr c4635600
    =============================================================================
    BUG kmalloc-64 (Tainted: PO): kasan error
    -----------------------------------------------------------------------------

    Disabling lock debugging due to kernel taint
    INFO: Allocated in new_task_smack+0x44/0xd8 age=39 cpu=0 pid=1866
    kmem_cache_alloc_trace+0x88/0x1bc
    new_task_smack+0x44/0xd8
    smack_cred_prepare+0x48/0x21c
    security_prepare_creds+0x44/0x4c
    prepare_creds+0xdc/0x110
    smack_setprocattr+0x104/0x150
    security_setprocattr+0x4c/0x54
    proc_pid_attr_write+0x12c/0x194
    vfs_write+0x1b0/0x370
    SyS_write+0x5c/0x94
    ret_fast_syscall+0x0/0x48
    INFO: Freed in smack_cred_free+0xc4/0xd0 age=27 cpu=0 pid=1564
    kfree+0x270/0x290
    smack_cred_free+0xc4/0xd0
    security_cred_free+0x34/0x3c
    put_cred_rcu+0x58/0xcc
    rcu_process_callbacks+0x738/0x998
    __do_softirq+0x264/0x4cc
    do_softirq+0x94/0xf4
    irq_exit+0xbc/0x120
    handle_IRQ+0x104/0x134
    gic_handle_irq+0x70/0xac
    __irq_svc+0x44/0x78
    _raw_spin_unlock+0x18/0x48
    sync_inodes_sb+0x17c/0x1d8
    sync_filesystem+0xac/0xfc
    vdfs_file_fsync+0x90/0xc0
    vfs_fsync_range+0x74/0x7c
    INFO: Slab 0xd3b23f50 objects=32 used=31 fp=0xc4635600 flags=0x4080
    INFO: Object 0xc4635600 @offset=5632 fp=0x (null)

    Bytes b4 c46355f0: 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
    Object c4635600: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
    Object c4635610: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
    Object c4635620: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
    Object c4635630: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 kkkkkkkkkkkkkkk.
    Redzone c4635640: bb bb bb bb ....
    Padding c46356e8: 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
    Padding c46356f8: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ
    CPU: 5 PID: 834 Comm: launchpad_prelo Tainted: PBO 3.10.30 #1
    Backtrace:
    [] (dump_backtrace+0x0/0x158) from [] (show_stack+0x20/0x24)
    r7:c4634010 r6:d3b23f50 r5:c4635600 r4:d1002140
    [] (show_stack+0x0/0x24) from [] (dump_stack+0x20/0x28)
    [] (dump_stack+0x0/0x28) from [] (print_trailer+0x124/0x144)
    [] (print_trailer+0x0/0x144) from [] (object_err+0x3c/0x44)
    r7:c4635600 r6:d1002140 r5:d3b23f50 r4:c4635600
    [] (object_err+0x0/0x44) from [] (kasan_report_error+0x2b8/0x538)
    r6:d1002140 r5:d3b23f50 r4:c6429cf8 r3:c09e1aa7
    [] (kasan_report_error+0x0/0x538) from [] (__asan_load4+0xd4/0xf8)
    [] (__asan_load4+0x0/0xf8) from [] (smack_task_to_inode+0x50/0x70)
    r5:c4635600 r4:ca9da000
    [] (smack_task_to_inode+0x0/0x70) from [] (security_task_to_inode+0x3c/0x44)
    r5:cca25e80 r4:c0ba9780
    [] (security_task_to_inode+0x0/0x44) from [] (pid_revalidate+0x124/0x178)
    r6:00000000 r5:cca25e80 r4:cbabe3c0 r3:00008124
    [] (pid_revalidate+0x0/0x178) from [] (lookup_fast+0x35c/0x43y4)
    r9:c6429efc r8:00000101 r7:c079d940 r6:c6429e90 r5:c6429ed8 r4:c83c4148
    [] (lookup_fast+0x0/0x434) from [] (do_last.isra.24+0x1c0/0x1108)
    [] (do_last.isra.24+0x0/0x1108) from [] (path_openat.isra.25+0xf4/0x648)
    [] (path_openat.isra.25+0x0/0x648) from [] (do_filp_open+0x3c/0x88)
    [] (do_filp_open+0x0/0x88) from [] (do_sys_open+0xf0/0x198)
    r7:00000001 r6:c0ea2180 r5:0000000b r4:00000000
    [] (do_sys_open+0x0/0x198) from [] (SyS_open+0x30/0x34)
    [] (SyS_open+0x0/0x34) from [] (ret_fast_syscall+0x0/0x48)
    Read of size 4 by thread T834:
    Memory state around the buggy address:
    c4635380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    c4635400: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
    c4635480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    c4635500: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
    c4635580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    >c4635600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
    ^
    c4635680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
    c4635700: 00 00 00 00 04 fc fc fc fc fc fc fc fc fc fc fc
    c4635780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    c4635800: 00 00 00 00 00 00 04 fc fc fc fc fc fc fc fc fc
    c4635880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    ==================================================================

    Signed-off-by: Andrey Ryabinin
    Cc:

    Andrey Ryabinin
     

21 Jan, 2015

3 commits

  • During UDS connection check, both sides are checked for write access to
    the other side. But only the first check is performed with audit support.
    The second one didn't produce any audit logs. This simple patch fixes that.

    Signed-off-by: Rafal Krypa

    Rafal Krypa
     
  • Smack uses CIPSO to label internet packets and thus provide
    for access control on delivery of packets. The netfilter facility
    was not used to allow for Smack to work properly without netfilter
    configuration. Smack does not need netfilter, however there are
    cases where it would be handy.

    As a side effect, the labeling of local IPv4 packets can be optimized
    and the handling of local IPv6 packets is just all out better.

    The best part is that the netfilter tools use "contexts" that
    are just strings, and they work just as well for Smack as they
    do for SELinux.

    All of the conditional compilation for IPv6 was implemented
    by Rafal Krypa

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     
  • This is one of those cases where you look at code you did
    years ago and wonder what you might have been thinking.
    There are a number of LSM hooks that work off of file pointers,
    and most of them really want the security data from the inode.
    Some, however, really want the security context that the process
    had when the file was opened. The difference went undetected in
    Smack until it started getting used in a real system with real
    testing. At that point it was clear that something was amiss.

    This patch corrects the misuse of the f_security value in several
    of the hooks. The behavior will not usually be any different, as
    the process had to be able to open the file in the first place, and
    the old check almost always succeeded, as will the new, but for
    different reasons.

    Thanks to the Samsung Tizen development team that identified this.

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

20 Jan, 2015

4 commits


15 Dec, 2014

1 commit

  • Pull security layer updates from James Morris:
    "In terms of changes, there's general maintenance to the Smack,
    SELinux, and integrity code.

    The IMA code adds a new kconfig option, IMA_APPRAISE_SIGNED_INIT,
    which allows IMA appraisal to require signatures. Support for reading
    keys from rootfs before init is call is also added"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (23 commits)
    selinux: Remove security_ops extern
    security: smack: fix out-of-bounds access in smk_parse_smack()
    VFS: refactor vfs_read()
    ima: require signature based appraisal
    integrity: provide a hook to load keys when rootfs is ready
    ima: load x509 certificate from the kernel
    integrity: provide a function to load x509 certificate from the kernel
    integrity: define a new function integrity_read_file()
    Security: smack: replace kzalloc with kmem_cache for inode_smack
    Smack: Lock mode for the floor and hat labels
    ima: added support for new kernel cmdline parameter ima_template_fmt
    ima: allocate field pointers array on demand in template_desc_init_fields()
    ima: don't allocate a copy of template_fmt in template_desc_init_fields()
    ima: display template format in meas. list if template name length is zero
    ima: added error messages to template-related functions
    ima: use atomic bit operations to protect policy update interface
    ima: ignore empty and with whitespaces policy lines
    ima: no need to allocate entry for comment
    ima: report policy load status
    ima: use path names cache
    ...

    Linus Torvalds