Skip to contentSkip to conversation

audit: create explicit AUDIT_SECCOMP event type

PATCH Superseded Kees Cook 2 participants 4 messages Nov 19, 2012 – Nov 28, 2012 Audit

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 audit: create explicit AUDIT_SECCOMP event type

The seccomp path was using AUDIT_ANOM_ABEND from when seccomp mode 1 could only kill a process. While we still want to make sure an audit record is forced on a kill, this should use a separate record type since seccomp mode 2 introduces other behaviors. In the case of "handled" behaviors (process wasn't killed), only emit a record if the process is under inspection.

Cc Julien Tinnes <[email protected]>
Cc Will Drewry <[email protected]>
---
 include/linux/audit.h      |    3 ++-
 include/uapi/linux/audit.h |    1 +
 kernel/auditsc.c           |   14 +++++++++++---
 3 files changed, 14 insertions(+), 4 deletions(-)
include/linux/audit.h +2 -1
index bce729a..9d5104d 100644
@@ -157,7 +157,8 @@ void audit_core_dumps(long signr);
 
 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
 {
-	if (unlikely(!audit_dummy_context()))
+	/* Force a record to be reported if a signal was delivered. */
+	if (signr || unlikely(!audit_dummy_context()))
 		__audit_seccomp(syscall, signr, code);
 }
 
include/uapi/linux/audit.h +1 -0
index 76352ac..09a2d94 100644
@@ -106,6 +106,7 @@
 #define AUDIT_MMAP		1323	/* Record showing descriptor and flags in mmap */
 #define AUDIT_NETFILTER_PKT	1324	/* Packets traversing netfilter chains */
 #define AUDIT_NETFILTER_CFG	1325	/* Netfilter chain modifications */
+#define AUDIT_SECCOMP		1326	/* Secure Computing event */
 
 #define AUDIT_AVC		1400	/* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR	1401	/* Internal SE Linux Errors */
kernel/auditsc.c +11 -3
index 2f186ed..157e989 100644
@@ -2735,7 +2735,7 @@ void __audit_mmap_fd(int fd, int flags)
 	context->type = AUDIT_MMAP;
 }
 
-static void audit_log_abend(struct audit_buffer *ab, char *reason, long signr)
+static void audit_log_task(struct audit_buffer *ab)
 {
 	kuid_t auid, uid;
 	kgid_t gid;
@@ -2753,6 +2753,11 @@ static void audit_log_abend(struct audit_buffer *ab, char *reason, long signr)
 	audit_log_task_context(ab);
 	audit_log_format(ab, " pid=%d comm=", current->pid);
 	audit_log_untrustedstring(ab, current->comm);
+}
+
+static void audit_log_abend(struct audit_buffer *ab, char *reason, long signr)
+{
+	audit_log_task(ab);
 	audit_log_format(ab, " reason=");
 	audit_log_string(ab, reason);
 	audit_log_format(ab, " sig=%ld", signr);
@@ -2783,8 +2788,11 @@ void __audit_seccomp(unsigned long syscall, long signr, int code)
 {
 	struct audit_buffer *ab;
 
-	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND);
-	audit_log_abend(ab, "seccomp", signr);
+	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_SECCOMP);
+	if (unlikely(!ab))
+		return;
+	audit_log_task(ab);
+	audit_log_format(ab, " sig=%ld", signr);
 	audit_log_format(ab, " syscall=%ld", syscall);
 	audit_log_format(ab, " compat=%d", is_compat_task());
 	audit_log_format(ab, " ip=0x%lx", KSTK_EIP(current));
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security
#1 lore raw
Quoted 6 lines · Kees Cook

The seccomp path was using AUDIT_ANOM_ABEND from when seccomp mode 1 could only kill a process. While we still want to make sure an audit record is forced on a kill, this should use a separate record type since seccomp mode 2 introduces other behaviors. In the case of "handled" behaviors (process wasn't killed), only emit a record if the process is under inspection.

Under the old record type, we know that the process is being terminated. Therefore the meaning of the action is known as its implicit in the record type. With this new type, we need to record what behavior is being enforced on the process. I don't see where that is being recorded.

Could we add that?

Thanks,
-Steve

Quoted 28 lines
Cc Julien Tinnes <[email protected]>
Cc Will Drewry <[email protected]>
---
 include/linux/audit.h      |    3 ++-
 include/uapi/linux/audit.h |    1 +
 kernel/auditsc.c           |   14 +++++++++++---
 3 files changed, 14 insertions(+), 4 deletions(-)
include/linux/audit.h +2 -1
index bce729a..9d5104d 100644
@@ -157,7 +157,8 @@ void audit_core_dumps(long signr);
 
 static inline void audit_seccomp(unsigned long syscall, long signr, int
 code) {
-	if (unlikely(!audit_dummy_context()))
+	/* Force a record to be reported if a signal was delivered. */
+	if (signr || unlikely(!audit_dummy_context()))
 		__audit_seccomp(syscall, signr, code);
 }
 
include/uapi/linux/audit.h +0 -0
index 76352ac..09a2d94 100644

include/uapi/linux/audit.h line 106

Quoted 1 line
include/uapi/linux/audit.h +0 -0
@@ -106,6 +106,7 @@
 #define AUDIT_MMAP		1323	/* Record showing descriptor and flags in 

mmap */

include/uapi/linux/audit.h line 107

Quoted 1 line
include/uapi/linux/audit.h +0 -0
 #define AUDIT_NETFILTER_PKT	1324	/* Packets traversing netfilter chains 

*/

Quoted 44 lines
include/uapi/linux/audit.h +1 -0
 #define AUDIT_NETFILTER_CFG	1325	/* Netfilter chain modifications */
+#define AUDIT_SECCOMP		1326	/* Secure Computing event */
 
 #define AUDIT_AVC		1400	/* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR	1401	/* Internal SE Linux Errors */
kernel/auditsc.c +9 -3
index 2f186ed..157e989 100644
@@ -2735,7 +2735,7 @@ void __audit_mmap_fd(int fd, int flags)
 	context->type = AUDIT_MMAP;
 }
 
-static void audit_log_abend(struct audit_buffer *ab, char *reason, long
 signr) +static void audit_log_task(struct audit_buffer *ab)
 {
 	kuid_t auid, uid;
 	kgid_t gid;
@@ -2753,6 +2753,11 @@ static void audit_log_abend(struct audit_buffer *ab,
 char *reason, long signr) audit_log_task_context(ab);
 	audit_log_format(ab, " pid=%d comm=", current->pid);
 	audit_log_untrustedstring(ab, current->comm);
+}
+
+static void audit_log_abend(struct audit_buffer *ab, char *reason, long
 signr) +{
+	audit_log_task(ab);
 	audit_log_format(ab, " reason=");
 	audit_log_string(ab, reason);
 	audit_log_format(ab, " sig=%ld", signr);
@@ -2783,8 +2788,11 @@ void __audit_seccomp(unsigned long syscall, long
 signr, int code) {
 	struct audit_buffer *ab;
 
-	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND);
-	audit_log_abend(ab, "seccomp", signr);
+	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_SECCOMP);
+	if (unlikely(!ab))
+		return;
+	audit_log_task(ab);
+	audit_log_format(ab, " sig=%ld", signr);
 	audit_log_format(ab, " syscall=%ld", syscall);
 	audit_log_format(ab, " compat=%d", is_compat_task());
 	audit_log_format(ab, " ip=0x%lx", KSTK_EIP(current));
author
#2 lore raw
Quoted 8 lines · Steve Grubb
Quoted 6 lines · Kees Cook

The seccomp path was using AUDIT_ANOM_ABEND from when seccomp mode 1 could only kill a process. While we still want to make sure an audit record is forced on a kill, this should use a separate record type since seccomp mode 2 introduces other behaviors. In the case of "handled" behaviors (process wasn't killed), only emit a record if the process is under inspection.

Quoted 4 lines

Under the old record type, we know that the process is being terminated. Therefore the meaning of the action is known as its implicit in the record type. With this new type, we need to record what behavior is being enforced on the process. I don't see where that is being recorded.

The action is encoded in the "code=". If one is doing seccomp auditing, this code will be meaningful already.

Quoted 1 line

Could we add that?

I'd rather not expand the code into the separate meanings if we don't have to. It's part of the BPF already, so it's useful to leave it as-is, IMO.

-Kees

Quoted 81 lines

Thanks,
-Steve

Quoted 28 lines
Cc Julien Tinnes <[email protected]>
Cc Will Drewry <[email protected]>
---
 include/linux/audit.h      |    3 ++-
 include/uapi/linux/audit.h |    1 +
 kernel/auditsc.c           |   14 +++++++++++---
 3 files changed, 14 insertions(+), 4 deletions(-)
include/linux/audit.h +2 -1
index bce729a..9d5104d 100644
@@ -157,7 +157,8 @@ void audit_core_dumps(long signr);
 
 static inline void audit_seccomp(unsigned long syscall, long signr, int
 code) {
-     if (unlikely(!audit_dummy_context()))
+     /* Force a record to be reported if a signal was delivered. */
+     if (signr || unlikely(!audit_dummy_context()))
              __audit_seccomp(syscall, signr, code);
 }
 
include/uapi/linux/audit.h +0 -0
index 76352ac..09a2d94 100644

include/uapi/linux/audit.h line 106

Quoted 1 line
include/uapi/linux/audit.h +0 -0
@@ -106,6 +106,7 @@
 #define AUDIT_MMAP           1323    /* Record showing descriptor and flags in

mmap */

include/uapi/linux/audit.h line 107

Quoted 1 line
include/uapi/linux/audit.h +0 -0
 #define AUDIT_NETFILTER_PKT  1324    /* Packets traversing netfilter chains

*/

Quoted 44 lines
include/uapi/linux/audit.h +1 -0
 #define AUDIT_NETFILTER_CFG  1325    /* Netfilter chain modifications */
+#define AUDIT_SECCOMP                1326    /* Secure Computing event */
 
 #define AUDIT_AVC            1400    /* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR    1401    /* Internal SE Linux Errors */
kernel/auditsc.c +9 -3
index 2f186ed..157e989 100644
@@ -2735,7 +2735,7 @@ void __audit_mmap_fd(int fd, int flags)
      context->type = AUDIT_MMAP;
 }
 
-static void audit_log_abend(struct audit_buffer *ab, char *reason, long
 signr) +static void audit_log_task(struct audit_buffer *ab)
 {
      kuid_t auid, uid;
      kgid_t gid;
@@ -2753,6 +2753,11 @@ static void audit_log_abend(struct audit_buffer *ab,
 char *reason, long signr) audit_log_task_context(ab);
      audit_log_format(ab, " pid=%d comm=", current->pid);
      audit_log_untrustedstring(ab, current->comm);
+}
+
+static void audit_log_abend(struct audit_buffer *ab, char *reason, long
 signr) +{
+     audit_log_task(ab);
      audit_log_format(ab, " reason=");
      audit_log_string(ab, reason);
      audit_log_format(ab, " sig=%ld", signr);
@@ -2783,8 +2788,11 @@ void __audit_seccomp(unsigned long syscall, long
 signr, int code) {
      struct audit_buffer *ab;
 
-     ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND);
-     audit_log_abend(ab, "seccomp", signr);
+     ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_SECCOMP);
+     if (unlikely(!ab))
+             return;
+     audit_log_task(ab);
+     audit_log_format(ab, " sig=%ld", signr);
      audit_log_format(ab, " syscall=%ld", syscall);
      audit_log_format(ab, " compat=%d", is_compat_task());
      audit_log_format(ab, " ip=0x%lx", KSTK_EIP(current));
Signature · 2 lines
Kees Cook
Chrome OS Security
#3 lore raw
Quoted 14 lines · Kees Cook
Quoted 8 lines · Steve Grubb
Quoted 6 lines · Kees Cook

The seccomp path was using AUDIT_ANOM_ABEND from when seccomp mode 1 could only kill a process. While we still want to make sure an audit record is forced on a kill, this should use a separate record type since seccomp mode 2 introduces other behaviors. In the case of "handled" behaviors (process wasn't killed), only emit a record if the process is under inspection.

Quoted 4 lines

Under the old record type, we know that the process is being terminated. Therefore the meaning of the action is known as its implicit in the record type. With this new type, we need to record what behavior is being enforced on the process. I don't see where that is being recorded.

Quoted 8 lines

The action is encoded in the "code=". If one is doing seccomp auditing, this code will be meaningful already.

Quoted 1 line

Could we add that?

I'd rather not expand the code into the separate meanings if we don't have to. It's part of the BPF already, so it's useful to leave it as-is, IMO.

Support for this has been added in the user space utilities. This event type switch actually fixes a problem where the seccomp use of AUDIT_ANOM_ABEND makes it malformed because it has different fields. This could be pushed into stable (after testing) in my opinion since it corrects a problem.

ack: Steve Grubb <[email protected]>

Quoted 101 lines
Quoted 101 lines
Quoted 32 lines
Cc Julien Tinnes <[email protected]>
Cc Will Drewry <[email protected]>

---

 include/linux/audit.h      |    3 ++-
 include/uapi/linux/audit.h |    1 +
 kernel/auditsc.c           |   14 +++++++++++---
 3 files changed, 14 insertions(+), 4 deletions(-)
include/linux/audit.h +2 -1
index bce729a..9d5104d 100644
@@ -157,7 +157,8 @@ void audit_core_dumps(long signr);
 
 static inline void audit_seccomp(unsigned long syscall, long signr, int
 
 code) {
-     if (unlikely(!audit_dummy_context()))
+     /* Force a record to be reported if a signal was delivered. */
+     if (signr || unlikely(!audit_dummy_context()))
 
              __audit_seccomp(syscall, signr, code);

}

include/uapi/linux/audit.h +0 -0
index 76352ac..09a2d94 100644

include/uapi/linux/audit.h line 108

Quoted 3 lines
include/uapi/linux/audit.h +0 -0
@@ -106,6 +106,7 @@
 
 #define AUDIT_MMAP           1323    /* Record showing descriptor and
 flags in> 

mmap */

include/uapi/linux/audit.h line 110

Quoted 2 lines
include/uapi/linux/audit.h +0 -0
 #define AUDIT_NETFILTER_PKT  1324    /* Packets traversing netfilter
 chains

*/

Quoted 59 lines
include/uapi/linux/audit.h +1 -0
 #define AUDIT_NETFILTER_CFG  1325    /* Netfilter chain modifications */
 
+#define AUDIT_SECCOMP                1326    /* Secure Computing event

*/

 #define AUDIT_AVC            1400    /* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR    1401    /* Internal SE Linux Errors */
kernel/auditsc.c +3 -1
index 2f186ed..157e989 100644
@@ -2735,7 +2735,7 @@ void __audit_mmap_fd(int fd, int flags)
 
      context->type = AUDIT_MMAP;
 
 }
 
-static void audit_log_abend(struct audit_buffer *ab, char *reason, long
 signr) +static void audit_log_task(struct audit_buffer *ab)
 
 {
 
      kuid_t auid, uid;
      kgid_t gid;
@@ -2753,6 +2753,11 @@ static void audit_log_abend(struct audit_buffer
 *ab,
 char *reason, long signr) audit_log_task_context(ab);
 
      audit_log_format(ab, " pid=%d comm=", current->pid);
      audit_log_untrustedstring(ab, current->comm);
 
+}
+
+static void audit_log_abend(struct audit_buffer *ab, char *reason, long

signr) +{

kernel/auditsc.c +6 -2
+     audit_log_task(ab);
 
      audit_log_format(ab, " reason=");
      audit_log_string(ab, reason);
      audit_log_format(ab, " sig=%ld", signr);
@@ -2783,8 +2788,11 @@ void __audit_seccomp(unsigned long syscall, long
 signr, int code) {
 
      struct audit_buffer *ab;
 
-     ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND);
-     audit_log_abend(ab, "seccomp", signr);
+     ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_SECCOMP);
+     if (unlikely(!ab))
+             return;
+     audit_log_task(ab);
+     audit_log_format(ab, " sig=%ld", signr);
 
      audit_log_format(ab, " syscall=%ld", syscall);
      audit_log_format(ab, " compat=%d", is_compat_task());
      audit_log_format(ab, " ip=0x%lx", KSTK_EIP(current));