18 Jul, 2018

1 commit

  • Commit c72051d5778a ("audit: use ktime_get_coarse_ts64() for time
    access") converted audit's use of current_kernel_time64() to the
    new ktime_get_coarse_ts64() function. Unfortunately this resulted
    in incorrect timestamps, e.g. events stamped with the year 1969
    despite it being 2018. This patch corrects this by using
    ktime_get_coarse_real_ts64() just like the current_kernel_time64()
    wrapper.

    Fixes: c72051d5778a ("audit: use ktime_get_coarse_ts64() for time access")
    Reviewed-by: Arnd Bergmann
    Signed-off-by: Paul Moore

    Paul Moore
     

03 Jul, 2018

1 commit


19 Jun, 2018

2 commits

  • Remove comparison of audit_enabled to magic numbers outside of audit.

    Related: https://github.com/linux-audit/audit-kernel/issues/86

    Signed-off-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     
  • The AUDIT_FILTER_TYPE name is vague and misleading due to not describing
    where or when the filter is applied and obsolete due to its available
    filter fields having been expanded.

    Userspace has already renamed it from AUDIT_FILTER_TYPE to
    AUDIT_FILTER_EXCLUDE without checking if it already exists. The
    userspace maintainer assures that as long as it is set to the same value
    it will not be a problem since the userspace code does not treat
    compiler warnings as errors. If this policy changes then checks if it
    already exists can be added at the same time.

    See: https://github.com/linux-audit/audit-kernel/issues/89

    Signed-off-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

15 May, 2018

1 commit

  • Recognizing that the audit context is an internal audit value, use an
    access function to retrieve the audit context pointer for the task
    rather than reaching directly into the task struct to get it.

    Signed-off-by: Richard Guy Briggs
    [PM: merge fuzz in auditsc.c and selinuxfs.c, checkpatch.pl fixes]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

21 Apr, 2018

1 commit


07 Apr, 2018

1 commit

  • Pull audit updates from Paul Moore:
    "We didn't have anything to send for v4.16, but we're back with a
    little more than usual for v4.17.

    Eleven patches in total, most fall into the small fix category, but
    there are three non-trivial changes worth calling out:

    - the audit entry filter is being removed after deprecating it for
    quite a while (years of no one really using it because it turns out
    to be not very practical)

    - created our own version of "__mutex_owner()" because the locking
    folks were upset we were using theirs

    - improved our handling of kernel command line parameters to make
    them more forgiving

    - we fixed auditing of symlink operations

    Everything passes the audit-testsuite and as of a few minutes ago it
    merges well with your tree"

    * tag 'audit-pr-20180403' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit:
    audit: add refused symlink to audit_names
    audit: remove path param from link denied function
    audit: link denied should not directly generate PATH record
    audit: make ANOM_LINK obey audit_enabled and audit_dummy_context
    audit: do not panic on invalid boot parameter
    audit: track the owner of the command mutex ourselves
    audit: return on memory error to avoid null pointer dereference
    audit: bail before bug check if audit disabled
    audit: deprecate the AUDIT_FILTER_ENTRY filter
    audit: session ID should not set arch quick field pointer
    audit: update bugtracker and source URIs

    Linus Torvalds
     

26 Mar, 2018

1 commit

  • Some functions definitions have either the initial open brace and/or
    the closing brace outside of column 1.

    Move those braces to column 1.

    This allows various function analyzers like gnu complexity to work
    properly for these modified functions.

    Signed-off-by: Joe Perches
    Acked-by: Andy Shevchenko
    Acked-by: Paul Moore
    Acked-by: Alex Deucher
    Acked-by: Dave Chinner
    Reviewed-by: Darrick J. Wong
    Acked-by: Alexandre Belloni
    Acked-by: Martin K. Petersen
    Acked-by: Takashi Iwai
    Acked-by: Mauro Carvalho Chehab
    Acked-by: Rafael J. Wysocki
    Acked-by: Nicolin Chen
    Acked-by: Martin K. Petersen
    Acked-by: Steven Rostedt (VMware)
    Signed-off-by: Jiri Kosina

    Joe Perches
     

21 Mar, 2018

1 commit


09 Mar, 2018

2 commits


07 Mar, 2018

1 commit

  • If you pass in an invalid audit boot parameter value, e.g. "audit=off",
    the kernel panics very early in boot before the regular console is
    initialized. Unless you have earlyprintk enabled, there is no
    indication of what the problem is on the console.

    Convert the panic() calls to pr_err(), and leave auditing enabled if an
    invalid parameter value was passed in.

    Modify the parameter to also accept "on" or "off" as valid values, and
    update the documentation accordingly.

    Signed-off-by: Greg Edwards
    Signed-off-by: Paul Moore

    Greg Edwards
     

24 Feb, 2018

1 commit

  • Evidently the __mutex_owner() function was never intended for use
    outside the core mutex code, so build a thing locking wrapper around
    the mutex code which allows us to track the mutex owner.

    One, arguably positive, side effect is that this allows us to hide
    the audit_cmd_mutex inside of kernel/audit.c behind the lock/unlock
    functions.

    Reported-by: Peter Zijlstra
    Reviewed-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Paul Moore
     

22 Feb, 2018

1 commit

  • If there is a memory allocation error when trying to change an audit
    kernel feature value, the ignored allocation error will trigger a NULL
    pointer dereference oops on subsequent use of that pointer. Return
    instead.

    Passes audit-testsuite.
    See: https://github.com/linux-audit/audit-kernel/issues/76

    Signed-off-by: Richard Guy Briggs
    [PM: not necessary (other funcs check for NULL), but a good practice]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

15 Feb, 2018

1 commit


11 Nov, 2017

7 commits


05 Sep, 2017

2 commits

  • Update the function comments to match the code.

    Signed-off-by: Geliang Tang
    Signed-off-by: Paul Moore

    Geliang Tang
     
  • Commit 2115bb250f26 ("audit: Use timespec64 to represent audit timestamps")
    noted that audit timestamps were not y2038 safe and used a 64-bit
    timestamp. In itself, this makes sense but the conversion was from
    CURRENT_TIME to ktime_get_real_ts64() which is a heavier call to record
    an accurate timestamp which is required in some, but not all, cases. The
    impact is that when auditd is running without any rules that all syscalls
    have higher overhead. This is visible in the sysbench-thread benchmark as
    a 11.5% performance hit. That benchmark is dumb as rocks but it's also
    visible in redis as an 8-10% hit on all operations which is of greater
    concern. It is somewhat stupid of audit to track syscalls without any
    rules related to syscalls but that is how it behaves.

    The overhead can be directly measured with perf comparing 4.9 with 4.12

    4.9
    7.76% sysbench [kernel.vmlinux] [k] __schedule
    7.62% sysbench [kernel.vmlinux] [k] _raw_spin_lock
    7.37% sysbench libpthread-2.22.so [.] __lll_lock_elision
    7.29% sysbench [kernel.vmlinux] [.] syscall_return_via_sysret
    6.59% sysbench [kernel.vmlinux] [k] native_sched_clock
    5.21% sysbench libc-2.22.so [.] __sched_yield
    4.38% sysbench [kernel.vmlinux] [k] entry_SYSCALL_64
    4.28% sysbench [kernel.vmlinux] [k] do_syscall_64
    3.49% sysbench libpthread-2.22.so [.] __lll_unlock_elision
    3.13% sysbench [kernel.vmlinux] [k] __audit_syscall_exit
    2.87% sysbench [kernel.vmlinux] [k] update_curr
    2.73% sysbench [kernel.vmlinux] [k] pick_next_task_fair
    2.31% sysbench [kernel.vmlinux] [k] syscall_trace_enter
    2.20% sysbench [kernel.vmlinux] [k] __audit_syscall_entry
    .....
    0.00% swapper [kernel.vmlinux] [k] read_tsc

    4.12
    7.84% sysbench [kernel.vmlinux] [k] __schedule
    7.05% sysbench [kernel.vmlinux] [k] _raw_spin_lock
    6.57% sysbench libpthread-2.22.so [.] __lll_lock_elision
    6.50% sysbench [kernel.vmlinux] [.] syscall_return_via_sysret
    5.95% sysbench [kernel.vmlinux] [k] read_tsc
    5.71% sysbench [kernel.vmlinux] [k] native_sched_clock
    4.78% sysbench libc-2.22.so [.] __sched_yield
    4.30% sysbench [kernel.vmlinux] [k] entry_SYSCALL_64
    3.94% sysbench [kernel.vmlinux] [k] do_syscall_64
    3.37% sysbench libpthread-2.22.so [.] __lll_unlock_elision
    3.32% sysbench [kernel.vmlinux] [k] __audit_syscall_exit
    2.91% sysbench [kernel.vmlinux] [k] __getnstimeofday64

    Note the additional overhead from read_tsc which goes from 0% to 5.95%.
    This is on a single-socket E3-1230 but similar overheads have been measured
    on an older machine which the patch also eliminates.

    The patch in question has no explanation as to why a fully-accurate timestamp
    is required and is likely an oversight. Using a coarser, but monotically
    increasing, timestamp the overhead can be eliminated. While it can be
    worked around by configuring or disabling audit, it's tricky enough to
    detect that a kernel fix is justified. With this patch, we see the following;

    sysbenchthread
    4.9.0 4.12.0 4.12.0
    vanilla vanilla coarse-v1r1
    Amean 1 1.49 ( 0.00%) 1.66 ( -11.42%) 1.51 ( -1.34%)
    Amean 3 1.48 ( 0.00%) 1.65 ( -11.45%) 1.50 ( -0.96%)
    Amean 5 1.49 ( 0.00%) 1.67 ( -12.31%) 1.51 ( -1.83%)
    Amean 7 1.49 ( 0.00%) 1.66 ( -11.72%) 1.50 ( -0.67%)
    Amean 12 1.48 ( 0.00%) 1.65 ( -11.57%) 1.52 ( -2.89%)
    Amean 16 1.49 ( 0.00%) 1.65 ( -11.13%) 1.51 ( -1.73%)

    The benchmark is reporting the time required for different thread counts to
    lock/unlock a private mutex which, while dense, demonstrates the syscall
    overhead. This is showing that 4.12 took a 11-12% hit but the overhead is
    almost eliminated by the patch. While the variance is not reported here,
    it's well within the noise with the patch applied.

    Signed-off-by: Mel Gorman
    Acked-by: Arnd Bergmann
    Acked-by: Deepa Dinamani
    Signed-off-by: Paul Moore

    Mel Gorman
     

21 Jul, 2017

1 commit


19 Jul, 2017

1 commit

  • Found this issue by kmemleak report, auditd_send_unicast_skb
    did not free skb if rcu_dereference(auditd_conn) returns null.

    unreferenced object 0xffff88082568ce00 (size 256):
    comm "auditd", pid 1119, jiffies 4294708499
    backtrace:
    [] kmemleak_alloc+0x4a/0xa0
    [] kmem_cache_alloc_node+0xcc/0x210
    [] __alloc_skb+0x5d/0x290
    [] audit_make_reply+0x54/0xd0
    [] audit_receive_msg+0x967/0xd70
    ----------------
    (gdb) list *audit_receive_msg+0x967
    0xffffffff8113dff7 is in audit_receive_msg (kernel/audit.c:1133).
    1132 skb = audit_make_reply(0, AUDIT_REPLACE, 0,
    0, &pvnr, sizeof(pvnr));
    ---------------
    [] audit_receive+0x52/0xa0
    [] netlink_unicast+0x181/0x240
    [] netlink_sendmsg+0x2c2/0x3b0
    [] sock_sendmsg+0x38/0x50
    [] SYSC_sendto+0x102/0x190
    [] SyS_sendto+0xe/0x10
    [] entry_SYSCALL_64_fastpath+0x1a/0xa5
    [] 0xffffffffffffffff

    Signed-off-by: Shu Wang
    Signed-off-by: Paul Moore

    Shu Wang
     

06 Jul, 2017

1 commit

  • Pull audit updates from Paul Moore:
    "Things are relatively quiet on the audit front for v4.13, just five
    patches for a total diffstat of 102 lines.

    There are two patches from Richard to consistently record the POSIX
    capabilities and add the ambient capability information as well.

    I also chipped in two patches to fix a race condition with the auditd
    tracking code and ensure we don't skip sending any records to the
    audit multicast group.

    Finally a single style fix that I accepted because I must have been in
    a good mood that day.

    Everything passes our test suite, and should be relatively harmless,
    please merge for v4.13"

    * 'stable-4.13' of git://git.infradead.org/users/pcmoore/audit:
    audit: make sure we never skip the multicast broadcast
    audit: fix a race condition with the auditd tracking code
    audit: style fix
    audit: add ambient capabilities to CAPSET and BPRM_FCAPS records
    audit: unswing cap_* fields in PATH records

    Linus Torvalds
     

16 Jun, 2017

1 commit

  • When the auditd connection is reset, either intentionally or due to
    a failure, any records that were in the main backlog queue would not
    be sent in a multicast broadcast. This patch fixes this problem by
    not flushing the main backlog queue on a connection reset, the main
    kauditd_thread() will take care of that normally.

    Resolves: https://github.com/linux-audit/audit-kernel/issues/41
    Reviewed-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Paul Moore
     

14 Jun, 2017

1 commit

  • Originally reported by Adam and Dusty, it appears we have a small
    race window in kauditd_thread(), as documented in the Fedora BZ:

    * https://bugzilla.redhat.com/show_bug.cgi?id=1459326#c35

    "This issue is partly due to the read-copy nature of RCU, and
    partly due to how we sync the auditd_connection state across
    kauditd_thread and the audit control channel. The kauditd_thread
    thread is always running so it can service the record queues and
    emit the multicast messages, if it happens to be just past the
    "main_queue" label, but before the "if (sk == NULL || ...)"
    if-statement which calls auditd_reset() when the new auditd
    connection is registered it could end up resetting the auditd
    connection, regardless of if it is valid or not. This is a rather
    small window and the variable nature of multi-core scheduling
    explains why this is proving rather difficult to reproduce."

    The fix is to have functions only call auditd_reset() when they
    believe that the kernel/auditd connection is still valid, e.g.
    non-NULL, and to have these callers pass their local copy of the
    auditd_connection pointer to auditd_reset() where it can be compared
    with the current connection state before resetting. If the caller
    has a stale state tracking pointer then the reset is ignored.

    We also make a small change to kauditd_thread() so that if the
    kernel/auditd connection is dead we skip the retry queue and send the
    records straight to the hold queue. This is necessary as we used to
    rely on auditd_reset() to occasionally purge the retry queue but we
    are going to be calling the reset function much less now and we want
    to make sure the retry queue doesn't grow unbounded.

    Reported-by: Adam Williamson
    Reported-by: Dusty Mabe
    Reviewed-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Paul Moore
     

24 May, 2017

1 commit

  • The cap_* fields swing in and out of PATH records.
    If no capabilities are set, the cap_* fields are completely missing and when
    one of the cap_fi or cap_fp values is empty, that field is omitted.

    Original:
    type=PATH msg=audit(04/20/2017 12:17:11.222:193) : item=1 name=/lib64/ld-linux-x86-64.so.2 inode=787694 dev=08:03 mode=file,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:ld_so_t:s0 nametype=NORMAL
    type=PATH msg=audit(04/20/2017 12:17:11.222:193) : item=0 name=/home/sleep inode=1319469 dev=08:03 mode=file,suid,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:bin_t:s0 nametype=NORMAL cap_fp=sys_admin cap_fe=1 cap_fver=2

    Normalize the PATH record by always printing all 4 cap_* fields.

    Fixed:
    type=PATH msg=audit(04/20/2017 13:01:31.679:201) : item=1 name=/lib64/ld-linux-x86-64.so.2 inode=787694 dev=08:03 mode=file,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:ld_so_t:s0 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0
    type=PATH msg=audit(04/20/2017 13:01:31.679:201) : item=0 name=/home/sleep inode=1319469 dev=08:03 mode=file,suid,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:bin_t:s0 nametype=NORMAL cap_fp=sys_admin cap_fi=none cap_fe=1 cap_fver=2

    See: https://github.com/linux-audit/audit-kernel/issues/42

    Signed-off-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

04 May, 2017

1 commit

  • Pull audit updates from Paul Moore:
    "Fourteen audit patches for v4.12 that span the full range of fixes,
    new features, and internal cleanups.

    We have a patches to move to 64-bit timestamps, convert refcounts from
    atomic_t to refcount_t, track PIDs using the pid struct instead of
    pid_t, convert our own private audit buffer cache to a standard
    kmem_cache, log kernel module names when they are unloaded, and
    normalize the NETFILTER_PKT to make the userspace folks happier.

    From a fixes perspective, the most important is likely the auditd
    connection tracking RCU fix; it was a rather brain dead bug that I'll
    take the blame for, but thankfully it didn't seem to affect many
    people (only one report).

    I think the patch subject lines and commit descriptions do a pretty
    good job of explaining the details and why the changes are important
    so I'll point you there instead of duplicating it here; as usual, if
    you have any questions you know where to find us.

    We also manage to take out more code than we put in this time, that
    always makes me happy :)"

    * 'stable-4.12' of git://git.infradead.org/users/pcmoore/audit:
    audit: fix the RCU locking for the auditd_connection structure
    audit: use kmem_cache to manage the audit_buffer cache
    audit: Use timespec64 to represent audit timestamps
    audit: store the auditd PID as a pid struct instead of pid_t
    audit: kernel generated netlink traffic should have a portid of 0
    audit: combine audit_receive() and audit_receive_skb()
    audit: convert audit_watch.count from atomic_t to refcount_t
    audit: convert audit_tree.count from atomic_t to refcount_t
    audit: normalize NETFILTER_PKT
    netfilter: use consistent ipv4 network offset in xt_AUDIT
    audit: log module name on delete_module
    audit: remove unnecessary semicolon in audit_watch_handle_event()
    audit: remove unnecessary semicolon in audit_mark_handle_event()
    audit: remove unnecessary semicolon in audit_field_valid()

    Linus Torvalds
     

02 May, 2017

6 commits


16 Apr, 2017

1 commit


14 Apr, 2017

1 commit

  • Add the base infrastructure and UAPI for netlink extended ACK
    reporting. All "manual" calls to netlink_ack() pass NULL for now and
    thus don't get extended ACK reporting.

    Big thanks goes to Pablo Neira Ayuso for not only bringing up the
    whole topic at netconf (again) but also coming up with the nlattr
    passing trick and various other ideas.

    Signed-off-by: Johannes Berg
    Reviewed-by: David Ahern
    Signed-off-by: David S. Miller

    Johannes Berg
     

10 Apr, 2017

1 commit

  • The retry queue is intended to provide a temporary buffer in the case
    of transient errors when communicating with auditd, it is not meant
    as a long life queue, that functionality is provided by the hold
    queue.

    This patch fixes a problem identified by Seth where the retry queue
    could grow uncontrollably if an auditd instance did not connect to
    the kernel to drain the queues. This commit fixes this by doing the
    following:

    * Make sure we always call auditd_reset() if we decide the connection
    with audit is really dead. There were some cases in
    kauditd_hold_skb() where we did not reset the connection, this patch
    relocates the reset calls to kauditd_thread() so all the error
    conditions are caught and the connection reset. As a side effect,
    this means we could move auditd_reset() and get rid of the forward
    definition at the top of kernel/audit.c.

    * We never checked the status of the auditd connection when
    processing the main audit queue which meant that the retry queue
    could grow unchecked. This patch adds a call to auditd_reset()
    after the main queue has been processed if auditd is not connected,
    the auditd_reset() call will make sure the retry and hold queues are
    correctly managed/flushed so that the retry queue remains reasonable.

    Cc: # 4.10.x-: 5b52330bbfe6
    Reported-by: Seth Forshee
    Signed-off-by: Paul Moore

    Paul Moore