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
     

22 Nov, 2014

1 commit

  • Setting smack label on file (e.g. 'attr -S -s SMACK64 -V "test" test')
    triggered following spew on the kernel with KASan applied:
    ==================================================================
    BUG: AddressSanitizer: out of bounds access in strncpy+0x28/0x60 at addr ffff8800059ad064
    =============================================================================
    BUG kmalloc-8 (Not tainted): kasan error
    -----------------------------------------------------------------------------

    Disabling lock debugging due to kernel taint
    INFO: Slab 0xffffea0000166b40 objects=128 used=7 fp=0xffff8800059ad080 flags=0x4000000000000080
    INFO: Object 0xffff8800059ad060 @offset=96 fp=0xffff8800059ad080

    Bytes b4 ffff8800059ad050: a0 df 9a 05 00 88 ff ff 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ
    Object ffff8800059ad060: 74 65 73 74 6b 6b 6b a5 testkkk.
    Redzone ffff8800059ad068: cc cc cc cc cc cc cc cc ........
    Padding ffff8800059ad078: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ
    CPU: 0 PID: 528 Comm: attr Tainted: G B 3.18.0-rc1-mm1+ #5
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
    0000000000000000 ffff8800059ad064 ffffffff81534cf2 ffff880005a5bc40
    ffffffff8112fe1a 0000000100800006 0000000f059ad060 ffff880006000f90
    0000000000000296 ffffea0000166b40 ffffffff8107ca97 ffff880005891060
    Call Trace:
    ? dump_stack (lib/dump_stack.c:52)
    ? kasan_report_error (mm/kasan/report.c:102 mm/kasan/report.c:178)
    ? preempt_count_sub (kernel/sched/core.c:2651)
    ? __asan_load1 (mm/kasan/kasan.h:50 mm/kasan/kasan.c:248 mm/kasan/kasan.c:358)
    ? strncpy (lib/string.c:121)
    ? strncpy (lib/string.c:121)
    ? smk_parse_smack (security/smack/smack_access.c:457)
    ? setxattr (fs/xattr.c:343)
    ? smk_import_entry (security/smack/smack_access.c:514)
    ? smack_inode_setxattr (security/smack/smack_lsm.c:1093 (discriminator 1))
    ? security_inode_setxattr (security/security.c:602)
    ? vfs_setxattr (fs/xattr.c:134)
    ? setxattr (fs/xattr.c:343)
    ? setxattr (fs/xattr.c:360)
    ? get_parent_ip (kernel/sched/core.c:2606)
    ? preempt_count_sub (kernel/sched/core.c:2651)
    ? __percpu_counter_add (arch/x86/include/asm/preempt.h:98 lib/percpu_counter.c:90)
    ? get_parent_ip (kernel/sched/core.c:2606)
    ? preempt_count_sub (kernel/sched/core.c:2651)
    ? __mnt_want_write (arch/x86/include/asm/preempt.h:98 fs/namespace.c:359)
    ? path_setxattr (fs/xattr.c:380)
    ? SyS_lsetxattr (fs/xattr.c:397)
    ? system_call_fastpath (arch/x86/kernel/entry_64.S:423)
    Read of size 1 by task attr:
    Memory state around the buggy address:
    ffff8800059ace80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    ffff8800059acf00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    ffff8800059acf80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    >ffff8800059ad000: 00 fc fc fc 00 fc fc fc 05 fc fc fc 04 fc fc fc
    ^
    ffff8800059ad080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
    ffff8800059ad100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
    ffff8800059ad180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
    ==================================================================

    strncpy() copies one byte more than the source string has.
    Fix this by passing the correct length to strncpy().

    Now we can remove initialization of the last byte in 'smack' string
    because kzalloc() already did this for us.

    Signed-off-by: Andrey Ryabinin

    Andrey Ryabinin
     

20 Nov, 2014

1 commit


01 Nov, 2014

1 commit

  • The patch use kmem_cache to allocate/free inode_smack since they are
    alloced in high volumes making it a perfect case for kmem_cache.

    As per analysis, 24 bytes of memory is wasted per allocation due
    to internal fragmentation. With kmem_cache, this can be avoided.

    Accounting of memory allocation is below :
    total slack net count-alloc/free caller
    Before (with kzalloc)
    1919872 719952 1919872 29998/0 new_inode_smack+0x14

    After (with kmem_cache)
    1201680 0 1201680 30042/0 new_inode_smack+0x18

    >From above data, we found that 719952 bytes(~700 KB) of memory is
    saved on allocation of 29998 smack inodes.

    Signed-off-by: Rohit

    Rohit
     

28 Oct, 2014

1 commit

  • The lock access mode allows setting a read lock on a file
    for with the process has only read access. The floor label is
    defined to make it easy to have the basic system installed such
    that everyone can read it. Once there's a desire to read lock
    (rationally or otherwise) a floor file a rule needs to get set.
    This happens all the time, so make the floor label a little bit
    more special and allow everyone lock access, too. By implication,
    give processes with the hat label (hat can read everything)
    lock access as well. This reduces clutter in the Smack rule set.

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

12 Oct, 2014

1 commit

  • Pull security subsystem updates from James Morris.

    Mostly ima, selinux, smack and key handling updates.

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (65 commits)
    integrity: do zero padding of the key id
    KEYS: output last portion of fingerprint in /proc/keys
    KEYS: strip 'id:' from ca_keyid
    KEYS: use swapped SKID for performing partial matching
    KEYS: Restore partial ID matching functionality for asymmetric keys
    X.509: If available, use the raw subjKeyId to form the key description
    KEYS: handle error code encoded in pointer
    selinux: normalize audit log formatting
    selinux: cleanup error reporting in selinux_nlmsg_perm()
    KEYS: Check hex2bin()'s return when generating an asymmetric key ID
    ima: detect violations for mmaped files
    ima: fix race condition on ima_rdwr_violation_check and process_measurement
    ima: added ima_policy_flag variable
    ima: return an error code from ima_add_boot_aggregate()
    ima: provide 'ima_appraise=log' kernel option
    ima: move keyring initialization to ima_init()
    PKCS#7: Handle PKCS#7 messages that contain no X.509 certs
    PKCS#7: Better handling of unsupported crypto
    KEYS: Overhaul key identification when searching for asymmetric keys
    KEYS: Implement binary asymmetric key ID handling
    ...

    Linus Torvalds
     

10 Sep, 2014

1 commit


30 Aug, 2014

3 commits


29 Aug, 2014

1 commit

  • People keep asking me for permissive mode, and I keep saying "no".

    Permissive mode is wrong for more reasons than I can enumerate,
    but the compelling one is that it's once on, never off.

    Nonetheless, there is an argument to be made for running a
    process with lots of permissions, logging which are required,
    and then locking the process down. There wasn't a way to do
    that with Smack, but this provides it.

    The notion is that you start out by giving the process an
    appropriate Smack label, such as "ATBirds". You create rules
    with a wide range of access and the "b" mode. On Tizen it
    might be:

    ATBirds System rwxalb
    ATBirds User rwxalb
    ATBirds _ rwxalb
    User ATBirds wb
    System ATBirds wb

    Accesses that fail will generate audit records. Accesses
    that succeed because of rules marked with a "b" generate
    log messages identifying the rule, the program and as much
    object information as is convenient.

    When the system is properly configured and the programs
    brought in line with the labeling scheme the "b" mode can
    be removed from the rules. When the system is ready for
    production the facility can be configured out.

    This provides the developer the convenience of permissive
    mode without creating a system that looks like it is
    enforcing a policy while it is not.

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

26 Aug, 2014

1 commit


09 Aug, 2014

3 commits

  • Values of extended attributes are stored as binary blobs. NULL-termination
    of them isn't required. It just wastes disk space and confuses command-line
    tools like getfattr because they have to print that zero byte at the end.

    This patch removes terminating zero byte from initial security label in
    smack_inode_init_security and cuts it out in function smack_inode_getsecurity
    which is used by syscall getxattr. This change seems completely safe, because
    function smk_parse_smack ignores everything after first zero byte.

    Signed-off-by: Konstantin Khlebnikov

    Konstantin Khlebnikov
     
  • Zero-length security labels are invalid but kernel should handle them.

    This patch fixes kernel panic after setting zero-length security labels:
    # attr -S -s "SMACK64" -V "" file

    And after writing zero-length string into smackfs files syslog and onlycp:
    # python -c 'import os; os.write(1, "")' > /smack/syslog

    The problem is caused by brain-damaged logic in function smk_parse_smack()
    which takes pointer to buffer and its length but if length below or equal zero
    it thinks that the buffer is zero-terminated. Unfortunately callers of this
    function are widely used and proper fix requires serious refactoring.

    Signed-off-by: Konstantin Khlebnikov

    Konstantin Khlebnikov
     
  • Security operation ->inode_listsecurity is used for generating list of
    available extended attributes for syscall listxattr. Currently it's used
    only in nfs4 or if filesystem doesn't provide i_op->listxattr.

    The list is the set of NULL-terminated names, one after the other.
    This method must include zero byte at the and into result.

    Also this function must return length even if string does not fit into
    output buffer or it is NULL, see similar method in selinux and man listxattr.

    Signed-off-by: Konstantin Khlebnikov

    Konstantin Khlebnikov
     

02 Aug, 2014

1 commit


01 Aug, 2014

3 commits

  • Historically the NetLabel LSM secattr catmap functions and data
    structures have had very long names which makes a mess of the NetLabel
    code and anyone who uses NetLabel. This patch renames the catmap
    functions and structures from "*_secattr_catmap_*" to just "*_catmap_*"
    which improves things greatly.

    There are no substantial code or logic changes in this patch.

    Signed-off-by: Paul Moore
    Tested-by: Casey Schaufler

    Paul Moore
     
  • The NetLabel secattr catmap functions, and the SELinux import/export
    glue routines, were broken in many horrible ways and the SELinux glue
    code fiddled with the NetLabel catmap structures in ways that we
    probably shouldn't allow. At some point this "worked", but that was
    likely due to a bit of dumb luck and sub-par testing (both inflicted
    by yours truly). This patch corrects these problems by basically
    gutting the code in favor of something less obtuse and restoring the
    NetLabel abstractions in the SELinux catmap glue code.

    Everything is working now, and if it decides to break itself in the
    future this code will be much easier to debug than the code it
    replaces.

    One noteworthy side effect of the changes is that it is no longer
    necessary to allocate a NetLabel catmap before calling one of the
    NetLabel APIs to set a bit in the catmap. NetLabel will automatically
    allocate the catmap nodes when needed, resulting in less allocations
    when the lowest bit is greater than 255 and less code in the LSMs.

    Cc: stable@vger.kernel.org
    Reported-by: Christian Evans
    Signed-off-by: Paul Moore
    Tested-by: Casey Schaufler

    Paul Moore
     
  • The NetLabel category (catmap) functions have a problem in that they
    assume categories will be set in an increasing manner, e.g. the next
    category set will always be larger than the last. Unfortunately, this
    is not a valid assumption and could result in problems when attempting
    to set categories less than the startbit in the lowest catmap node.
    In some cases kernel panics and other nasties can result.

    This patch corrects the problem by checking for this and allocating a
    new catmap node instance and placing it at the front of the list.

    Cc: stable@vger.kernel.org
    Reported-by: Christian Evans
    Signed-off-by: Paul Moore
    Tested-by: Casey Schaufler

    Paul Moore
     

20 May, 2014

1 commit


07 May, 2014

1 commit


01 May, 2014

1 commit

  • The cgroup filesystem isn't ready for an LSM to
    properly use extented attributes. This patch makes
    files created in the cgroup filesystem usable by
    a system running Smack and systemd.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

23 Apr, 2014

1 commit

  • Smack believes that many of the operatons that can
    be performed on an open file descriptor are read operations.
    The fstat and lseek system calls are examples.
    An implication of this is that files shouldn't be open
    if the task doesn't have read access even if it has
    write access and the file is being opened write only.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

12 Apr, 2014

8 commits

  • Smack IPC policy requires that the sender have write access
    to the receiver. UDS streams don't do per-packet checks. The
    only check is done at connect time. The existing code checks
    if the connecting process can write to the other, but not the
    other way around. This change adds a check that the other end
    can write to the connecting process.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schuafler

    Casey Schaufler
     
  • Sam Henderson points out that removing the SMACK64TRANSMUTE
    attribute from a directory does not result in the directory
    transmuting. This is because the inode flag indicating that
    the directory is transmuting isn't cleared. The fix is a tad
    less than trivial because smk_task and smk_mmap should have
    been broken out, too.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     
  • The function `smack_inode_post_setxattr` is called each
    time that a setxattr is done, for any value of name.
    The kernel allow to put value==NULL when size==0
    to set an empty attribute value. The systematic
    call to smk_import_entry was causing the dereference
    of a NULL pointer hence a KERNEL PANIC!

    The problem can be produced easily by issuing the
    command `setfattr -n user.data file` under bash prompt
    when SMACK is active.

    Moving the call to smk_import_entry as proposed by this
    patch is correcting the behaviour because the function
    smack_inode_post_setxattr is called for the SMACK's
    attributes only if the function smack_inode_setxattr validated
    the value and its size (what will not be the case when size==0).

    It also has a benefical effect to not fill the smack hash
    with garbage values coming from any extended attribute
    write.

    Change-Id: Iaf0039c2be9bccb6cee11c24a3b44d209101fe47
    Signed-off-by: José Bollo

    José Bollo
     
  • 1. In order to remove any SMACK extended attribute from a file, a user
    should have CAP_MAC_ADMIN capability. But user without having this
    capability is able to remove SMACK64MMAP security attribute.

    2. While validating size and value of smack extended attribute in
    smack_inode_setsecurity hook, wrong error code is returned.

    Signed-off-by: Pankaj Kumar
    Signed-off-by: Himanshu Shukla

    Pankaj Kumar
     
  • This allows to limit ptrace beyond the regular smack access rules.
    It adds a smackfs/ptrace interface that allows smack to be configured
    to require equal smack labels for PTRACE_MODE_ATTACH access.
    See the changes in Documentation/security/Smack.txt below for details.

    Signed-off-by: Lukasz Pawelczyk
    Signed-off-by: Rafal Krypa

    Lukasz Pawelczyk
     
  • The decision whether we can trace a process is made in the following
    functions:
    smack_ptrace_traceme()
    smack_ptrace_access_check()
    smack_bprm_set_creds() (in case the proces is traced)

    This patch unifies all those decisions by introducing one function that
    checks whether ptrace is allowed: smk_ptrace_rule_check().

    This makes possible to actually trace with TRACEME where first the
    TRACEME itself must be allowed and then exec() on a traced process.

    Additional bugs fixed:
    - The decision is made according to the mode parameter that is now correctly
    translated from PTRACE_MODE_* to MAY_* instead of being treated 1:1.
    PTRACE_MODE_READ requires MAY_READ.
    PTRACE_MODE_ATTACH requires MAY_READWRITE.
    - Add a smack audit log in case of exec() refused by bprm_set_creds().
    - Honor the PTRACE_MODE_NOAUDIT flag and don't put smack audit info
    in case this flag is set.

    Signed-off-by: Lukasz Pawelczyk
    Signed-off-by: Rafal Krypa

    Lukasz Pawelczyk
     
  • The order of subject/object is currently reversed in
    smack_ptrace_traceme(). It is currently checked if the tracee has a
    capability to trace tracer and according to this rule a decision is made
    whether the tracer will be allowed to trace tracee.

    Signed-off-by: Lukasz Pawelczyk
    Signed-off-by: Rafal Krypa

    Lukasz Pawelczyk
     
  • Fix a possible memory access fault when transmute is true and isp is NULL.

    Signed-off-by: José Bollo

    José Bollo
     

15 Mar, 2014

2 commits

  • For any keyring access type SMACK always used MAY_READWRITE access check.
    It prevents reading the key with label "_", which should be allowed for anyone.

    This patch changes default access check to MAY_READ and use MAY_READWRITE in only
    appropriate cases.

    Signed-off-by: Dmitry Kasatkin
    Signed-off-by: David Howells
    Acked-by: Casey Schaufler

    Dmitry Kasatkin
     
  • Move the flags representing required permission to linux/key.h as the perm
    parameter of security_key_permission() is in terms of them - and not the
    permissions mask flags used in key->perm.

    Whilst we're at it:

    (1) Rename them to be KEY_NEED_xxx rather than KEY_xxx to avoid collisions
    with symbols in uapi/linux/input.h.

    (2) Don't use key_perm_t for a mask of required permissions, but rather limit
    it to the permissions mask attached to the key and arguments related
    directly to that.

    Signed-off-by: David Howells
    Tested-by: Dmitry Kasatkin

    David Howells
     

24 Jan, 2014

1 commit

  • Pull audit update from Eric Paris:
    "Again we stayed pretty well contained inside the audit system.
    Venturing out was fixing a couple of function prototypes which were
    inconsistent (didn't hurt anything, but we used the same value as an
    int, uint, u32, and I think even a long in a couple of places).

    We also made a couple of minor changes to when a couple of LSMs called
    the audit system. We hoped to add aarch64 audit support this go
    round, but it wasn't ready.

    I'm disappearing on vacation on Thursday. I should have internet
    access, but it'll be spotty. If anything goes wrong please be sure to
    cc rgb@redhat.com. He'll make fixing things his top priority"

    * git://git.infradead.org/users/eparis/audit: (50 commits)
    audit: whitespace fix in kernel-parameters.txt
    audit: fix location of __net_initdata for audit_net_ops
    audit: remove pr_info for every network namespace
    audit: Modify a set of system calls in audit class definitions
    audit: Convert int limit uses to u32
    audit: Use more current logging style
    audit: Use hex_byte_pack_upper
    audit: correct a type mismatch in audit_syscall_exit()
    audit: reorder AUDIT_TTY_SET arguments
    audit: rework AUDIT_TTY_SET to only grab spin_lock once
    audit: remove needless switch in AUDIT_SET
    audit: use define's for audit version
    audit: documentation of audit= kernel parameter
    audit: wait_for_auditd rework for readability
    audit: update MAINTAINERS
    audit: log task info on feature change
    audit: fix incorrect set of audit_sock
    audit: print error message when fail to create audit socket
    audit: fix dangling keywords in audit_log_set_loginuid() output
    audit: log on errors from filter user rules
    ...

    Linus Torvalds
     

14 Jan, 2014

1 commit


01 Jan, 2014

2 commits

  • Eric Paris politely points out:

    Inside smack_file_receive() it seems like you are initting the audit
    field with LSM_AUDIT_DATA_TASK. And then use
    smk_ad_setfield_u_fs_path().

    Seems like LSM_AUDIT_DATA_PATH would make more sense. (and depending
    on how it's used fix a crash...)

    He is correct. This puts things in order.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     
  • The mount restrictions imposed by Smack rely heavily on the
    use of the filesystem "floor", which is the label that all
    processes writing to the filesystem must have access to. It
    turns out that while the "floor" notion is sound, it has yet
    to be fully implemented and has never been used.

    The sb_mount and sb_umount hooks only make sense if the
    filesystem floor is used actively, and it isn't. They can
    be reintroduced if a rational restriction comes up. Until
    then, they get removed.

    The sb_kern_mount hook is required for the option processing.
    It is too permissive in the case of unprivileged mounts,
    effectively bypassing the CAP_MAC_ADMIN restrictions if
    any of the smack options are specified. Unprivileged mounts
    are no longer allowed to set Smack filesystem options.
    Additionally, the root and default values are set to the
    label of the caller, in keeping with the policy that objects
    get the label of their creator.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

24 Dec, 2013

2 commits

  • smk_write_change_rule() is calling capable rather than
    the more correct smack_privileged(). This allows for setting
    rules in violation of the onlycap facility. This is the
    simple repair.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     
  • The syslog control requires that the calling proccess
    have the floor ("_") Smack label. Tizen does not run any
    processes except for kernel helpers with the floor label.
    This changes allows the admin to configure a specific
    label for syslog. The default value is the star ("*")
    label, effectively removing the restriction. The value
    can be set using smackfs/syslog for anyone who wants
    a more restrictive behavior.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schaufler

    Casey Schaufler
     

20 Dec, 2013

1 commit

  • Smack prohibits processes from using the star ("*") and web ("@") labels
    because we don't want files with those labels getting created implicitly.
    All setting of those labels should be done explicitly. The trouble is that
    there is no check for these labels in the processing of SMACK64EXEC. That
    is repaired.

    Targeted for git://git.gitorious.org/smack-next/kernel.git

    Signed-off-by: Casey Schaufler

    Casey Schaufler