From: Steven Rostedt <rostedt@goodmis.org>
To: Mathias Krause <minipli@grsecurity.net>
Cc: "Ajay Kaher" <ajay.kaher@broadcom.com>,
"Masami Hiramatsu" <mhiramat@kernel.org>,
"Ilkka Naulapää" <digirigawa@gmail.com>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
"Al Viro" <viro@zeniv.linux.org.uk>,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
regressions@leemhuis.info,
"Dan Carpenter" <dan.carpenter@linaro.org>,
"Vasavi Sirnapalli" <vasavi.sirnapalli@broadcom.com>,
"Alexey Makhalov" <alexey.makhalov@broadcom.com>,
"Florian Fainelli" <florian.fainelli@broadcom.com>,
"Beau Belgrave" <beaub@linux.microsoft.com>
Subject: Re: tracing: user events UAF crash report
Date: Thu, 25 Jul 2024 16:15:19 -0400 [thread overview]
Message-ID: <20240725161519.35fd3bd6@gandalf.local.home> (raw)
In-Reply-To: <0d1a8c46-43a7-42d6-bcbf-647a5a68c3c5@grsecurity.net>
On Thu, 25 Jul 2024 21:42:41 +0200
Mathias Krause <minipli@grsecurity.net> wrote:
> Right. But the point is, that 'event_call' is really some '&user->call'.
> With 'user' being free'd memory, what gives? Dereferencing 'event_call'
> is UB, so this function is doomed to fail because it cannot know if its
> only argument points to still valid memory or not. And that's the core
> issue -- calling that function for an object that's long gone -- the
> missing refcounting I hinted at in my first Email.
Ah, I missed that the call was part of the user structure. But I think I
found the real fix.
>
> >
> > Where it calls the ->class->get_fields(event_call);
> >
> > that calls this function. By setting:
> >
> > user->call.get_fields = NULL;
> >
> > this will never get called and no random data will be accessed.
>
> As 'user' is free'd or soon-to-be-free'd memory, that's a non-starter.
>
> >
> > That said, I was talking with Beau, we concluded that this shouldn't be the
> > responsibility of the user of event call, and should be cleaned up by the
> > event system.
> >
> > Here's the proper fix:
> >
> > diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> > index 6ef29eba90ce..3a2d2ff1625b 100644
> > --- a/kernel/trace/trace_events.c
> > +++ b/kernel/trace/trace_events.c
> > @@ -3140,8 +3140,10 @@ EXPORT_SYMBOL_GPL(trace_add_event_call);
> > */
> > static void __trace_remove_event_call(struct trace_event_call *call)
> > {
> > + lockdep_assert_held(&event_mutex);
> > event_remove(call);
> > trace_destroy_fields(call);
> > + call->get_fields = NULL;
Actually, this is wrong as it would be: call->class->get_fields, and this
is not the right place to clear it, as class can be used by multiple calls.
> > free_event_filter(call->filter);
> > call->filter = NULL;
> > }
> >
> > Can you try it out?
>
> I can try but I don't think that's the proper fix for above reasons, I'm
> sorry.
I believe the issue is that f_start() needs to check if the event file has
been freed.
New patch:
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 6ef29eba90ce..5fbfa1c885de 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1627,12 +1627,14 @@ static int f_show(struct seq_file *m, void *v)
static void *f_start(struct seq_file *m, loff_t *pos)
{
+ struct trace_event_file *file;
void *p = (void *)FORMAT_HEADER;
loff_t l = 0;
/* ->stop() is called even if ->start() fails */
mutex_lock(&event_mutex);
- if (!event_file_data(m->private))
+ file = event_file_data(m->private);
+ if (!file || (file->flags & EVENT_FILE_FL_FREED))
return ERR_PTR(-ENODEV);
while (l < *pos && p)
-- Steve
next prev parent reply other threads:[~2024-07-25 20:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-19 20:47 tracing: user events UAF crash report Mathias Krause
2024-07-20 3:33 ` Dan Carpenter
2024-07-22 11:13 ` Ajay Kaher
2024-07-22 12:08 ` Mathias Krause
2024-07-25 13:33 ` Ajay Kaher
2024-07-25 16:15 ` Ajay Kaher
2024-07-25 16:30 ` Ajay Kaher
2024-07-25 17:10 ` Steven Rostedt
2024-07-25 17:16 ` Steven Rostedt
2024-07-25 18:12 ` Mathias Krause
2024-07-25 19:05 ` Steven Rostedt
2024-07-25 19:42 ` Mathias Krause
2024-07-25 20:15 ` Steven Rostedt [this message]
2024-07-25 20:41 ` Mathias Krause
2024-07-25 21:14 ` Steven Rostedt
2024-07-25 21:32 ` Mathias Krause
2024-07-25 23:06 ` Steven Rostedt
2024-07-26 8:25 ` Mathias Krause
2024-07-25 19:53 ` Mathias Krause
2024-07-25 16:48 ` Steven Rostedt
2024-07-23 0:11 ` Steven Rostedt
2024-07-23 12:25 ` [PATCH] eventfs: Don't return NULL in eventfs_create_dir() Mathias Krause
2024-07-23 14:43 ` tracing: user events UAF crash report Steven Rostedt
2024-07-23 20:54 ` Mathias Krause
2024-07-23 21:07 ` [PATCH] eventfs: Use SRCU for freeing eventfs_inodes Mathias Krause
2024-07-23 21:23 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240725161519.35fd3bd6@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=ajay.kaher@broadcom.com \
--cc=alexey.makhalov@broadcom.com \
--cc=beaub@linux.microsoft.com \
--cc=dan.carpenter@linaro.org \
--cc=digirigawa@gmail.com \
--cc=florian.fainelli@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=minipli@grsecurity.net \
--cc=regressions@leemhuis.info \
--cc=torvalds@linux-foundation.org \
--cc=vasavi.sirnapalli@broadcom.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.