diff mbox series

eventfs: Test for dentries array allocated in eventfs_release()

Message ID 20230930090106.1c3164e9@rorschach.local.home (mailing list archive)
State Accepted
Commit 2598bd3ca8dcf5bbca1161ee5b271b432398da37
Headers show
Series eventfs: Test for dentries array allocated in eventfs_release() | expand

Commit Message

Steven Rostedt Sept. 30, 2023, 1:01 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The dcache_dir_open_wrapper() could be called when a dynamic event is
being deleted leaving a dentry with no children. In this case the
dlist->dentries array will never be allocated. This needs to be checked
for in eventfs_release(), otherwise it will trigger a NULL pointer
dereference.

Fixes: ef36b4f92868 ("eventfs: Remember what dentries were created on dir open")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 fs/tracefs/event_inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Masami Hiramatsu (Google) Sept. 30, 2023, 3:12 p.m. UTC | #1
On Sat, 30 Sep 2023 09:01:06 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> The dcache_dir_open_wrapper() could be called when a dynamic event is
> being deleted leaving a dentry with no children. In this case the
> dlist->dentries array will never be allocated. This needs to be checked
> for in eventfs_release(), otherwise it will trigger a NULL pointer
> dereference.

Looks good to me.

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

Thank you,

> 
> Fixes: ef36b4f92868 ("eventfs: Remember what dentries were created on dir open")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  fs/tracefs/event_inode.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
> index 5f1714089884..8c8d64e76103 100644
> --- a/fs/tracefs/event_inode.c
> +++ b/fs/tracefs/event_inode.c
> @@ -421,7 +421,7 @@ static int eventfs_release(struct inode *inode, struct file *file)
>  	if (WARN_ON_ONCE(!dlist))
>  		return -EINVAL;
>  
> -	for (i = 0; dlist->dentries[i]; i++) {
> +	for (i = 0; dlist->dentries && dlist->dentries[i]; i++) {
>  		dput(dlist->dentries[i]);
>  	}
>  
> -- 
> 2.40.1
>
diff mbox series

Patch

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 5f1714089884..8c8d64e76103 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -421,7 +421,7 @@  static int eventfs_release(struct inode *inode, struct file *file)
 	if (WARN_ON_ONCE(!dlist))
 		return -EINVAL;
 
-	for (i = 0; dlist->dentries[i]; i++) {
+	for (i = 0; dlist->dentries && dlist->dentries[i]; i++) {
 		dput(dlist->dentries[i]);
 	}