public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts
@ 2022-05-17 10:32 Julian Orth
  2022-05-17 10:32 ` [PATCH 1/1] " Julian Orth
  0 siblings, 1 reply; 4+ messages in thread
From: Julian Orth @ 2022-05-17 10:32 UTC (permalink / raw)
  To: Paul Moore, Eric Paris; +Cc: ju.orth, linux-audit, linux-kernel, Jens Axboe

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(-)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts
  2022-05-17 10:32 [PATCH 0/1] audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts Julian Orth
@ 2022-05-17 10:32 ` Julian Orth
  2022-05-17 13:12   ` Paul Moore
  0 siblings, 1 reply; 4+ messages in thread
From: Julian Orth @ 2022-05-17 10:32 UTC (permalink / raw)
  To: Paul Moore, Eric Paris; +Cc: ju.orth, linux-audit, linux-kernel, Jens Axboe

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

Fixes: 5bd2182d58e9 ("audit,io_uring,io-wq: add some basic audit support to io_uring")
Signed-off-by: Julian Orth <ju.orth@gmail.com>
---
 include/linux/audit.h | 2 +-
 kernel/auditsc.c      | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/audit.h b/include/linux/audit.h
index d06134ac6245..cece70231138 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -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,
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index ea2ee1181921..f3a2abd6d1a1 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -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
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts
  2022-05-17 10:32 ` [PATCH 1/1] " Julian Orth
@ 2022-05-17 13:12   ` Paul Moore
  2022-05-17 21:34     ` Paul Moore
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Moore @ 2022-05-17 13:12 UTC (permalink / raw)
  To: Julian Orth; +Cc: Eric Paris, linux-audit, linux-kernel, Jens Axboe

On Tue, May 17, 2022 at 6:33 AM Julian Orth <ju.orth@gmail.com> wrote:
>
> 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
>
> Fixes: 5bd2182d58e9 ("audit,io_uring,io-wq: add some basic audit support to io_uring")
> Signed-off-by: Julian Orth <ju.orth@gmail.com>
> ---
>  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.

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts
  2022-05-17 13:12   ` Paul Moore
@ 2022-05-17 21:34     ` Paul Moore
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Moore @ 2022-05-17 21:34 UTC (permalink / raw)
  To: Julian Orth; +Cc: Eric Paris, linux-audit, linux-kernel, Jens Axboe

On Tue, May 17, 2022 at 9:12 AM Paul Moore <paul@paul-moore.com> wrote:
> On Tue, May 17, 2022 at 6:33 AM Julian Orth <ju.orth@gmail.com> wrote:
> >
> > 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
> >
> > Fixes: 5bd2182d58e9 ("audit,io_uring,io-wq: add some basic audit support to io_uring")
> > Signed-off-by: Julian Orth <ju.orth@gmail.com>
> > ---
> >  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.

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.

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-17 21:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-17 10:32 [PATCH 0/1] audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts Julian Orth
2022-05-17 10:32 ` [PATCH 1/1] " Julian Orth
2022-05-17 13:12   ` Paul Moore
2022-05-17 21:34     ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox