audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts
cover audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts
After porting my wayland compositor to io_uring, I noticed that my logs were getting spammed with the following messages (tested with 5.17.7 and 5.18.0-rc7):
WARNING: CPU: 10 PID: 983 at kernel/auditsc.c:2041 __audit_syscall_entry+0x1>
Modules linked in: vrf wireguard curve25519_x86_64 libchacha20poly1305 chach>
ipmi_msghandler crypto_user ip_tables x_tables ext4 crc32c_generic crc16 mb>
CPU: 10 PID: 983 Comm: jay Tainted: G W 5.18.0-rc7-dirty #5 1>
Hardware name: Gigabyte Technology Co., Ltd. B450M DS3H/B450M DS3H-CF, BIOS >
RIP: 0010:__audit_syscall_entry+0x111/0x140
Code: e8 24 69 ff ff 48 8b 34 24 48 8b 54 24 08 85 c0 48 8b 4c 24 10 4c 8b 4>
RSP: 0018:ffffa6e480887de8 EFLAGS: 00010202
RAX: 0000000000000000 RBX: ffff969c92f22400 RCX: 0000000000000001
RDX: 0000000000000001 RSI: 0000000000000007 RDI: ffff969c8fa4c080
RBP: 00000000000001aa R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000002 R11: 0000000000000001 R12: 00000000000001aa
R13: ffffa6e480887f58 R14: 00000000000001aa R15: 0000000000000000
FS: 00007fefe020f040(0000) GS:ffff96a39ea80000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fefac429000 CR3: 0000000103674000 CR4: 00000000003506e0
Call Trace:
<TASK>
? get_signal+0x8d/0x990
syscall_trace_enter.constprop.0+0x121/0x1a0
do_syscall_64+0x36/0x80
? arch_do_signal_or_restart+0x44/0x750
? syscall_exit_to_user_mode+0x22/0x40
? exit_to_user_mode_prepare+0xd3/0x140
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7fefe0d0b67d
Code: 5d c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 4>
RSP: 002b:00007fff383a6c58 EFLAGS: 00000246 ORIG_RAX: 00000000000001aa
RAX: ffffffffffffffda RBX: 00005595f1c25e00 RCX: 00007fefe0d0b67d
RDX: 0000000000000001 RSI: 0000000000000001 RDI: 0000000000000007
RBP: 00005595f1c1b700 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000246 R12: 0000000000000001
R13: 0000000000000005 R14: 00005595f1c21f60 R15: 0000000000000001
</TASK>
---[ end trace 0000000000000000 ]---
audit: unrecoverable error in audit_syscall_entry()I traced this to the context not being reset after audit_uring_entry if the created context was a dummy context. I am surprised that I would be the first one to find this problem but maybe io_uring is rarely used on systems where auditing is enabled or a recent kernel change elsewhere caused this problem to surface.
Julian Orth (1):
audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts
include/linux/audit.h | 2 +- kernel/auditsc.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.36.1
PATCH 1/1 audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts
Not calling the function for dummy contexts will cause the context to not be reset. During the next syscall, this will cause an error in __audit_syscall_entry:
WARN_ON(context->context != AUDIT_CTX_UNUSED);
WARN_ON(context->name_count);
if (context->context != AUDIT_CTX_UNUSED || context->name_count) {
audit_panic("unrecoverable error in audit_syscall_entry()");
return;
}These problematic dummy contexts are created via the following call chain:
exit_to_user_mode_prepare
-> arch_do_signal_or_restart
-> get_signal
-> task_work_run
-> tctx_task_work
-> io_req_task_submit
-> io_issue_sqe
-> audit_uring_entry--- include/linux/audit.h | 2 +- kernel/auditsc.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/audit.h +1 -1
@@ -339,7 +339,7 @@ static inline void audit_uring_entry(u8 op) }static inline void audit_uring_exit (int success,long code) { -if (unlikely (!audit_dummy_context ())) +if (unlikely (audit_context ()))__audit_uring_exit (success, code); } static inline void audit_syscall_entry(int major, unsigned long a0,
kernel/auditsc.c +6 -0
@@ -1959,6 +1959,12 @@ void __audit_uring_exit(int success, long code) {struct audit_context *ctx =audit_context (); +if (ctx->dummy) { +if (ctx->context !=AUDIT_CTX_URING ) +return ; + goto out; + } +if (ctx->context ==AUDIT_CTX_SYSCALL ) {/* * NOTE: See the note in __audit_uring_entry() about the case
Signature · 1 line
2.36.1
Paul Moore
maintainerQuoted 24 lines · Julian Orth
Not calling the function for dummy contexts will cause the context to not be reset. During the next syscall, this will cause an error in
__audit_syscall_entry:WARN_ON(context->context != AUDIT_CTX_UNUSED); WARN_ON(context->name_count); if (context->context != AUDIT_CTX_UNUSED || context->name_count) { audit_panic("unrecoverable error in audit_syscall_entry()"); return; }These problematic dummy contexts are created via the following call chain:
exit_to_user_mode_prepare -> arch_do_signal_or_restart -> get_signal -> task_work_run -> tctx_task_work -> io_req_task_submit -> io_issue_sqe -> audit_uring_entry
Quoted 6 lines
Fixes 5bd2182d58e9 ("audit,io_uring,io-wq: add some basic audit support to io_uring")Signed-off-by Julian Orth <[email protected]>--- include/linux/audit.h | 2 +- kernel/auditsc.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
Hi Julian,
Thanks for the report and the patch too! I agree that it does seem a little odd that we haven't seen this before, let me dig into this a bit more today and respond back.
Signature · 6 lines
paul-moore.com -- Linux-audit mailing list [email protected] https://listman.redhat.com/mailman/listinfo/linux-audit
Paul Moore
maintainerQuoted 32 lines · Paul Moore
Quoted 24 lines · Julian Orth
Not calling the function for dummy contexts will cause the context to not be reset. During the next syscall, this will cause an error in
__audit_syscall_entry:WARN_ON(context->context != AUDIT_CTX_UNUSED); WARN_ON(context->name_count); if (context->context != AUDIT_CTX_UNUSED || context->name_count) { audit_panic("unrecoverable error in audit_syscall_entry()"); return; }These problematic dummy contexts are created via the following call chain:
exit_to_user_mode_prepare -> arch_do_signal_or_restart -> get_signal -> task_work_run -> tctx_task_work -> io_req_task_submit -> io_issue_sqe -> audit_uring_entryQuoted 6 lines
Fixes 5bd2182d58e9 ("audit,io_uring,io-wq: add some basic audit support to io_uring")Signed-off-by Julian Orth <[email protected]>--- include/linux/audit.h | 2 +- kernel/auditsc.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
Quoted 5 lines
Hi Julian,
Thanks for the report and the patch too! I agree that it does seem a little odd that we haven't seen this before, let me dig into this a bit more today and respond back.
The patch looks good to me, thanks again. I just merged this into the audit/stable-5.18 branch and added a stable tag; assuming the test runs go okay I'll send this up to Linus tomorrow.
Signature · 1 line
paul-moore.com