Message ID | 20240829085025.3600021-1-chizhiling@163.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v2] eventfs: fix a null pointer access in eventfs_iterate | expand |
On Thu, 29 Aug 2024 16:50:25 +0800 Chi Zhiling <chizhiling@163.com> wrote: > --- > fs/tracefs/event_inode.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c > index 01e99e98457d..18aae67704dc 100644 > --- a/fs/tracefs/event_inode.c > +++ b/fs/tracefs/event_inode.c > @@ -642,6 +642,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) > /* Subtract the skipped entries above */ > c -= min((unsigned int)c, (unsigned int)ei->nr_entries); > > + mutex_lock(&eventfs_mutex); > + if (ei->is_freed) { > + mutex_unlock(&eventfs_mutex); > + goto out; > + } > + > list_for_each_entry_srcu(ei_child, &ei->children, list, > srcu_read_lock_held(&eventfs_srcu)) { > > @@ -659,9 +665,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) > > ino = eventfs_dir_ino(ei_child); > > - if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) > + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) { > + mutex_unlock(&eventfs_mutex); > goto out_dec; > + } > } > + mutex_unlock(&eventfs_mutex); > ret = 1; > out: > srcu_read_unlock(&eventfs_srcu, idx); > -- Nope, still not correct. See my reply to v1. Thanks! -- Steve
diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 01e99e98457d..18aae67704dc 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -642,6 +642,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) /* Subtract the skipped entries above */ c -= min((unsigned int)c, (unsigned int)ei->nr_entries); + mutex_lock(&eventfs_mutex); + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out; + } + list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { @@ -659,9 +665,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ino = eventfs_dir_ino(ei_child); - if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) { + mutex_unlock(&eventfs_mutex); goto out_dec; + } } + mutex_unlock(&eventfs_mutex); ret = 1; out: srcu_read_unlock(&eventfs_srcu, idx);