Skip to contentSkip to conversation

audit: handle unknown status requests in audit_receive_msg

PATCH Superseded Ricardo Robaina 2 participants 3 messages Mar 3 – Mar 9 Audit

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 audit: handle unknown status requests in audit_receive_msg

Currently, audit_receive_msg() ignores unknown status bits in AUDIT_SET requests, incorrectly returning success to newer user space tools querying unsupported features. This breaks forward compatibility.

Fix this by defining AUDIT_STATUS_ALL in the UAPI header and returning -EINVAL if any unrecognized bits are set (s.mask & ~AUDIT_STATUS_ALL). This ensures invalid requests are safely rejected, allowing user space to reliably test for and gracefully handle feature detection on older kernels.

---
 include/uapi/linux/audit.h | 9 +++++++++
 kernel/audit.c             | 2 ++
 2 files changed, 11 insertions(+)
include/uapi/linux/audit.h +9 -0
index 14a1c1fe013a..1d5122b9274a 100644
@@ -356,6 +356,15 @@ enum {
 #define AUDIT_STATUS_LOST			0x0040
 #define AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL	0x0080
 
+#define AUDIT_STATUS_ALL (AUDIT_STATUS_ENABLED | \
+			  AUDIT_STATUS_FAILURE | \
+			  AUDIT_STATUS_PID | \
+			  AUDIT_STATUS_RATE_LIMIT | \
+			  AUDIT_STATUS_BACKLOG_LIMIT | \
+			  AUDIT_STATUS_BACKLOG_WAIT_TIME | \
+			  AUDIT_STATUS_LOST | \
+			  AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL)
+
 #define AUDIT_FEATURE_BITMAP_BACKLOG_LIMIT	0x00000001
 #define AUDIT_FEATURE_BITMAP_BACKLOG_WAIT_TIME	0x00000002
 #define AUDIT_FEATURE_BITMAP_EXECUTABLE_PATH	0x00000004
kernel/audit.c +2 -0
index 5a0216056524..592383dce090 100644
@@ -1295,6 +1295,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
 		memset(&s, 0, sizeof(s));
 		/* guard against past and future API changes */
 		memcpy(&s, data, min_t(size_t, sizeof(s), data_len));
+		if (s.mask & ~AUDIT_STATUS_ALL)
+			return -EINVAL;
 		if (s.mask & AUDIT_STATUS_ENABLED) {
 			err = audit_set_enabled(s.enabled);
 			if (err < 0)
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 24 lines · Ricardo Robaina

Currently, audit_receive_msg() ignores unknown status bits in AUDIT_SET requests, incorrectly returning success to newer user space tools querying unsupported features. This breaks forward compatibility.

Fix this by defining AUDIT_STATUS_ALL in the UAPI header and returning -EINVAL if any unrecognized bits are set (s.mask & ~AUDIT_STATUS_ALL). This ensures invalid requests are safely rejected, allowing user space to reliably test for and gracefully handle feature detection on older kernels.

---
 include/uapi/linux/audit.h | 9 +++++++++
 kernel/audit.c             | 2 ++
 2 files changed, 11 insertions(+)
include/uapi/linux/audit.h +0 -0
index 14a1c1fe013a..1d5122b9274a 100644
@@ -356,6 +356,15 @@ enum {
 #define AUDIT_STATUS_LOST                      0x0040

include/uapi/linux/audit.h enum { · line 366

Quoted 10 lines
include/uapi/linux/audit.h +8 -0
 #define AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL  0x0080
 
+#define AUDIT_STATUS_ALL (AUDIT_STATUS_ENABLED | \
+                         AUDIT_STATUS_FAILURE | \
+                         AUDIT_STATUS_PID | \
+                         AUDIT_STATUS_RATE_LIMIT | \
+                         AUDIT_STATUS_BACKLOG_LIMIT | \
+                         AUDIT_STATUS_BACKLOG_WAIT_TIME | \
+                         AUDIT_STATUS_LOST | \
+                         AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL)

Overall I think this is fine and good, but AUDIT_STATUS_ALL doesn't need to be in the UAPI so why don't we move it to include/linux/audit.h? You can put it at the very top, right above the AUDIT_INO_UNSET macro.

Quoted 18 lines
include/uapi/linux/audit.h +0 -0
 #define AUDIT_FEATURE_BITMAP_BACKLOG_LIMIT     0x00000001
 #define AUDIT_FEATURE_BITMAP_BACKLOG_WAIT_TIME 0x00000002
 #define AUDIT_FEATURE_BITMAP_EXECUTABLE_PATH   0x00000004
kernel/audit.c +2 -1
index 5a0216056524..592383dce090 100644
@@ -1295,6 +1295,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
                memset(&s, 0, sizeof(s));
                /* guard against past and future API changes */
                memcpy(&s, data, min_t(size_t, sizeof(s), data_len));
+               if (s.mask & ~AUDIT_STATUS_ALL)
+                       return -EINVAL;
                if (s.mask & AUDIT_STATUS_ENABLED) {
                        err = audit_set_enabled(s.enabled);
                        if (err < 0)
--

2.53.0

Signature · 1 line
paul-moore.com
#2 lore raw
Quoted 28 lines · Paul Moore
Quoted 26 lines · Ricardo Robaina

Currently, audit_receive_msg() ignores unknown status bits in AUDIT_SET requests, incorrectly returning success to newer user space tools querying unsupported features. This breaks forward compatibility.

Fix this by defining AUDIT_STATUS_ALL in the UAPI header and returning -EINVAL if any unrecognized bits are set (s.mask & ~AUDIT_STATUS_ALL). This ensures invalid requests are safely rejected, allowing user space to reliably test for and gracefully handle feature detection on older kernels.

---
 include/uapi/linux/audit.h | 9 +++++++++
 kernel/audit.c             | 2 ++
 2 files changed, 11 insertions(+)
include/uapi/linux/audit.h +0 -0
index 14a1c1fe013a..1d5122b9274a 100644
@@ -356,6 +356,15 @@ enum {
 #define AUDIT_STATUS_LOST                      0x0040
 #define AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL  0x0080
 
Quoted 14 lines

include/uapi/linux/audit.h enum { · line 366

Quoted 8 lines
include/uapi/linux/audit.h +8 -0
+#define AUDIT_STATUS_ALL (AUDIT_STATUS_ENABLED | \
+                         AUDIT_STATUS_FAILURE | \
+                         AUDIT_STATUS_PID | \
+                         AUDIT_STATUS_RATE_LIMIT | \
+                         AUDIT_STATUS_BACKLOG_LIMIT | \
+                         AUDIT_STATUS_BACKLOG_WAIT_TIME | \
+                         AUDIT_STATUS_LOST | \
+                         AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL)

Overall I think this is fine and good, but AUDIT_STATUS_ALL doesn't need to be in the UAPI so why don't we move it to include/linux/audit.h? You can put it at the very top, right above the AUDIT_INO_UNSET macro.

Thanks for reviewing this patch, Paul! Sounds like a good idea, I'll work on the V2.

Quoted 22 lines
Quoted 17 lines
include/uapi/linux/audit.h +0 -0
 #define AUDIT_FEATURE_BITMAP_BACKLOG_LIMIT     0x00000001
 #define AUDIT_FEATURE_BITMAP_BACKLOG_WAIT_TIME 0x00000002
 #define AUDIT_FEATURE_BITMAP_EXECUTABLE_PATH   0x00000004
kernel/audit.c +2 -1
index 5a0216056524..592383dce090 100644
@@ -1295,6 +1295,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
                memset(&s, 0, sizeof(s));
                /* guard against past and future API changes */
                memcpy(&s, data, min_t(size_t, sizeof(s), data_len));
+               if (s.mask & ~AUDIT_STATUS_ALL)
+                       return -EINVAL;
                if (s.mask & AUDIT_STATUS_ENABLED) {
                        err = audit_set_enabled(s.enabled);
                        if (err < 0)
--
Quoted 1 line

2.53.0

--
paul-moore.com