seccomp: Don't special case audited processes when logging
authorTyler Hicks <tyhicks@canonical.com>
Fri, 4 May 2018 01:08:15 +0000 (01:08 +0000)
committerPaul Moore <paul@paul-moore.com>
Tue, 8 May 2018 06:04:23 +0000 (02:04 -0400)
Seccomp logging for "handled" actions such as RET_TRAP, RET_TRACE, or
RET_ERRNO can be very noisy for processes that are being audited. This
patch modifies the seccomp logging behavior to treat processes that are
being inspected via the audit subsystem the same as processes that
aren't under inspection. Handled actions will no longer be logged just
because the process is being inspected. Since v4.14, applications have
the ability to request logging of handled actions by using the
SECCOMP_FILTER_FLAG_LOG flag when loading seccomp filters.

With this patch, the logic for deciding if an action will be logged is:

  if action == RET_ALLOW:
    do not log
  else if action not in actions_logged:
    do not log
  else if action == RET_KILL:
    log
  else if action == RET_LOG:
    log
  else if filter-requests-logging:
    log
  else:
    do not log

Reported-by: Steve Grubb <sgrubb@redhat.com>
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Documentation/userspace-api/seccomp_filter.rst
include/linux/audit.h
kernel/auditsc.c
kernel/seccomp.c

index 099c412951d6b9dea515b08384e023e2c2d69025..82a468bc7560c179de34cf98aa1a050d092d2721 100644 (file)
@@ -207,13 +207,6 @@ directory. Here's a description of each file in that directory:
        to the file do not need to be in ordered form but reads from the file
        will be ordered in the same way as the actions_avail sysctl.
 
-       It is important to note that the value of ``actions_logged`` does not
-       prevent certain actions from being logged when the audit subsystem is
-       configured to audit a task. If the action is not found in
-       ``actions_logged`` list, the final decision on whether to audit the
-       action for that task is ultimately left up to the audit subsystem to
-       decide for all seccomp return values other than ``SECCOMP_RET_ALLOW``.
-
        The ``allow`` string is not accepted in the ``actions_logged`` sysctl
        as it is not possible to log ``SECCOMP_RET_ALLOW`` actions. Attempting
        to write ``allow`` to the sysctl will result in an EINVAL being
index d4e35e7a80c05443dc44c2e096533085c7f0e7d4..b639cf1f55ff6c16f9649fbc803cbb98c3cf6435 100644 (file)
@@ -232,7 +232,7 @@ extern void __audit_file(const struct file *);
 extern void __audit_inode_child(struct inode *parent,
                                const struct dentry *dentry,
                                const unsigned char type);
-extern void __audit_seccomp(unsigned long syscall, long signr, int code);
+extern void audit_seccomp(unsigned long syscall, long signr, int code);
 extern void audit_seccomp_actions_logged(const char *names,
                                         const char *old_names, int res);
 extern void __audit_ptrace(struct task_struct *t);
@@ -304,12 +304,6 @@ static inline void audit_inode_child(struct inode *parent,
 }
 void audit_core_dumps(long signr);
 
-static inline void audit_seccomp(unsigned long syscall, long signr, int code)
-{
-       if (audit_enabled && unlikely(!audit_dummy_context()))
-               __audit_seccomp(syscall, signr, code);
-}
-
 static inline void audit_ptrace(struct task_struct *t)
 {
        if (unlikely(!audit_dummy_context()))
@@ -500,8 +494,6 @@ static inline void audit_inode_child(struct inode *parent,
 { }
 static inline void audit_core_dumps(long signr)
 { }
-static inline void __audit_seccomp(unsigned long syscall, long signr, int code)
-{ }
 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
 { }
 static inline void audit_seccomp_actions_logged(const char *names,
index 46ef2c23618d1cc40ef3375326fb3ed77ea0a89c..0d4e7ab847b1dff0d04464a56879d5149065ed6e 100644 (file)
@@ -2466,7 +2466,19 @@ void audit_core_dumps(long signr)
        audit_log_end(ab);
 }
 
-void __audit_seccomp(unsigned long syscall, long signr, int code)
+/**
+ * audit_seccomp - record information about a seccomp action
+ * @syscall: syscall number
+ * @signr: signal value
+ * @code: the seccomp action
+ *
+ * Record the information associated with a seccomp action. Event filtering for
+ * seccomp actions that are not to be logged is done in seccomp_log().
+ * Therefore, this function forces auditing independent of the audit_enabled
+ * and dummy context state because seccomp actions should be logged even when
+ * audit is not in use.
+ */
+void audit_seccomp(unsigned long syscall, long signr, int code)
 {
        struct audit_buffer *ab;
 
index f5630d1a88fe45efd1907e203300fa7789198aee..5386749cdd21656900f0e15dfcba390f45b3c8b7 100644 (file)
@@ -584,18 +584,15 @@ static inline void seccomp_log(unsigned long syscall, long signr, u32 action,
        }
 
        /*
-        * Force an audit message to be emitted when the action is RET_KILL_*,
-        * RET_LOG, or the FILTER_FLAG_LOG bit was set and the action is
-        * allowed to be logged by the admin.
+        * Emit an audit message when the action is RET_KILL_*, RET_LOG, or the
+        * FILTER_FLAG_LOG bit was set. The admin has the ability to silence
+        * any action from being logged by removing the action name from the
+        * seccomp_actions_logged sysctl.
         */
-       if (log)
-               return __audit_seccomp(syscall, signr, action);
+       if (!log)
+               return;
 
-       /*
-        * Let the audit subsystem decide if the action should be audited based
-        * on whether the current task itself is being audited.
-        */
-       return audit_seccomp(syscall, signr, action);
+       audit_seccomp(syscall, signr, action);
 }
 
 /*