29 Mar, 2011

1 commit

  • Commit 6f5317e730505d5cbc851c435a2dfe3d5a21d343 introduced a bug in the
    handling of userspace object classes that is causing breakage for Xorg
    when XSELinux is enabled. Fix the bug by changing map_class() to return
    SECCLASS_NULL when the class cannot be mapped to a kernel object class.

    Reported-by: "Justin P. Mattock"
    Signed-off-by: Stephen Smalley
    Signed-off-by: James Morris

    Stephen Smalley
     

08 Mar, 2011

2 commits


04 Mar, 2011

1 commit

  • The socket SID would be computed on creation and no longer inherit
    its creator's SID by default. Socket may have a different type but
    needs to retain the creator's role and MLS attribute in order not
    to break labeled networking and network access control.

    The kernel value for a class would be used to determine if the class
    if one of socket classes. If security_compute_sid is called from
    userspace the policy value for a class would be mapped to the relevant
    kernel value first.

    Signed-off-by: Harry Ciao
    Signed-off-by: Eric Paris
    Acked-by: Stephen Smalley

    Harry Ciao
     

02 Feb, 2011

1 commit

  • Currently SELinux has rules which label new objects according to 3 criteria.
    The label of the process creating the object, the label of the parent
    directory, and the type of object (reg, dir, char, block, etc.) This patch
    adds a 4th criteria, the dentry name, thus we can distinguish between
    creating a file in an etc_t directory called shadow and one called motd.

    There is no file globbing, regex parsing, or anything mystical. Either the
    policy exactly (strcmp) matches the dentry name of the object or it doesn't.
    This patch has no changes from today if policy does not implement the new
    rules.

    Signed-off-by: Eric Paris

    Eric Paris
     

24 Jan, 2011

2 commits


08 Dec, 2010

1 commit

  • 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
     

01 Dec, 2010

6 commits


21 Oct, 2010

10 commits

  • Include vmalloc.h for vmalloc_user (fixes ppc build warning).
    Acked-by: Eric Paris

    Signed-off-by: James Morris

    Stephen Rothwell
     
  • /selinux/policy allows a user to copy the policy back out of the kernel.
    This patch allows userspace to actually mmap that file and use it directly.

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

    Eric Paris
     
  • There is interest in being able to see what the actual policy is that was
    loaded into the kernel. The patch creates a new selinuxfs file
    /selinux/policy which can be read by userspace. The actual policy that is
    loaded into the kernel will be written back out to userspace.

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

    Eric Paris
     
  • AVTAB_MAX_SIZE was a define which was supposed to be used in userspace to
    define a maximally sized avtab when userspace wasn't sure how big of a table
    it needed. It doesn't make sense in the kernel since we always know our table
    sizes. The only place it is used we have a more appropiately named define
    called AVTAB_MAX_HASH_BUCKETS, use that instead.

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

    Eric Paris
     
  • Range transition rules are placed in the hash table in an (almost)
    arbitrary order. This patch inserts them in a fixed order to make policy
    retrival more predictable.

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

    Eric Paris
     
  • With the (long ago) interface change to have the secid_to_secctx functions
    do the string allocation instead of having the caller do the allocation we
    lost the ability to query the security server for the length of the
    upcoming string. The SECMARK code would like to allocate a netlink skb
    with enough length to hold the string but it is just too unclean to do the
    string allocation twice or to do the allocation the first time and hold
    onto the string and slen. This patch adds the ability to call
    security_secid_to_secctx() with a NULL data pointer and it will just set
    the slen pointer.

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

    Eric Paris
     
  • This patch fixes up coding-style problem at this commit:

    4f27a7d49789b04404eca26ccde5f527231d01d5
    selinux: fast status update interface (/selinux/status)

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

    KaiGai Kohei
     
  • While the previous change to the selinux Makefile reduced the window
    significantly for this failure, it is still possible to see a compile
    failure where cpp starts processing selinux files before the auto
    generated flask.h file is completed. This is easily reproduced by
    adding the following temporary change to expose the issue everytime:

    - cmd_flask = scripts/selinux/genheaders/genheaders ...
    + cmd_flask = sleep 30 ; scripts/selinux/genheaders/genheaders ...

    This failure happens because the creation of the object files in the ss
    subdir also depends on flask.h. So simply incorporate them into the
    parent Makefile, as the ss/Makefile really doesn't do anything unique.

    With this change, compiling of all selinux files is dependent on
    completion of the header file generation, and this test case with
    the "sleep 30" now confirms it is functioning as expected.

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

    Paul Gortmaker
     
  • This patch provides a new /selinux/status entry which allows applications
    read-only mmap(2).
    This region reflects selinux_kernel_status structure in kernel space.
    struct selinux_kernel_status
    {
    u32 length; /* length of this structure */
    u32 sequence; /* sequence number of seqlock logic */
    u32 enforcing; /* current setting of enforcing mode */
    u32 policyload; /* times of policy reloaded */
    u32 deny_unknown; /* current setting of deny_unknown */
    };

    When userspace object manager caches access control decisions provided
    by SELinux, it needs to invalidate the cache on policy reload and setenforce
    to keep consistency.
    However, the applications need to check the kernel state for each accesses
    on userspace avc, or launch a background worker process.
    In heuristic, frequency of invalidation is much less than frequency of
    making access control decision, so it is annoying to invoke a system call
    to check we don't need to invalidate the userspace cache.
    If we can use a background worker thread, it allows to receive invalidation
    messages from the kernel. But it requires us an invasive coding toward the
    base application in some cases; E.g, when we provide a feature performing
    with SELinux as a plugin module, it is unwelcome manner to launch its own
    worker thread from the module.

    If we could map /selinux/status to process memory space, application can
    know updates of selinux status; policy reload or setenforce.

    A typical application checks selinux_kernel_status::sequence when it tries
    to reference userspace avc. If it was changed from the last time when it
    checked userspace avc, it means something was updated in the kernel space.
    Then, the application can reset userspace avc or update current enforcing
    mode, without any system call invocations.
    This sequence number is updated according to the seqlock logic, so we need
    to wait for a while if it is odd number.

    Signed-off-by: KaiGai Kohei
    Acked-by: Eric Paris
    --
    security/selinux/include/security.h | 21 ++++++
    security/selinux/selinuxfs.c | 56 +++++++++++++++
    security/selinux/ss/Makefile | 2 +-
    security/selinux/ss/services.c | 3 +
    security/selinux/ss/status.c | 129 +++++++++++++++++++++++++++++++++++
    5 files changed, 210 insertions(+), 1 deletions(-)
    Signed-off-by: James Morris

    KaiGai Kohei
     
  • type is not used at all, stop declaring and assigning it.

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

    Eric Paris
     

02 Aug, 2010

11 commits

  • Current selinux policy can have over 3000 types. The type_attr_map in
    policy is an array sized by the number of types times sizeof(struct ebitmap)
    (12 on x86_64). Basic math tells us the array is going to be of length
    3000 x 12 = 36,000 bytes. The largest 'safe' allocation on a long running
    system is 16k. Most of the time a 32k allocation will work. But on long
    running systems a 64k allocation (what we need) can fail quite regularly.
    In order to deal with this I am converting the type_attr_map to use
    flex_arrays. Let the library code deal with breaking this into PAGE_SIZE
    pieces.

    -v2
    rework some of the if(!obj) BUG() to be BUG_ON(!obj)
    drop flex_array_put() calls and just use a _get() object directly

    -v3
    make apply to James' tree (drop the policydb_write changes)

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

    Eric Paris
     
  • Move the reading of ocontext type data out of policydb_read() in a separate
    function ocontext_read()

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

    Eric Paris
     
  • move genfs read functionality out of policydb_read() and into a new
    function called genfs_read()

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

    Eric Paris
     
  • hashtab_create() only returns NULL on allocation failures to -ENOMEM is
    appropriate here.

    Signed-off-by: Dan Carpenter
    Acked-by: Eric Paris
    Acked-by: Stephen D. Smalley
    Signed-off-by: James Morris

    Dan Carpenter
     
  • The original code always returned -1 (-EPERM) on error. The new code
    returns either -ENOMEM, or -EINVAL or it propagates the error codes from
    lower level functions next_entry() or hashtab_insert().

    next_entry() returns -EINVAL.
    hashtab_insert() returns -EINVAL, -EEXIST, or -ENOMEM.

    Signed-off-by: Dan Carpenter
    Acked-by: Stephen D. Smalley
    Signed-off-by: James Morris

    Dan Carpenter
     
  • It's better to propagate the error code from avtab_init() instead of
    returning -1 (-EPERM). It turns out that avtab_init() never fails so
    this patch doesn't change how the code runs but it's still a clean up.

    Signed-off-by: Dan Carpenter
    Acked-by: Stephen D. Smalley
    Signed-off-by: James Morris

    Dan Carpenter
     
  • Originally cond_read_node() returned -1 (-EPERM) on errors which was
    incorrect. Now it either propagates the error codes from lower level
    functions next_entry() or cond_read_av_list() or it returns -ENOMEM or
    -EINVAL.

    next_entry() returns -EINVAL.
    cond_read_av_list() returns -EINVAL or -ENOMEM.

    Signed-off-by: Dan Carpenter
    Acked-by: Stephen D. Smalley
    Signed-off-by: James Morris

    Dan Carpenter
     
  • After this patch cond_read_av_list() no longer returns -1 for any
    errors. It just propagates error code back from lower levels. Those can
    either be -EINVAL or -ENOMEM.

    I also modified cond_insertf() since cond_read_av_list() passes that as a
    function pointer to avtab_read_item(). It isn't used anywhere else.

    Signed-off-by: Dan Carpenter
    Acked-by: Stephen D. Smalley
    Signed-off-by: James Morris

    Dan Carpenter
     
  • These are passed back when the security module gets loaded.

    The original code always returned -1 (-EPERM) on error but after this
    patch it can return -EINVAL, or -ENOMEM or propagate the error code from
    cond_read_node(). cond_read_node() still returns -1 all the time, but I
    fix that in a later patch.

    Signed-off-by: Dan Carpenter
    Acked-by: Stephen D. Smalley
    Signed-off-by: James Morris

    Dan Carpenter
     
  • The avtab_read_item() function tends to return -1 as a default error
    code which is wrong (-1 means -EPERM). I modified it to return
    appropriate error codes which is -EINVAL or the error code from
    next_entry() or insertf().

    next_entry() returns -EINVAL.
    insertf() is a function pointer to either avtab_insert() or
    cond_insertf().
    avtab_insert() returns -EINVAL, -ENOMEM, and -EEXIST.
    cond_insertf() currently returns -1, but I will fix it in a later patch.

    There is code in avtab_read() which translates the -1 returns from
    avtab_read_item() to -EINVAL. The translation is no longer needed, so I
    removed it.

    Signed-off-by: Dan Carpenter
    Acked-by: Stephen D. Smalley
    Signed-off-by: James Morris

    Dan Carpenter
     
  • Move the range transition rule to a separate function, range_read(), rather
    than doing it all in policydb_read()

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

    Eric Paris
     

17 May, 2010

1 commit

  • Use kstrdup when the goal of an allocation is copy a string into the
    allocated region.

    The semantic patch that makes this change is as follows:
    (http://coccinelle.lip6.fr/)

    //
    @@
    expression from,to;
    expression flag,E1,E2;
    statement S;
    @@

    - to = kmalloc(strlen(from) + 1,flag);
    + to = kstrdup(from, flag);
    ... when != \(from = E1 \| to = E1 \)
    if (to==NULL || ...) S
    ... when != \(from = E2 \| to = E2 \)
    - strcpy(to, from);
    //

    Signed-off-by: Julia Lawall
    Acked-by: Eric Paris
    Signed-off-by: James Morris

    Julia Lawall
     

21 Apr, 2010

1 commit

  • policy load failure always return EINVAL even if the failure was for some
    other reason (usually ENOMEM). This patch passes error codes back up the
    stack where they will make their way to userspace. This might help in
    debugging future problems with policy load.

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

    Eric Paris
     

09 Apr, 2010

1 commit


16 Mar, 2010

1 commit

  • Reduce MAX_AVTAB_HASH_BITS so that the avtab allocation is an order 2
    allocation rather than an order 4 allocation on x86_64. This
    addresses reports of page allocation failures:
    http://marc.info/?l=selinux&m=126757230625867&w=2
    https://bugzilla.redhat.com/show_bug.cgi?id=570433

    Reported-by: Russell Coker
    Signed-off-by: Stephen D. Smalley
    Acked-by: Eric Paris
    Signed-off-by: James Morris

    Stephen Smalley
     

09 Mar, 2010

1 commit