26 Jan, 2011

1 commit

  • Fix __key_link_end()'s attempt to fix up the quota if an error occurs.

    There are two erroneous cases: Firstly, we always decrease the quota if
    the preallocated replacement keyring needs cleaning up, irrespective of
    whether or not we should (we may have replaced a pointer rather than
    adding another pointer).

    Secondly, we never clean up the quota if we added a pointer without the
    keyring storage being extended (we allocate multiple pointers at a time,
    even if we're not going to use them all immediately).

    We handle this by setting the bottom bit of the preallocation pointer in
    __key_link_begin() to indicate that the quota needs fixing up, which is
    then passed to __key_link() (which clears the whole thing) and
    __key_link_end().

    Signed-off-by: David Howells
    Signed-off-by: Linus Torvalds

    David Howells
     

24 Jan, 2011

4 commits


22 Jan, 2011

2 commits

  • Fix up comments in the key management code. No functional changes.

    Signed-off-by: David Howells
    Signed-off-by: Linus Torvalds

    David Howells
     
  • Do a bit of a style clean up in the key management code. No functional
    changes.

    Done using:

    perl -p -i -e 's!^/[*]*/\n!!' security/keys/*.c
    perl -p -i -e 's!} /[*] end [a-z0-9_]*[(][)] [*]/\n!}\n!' security/keys/*.c
    sed -i -s -e ": next" -e N -e 's/^\n[}]$/}/' -e t -e P -e 's/^.*\n//' -e "b next" security/keys/*.c

    To remove /*****/ lines, remove comments on the closing brace of a
    function to name the function and remove blank lines before the closing
    brace of a function.

    Signed-off-by: David Howells
    Signed-off-by: Linus Torvalds

    David Howells
     

19 Jan, 2011

3 commits

  • We can avoid scattering va_end() within the

    va_start();
    for (;;) {

    }
    va_end();

    loop, assuming that crypto_shash_init()/crypto_shash_update() return 0 on
    success and negative value otherwise.

    Make TSS_authhmac()/TSS_checkhmac1()/TSS_checkhmac2() similar to TSS_rawhmac()
    by removing "va_end()/goto" from the loop.

    Signed-off-by: Tetsuo Handa
    Reviewed-by: Jesper Juhl
    Acked-by: Mimi Zohar
    Acked-by: David Howells
    Signed-off-by: James Morris

    Tetsuo Handa
     
  • TSS_rawhmac() checks for data != NULL before using it.
    We should do the same thing for TSS_authhmac().

    Signed-off-by: Tetsuo Handa
    Reviewed-by: Jesper Juhl
    Acked-by: Mimi Zohar
    Acked-by: David Howells
    Signed-off-by: James Morris

    Tetsuo Handa
     
  • TSS_rawhmac() forgot to call va_end()/kfree() when data == NULL and
    forgot to call va_end() when crypto_shash_update() < 0.
    Fix these bugs by escaping from the loop using "break"
    (rather than "return"/"goto") in order to make sure that
    va_end()/kfree() are always called.

    Signed-off-by: Tetsuo Handa
    Reviewed-by: Jesper Juhl
    Acked-by: Mimi Zohar
    Acked-by: David Howells
    Signed-off-by: James Morris

    Tetsuo Handa
     

14 Jan, 2011

2 commits

  • Add missing kfree(td) in tpm_seal() before the return, freeing
    td on error paths as well.

    Reported-by: Dan Carpenter
    Signed-off-by: Mimi Zohar
    Acked-by: David Safford
    Acked-by: David Howells
    Signed-off-by: Serge Hallyn
    Signed-off-by: James Morris

    Mimi Zohar
     
  • * 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial: (43 commits)
    Documentation/trace/events.txt: Remove obsolete sched_signal_send.
    writeback: fix global_dirty_limits comment runtime -> real-time
    ppc: fix comment typo singal -> signal
    drivers: fix comment typo diable -> disable.
    m68k: fix comment typo diable -> disable.
    wireless: comment typo fix diable -> disable.
    media: comment typo fix diable -> disable.
    remove doc for obsolete dynamic-printk kernel-parameter
    remove extraneous 'is' from Documentation/iostats.txt
    Fix spelling milisec -> ms in snd_ps3 module parameter description
    Fix spelling mistakes in comments
    Revert conflicting V4L changes
    i7core_edac: fix typos in comments
    mm/rmap.c: fix comment
    sound, ca0106: Fix assignment to 'channel'.
    hrtimer: fix a typo in comment
    init/Kconfig: fix typo
    anon_inodes: fix wrong function name in comment
    fix comment typos concerning "consistent"
    poll: fix a typo in comment
    ...

    Fix up trivial conflicts in:
    - drivers/net/wireless/iwlwifi/iwl-core.c (moved to iwl-legacy.c)
    - fs/ext4/ext4.h

    Also fix missed 'diabled' typo in drivers/net/bnx2x/bnx2x.h while at it.

    Linus Torvalds
     

11 Jan, 2011

3 commits

  • …s/security-testing-2.6

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6: (30 commits)
    MAINTAINERS: Add tomoyo-dev-en ML.
    SELinux: define permissions for DCB netlink messages
    encrypted-keys: style and other cleanup
    encrypted-keys: verify datablob size before converting to binary
    trusted-keys: kzalloc and other cleanup
    trusted-keys: additional TSS return code and other error handling
    syslog: check cap_syslog when dmesg_restrict
    Smack: Transmute labels on specified directories
    selinux: cache sidtab_context_to_sid results
    SELinux: do not compute transition labels on mountpoint labeled filesystems
    This patch adds a new security attribute to Smack called SMACK64EXEC. It defines label that is used while task is running.
    SELinux: merge policydb_index_classes and policydb_index_others
    selinux: convert part of the sym_val_to_name array to use flex_array
    selinux: convert type_val_to_struct to flex_array
    flex_array: fix flex_array_put_ptr macro to be valid C
    SELinux: do not set automatic i_ino in selinuxfs
    selinux: rework security_netlbl_secattr_to_sid
    SELinux: standardize return code handling in selinuxfs.c
    SELinux: standardize return code handling in selinuxfs.c
    SELinux: standardize return code handling in policydb.c
    ...

    Linus Torvalds
     
  • Remove kobject.h from files which don't need it, notably,
    sched.h and fs.h.

    Signed-off-by: Alexey Dobriyan
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     
  • Remove path.h from sched.h and other files.

    Signed-off-by: Alexey Dobriyan
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

10 Jan, 2011

2 commits


08 Jan, 2011

1 commit

  • …t/npiggin/linux-npiggin

    * 'vfs-scale-working' of git://git.kernel.org/pub/scm/linux/kernel/git/npiggin/linux-npiggin: (57 commits)
    fs: scale mntget/mntput
    fs: rename vfsmount counter helpers
    fs: implement faster dentry memcmp
    fs: prefetch inode data in dcache lookup
    fs: improve scalability of pseudo filesystems
    fs: dcache per-inode inode alias locking
    fs: dcache per-bucket dcache hash locking
    bit_spinlock: add required includes
    kernel: add bl_list
    xfs: provide simple rcu-walk ACL implementation
    btrfs: provide simple rcu-walk ACL implementation
    ext2,3,4: provide simple rcu-walk ACL implementation
    fs: provide simple rcu-walk generic_check_acl implementation
    fs: provide rcu-walk aware permission i_ops
    fs: rcu-walk aware d_revalidate method
    fs: cache optimise dentry and inode for rcu-walk
    fs: dcache reduce branches in lookup path
    fs: dcache remove d_mounted
    fs: fs_struct use seqlock
    fs: rcu-walk for path lookup
    ...

    Linus Torvalds
     

07 Jan, 2011

6 commits

  • Perform common cases of path lookups without any stores or locking in the
    ancestor dentry elements. This is called rcu-walk, as opposed to the current
    algorithm which is a refcount based walk, or ref-walk.

    This results in far fewer atomic operations on every path element,
    significantly improving path lookup performance. It also avoids cacheline
    bouncing on common dentries, significantly improving scalability.

    The overall design is like this:
    * LOOKUP_RCU is set in nd->flags, which distinguishes rcu-walk from ref-walk.
    * Take the RCU lock for the entire path walk, starting with the acquiring
    of the starting path (eg. root/cwd/fd-path). So now dentry refcounts are
    not required for dentry persistence.
    * synchronize_rcu is called when unregistering a filesystem, so we can
    access d_ops and i_ops during rcu-walk.
    * Similarly take the vfsmount lock for the entire path walk. So now mnt
    refcounts are not required for persistence. Also we are free to perform mount
    lookups, and to assume dentry mount points and mount roots are stable up and
    down the path.
    * Have a per-dentry seqlock to protect the dentry name, parent, and inode,
    so we can load this tuple atomically, and also check whether any of its
    members have changed.
    * Dentry lookups (based on parent, candidate string tuple) recheck the parent
    sequence after the child is found in case anything changed in the parent
    during the path walk.
    * inode is also RCU protected so we can load d_inode and use the inode for
    limited things.
    * i_mode, i_uid, i_gid can be tested for exec permissions during path walk.
    * i_op can be loaded.

    When we reach the destination dentry, we lock it, recheck lookup sequence,
    and increment its refcount and mountpoint refcount. RCU and vfsmount locks
    are dropped. This is termed "dropping rcu-walk". If the dentry refcount does
    not match, we can not drop rcu-walk gracefully at the current point in the
    lokup, so instead return -ECHILD (for want of a better errno). This signals the
    path walking code to re-do the entire lookup with a ref-walk.

    Aside from the final dentry, there are other situations that may be encounted
    where we cannot continue rcu-walk. In that case, we drop rcu-walk (ie. take
    a reference on the last good dentry) and continue with a ref-walk. Again, if
    we can drop rcu-walk gracefully, we return -ECHILD and do the whole lookup
    using ref-walk. But it is very important that we can continue with ref-walk
    for most cases, particularly to avoid the overhead of double lookups, and to
    gain the scalability advantages on common path elements (like cwd and root).

    The cases where rcu-walk cannot continue are:
    * NULL dentry (ie. any uncached path element)
    * parent with d_inode->i_op->permission or ACLs
    * dentries with d_revalidate
    * Following links

    In future patches, permission checks and d_revalidate become rcu-walk aware. It
    may be possible eventually to make following links rcu-walk aware.

    Uncached path elements will always require dropping to ref-walk mode, at the
    very least because i_mutex needs to be grabbed, and objects allocated.

    Signed-off-by: Nick Piggin

    Nick Piggin
     
  • dget_locked was a shortcut to avoid the lazy lru manipulation when we already
    held dcache_lock (lru manipulation was relatively cheap at that point).
    However, how that the lru lock is an innermost one, we never hold it at any
    caller, so the lock cost can now be avoided. We already have well working lazy
    dcache LRU, so it should be fine to defer LRU manipulations to scan time.

    Signed-off-by: Nick Piggin

    Nick Piggin
     
  • dcache_lock no longer protects anything. remove it.

    Signed-off-by: Nick Piggin

    Nick Piggin
     
  • Protect d_subdirs and d_child with d_lock, except in filesystems that aren't
    using dcache_lock for these anyway (eg. using i_mutex).

    Note: if we change the locking rule in future so that ->d_child protection is
    provided only with ->d_parent->d_lock, it may allow us to reduce some locking.
    But it would be an exception to an otherwise regular locking scheme, so we'd
    have to see some good results. Probably not worthwhile.

    Signed-off-by: Nick Piggin

    Nick Piggin
     
  • Protect d_unhashed(dentry) condition with d_lock. This means keeping
    DCACHE_UNHASHED bit in synch with hash manipulations.

    Signed-off-by: Nick Piggin

    Nick Piggin
     
  • * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6: (1436 commits)
    cassini: Use local-mac-address prom property for Cassini MAC address
    net: remove the duplicate #ifdef __KERNEL__
    net: bridge: check the length of skb after nf_bridge_maybe_copy_header()
    netconsole: clarify stopping message
    netconsole: don't announce stopping if nothing happened
    cnic: Fix the type field in SPQ messages
    netfilter: fix export secctx error handling
    netfilter: fix the race when initializing nf_ct_expect_hash_rnd
    ipv4: IP defragmentation must be ECN aware
    net: r6040: Return proper error for r6040_init_one
    dcb: use after free in dcb_flushapp()
    dcb: unlock on error in dcbnl_ieee_get()
    net: ixp4xx_eth: Return proper error for eth_init_one
    include/linux/if_ether.h: Add #define ETH_P_LINK_CTL for HPNA and wlan local tunnel
    net: add POLLPRI to sock_def_readable()
    af_unix: Avoid socket->sk NULL OOPS in stream connect security hooks.
    net_sched: pfifo_head_drop problem
    mac80211: remove stray extern
    mac80211: implement off-channel TX using hw r-o-c offload
    mac80211: implement hardware offload for remain-on-channel
    ...

    Linus Torvalds
     

06 Jan, 2011

1 commit

  • unix_release() can asynchornously set socket->sk to NULL, and
    it does so without holding the unix_state_lock() on "other"
    during stream connects.

    However, the reverse mapping, sk->sk_socket, is only transitioned
    to NULL under the unix_state_lock().

    Therefore make the security hooks follow the reverse mapping instead
    of the forward mapping.

    Reported-by: Jeremy Fitzhardinge
    Reported-by: Linus Torvalds
    Signed-off-by: David S. Miller

    David S. Miller
     

04 Jan, 2011

1 commit

  • If security_filter_rule_init() doesn't return a rule, then not everything
    is as fine as the return code implies.

    This bug only occurs when the LSM (eg. SELinux) is disabled at runtime.

    Adding an empty LSM rule causes ima_match_rules() to always succeed,
    ignoring any remaining rules.

    default IMA TCB policy:
    # PROC_SUPER_MAGIC
    dont_measure fsmagic=0x9fa0
    # SYSFS_MAGIC
    dont_measure fsmagic=0x62656572
    # DEBUGFS_MAGIC
    dont_measure fsmagic=0x64626720
    # TMPFS_MAGIC
    dont_measure fsmagic=0x01021994
    # SECURITYFS_MAGIC
    dont_measure fsmagic=0x73636673

    < LSM specific rule >
    dont_measure obj_type=var_log_t

    measure func=BPRM_CHECK
    measure func=FILE_MMAP mask=MAY_EXEC
    measure func=FILE_CHECK mask=MAY_READ uid=0

    Thus without the patch, with the boot parameters 'tcb selinux=0', adding
    the above 'dont_measure obj_type=var_log_t' rule to the default IMA TCB
    measurement policy, would result in nothing being measured. The patch
    prevents the default TCB policy from being replaced.

    Signed-off-by: Mimi Zohar
    Cc: James Morris
    Acked-by: Serge Hallyn
    Cc: David Safford
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Mimi Zohar
     

27 Dec, 2010

1 commit


24 Dec, 2010

1 commit

  • In construct_alloc_key(), up_write() is called in the error path if
    __key_link_begin() fails, but this is incorrect as __key_link_begin() only
    returns with the nominated keyring locked if it returns successfully.

    Without this patch, you might see the following in dmesg:

    =====================================
    [ BUG: bad unlock balance detected! ]
    -------------------------------------
    mount.cifs/5769 is trying to release lock (&key->sem) at:
    [] request_key_and_link+0x263/0x3fc
    but there are no more locks to release!

    other info that might help us debug this:
    3 locks held by mount.cifs/5769:
    #0: (&type->s_umount_key#41/1){+.+.+.}, at: [] sget+0x278/0x3e7
    #1: (&ret_buf->session_mutex){+.+.+.}, at: [] cifs_get_smb_ses+0x35a/0x443 [cifs]
    #2: (root_key_user.cons_lock){+.+.+.}, at: [] request_key_and_link+0x10a/0x3fc

    stack backtrace:
    Pid: 5769, comm: mount.cifs Not tainted 2.6.37-rc6+ #1
    Call Trace:
    [] ? request_key_and_link+0x263/0x3fc
    [] print_unlock_inbalance_bug+0xca/0xd5
    [] lock_release_non_nested+0xc1/0x263
    [] ? request_key_and_link+0x263/0x3fc
    [] ? request_key_and_link+0x263/0x3fc
    [] lock_release+0x17d/0x1a4
    [] up_write+0x23/0x3b
    [] request_key_and_link+0x263/0x3fc
    [] ? cifs_get_spnego_key+0x61/0x21f [cifs]
    [] request_key+0x41/0x74
    [] cifs_get_spnego_key+0x200/0x21f [cifs]
    [] CIFS_SessSetup+0x55d/0x1273 [cifs]
    [] cifs_setup_session+0x90/0x1ae [cifs]
    [] cifs_get_smb_ses+0x37f/0x443 [cifs]
    [] cifs_mount+0x1aa1/0x23f3 [cifs]
    [] ? alloc_debug_processing+0xdb/0x120
    [] ? cifs_get_spnego_key+0x1ef/0x21f [cifs]
    [] cifs_do_mount+0x165/0x2b3 [cifs]
    [] vfs_kern_mount+0xaf/0x1dc
    [] do_kern_mount+0x4d/0xef
    [] do_mount+0x6f4/0x733
    [] sys_mount+0x88/0xc2
    [] system_call_fastpath+0x16/0x1b

    Reported-by: Jeff Layton
    Signed-off-by: David Howells
    Reviewed-and-Tested-by: Jeff Layton
    Signed-off-by: Linus Torvalds

    David Howells
     

23 Dec, 2010

1 commit


17 Dec, 2010

1 commit

  • Commit 2f90b865 added two new netlink message types to the netlink route
    socket. SELinux has hooks to define if netlink messages are allowed to
    be sent or received, but it did not know about these two new message
    types. By default we allow such actions so noone likely noticed. This
    patch adds the proper definitions and thus proper permissions
    enforcement.

    Signed-off-by: Eric Paris

    Eric Paris
     

15 Dec, 2010

4 commits

  • Cleanup based on David Howells suggestions:
    - use static const char arrays instead of #define
    - rename init_sdesc to alloc_sdesc
    - convert 'unsigned int' definitions to 'size_t'
    - revert remaining 'const unsigned int' definitions to 'unsigned int'

    Signed-off-by: Mimi Zohar
    Acked-by: David Howells
    Signed-off-by: James Morris

    Mimi Zohar
     
  • Verify the hex ascii datablob length is correct before converting the IV,
    encrypted data, and HMAC to binary.

    Reported-by: David Howells
    Signed-off-by: Mimi Zohar
    Acked-by: David Howells
    Signed-off-by: James Morris

    Mimi Zohar
     
  • Cleanup based on David Howells suggestions:
    - replace kzalloc, where possible, with kmalloc
    - revert 'const unsigned int' definitions to 'unsigned int'

    Signed-off-by: David Safford
    Acked-by: Mimi Zohar
    Acked-by: David Howells
    Signed-off-by: James Morris

    Mimi Zohar
     
  • Previously not all TSS return codes were tested, as they were all eventually
    caught by the TPM. Now all returns are tested and handled immediately.

    This patch also fixes memory leaks in error and non-error paths.

    Signed-off-by: David Safford
    Acked-by: Mimi Zohar
    Acked-by: David Howells
    Acked-by: Serge E. Hallyn
    Signed-off-by: James Morris

    Mimi Zohar
     

08 Dec, 2010

2 commits

  • In a situation where Smack access rules allow processes
    with multiple labels to write to a directory it is easy
    to get into a situation where the directory gets cluttered
    with files that the owner can't deal with because while
    they could be written to the directory a process at the
    label of the directory can't write them. This is generally
    the desired behavior, but when it isn't it is a real
    issue.

    This patch introduces a new attribute SMACK64TRANSMUTE that
    instructs Smack to create the file with the label of the directory
    under certain circumstances.

    A new access mode, "t" for transmute, is made available to
    Smack access rules, which are expanded from "rwxa" to "rwxat".
    If a file is created in a directory marked as transmutable
    and if access was granted to perform the operation by a rule
    that included the transmute mode, then the file gets the
    Smack label of the directory instead of the Smack label of the
    creating process.

    Note that this is equivalent to creating an empty file at the
    label of the directory and then having the other process write
    to it. The transmute scheme requires that both the access rule
    allows transmutation and that the directory be explicitly marked.

    Signed-off-by: Jarkko Sakkinen
    Signed-off-by: Casey Schaufler

    Jarkko Sakkinen
     
  • sidtab_context_to_sid takes up a large share of time when creating large
    numbers of new inodes (~30-40% in oprofile runs). This patch implements a
    cache of 3 entries which is checked before we do a full context_to_sid lookup.
    On one system this showed over a x3 improvement in the number of inodes that
    could be created per second and around a 20% improvement on another system.

    Any time we look up the same context string sucessivly (imagine ls -lZ) we
    should hit this cache hot. A cache miss should have a relatively minor affect
    on performance next to doing the full table search.

    All operations on the cache are done COMPLETELY lockless. We know that all
    struct sidtab_node objects created will never be deleted until a new policy is
    loaded thus we never have to worry about a pointer being dereferenced. Since
    we also know that pointer assignment is atomic we know that the cache will
    always have valid pointers. Given this information we implement a FIFO cache
    in an array of 3 pointers. Every result (whether a cache hit or table lookup)
    will be places in the 0 spot of the cache and the rest of the entries moved
    down one spot. The 3rd entry will be lost.

    Races are possible and are even likely to happen. Lets assume that 4 tasks
    are hitting sidtab_context_to_sid. The first task checks against the first
    entry in the cache and it is a miss. Now lets assume a second task updates
    the cache with a new entry. This will push the first entry back to the second
    spot. Now the first task might check against the second entry (which it
    already checked) and will miss again. Now say some third task updates the
    cache and push the second entry to the third spot. The first task my check
    the third entry (for the third time!) and again have a miss. At which point
    it will just do a full table lookup. No big deal!

    Signed-off-by: Eric Paris

    Eric Paris
     

03 Dec, 2010

1 commit

  • selinux_inode_init_security computes transitions sids even for filesystems
    that use mount point labeling. It shouldn't do that. It should just use
    the mount point label always and no matter what.

    This causes 2 problems. 1) it makes file creation slower than it needs to be
    since we calculate the transition sid and 2) it allows files to be created
    with a different label than the mount point!

    # id -Z
    staff_u:sysadm_r:sysadm_t:s0-s0:c0.c1023
    # sesearch --type --class file --source sysadm_t --target tmp_t
    Found 1 semantic te rules:
    type_transition sysadm_t tmp_t : file user_tmp_t;

    # mount -o loop,context="system_u:object_r:tmp_t:s0" /tmp/fs /mnt/tmp

    # ls -lZ /mnt/tmp
    drwx------. root root system_u:object_r:tmp_t:s0 lost+found
    # touch /mnt/tmp/file1
    # ls -lZ /mnt/tmp
    -rw-r--r--. root root staff_u:object_r:user_tmp_t:s0 file1
    drwx------. root root system_u:object_r:tmp_t:s0 lost+found

    Whoops, we have a mount point labeled filesystem tmp_t with a user_tmp_t
    labeled file!

    Signed-off-by: Eric Paris
    Reviewed-by: Reviewed-by: James Morris

    Eric Paris
     

02 Dec, 2010

1 commit

  • SMACK64EXEC. It defines label that is used while task is
    running.

    Exception: in smack_task_wait() child task is checked
    for write access to parent task using label inherited
    from the task that forked it.

    Fixed issues from previous submit:
    - SMACK64EXEC was not read when SMACK64 was not set.
    - inode security blob was not updated after setting
    SMACK64EXEC
    - inode security blob was not updated when removing
    SMACK64EXEC

    Casey Schaufler
     

01 Dec, 2010

2 commits