25 May, 2013

1 commit

  • Fix kernel-doc warnings in kernel/auditfilter.c:

    Warning(kernel/auditfilter.c:1029): Excess function parameter 'loginuid' description in 'audit_receive_filter'
    Warning(kernel/auditfilter.c:1029): Excess function parameter 'sessionid' description in 'audit_receive_filter'
    Warning(kernel/auditfilter.c:1029): Excess function parameter 'sid' description in 'audit_receive_filter'

    Signed-off-by: Randy Dunlap
    Cc: Eric Paris
    Cc: Al Viro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

12 May, 2013

1 commit

  • Pull audit changes from Eric Paris:
    "Al used to send pull requests every couple of years but he told me to
    just start pushing them to you directly.

    Our touching outside of core audit code is pretty straight forward. A
    couple of interface changes which hit net/. A simple argument bug
    calling audit functions in namei.c and the removal of some assembly
    branch prediction code on ppc"

    * git://git.infradead.org/users/eparis/audit: (31 commits)
    audit: fix message spacing printing auid
    Revert "audit: move kaudit thread start from auditd registration to kaudit init"
    audit: vfs: fix audit_inode call in O_CREAT case of do_last
    audit: Make testing for a valid loginuid explicit.
    audit: fix event coverage of AUDIT_ANOM_LINK
    audit: use spin_lock in audit_receive_msg to process tty logging
    audit: do not needlessly take a lock in tty_audit_exit
    audit: do not needlessly take a spinlock in copy_signal
    audit: add an option to control logging of passwords with pam_tty_audit
    audit: use spin_lock_irqsave/restore in audit tty code
    helper for some session id stuff
    audit: use a consistent audit helper to log lsm information
    audit: push loginuid and sessionid processing down
    audit: stop pushing loginid, uid, sessionid as arguments
    audit: remove the old depricated kernel interface
    audit: make validity checking generic
    audit: allow checking the type of audit message in the user filter
    audit: fix build break when AUDIT_DEBUG == 2
    audit: remove duplicate export of audit_enabled
    Audit: do not print error when LSMs disabled
    ...

    Linus Torvalds
     

08 May, 2013

1 commit

  • audit rule additions containing "-F auid!=4294967295" were failing
    with EINVAL because of a regression caused by e1760bd.

    Apparently some userland audit rule sets want to know if loginuid uid
    has been set and are using a test for auid != 4294967295 to determine
    that.

    In practice that is a horrible way to ask if a value has been set,
    because it relies on subtle implementation details and will break
    every time the uid implementation in the kernel changes.

    So add a clean way to test if the audit loginuid has been set, and
    silently convert the old idiom to the cleaner and more comprehensible
    new idiom.

    Cc: # 3.7
    Reported-By: Richard Guy Briggs
    Signed-off-by: "Eric W. Biederman"
    Tested-by: Richard Guy Briggs
    Signed-off-by: Eric Paris

    Eric W. Biederman
     

01 May, 2013

4 commits


30 Apr, 2013

1 commit

  • In audit_data_to_entry() when a failure occurs we must check and free
    the tree and watch to avoid a memory leak.

    test:
    plan:
    test command:
    "auditctl -a exit,always -w /etc -F auid=-1"
    (on fedora17, need modify auditctl to let "-w /etc" has effect)
    running:
    under fedora17 x86_64, 2 CPUs 3.20GHz, 2.5GB RAM.
    let 15 auditctl processes continue running at the same time.
    monitor command:
    watch -d -n 1 "cat /proc/meminfo | awk '{print \$2}' \
    | head -n 4 | xargs \
    | awk '{print \"used \",\$1 - \$2 - \$3 - \$4}'"

    result:
    for original version:
    will use up all memory, within 3 hours.
    kill all auditctl, the memory still does not free.
    for new version (apply this patch):
    after 14 hours later, not find issues.

    Signed-off-by: Chen Gang
    Cc: Eric Paris
    Cc: Al Viro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Chen Gang
     

17 Apr, 2013

1 commit

  • When userspace sends messages to the audit system it includes a type.
    We want to be able to filter messages based on that type without have to
    do the all or nothing option currently available on the
    AUDIT_FILTER_TYPE filter list. Instead we should be able to use the
    AUDIT_FILTER_USER filter list and just use the message type as one part
    of the matching decision.

    Signed-off-by: Eric Paris

    Eric Paris
     

11 Jan, 2013

1 commit

  • Fix new kernel-doc warning in auditfilter.c:

    Warning(kernel/auditfilter.c:1157): Excess function parameter 'uid' description in 'audit_receive_filter'

    Signed-off-by: Randy Dunlap
    Cc: Al Viro
    Cc: Eric Paris
    Cc: linux-audit@redhat.com (subscribers-only)
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

12 Oct, 2012

4 commits


18 Sep, 2012

4 commits

  • Always store audit loginuids in type kuid_t.

    Print loginuids by converting them into uids in the appropriate user
    namespace, and then printing the resulting uid.

    Modify audit_get_loginuid to return a kuid_t.

    Modify audit_set_loginuid to take a kuid_t.

    Modify /proc//loginuid on read to convert the loginuid into the
    user namespace of the opener of the file.

    Modify /proc//loginud on write to convert the loginuid
    rom the user namespace of the opener of the file.

    Cc: Al Viro
    Cc: Eric Paris
    Cc: Paul Moore ?
    Cc: David Miller
    Signed-off-by: Eric W. Biederman

    Eric W. Biederman
     
  • The audit filter code guarantees that uid are always compared with
    uids and gids are always compared with gids, as the comparason
    operations are type specific. Take advantage of this proper to define
    audit_uid_comparator and audit_gid_comparator which use the type safe
    comparasons from uidgid.h.

    Build on audit_uid_comparator and audit_gid_comparator and replace
    audit_compare_id with audit_compare_uid and audit_compare_gid. This
    is one of those odd cases where being type safe and duplicating code
    leads to simpler shorter and more concise code.

    Don't allow bitmask operations in uid and gid comparisons in
    audit_data_to_entry. Bitmask operations are already denined in
    audit_rule_to_entry.

    Convert constants in audit_rule_to_entry and audit_data_to_entry into
    kuids and kgids when appropriate.

    Convert the uid and gid field in struct audit_names to be of type
    kuid_t and kgid_t respectively, so that the new uid and gid comparators
    can be applied in a type safe manner.

    Cc: Al Viro
    Cc: Eric Paris
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     
  • Cc: Al Viro
    Cc: Eric Paris
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     
  • Get caller process uid and gid and pid values from the current task
    instead of the NETLINK_CB. This is simpler than passing NETLINK_CREDS
    from from audit_receive_msg to audit_filter_user_rules and avoid the
    chance of being hit by the occassional bugs in netlink uid/gid
    credential passing. This is a safe changes because all netlink
    requests are processed in the task of the sending process.

    Cc: Al Viro
    Cc: Eric Paris
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

18 Jan, 2012

5 commits

  • We wish to be able to audit when a uid=500 task accesses a file which is
    uid=0. Or vice versa. This patch introduces a new audit filter type
    AUDIT_FIELD_COMPARE which takes as an 'enum' which indicates which fields
    should be compared. At this point we only define the task->uid vs
    inode->uid, but other comparisons can be added.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Much like the ability to filter audit on the uid of an inode collected, we
    should be able to filter on the gid of the inode.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Allow syscall exit filter matching based on the uid of the owner of an
    inode used in a syscall. aka:

    auditctl -a always,exit -S open -F obj_uid=0 -F perm=wa

    Signed-off-by: Eric Paris

    Eric Paris
     
  • We deprecated entry,always rules a long time ago. Reject those rules as
    invalid.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Every other filter that matches part of the inodes list collected by audit
    will match against any of the inodes on that list. The filetype matching
    however had a strange way of doing things. It allowed userspace to
    indicated if it should match on the first of the second name collected by
    the kernel. Name collection ordering seems like a kernel internal and
    making userspace rules get that right just seems like a bad idea. As it
    turns out the userspace audit writers had no idea it was doing this and
    thus never overloaded the value field. The kernel always checked the first
    name collected which for the tested rules was always correct.

    This patch just makes the filetype matching like the major, minor, inode,
    and LSM rules in that it will match against any of the names collected. It
    also changes the rule validation to reject the old unused rule types.

    Noone knew it was there. Noone used it. Why keep around the extra code?

    Signed-off-by: Eric Paris

    Eric Paris
     

04 Mar, 2011

1 commit


30 Oct, 2010

1 commit

  • Add support for matching by security label (e.g. SELinux context) of
    the sender of an user-space audit record.

    The audit filter code already allows user space to configure such
    filters, but they were ignored during evaluation. This patch implements
    evaluation of these filters.

    For example, after application of this patch, PAM authentication logs
    caused by cron can be disabled using
    auditctl -a user,never -F subj_type=crond_t

    Signed-off-by: Miloslav Trmac
    Acked-by: Eric Paris
    Signed-off-by: Al Viro

    Miloslav Trmac
     

28 Jul, 2010

2 commits

  • deleting audit watch rules is not currently done under audit_filter_mutex.
    It was done this way because we could not hold the mutex during inotify
    manipulation. Since we are using fsnotify we don't need to do the extra
    get/put pair nor do we need the private list on which to store the parents
    while they are about to be freed.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • No real changes, just cleanup to the audit_watch split patch which we done
    with minimal code changes for easy review. Now fix interfaces to make
    things work better.

    Signed-off-by: Eric Paris

    Eric Paris
     

30 Mar, 2010

1 commit

  • …it slab.h inclusion from percpu.h

    percpu.h is included by sched.h and module.h and thus ends up being
    included when building most .c files. percpu.h includes slab.h which
    in turn includes gfp.h making everything defined by the two files
    universally available and complicating inclusion dependencies.

    percpu.h -> slab.h dependency is about to be removed. Prepare for
    this change by updating users of gfp and slab facilities include those
    headers directly instead of assuming availability. As this conversion
    needs to touch large number of source files, the following script is
    used as the basis of conversion.

    http://userweb.kernel.org/~tj/misc/slabh-sweep.py

    The script does the followings.

    * Scan files for gfp and slab usages and update includes such that
    only the necessary includes are there. ie. if only gfp is used,
    gfp.h, if slab is used, slab.h.

    * When the script inserts a new include, it looks at the include
    blocks and try to put the new include such that its order conforms
    to its surrounding. It's put in the include block which contains
    core kernel includes, in the same order that the rest are ordered -
    alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
    doesn't seem to be any matching order.

    * If the script can't find a place to put a new include (mostly
    because the file doesn't have fitting include block), it prints out
    an error message indicating which .h file needs to be added to the
    file.

    The conversion was done in the following steps.

    1. The initial automatic conversion of all .c files updated slightly
    over 4000 files, deleting around 700 includes and adding ~480 gfp.h
    and ~3000 slab.h inclusions. The script emitted errors for ~400
    files.

    2. Each error was manually checked. Some didn't need the inclusion,
    some needed manual addition while adding it to implementation .h or
    embedding .c file was more appropriate for others. This step added
    inclusions to around 150 files.

    3. The script was run again and the output was compared to the edits
    from #2 to make sure no file was left behind.

    4. Several build tests were done and a couple of problems were fixed.
    e.g. lib/decompress_*.c used malloc/free() wrappers around slab
    APIs requiring slab.h to be added manually.

    5. The script was run on all .h files but without automatically
    editing them as sprinkling gfp.h and slab.h inclusions around .h
    files could easily lead to inclusion dependency hell. Most gfp.h
    inclusion directives were ignored as stuff from gfp.h was usually
    wildly available and often used in preprocessor macros. Each
    slab.h inclusion directive was examined and added manually as
    necessary.

    6. percpu.h was updated not to include slab.h.

    7. Build test were done on the following configurations and failures
    were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
    distributed build env didn't work with gcov compiles) and a few
    more options had to be turned off depending on archs to make things
    build (like ipr on powerpc/64 which failed due to missing writeq).

    * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
    * powerpc and powerpc64 SMP allmodconfig
    * sparc and sparc64 SMP allmodconfig
    * ia64 SMP allmodconfig
    * s390 SMP allmodconfig
    * alpha SMP allmodconfig
    * um on x86_64 SMP allmodconfig

    8. percpu.h modifications were reverted so that it could be applied as
    a separate patch and serve as bisection point.

    Given the fact that I had only a couple of failures from tests on step
    6, I'm fairly confident about the coverage of this conversion patch.
    If there is a breakage, it's likely to be something in one of the arch
    headers which should be easily discoverable easily on most builds of
    the specific arch.

    Signed-off-by: Tejun Heo <tj@kernel.org>
    Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>

    Tejun Heo
     

24 Jun, 2009

5 commits

  • A number of places in the audit system we send an op= followed by a string
    that includes spaces. Somehow this works but it's just wrong. This patch
    moves all of those that I could find to be quoted.

    Example:

    Change From: type=CONFIG_CHANGE msg=audit(1244666690.117:31): auid=0 ses=1
    subj=unconfined_u:unconfined_r:auditctl_t:s0-s0:c0.c1023 op=remove rule
    key="number2" list=4 res=0

    Change To: type=CONFIG_CHANGE msg=audit(1244666690.117:31): auid=0 ses=1
    subj=unconfined_u:unconfined_r:auditctl_t:s0-s0:c0.c1023 op="remove rule"
    key="number2" list=4 res=0

    Signed-off-by: Eric Paris

    Eric Paris
     
  • audit_get_nd() is only used by audit_watch and could be more cleanly
    implemented by having the audit watch functions call it when needed rather
    than making the generic audit rule parsing code deal with those objects.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • In preparation for converting audit to use fsnotify instead of inotify we
    seperate the inode watching code into it's own file. This is similar to
    how the audit tree watching code is already seperated into audit_tree.c

    Signed-off-by: Eric Paris

    Eric Paris
     
  • audit_update_watch() runs all of the rules for a given watch and duplicates
    them, attaches a new watch to them, and then when it finishes that process
    and has called free on all of the old rules (ok maybe still inside the rcu
    grace period) it proceeds to use the last element from list_for_each_entry_safe()
    as if it were a krule rather than being the audit_watch which was anchoring
    the list to output a message about audit rules changing.

    This patch unfies the audit message from two different places into a helper
    function and calls it from the correct location in audit_update_rules(). We
    will now get an audit message about the config changing for each rule (with
    each rules filterkey) rather than the previous garbage.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • When an audit watch is added to a parent the temporary watch inside the
    original krule from userspace is freed. Yet the original watch is used after
    the real watch was created in audit_add_rules()

    Signed-off-by: Eric Paris

    Eric Paris
     

07 May, 2009

1 commit

  • There is what we believe to be a false positive reported by lockdep.

    inotify_inode_queue_event() => take inotify_mutex => kernel_event() =>
    kmalloc() => SLOB => alloc_pages_node() => page reclaim => slab reclaim =>
    dcache reclaim => inotify_inode_is_dead => take inotify_mutex => deadlock

    The plan is to fix this via lockdep annotation, but that is proving to be
    quite involved.

    The patch flips the allocation over to GFP_NFS to shut the warning up, for
    the 2.6.30 release.

    Hopefully we will fix this for real in 2.6.31. I'll queue a patch in -mm
    to switch it back to GFP_KERNEL so we don't forget.

    =================================
    [ INFO: inconsistent lock state ]
    2.6.30-rc2-next-20090417 #203
    ---------------------------------
    inconsistent {RECLAIM_FS-ON-W} -> {IN-RECLAIM_FS-W} usage.
    kswapd0/380 [HC0[0]:SC0[0]:HE1:SE1] takes:
    (&inode->inotify_mutex){+.+.?.}, at: [] inotify_inode_is_dead+0x35/0xb0
    {RECLAIM_FS-ON-W} state was registered at:
    [] mark_held_locks+0x68/0x90
    [] lockdep_trace_alloc+0xf5/0x100
    [] __kmalloc_node+0x31/0x1e0
    [] kernel_event+0xe2/0x190
    [] inotify_dev_queue_event+0x126/0x230
    [] inotify_inode_queue_event+0xc6/0x110
    [] vfs_create+0xcd/0x140
    [] do_filp_open+0x88d/0xa20
    [] do_sys_open+0x98/0x140
    [] sys_open+0x20/0x30
    [] system_call_fastpath+0x16/0x1b
    [] 0xffffffffffffffff
    irq event stamp: 690455
    hardirqs last enabled at (690455): [] _spin_unlock_irqrestore+0x44/0x80
    hardirqs last disabled at (690454): [] _spin_lock_irqsave+0x32/0xa0
    softirqs last enabled at (690178): [] __do_softirq+0x202/0x220
    softirqs last disabled at (690157): [] call_softirq+0x1c/0x50

    other info that might help us debug this:
    2 locks held by kswapd0/380:
    #0: (shrinker_rwsem){++++..}, at: [] shrink_slab+0x37/0x180
    #1: (&type->s_umount_key#17){++++..}, at: [] shrink_dcache_memory+0x11f/0x1e0

    stack backtrace:
    Pid: 380, comm: kswapd0 Not tainted 2.6.30-rc2-next-20090417 #203
    Call Trace:
    [] print_usage_bug+0x19f/0x200
    [] ? save_stack_trace+0x2f/0x50
    [] mark_lock+0x4bb/0x6d0
    [] ? check_usage_forwards+0x0/0xc0
    [] __lock_acquire+0xc62/0x1ae0
    [] ? slob_free+0x10c/0x370
    [] lock_acquire+0xe1/0x120
    [] ? inotify_inode_is_dead+0x35/0xb0
    [] mutex_lock_nested+0x63/0x420
    [] ? inotify_inode_is_dead+0x35/0xb0
    [] ? inotify_inode_is_dead+0x35/0xb0
    [] ? sched_clock+0x9/0x10
    [] ? lock_release_holdtime+0x35/0x1c0
    [] inotify_inode_is_dead+0x35/0xb0
    [] dentry_iput+0xbc/0xe0
    [] d_kill+0x33/0x60
    [] __shrink_dcache_sb+0x2d3/0x350
    [] shrink_dcache_memory+0x15a/0x1e0
    [] shrink_slab+0x125/0x180
    [] kswapd+0x560/0x7a0
    [] ? isolate_pages_global+0x0/0x2c0
    [] ? autoremove_wake_function+0x0/0x40
    [] ? trace_hardirqs_on+0xd/0x10
    [] ? kswapd+0x0/0x7a0
    [] kthread+0x5b/0xa0
    [] child_rip+0xa/0x20
    [] ? restore_args+0x0/0x30
    [] ? kthread+0x0/0xa0
    [] ? child_rip+0x0/0x20

    [eparis@redhat.com: fix audit too]
    Cc: Al Viro
    Cc: Matt Mackall
    Cc: Christoph Lameter
    Signed-off-by: Wu Fengguang
    Signed-off-by: Eric Paris
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wu Fengguang
     

06 Apr, 2009

1 commit

  • make the e->rule.xxx shorter in kernel/auditfilter.c
    --
    ---------------------------------
    Zhenwen Xu - Open and Free
    Home Page: http://zhwen.org
    My Studio: http://dim4.cn

    >From 99692dc640b278f1cb1a15646ce42f22e89c0f77 Mon Sep 17 00:00:00 2001
    From: Zhenwen Xu
    Date: Thu, 12 Mar 2009 22:04:59 +0800
    Subject: [PATCH] make the e->rule.xxx shorter in kernel/auditfilter.c

    Signed-off-by: Zhenwen Xu
    Signed-off-by: Al Viro

    Zhenwen Xu
     

05 Jan, 2009

5 commits