The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] eventfs: Fix use-after-free in eventfs_remove_rec()
Date: Sat, 8 Aug 2026 07:13:11 +0900	[thread overview]
Message-ID: <20260808071311.c069dd27dc49e5cb68eed731@kernel.org> (raw)
In-Reply-To: <20260806022719.375354-1-shuangpeng.kernel@gmail.com>

On Wed,  5 Aug 2026 22:27:19 -0400
Shuangpeng Bai <shuangpeng.kernel@gmail.com> wrote:

> eventfs_remove_rec() recursively removes the child at the current loop
> position. After the recursive call returns, list_for_each_entry() advances
> by reading list.next from the removed child.
> 
> If free_ei() drops the final reference, release_ei() reuses the list/rcu
> union to queue an SRCU callback. The child may be freed before that read.
> The eventfs_mutex serializes list updates, but it does not keep the removed
> child alive or prevent the SRCU callback from running.
> 
> Use list_for_each_entry_safe() to save the next sibling before recursively
> removing the current child.
> 

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> Fixes: 43aa6f97c2d0 ("eventfs: Get rid of dentry pointers without refcounts")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
> ---
>  fs/tracefs/event_inode.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
> index 39c7a34531e8..93bc4f83b73e 100644
> --- a/fs/tracefs/event_inode.c
> +++ b/fs/tracefs/event_inode.c
> @@ -822,7 +822,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry
>   */
>  static void eventfs_remove_rec(struct eventfs_inode *ei, int level)
>  {
> -	struct eventfs_inode *ei_child;
> +	struct eventfs_inode *ei_child, *tmp;
>  
>  	/*
>  	 * Check recursion depth. It should never be greater than 3:
> @@ -835,7 +835,7 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level)
>  		return;
>  
>  	/* search for nested folders or files */
> -	list_for_each_entry(ei_child, &ei->children, list)
> +	list_for_each_entry_safe(ei_child, tmp, &ei->children, list)
>  		eventfs_remove_rec(ei_child, level + 1);
>  
>  	list_del_rcu(&ei->list);
> -- 
> 2.43.0
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

      reply	other threads:[~2026-08-07 22:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06  2:27 [PATCH] eventfs: Fix use-after-free in eventfs_remove_rec() Shuangpeng Bai
2026-08-07 22:13 ` Masami Hiramatsu [this message]

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=20260808071311.c069dd27dc49e5cb68eed731@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=rostedt@goodmis.org \
    --cc=shuangpeng.kernel@gmail.com \
    --cc=stable@vger.kernel.org \
    /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