24 Jan, 2012

1 commit

  • Fix new kernel-doc warnings in auditsc.c:

    Warning(kernel/auditsc.c:1875): No description found for parameter 'success'
    Warning(kernel/auditsc.c:1875): No description found for parameter 'return_code'
    Warning(kernel/auditsc.c:1875): Excess function parameter 'pt_regs' description in '__audit_syscall_exit'

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

    Randy Dunlap
     

18 Jan, 2012

22 commits

  • audit_log_d_path() injects an additional space before the prefix,
    which serves no purpose and doesn't mix well with other audit_log*()
    functions that do not sneak extra characters into the log.

    Signed-off-by: Kees Cook
    Signed-off-by: Eric Paris

    Kees Cook
     
  • In the loop, a size_t "len" is used to hold the return value of
    audit_log_single_execve_arg(), which returns -1 on error. In that
    case the error handling (len
    Signed-off-by: Eric Paris

    Xi Wang
     
  • This allows audit to specify rules in which we compare two fields of a
    process. Such as is the running process uid != to the running process
    euid?

    Signed-off-by: Peter Moody
    Signed-off-by: Eric Paris

    Peter Moody
     
  • This completes the matrix of interfield comparisons between uid/gid
    information for the current task and the uid/gid information for inodes.
    aka I can audit based on differences between the euid of the process and
    the uid of fs objects.

    Signed-off-by: Peter Moody
    Signed-off-by: Eric Paris

    Peter Moody
     
  • Allow audit rules to compare the gid of the running task to the gid of the
    inode in question.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Rather than code the same loop over and over implement a helper function which
    uses some pointer magic to make it generic enough to be used numerous places
    as we implement more audit interfield comparisons

    Signed-off-by: Eric Paris

    Eric Paris
     
  • 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
     
  • Just a code cleanup really. We don't need to make a function call just for
    it to return on error. This also makes the VFS function even easier to follow
    and removes a conditional on a hot path.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • At the moment we allow tasks to set their loginuid if they have
    CAP_AUDIT_CONTROL. In reality we want tasks to set the loginuid when they
    log in and it be impossible to ever reset. We had to make it mutable even
    after it was once set (with the CAP) because on update and admin might have
    to restart sshd. Now sshd would get his loginuid and the next user which
    logged in using ssh would not be able to set his loginuid.

    Systemd has changed how userspace works and allowed us to make the kernel
    work the way it should. With systemd users (even admins) are not supposed
    to restart services directly. The system will restart the service for
    them. Thus since systemd is going to loginuid==-1, sshd would get -1, and
    sshd would be allowed to set a new loginuid without special permissions.

    If an admin in this system were to manually start an sshd he is inserting
    himself into the system chain of trust and thus, logically, it's his
    loginuid that should be used! Since we have old systems I make this a
    Kconfig option.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • The function always deals with current. Don't expose an option
    pretending one can use it for something. You can't.

    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
     
  • Audit entry,always rules are not allowed and are automatically changed in
    exit,always rules in userspace. The kernel refuses to load such rules.

    Thus a task in the middle of a syscall (and thus in audit_finish_fork())
    can only be in one of two states: AUDIT_BUILD_CONTEXT or AUDIT_DISABLED.
    Since the current task cannot be in AUDIT_RECORD_CONTEXT we aren't every
    going to actually use the code in audit_finish_fork() since it will
    return without doing anything. Thus drop the code.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • make the conditional a static inline instead of doing it in generic code.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • A number of audit hooks make function calls before they determine that
    auxilary records do not need to be collected. Do those checks as static
    inlines since the most common case is going to be that records are not
    needed and we can skip the function call overhead.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • The audit code makes heavy use of likely() and unlikely() macros, but they
    don't always make sense. Drop any that seem questionable and let the
    computer do it's thing.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Every arch calls:

    if (unlikely(current->audit_context))
    audit_syscall_entry()

    which requires knowledge about audit (the existance of audit_context) in
    the arch code. Just do it all in static inline in audit.h so that arch's
    can remain blissfully ignorant.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • The audit system previously expected arches calling to audit_syscall_exit to
    supply as arguments if the syscall was a success and what the return code was.
    Audit also provides a helper AUDITSC_RESULT which was supposed to simplify things
    by converting from negative retcodes to an audit internal magic value stating
    success or failure. This helper was wrong and could indicate that a valid
    pointer returned to userspace was a failed syscall. The fix is to fix the
    layering foolishness. We now pass audit_syscall_exit a struct pt_reg and it
    in turns calls back into arch code to collect the return value and to
    determine if the syscall was a success or failure. We also define a generic
    is_syscall_success() macro which determines success/failure based on if the
    value is < -MAX_ERRNO. This works for arches like x86 which do not use a
    separate mechanism to indicate syscall failure.

    We make both the is_syscall_success() and regs_return_value() static inlines
    instead of macros. The reason is because the audit function must take a void*
    for the regs. (uml calls theirs struct uml_pt_regs instead of just struct
    pt_regs so audit_syscall_exit can't take a struct pt_regs). Since the audit
    function takes a void* we need to use static inlines to cast it back to the
    arch correct structure to dereference it.

    The other major change is that on some arches, like ia64, MIPS and ppc, we
    change regs_return_value() to give us the negative value on syscall failure.
    THE only other user of this macro, kretprobe_example.c, won't notice and it
    makes the value signed consistently for the audit functions across all archs.

    In arch/sh/kernel/ptrace_64.c I see that we were using regs[9] in the old
    audit code as the return value. But the ptrace_64.h code defined the macro
    regs_return_value() as regs[3]. I have no idea which one is correct, but this
    patch now uses the regs_return_value() function, so it now uses regs[3].

    For powerpc we previously used regs->result but now use the
    regs_return_value() function which uses regs->gprs[3]. regs->gprs[3] is
    always positive so the regs_return_value(), much like ia64 makes it negative
    before calling the audit code when appropriate.

    Signed-off-by: Eric Paris
    Acked-by: H. Peter Anvin [for x86 portion]
    Acked-by: Tony Luck [for ia64]
    Acked-by: Richard Weinberger [for uml]
    Acked-by: David S. Miller [for sparc]
    Acked-by: Ralf Baechle [for mips]
    Acked-by: Benjamin Herrenschmidt [for ppc]

    Eric Paris
     
  • The audit system likes to collect information about processes that end
    abnormally (SIGSEGV) as this may me useful intrusion detection information.
    This patch adds audit support to collect information when seccomp forces a
    task to exit because of misbehavior in a similar way.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • The audit system has the ability to filter on the major and minor number of
    the device containing the inode being operated upon. Lets say that
    /dev/sda1 has major,minor 8,1 and that we mount /dev/sda1 on /boot. Now lets
    say we add a watch with a filter on 8,1. If we proceed to open an inode
    inside /boot, such as /vboot/vmlinuz, we will match the major,minor filter.

    Lets instead assume that one were to use a tool like debugfs and were to
    open /dev/sda1 directly and to modify it's contents. We might hope that
    this would also be logged, but it isn't. The rules will check the
    major,minor of the device containing /dev/sda1. In other words the rule
    would match on the major/minor of the tmpfs mounted at /dev.

    I believe these rules should trigger on either device. The man page is
    devoid of useful information about the intended semantics. It only seems
    logical that if you want to know everything that happened on a major,minor
    that would include things that happened to the device itself...

    Signed-off-by: Eric Paris

    Eric Paris
     
  • This patch does 2 things. First it reduces the number of audit_names
    allocated in every audit context from 20 to 5. 5 should be enough for all
    'normal' syscalls (rename being the worst). Some syscalls can still touch
    more the 5 inodes such as mount. When rpc filesystem is mounted it will
    create inodes and those can exceed 5. To handle that problem this patch will
    dynamically allocate audit_names if it needs more than 5. This should
    decrease the typicall memory usage while still supporting all the possible
    kernel operations.

    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 Jan, 2012

3 commits


31 Oct, 2011

1 commit

  • The changed files were only including linux/module.h for the
    EXPORT_SYMBOL infrastructure, and nothing else. Revector them
    onto the isolated export header for faster compile times.

    Nothing to see here but a whole lot of instances of:

    -#include
    +#include

    This commit is only changing the kernel dir; next targets
    will probably be mm, fs, the arch dirs, etc.

    Signed-off-by: Paul Gortmaker

    Paul Gortmaker
     

27 Jul, 2011

1 commit

  • This allows us to move duplicated code in
    (atomic_inc_not_zero() for now) to

    Signed-off-by: Arun Sharma
    Reviewed-by: Eric Dumazet
    Cc: Ingo Molnar
    Cc: David Miller
    Cc: Eric Dumazet
    Acked-by: Mike Frysinger
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arun Sharma
     

27 Apr, 2011

1 commit

  • Commit c69e8d9c01db ("CRED: Use RCU to access another task's creds and to
    release a task's own creds") added calls to get_task_cred and put_cred in
    audit_filter_rules. Profiling with a large number of audit rules active
    on the exit chain shows that we are spending upto 48% in this routine for
    syscall intensive tests, most of which is in the atomic ops.

    1. The code should be accessing tsk->cred rather than tsk->real_cred.
    2. Since tsk is current (or tsk is being created by copy_process) access to
    tsk->cred without rcu read lock is possible. At the request of the audit
    maintainer, a new flag has been added to audit_filter_rules in order to make
    this explicit and guide future code.

    Signed-off-by: Tony Jones
    Acked-by: Eric Paris
    Signed-off-by: Jiri Kosina

    Tony Jones
     

31 Mar, 2011

1 commit


30 Oct, 2010

1 commit

  • Normal syscall audit doesn't catch 5th argument of syscall. It also
    doesn't catch the contents of userland structures pointed to be
    syscall argument, so for both old and new mmap(2) ABI it doesn't
    record the descriptor we are mapping. For old one it also misses
    flags.

    Signed-off-by: Al Viro

    Al Viro
     

11 Aug, 2010

1 commit


28 Jul, 2010

4 commits


06 Apr, 2010

1 commit

  • There have been a number of reports of people seeing the message:
    "name_count maxed, losing inode data: dev=00:05, inode=3185"
    in dmesg. These usually lead to people reporting problems to the filesystem
    group who are in turn clueless what they mean.

    Eventually someone finds me and I explain what is going on and that
    these come from the audit system. The basics of the problem is that the
    audit subsystem never expects a single syscall to 'interact' (for some
    wish washy meaning of interact) with more than 20 inodes. But in fact
    some operations like loading kernel modules can cause changes to lots of
    inodes in debugfs.

    There are a couple real fixes being bandied about including removing the
    fixed compile time limit of 20 or not auditing changes in debugfs (or
    both) but neither are small and obvious so I am not sending them for
    immediate inclusion (I hope Al forwards a real solution next devel
    window).

    In the meantime this patch simply adds 'audit' to the beginning of the
    crap message so if a user sees it, they come blame me first and we can
    talk about what it means and make sure we understand all of the reasons
    it can happen and make sure this gets solved correctly in the long run.

    Signed-off-by: Eric Paris
    Signed-off-by: Linus Torvalds

    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
     

09 Feb, 2010

1 commit


23 Dec, 2009

1 commit

  • * pull ACC_MODE to fs.h; we have several copies all over the place
    * nightmarish expression calculating f_mode by f_flags deserves a helper
    too (OPEN_FMODE(flags))

    Signed-off-by: Al Viro

    Al Viro