[PATCH v2 01/13] audit: log all six syscall arguments in the SYSCALL record
Ricardo Robaina
rrobaina at redhat.com
Wed Sep 2 07:43:34 PDT 2026
The SYSCALL record currently logs only four of the six syscall
arguments (a0-a3). The remaining two are captured but silently
discarded before reaching the audit context. This leads to the
need for auxiliary records when audit-relevant data lands in the
5th or 6th argument of a syscall.
Extend the SYSCALL record to log all six arguments, by adding
arguments a4 and a5 (5th and 6th syscall arguments respectively)
inline within the existing record. Also add the two new args to
the audit rules switch case, so audit rules can filter on them.
Rather than plumbing two more register arguments through every
architecture's syscall entry path, change __audit_syscall_entry()
to take a pointer to pt_regs and use syscall_get_arguments() to
retrieve all six arguments.
audit-testsuite# make test
audit-testsuite# ausearch -i -m SYSCALL
...
type=SYSCALL ... syscall=sendto success=yes exit=1088 a0=0x4
a1=0x7ffe43518b60 a2=0x440 a3=0x0 a4=7ffe43518b4c a5=c
type=SYSCALL ... syscall=openat2 success=yes exit=4 a0=0x3
a1=0x7fffc74692c8 a2=0x7fffc7467390 a3=0x18 a4=0 a5=7fffc74674f8
type=SYSCALL ... syscall=openat success=yes exit=3 a0=AT_FDCWD
a1=0x557ced4141a2 a2=O_RDWR|O_NONBLOCK a3=0x0 a4=0 a5=0
...
Suggested-by: Will Deacon <will at kernel.org>
Link: https://lore.kernel.org/audit/CAHC9VhSjEt_-Bsra4AEqWv+Daw5Ff=gqy7dX4Ah11RVhdyCBUQ@mail.gmail.com/T/#t
Signed-off-by: Ricardo Robaina <rrobaina at redhat.com>
---
include/linux/audit.h | 13 ++++---------
include/uapi/linux/audit.h | 2 ++
kernel/audit.h | 2 +-
kernel/auditfilter.c | 2 ++
kernel/auditsc.c | 19 ++++++++-----------
kernel/entry/syscall-common.c | 4 +---
6 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/include/linux/audit.h b/include/linux/audit.h
index 45abb3722d30..9ce5962bc537 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -323,8 +323,7 @@ extern int audit_alloc(struct task_struct *task);
extern void __audit_free(struct task_struct *task);
extern void __audit_uring_entry(u8 op);
extern void __audit_uring_exit(int success, long code);
-extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1,
- unsigned long a2, unsigned long a3);
+extern void __audit_syscall_entry(int major, struct pt_regs *regs);
extern void __audit_syscall_exit(int ret_success, long ret_value);
extern void __audit_getname(struct filename *name);
extern void __audit_inode(struct filename *name, const struct dentry *dentry,
@@ -373,12 +372,10 @@ static inline void audit_uring_exit(int success, long code)
if (unlikely(audit_context()))
__audit_uring_exit(success, code);
}
-static inline void audit_syscall_entry(int major, unsigned long a0,
- unsigned long a1, unsigned long a2,
- unsigned long a3)
+static inline void audit_syscall_entry(int major, struct pt_regs *regs)
{
if (unlikely(audit_context()))
- __audit_syscall_entry(major, a0, a1, a2, a3);
+ __audit_syscall_entry(major, regs);
}
static inline void audit_syscall_exit(void *pt_regs)
{
@@ -611,9 +608,7 @@ static inline void audit_uring_entry(u8 op)
{ }
static inline void audit_uring_exit(int success, long code)
{ }
-static inline void audit_syscall_entry(int major, unsigned long a0,
- unsigned long a1, unsigned long a2,
- unsigned long a3)
+static inline void audit_syscall_entry(int major, struct pt_regs *regs)
{ }
static inline void audit_syscall_exit(void *pt_regs)
{ }
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index e8f5ce677df7..6726059d6df1 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -303,6 +303,8 @@
#define AUDIT_ARG1 (AUDIT_ARG0+1)
#define AUDIT_ARG2 (AUDIT_ARG0+2)
#define AUDIT_ARG3 (AUDIT_ARG0+3)
+#define AUDIT_ARG4 (AUDIT_ARG0+4)
+#define AUDIT_ARG5 (AUDIT_ARG0+5)
#define AUDIT_FILTERKEY 210
diff --git a/kernel/audit.h b/kernel/audit.h
index 92d5e723d570..83011b14af18 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -117,7 +117,7 @@ struct audit_context {
struct audit_stamp stamp; /* event identifier */
int major; /* syscall number */
int uring_op; /* uring operation */
- unsigned long argv[4]; /* syscall arguments */
+ unsigned long argv[6]; /* syscall arguments */
long return_code;/* syscall return code */
u64 prio;
int return_valid; /* return code is valid */
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index f52645625214..cded3696e3c5 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -358,6 +358,8 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
case AUDIT_ARG1:
case AUDIT_ARG2:
case AUDIT_ARG3:
+ case AUDIT_ARG4:
+ case AUDIT_ARG5:
case AUDIT_PERS: /* <uapi/linux/personality.h> */
case AUDIT_DEVMINOR:
/* all ops are valid */
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 2b9ce0b52511..cf45c782b03d 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -728,6 +728,8 @@ static int audit_filter_rules(struct task_struct *tsk,
case AUDIT_ARG1:
case AUDIT_ARG2:
case AUDIT_ARG3:
+ case AUDIT_ARG4:
+ case AUDIT_ARG5:
if (ctx)
result = audit_comparator(ctx->argv[f->type-AUDIT_ARG0], f->op, f->val);
break;
@@ -1674,11 +1676,13 @@ static void audit_log_exit(void)
AUDITSC_SUCCESS),
context->return_code);
audit_log_format(ab,
- " a0=%lx a1=%lx a2=%lx a3=%lx items=%d",
+ " a0=%lx a1=%lx a2=%lx a3=%lx a4=%lx a5=%lx items=%d",
context->argv[0],
context->argv[1],
context->argv[2],
context->argv[3],
+ context->argv[4],
+ context->argv[5],
context->name_count);
audit_log_task_info(ab);
audit_log_key(ab, context->filterkey);
@@ -1970,10 +1974,7 @@ void __audit_uring_exit(int success, long code)
/**
* __audit_syscall_entry - fill in an audit record at syscall entry
* @major: major syscall type (function)
- * @a1: additional syscall register 1
- * @a2: additional syscall register 2
- * @a3: additional syscall register 3
- * @a4: additional syscall register 4
+ * @regs: the task's register state at syscall entry
*
* Fill in audit context at syscall entry. This only happens if the
* audit context was created when the task was created and the state or
@@ -1983,8 +1984,7 @@ void __audit_uring_exit(int success, long code)
* will only be written if another part of the kernel requests that it
* be written).
*/
-void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2,
- unsigned long a3, unsigned long a4)
+void __audit_syscall_entry(int major, struct pt_regs *regs)
{
struct audit_context *context = audit_context();
enum audit_state state;
@@ -2012,10 +2012,7 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2,
context->arch = syscall_get_arch(current);
context->major = major;
- context->argv[0] = a1;
- context->argv[1] = a2;
- context->argv[2] = a3;
- context->argv[3] = a4;
+ syscall_get_arguments(current, regs, context->argv);
context->context = AUDIT_CTX_SYSCALL;
context->current_state = state;
ktime_get_coarse_real_ts64(&context->stamp.ctime);
diff --git a/kernel/entry/syscall-common.c b/kernel/entry/syscall-common.c
index b8eac9efb6fd..471db2a8e09d 100644
--- a/kernel/entry/syscall-common.c
+++ b/kernel/entry/syscall-common.c
@@ -22,9 +22,7 @@ void trace_syscall_exit(struct pt_regs *regs, long ret)
void syscall_enter_audit(struct pt_regs *regs)
{
long syscall = syscall_get_nr(current, regs);
- unsigned long args[6];
- syscall_get_arguments(current, regs, args);
- __audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]);
+ __audit_syscall_entry(syscall, regs);
}
#endif
--
2.55.0
More information about the linux-arm-kernel
mailing list