mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mathias Krause <minipli@grsecurity.net>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: "Masami Hiramatsu" <mhiramat@kernel.org>,
	"Ajay Kaher" <ajay.kaher@broadcom.com>,
	"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>
Subject: Re: tracing: user events UAF crash report
Date: Tue, 23 Jul 2024 22:54:49 +0200	[thread overview]
Message-ID: <10dd9e0f-fb2d-4667-8fba-171040690055@grsecurity.net> (raw)
In-Reply-To: <20240723104348.645bf027@gandalf.local.home>

On 23.07.24 16:43, Steven Rostedt wrote:
> On Fri, 19 Jul 2024 22:47:01 +0200
> Mathias Krause <minipli@grsecurity.net> wrote:
> 
>> Beside the obvious bug, I noticed the following (not fixing the issue,
>> tho):
>>
>> diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
>> index 5d88c184f0fc..687ad0a26458 100644
>> --- a/fs/tracefs/event_inode.c
>> +++ b/fs/tracefs/event_inode.c
>> @@ -112,7 +112,7 @@ static void release_ei(struct kref *ref)
>>  			entry->release(entry->name, ei->data);
>>  	}
>>  
>> -	call_rcu(&ei->rcu, free_ei_rcu);
>> +	call_srcu(&eventfs_srcu, &ei->rcu, free_ei_rcu);
>>  }
> 
> This should be fixed too. Care to send a patch for this as well?

Sure, will do.

> 
> It use to need RCU but then everything was switched over to SRCU. This was
> just leftover.

SRCU usage came up with commit 63940449555e ("eventfs: Implement eventfs
lookup, read, open functions") and following, was further extended just
to get almost completely nuked by [1] earlier this year.

[1]
https://lore.kernel.org/linux-trace-kernel/20240131184918.945345370@goodmis.org/

> 
>>  
>>  static inline void put_ei(struct eventfs_inode *ei)
>> @@ -735,7 +735,9 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode
>>  
>>  	/* Was the parent freed? */
>>  	if (list_empty(&ei->list)) {
>> +		mutex_lock(&eventfs_mutex);
>>  		cleanup_ei(ei);
>> +		mutex_unlock(&eventfs_mutex);
> 
> Why do you think this is needed? The ei is not on the list and has not been
> made visible. It was just allocated but the parent it was going to be
> attached to is about to be freed.

I have no strong understanding of the code, just reading into what the
context told me the rules should be, which would be on one hand the
following comment...:

/*
 * The eventfs_inode (ei) itself is protected by SRCU. It is released from
 * its parent's list and will have is_freed set (under eventfs_mutex).
 * After the SRCU grace period is over and the last dput() is called
 * the ei is freed.
 */

...and on the other the common pattern, mostly complying to the rule of
first taking the eventfs_mutex, then checking 'is_freed' for a given ei
-- supposedly implying, it can only be set under that very same mutex.

As cleanup_ei() is just a glorified free_ei() which sets ei->is_freed to
1, I was implying the lack of taking eventfs_mutex is a bug. But looking
further for the precondition, getting 'ei' unchained again after it was
put to the parent's children list, I can find eventfs_remove_rec() which
is only ever called under eventfs_mutex and does:

    list_del(&ei->list);
    free_ei(ei);

So you're right and I wasn't paying close enough attention and got
mislead by cleanup_ei() also setting ei->is_freed. But as it should
already be 1 at that point, no bug here.

Thanks,
Mathias

  reply	other threads:[~2024-07-23 20:54 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-19 20:47 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
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 [this message]
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=10dd9e0f-fb2d-4667-8fba-171040690055@grsecurity.net \
    --to=minipli@grsecurity.net \
    --cc=ajay.kaher@broadcom.com \
    --cc=dan.carpenter@linaro.org \
    --cc=digirigawa@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=regressions@leemhuis.info \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®