17 Oct, 2007

6 commits

  • Make request_key() and co fundamentally asynchronous to make it easier for
    NFS to make use of them. There are now accessor functions that do
    asynchronous constructions, a wait function to wait for construction to
    complete, and a completion function for the key type to indicate completion
    of construction.

    Note that the construction queue is now gone. Instead, keys under
    construction are linked in to the appropriate keyring in advance, and that
    anyone encountering one must wait for it to be complete before they can use
    it. This is done automatically for userspace.

    The following auxiliary changes are also made:

    (1) Key type implementation stuff is split from linux/key.h into
    linux/key-type.h.

    (2) AF_RXRPC provides a way to allocate null rxrpc-type keys so that AFS does
    not need to call key_instantiate_and_link() directly.

    (3) Adjust the debugging macros so that they're -Wformat checked even if
    they are disabled, and make it so they can be enabled simply by defining
    __KDEBUG to be consistent with other code of mine.

    (3) Documentation.

    [alan@lxorguk.ukuu.org.uk: keys: missing word in documentation]
    Signed-off-by: David Howells
    Signed-off-by: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Howells
     
  • This patch kills ugly warnings when the "Improve SELinux performance
    when ACV misses" patch.

    Signed-off-by: KaiGai Kohei
    Signed-off-by: James Morris

    KaiGai Kohei
     
  • * We add ebitmap_for_each_positive_bit() which enables to walk on
    any positive bit on the given ebitmap, to improve its performance
    using common bit-operations defined in linux/bitops.h.
    In the previous version, this logic was implemented using a combination
    of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
    in performance aspect.
    This logic is most frequestly used to compute a new AVC entry,
    so this patch can improve SELinux performance when AVC misses are happen.
    * struct ebitmap_node is redefined as an array of "unsigned long", to get
    suitable for using find_next_bit() which is fasted than iteration of
    shift and logical operation, and to maximize memory usage allocated
    from general purpose slab.
    * Any ebitmap_for_each_bit() are repleced by the new implementation
    in ss/service.c and ss/mls.c. Some of related implementation are
    changed, however, there is no incompatibility with the previous
    version.
    * The width of any new line are less or equal than 80-chars.

    The following benchmark shows the effect of this patch, when we
    access many files which have different security context one after
    another. The number is more than /selinux/avc/cache_threshold, so
    any access always causes AVC misses.

    selinux-2.6 selinux-2.6-ebitmap
    AVG: 22.763 [s] 8.750 [s]
    STD: 0.265 0.019
    ------------------------------------------
    1st: 22.558 [s] 8.786 [s]
    2nd: 22.458 [s] 8.750 [s]
    3rd: 22.478 [s] 8.754 [s]
    4th: 22.724 [s] 8.745 [s]
    5th: 22.918 [s] 8.748 [s]
    6th: 22.905 [s] 8.764 [s]
    7th: 23.238 [s] 8.726 [s]
    8th: 22.822 [s] 8.729 [s]

    Signed-off-by: KaiGai Kohei
    Acked-by: Stephen Smalley
    Signed-off-by: James Morris

    KaiGai Kohei
     
  • Allow policy to select, in much the same way as it selects MLS support, how
    the kernel should handle access decisions which contain either unknown
    classes or unknown permissions in known classes. The three choices for the
    policy flags are

    0 - Deny unknown security access. (default)
    2 - reject loading policy if it does not contain all definitions
    4 - allow unknown security access

    The policy's choice is exported through 2 booleans in
    selinuxfs. /selinux/deny_unknown and /selinux/reject_unknown.

    Signed-off-by: Eric Paris
    Acked-by: Stephen Smalley
    Signed-off-by: James Morris

    Eric Paris
     
  • It reduces the selinux overhead on read/write by only revalidating
    permissions in selinux_file_permission if the task or inode labels have
    changed or the policy has changed since the open-time check. A new LSM
    hook, security_dentry_open, is added to capture the necessary state at open
    time to allow this optimization.

    (see http://marc.info/?l=selinux&m=118972995207740&w=2)

    Signed-off-by: Yuichi Nakamura
    Acked-by: Stephen Smalley
    Signed-off-by: James Morris

    Yuichi Nakamura
     
  • This patch reduces memory usage of SELinux by tuning avtab. Number of hash
    slots in avtab was 32768. Unused slots used memory when number of rules is
    fewer. This patch decides number of hash slots dynamically based on number
    of rules. (chain length)^2 is also printed out in avtab_hash_eval to see
    standard deviation of avtab hash table.

    Signed-off-by: Yuichi Nakamura
    Acked-by: Stephen Smalley
    Signed-off-by: James Morris

    Yuichi Nakamura
     

16 Oct, 2007

1 commit


11 Oct, 2007

3 commits

  • Expansion of original idea from Denis V. Lunev

    Add robustness and locking to the local_port_range sysctl.
    1. Enforce that low < high when setting.
    2. Use seqlock to ensure atomic update.

    The locking might seem like overkill, but there are
    cases where sysadmin might want to change value in the
    middle of a DoS attack.

    Signed-off-by: Stephen Hemminger
    Signed-off-by: David S. Miller

    Stephen Hemminger
     
  • Each netlink socket will live in exactly one network namespace,
    this includes the controlling kernel sockets.

    This patch updates all of the existing netlink protocols
    to only support the initial network namespace. Request
    by clients in other namespaces will get -ECONREFUSED.
    As they would if the kernel did not have the support for
    that netlink protocol compiled in.

    As each netlink protocol is updated to be multiple network
    namespace safe it can register multiple kernel sockets
    to acquire a presence in the rest of the network namespaces.

    The implementation in af_netlink is a simple filter implementation
    at hash table insertion and hash table look up time.

    Signed-off-by: Eric W. Biederman
    Signed-off-by: David S. Miller

    Eric W. Biederman
     
  • Every user of the network device notifiers is either a protocol
    stack or a pseudo device. If a protocol stack that does not have
    support for multiple network namespaces receives an event for a
    device that is not in the initial network namespace it quite possibly
    can get confused and do the wrong thing.

    To avoid problems until all of the protocol stacks are converted
    this patch modifies all netdev event handlers to ignore events on
    devices that are not in the initial network namespace.

    As the rest of the code is made network namespace aware these
    checks can be removed.

    Signed-off-by: Eric W. Biederman
    Signed-off-by: David S. Miller

    Eric W. Biederman
     

20 Sep, 2007

1 commit


31 Aug, 2007

1 commit


23 Aug, 2007

1 commit

  • The new exec code inserts an accounted vma into an mm struct which is not
    current->mm. The existing memory check code has a hard coded assumption
    that this does not happen as does the security code.

    As the correct mm is known we pass the mm to the security method and the
    helper function. A new security test is added for the case where we need
    to pass the mm and the existing one is modified to pass current->mm to
    avoid the need to change large amounts of code.

    (Thanks to Tobias for fixing rejects and testing)

    Signed-off-by: Alan Cox
    Cc: WU Fengguang
    Cc: James Morris
    Cc: Tobias Diedrich
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     

16 Aug, 2007

1 commit


02 Aug, 2007

2 commits


01 Aug, 2007

1 commit


26 Jul, 2007

1 commit


23 Jul, 2007

1 commit


22 Jul, 2007

1 commit

  • Selinux folks had been complaining about the lack of AVC_PATH
    records when audit is disabled. I must admit my stupidity - I assumed
    that avc_audit() really couldn't use audit_log_d_path() because of
    deadlocks (== could be called with dcache_lock or vfsmount_lock held).
    Shouldn't have made that assumption - it never gets called that way.
    It _is_ called under spinlocks, but not those.

    Since audit_log_d_path() uses ab->gfp_mask for allocations,
    kmalloc() in there is not a problem. IOW, the simple fix is sufficient:
    let's rip AUDIT_AVC_PATH out and simply generate pathname as part of main
    record. It's trivial to do.

    Signed-off-by: Al Viro
    Acked-by: James Morris

    Al Viro
     

20 Jul, 2007

3 commits

  • Slab destructors were no longer supported after Christoph's
    c59def9f222d44bb7e2f0a559f2906191a0862d7 change. They've been
    BUGs for both slab and slub, and slob never supported them
    either.

    This rips out support for the dtor pointer from kmem_cache_create()
    completely and fixes up every single callsite in the kernel (there were
    about 224, not including the slab allocator definitions themselves,
    or the documentation references).

    Signed-off-by: Paul Mundt

    Paul Mundt
     
  • * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6:
    SELinux: use SECINITSID_NETMSG instead of SECINITSID_UNLABELED for NetLabel
    SELinux: enable dynamic activation/deactivation of NetLabel/SELinux enforcement

    Linus Torvalds
     
  • This patch changes mm_struct.dumpable to a pair of bit flags.

    set_dumpable() converts three-value dumpable to two flags and stores it into
    lower two bits of mm_struct.flags instead of mm_struct.dumpable.
    get_dumpable() behaves in the opposite way.

    [akpm@linux-foundation.org: export set_dumpable]
    Signed-off-by: Hidehiro Kawai
    Cc: Alan Cox
    Cc: David Howells
    Cc: Hugh Dickins
    Cc: Nick Piggin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kawai, Hidehiro
     

19 Jul, 2007

2 commits

  • These changes will make NetLabel behave like labeled IPsec where there is an
    access check for both labeled and unlabeled packets as well as providing the
    ability to restrict domains to receiving only labeled packets when NetLabel is
    in use. The changes to the policy are straight forward with the following
    necessary to receive labeled traffic (with SECINITSID_NETMSG defined as
    "netlabel_peer_t"):

    allow mydom_t netlabel_peer_t:{ tcp_socket udp_socket rawip_socket } recvfrom;

    The policy for unlabeled traffic would be:

    allow mydom_t unlabeled_t:{ tcp_socket udp_socket rawip_socket } recvfrom;

    These policy changes, as well as more general NetLabel support, are included in
    the latest SELinux Reference Policy release 20070629 or later. Users who make
    use of NetLabel are strongly encouraged to upgrade their policy to avoid
    network problems. Users who do not make use of NetLabel will not notice any
    difference.

    Signed-off-by: Paul Moore
    Signed-off-by: James Morris

    Paul Moore
     
  • Create a new NetLabel KAPI interface, netlbl_enabled(), which reports on the
    current runtime status of NetLabel based on the existing configuration. LSMs
    that make use of NetLabel, i.e. SELinux, can use this new function to determine
    if they should perform NetLabel access checks. This patch changes the
    NetLabel/SELinux glue code such that SELinux only enforces NetLabel related
    access checks when netlbl_enabled() returns true.

    At present NetLabel is considered to be enabled when there is at least one
    labeled protocol configuration present. The result is that by default NetLabel
    is considered to be disabled, however, as soon as an administrator configured
    a CIPSO DOI definition NetLabel is enabled and SELinux starts enforcing
    NetLabel related access controls - including unlabeled packet controls.

    This patch also tries to consolidate the multiple "#ifdef CONFIG_NETLABEL"
    blocks into a single block to ease future review as recommended by Linus.

    Signed-off-by: Paul Moore
    Signed-off-by: James Morris

    Paul Moore
     

18 Jul, 2007

2 commits

  • Rather than using a tri-state integer for the wait flag in
    call_usermodehelper_exec, define a proper enum, and use that. I've
    preserved the integer values so that any callers I've missed should
    still work OK.

    Signed-off-by: Jeremy Fitzhardinge
    Cc: James Bottomley
    Cc: Randy Dunlap
    Cc: Christoph Hellwig
    Cc: Andi Kleen
    Cc: Paul Mackerras
    Cc: Johannes Berg
    Cc: Ralf Baechle
    Cc: Bjorn Helgaas
    Cc: Joel Becker
    Cc: Tony Luck
    Cc: Kay Sievers
    Cc: Srivatsa Vaddagiri
    Cc: Oleg Nesterov
    Cc: David Howells

    Jeremy Fitzhardinge
     
  • Introduce is_owner_or_cap() macro in fs.h, and convert over relevant
    users to it. This is done because we want to avoid bugs in the future
    where we check for only effective fsuid of the current task against a
    file's owning uid, without simultaneously checking for CAP_FOWNER as
    well, thus violating its semantics.
    [ XFS uses special macros and structures, and in general looked ...
    untouchable, so we leave it alone -- but it has been looked over. ]

    The (current->fsuid != inode->i_uid) check in generic_permission() and
    exec_permission_lite() is left alone, because those operations are
    covered by CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH. Similarly operations
    falling under the purview of CAP_CHOWN and CAP_LEASE are also left alone.

    Signed-off-by: Satyam Sharma
    Cc: Al Viro
    Acked-by: Serge E. Hallyn
    Signed-off-by: Linus Torvalds

    Satyam Sharma
     

17 Jul, 2007

1 commit

  • Add TTY input auditing, used to audit system administrator's actions. This is
    required by various security standards such as DCID 6/3 and PCI to provide
    non-repudiation of administrator's actions and to allow a review of past
    actions if the administrator seems to overstep their duties or if the system
    becomes misconfigured for unknown reasons. These requirements do not make it
    necessary to audit TTY output as well.

    Compared to an user-space keylogger, this approach records TTY input using the
    audit subsystem, correlated with other audit events, and it is completely
    transparent to the user-space application (e.g. the console ioctls still
    work).

    TTY input auditing works on a higher level than auditing all system calls
    within the session, which would produce an overwhelming amount of mostly
    useless audit events.

    Add an "audit_tty" attribute, inherited across fork (). Data read from TTYs
    by process with the attribute is sent to the audit subsystem by the kernel.
    The audit netlink interface is extended to allow modifying the audit_tty
    attribute, and to allow sending explanatory audit events from user-space (for
    example, a shell might send an event containing the final command, after the
    interactive command-line editing and history expansion is performed, which
    might be difficult to decipher from the TTY input alone).

    Because the "audit_tty" attribute is inherited across fork (), it would be set
    e.g. for sshd restarted within an audited session. To prevent this, the
    audit_tty attribute is cleared when a process with no open TTY file
    descriptors (e.g. after daemon startup) opens a TTY.

    See https://www.redhat.com/archives/linux-audit/2007-June/msg00000.html for a
    more detailed rationale document for an older version of this patch.

    [akpm@linux-foundation.org: build fix]
    Signed-off-by: Miloslav Trmac
    Cc: Al Viro
    Cc: Alan Cox
    Cc: Paul Fulghum
    Cc: Casey Schaufler
    Cc: Steve Grubb
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Miloslav Trmac
     

14 Jul, 2007

1 commit

  • This reverts commit 9faf65fb6ee2b4e08325ba2d69e5ccf0c46453d0.

    It bit people like Michal Piotrowski:

    "My system is too secure, I can not login :)"

    because it changed how CONFIG_NETLABEL worked, and broke older SElinux
    policies.

    As a result, quoth James Morris:

    "Can you please revert this patch?

    We thought it only affected people running MLS, but it will affect others.

    Sorry for the hassle."

    Cc: James Morris
    Cc: Stephen Smalley
    Cc: Michal Piotrowski
    Cc: Paul Moore
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

12 Jul, 2007

10 commits

  • Remove unneeded export.

    Signed-off-by: Adrian Bunk
    Signed-off-by: James Morris

    Adrian Bunk
     
  • These changes will make NetLabel behave like labeled IPsec where there is an
    access check for both labeled and unlabeled packets as well as providing the
    ability to restrict domains to receiving only labeled packets when NetLabel
    is in use. The changes to the policy are straight forward with the
    following necessary to receive labeled traffic (with SECINITSID_NETMSG
    defined as "netlabel_peer_t"):

    allow mydom_t netlabel_peer_t:{ tcp_socket udp_socket rawip_socket } recvfrom;

    The policy for unlabeled traffic would be:

    allow mydom_t unlabeled_t:{ tcp_socket udp_socket rawip_socket } recvfrom;

    These policy changes, as well as more general NetLabel support, are included
    in the SELinux Reference Policy SVN tree, r2352 or later. Users who enable
    NetLabel support in the kernel are strongly encouraged to upgrade their
    policy to avoid network problems.

    Signed-off-by: Paul Moore
    Signed-off-by: James Morris

    Paul Moore
     
  • Add a new security check on mmap operations to see if the user is attempting
    to mmap to low area of the address space. The amount of space protected is
    indicated by the new proc tunable /proc/sys/vm/mmap_min_addr and defaults to
    0, preserving existing behavior.

    This patch uses a new SELinux security class "memprotect." Policy already
    contains a number of allow rules like a_t self:process * (unconfined_t being
    one of them) which mean that putting this check in the process class (its
    best current fit) would make it useless as all user processes, which we also
    want to protect against, would be allowed. By taking the memprotect name of
    the new class it will also make it possible for us to move some of the other
    memory protect permissions out of 'process' and into the new class next time
    we bump the policy version number (which I also think is a good future idea)

    Acked-by: Stephen Smalley
    Acked-by: Chris Wright
    Signed-off-by: Eric Paris
    Signed-off-by: James Morris

    Eric Paris
     
  • Inode numbers are unsigned long and so need to %lu as format string of printf.

    Signed-off-by: Tobias Oed
    Signed-off-by: James Morris

    Tobias Oed
     
  • In security_get_user_sids, move the transition permission checks
    outside of the section holding the policy rdlock, and use the AVC to
    perform the checks, calling cond_resched after each one. These
    changes should allow preemption between the individual checks and
    enable caching of the results. It may however increase the overall
    time spent in the function in some cases, particularly in the cache
    miss case.

    The long term fix will be to take much of this logic to userspace by
    exporting additional state via selinuxfs, and ultimately deprecating
    and eliminating this interface from the kernel.

    Tested-by: Ingo Molnar
    Signed-off-by: Stephen Smalley
    Signed-off-by: James Morris

    Stephen Smalley
     
  • During the LSPP testing we found that it was possible for
    policydb_destroy() to take 10+ seconds of kernel time to complete.
    Basically all policydb_destroy() does is walk some (possibly long) lists
    and free the memory it finds. Turning off slab debugging config options
    made the problem go away since the actual functions which took most of
    the time were (as seen by oprofile)

    > 121202 23.9879 .check_poison_obj
    > 78247 15.4864 .check_slabp

    were caused by that. So I decided to also add some voluntary schedule
    points in that code so config voluntary preempt would be enough to solve
    the problem. Something similar was done in places like
    shmem_free_pages() when we have to walk a list of memory and free it.
    This was tested by the LSPP group on the hardware which could reproduce
    the problem just loading a new policy and was found to not trigger the
    softlock detector. It takes just as much processing time, but the
    kernel doesn't spend all that time stuck doing one thing and never
    scheduling.

    Someday a better way to handle memory might make the time needed in this
    function a lot less, but this fixes the current issue as it stands
    today.

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

    Eric Paris
     
  • The structure is as follows (relative to selinuxfs root):

    /class/file/index
    /class/file/perms/read
    /class/file/perms/write
    ...

    Each class is allocated 33 inodes, 1 for the class index and 32 for
    permissions. Relative to SEL_CLASS_INO_OFFSET, the inode of the index file
    DIV 33 is the class number. The inode of the permission file % 33 is the
    index of the permission for that class.

    Signed-off-by: Christopher J. PeBenito
    Signed-off-by: James Morris

    Christopher J. PeBenito
     
  • Specify the inode counter explicitly in sel_make_dir(), rather than always
    using sel_last_ino.

    Signed-off-by: Christopher J. PeBenito
    Signed-off-by: James Morris

    Christopher J. PeBenito
     
  • sel_remove_bools() will also be used by the object class discovery, rename
    it for more general use.

    Signed-off-by: Christopher J. PeBenito
    Signed-off-by: James Morris

    Christopher J. PeBenito
     
  • Add support to the SELinux security server for obtaining a list of classes,
    and for obtaining a list of permissions for a specified class.

    Signed-off-by: Christopher J. PeBenito
    Signed-off-by: James Morris

    Christopher J. PeBenito
     

09 Jun, 2007

1 commit

  • The current NetLabel code has some redundant APIs which allow both
    "struct socket" and "struct sock" types to be used; this may have made
    sense at some point but it is wasteful now. Remove the functions that
    operate on sockets and convert the callers. Not only does this make
    the code smaller and more consistent but it pushes the locking burden
    up to the caller which can be more intelligent about the locks. Also,
    perform the same conversion (socket to sock) on the SELinux/NetLabel
    glue code where it make sense.

    Signed-off-by: Paul Moore
    Acked-by: James Morris
    Signed-off-by: David S. Miller

    Paul Moore