* [PATCH] fsnotify: fix UAF from FS_ERROR event on a shutting down filesystem
@ 2024-04-16 18:14 Amir Goldstein
2024-04-17 10:05 ` Jan Kara
2024-04-17 11:35 ` Christian Brauner
0 siblings, 2 replies; 3+ messages in thread
From: Amir Goldstein @ 2024-04-16 18:14 UTC (permalink / raw)
To: Jan Kara; +Cc: Hillf Danton, Christian Brauner, linux-fsdevel
Protect against use after free when filesystem calls fsnotify_sb_error()
during fs shutdown.
Move freeing of sb->s_fsnotify_info to destroy_super_work(), because it
may be accessed from fs shutdown context.
Reported-by: syzbot+5e3f9b2a67b45f16d4e6@syzkaller.appspotmail.com
Suggested-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/linux-fsdevel/20240416173211.4lnmgctyo4jn5fha@quack3/
Fixes: 07a3b8d0bf72 ("fsnotify: lazy attach fsnotify_sb_info state to sb")
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/notify/fsnotify.c | 6 +++++-
fs/super.c | 1 +
include/linux/fsnotify_backend.h | 4 ++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 2ae965ef37e8..ff69ae24c4e8 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -103,7 +103,11 @@ void fsnotify_sb_delete(struct super_block *sb)
WARN_ON(fsnotify_sb_has_priority_watchers(sb, FSNOTIFY_PRIO_CONTENT));
WARN_ON(fsnotify_sb_has_priority_watchers(sb,
FSNOTIFY_PRIO_PRE_CONTENT));
- kfree(sbinfo);
+}
+
+void fsnotify_sb_free(struct super_block *sb)
+{
+ kfree(sb->s_fsnotify_info);
}
/*
diff --git a/fs/super.c b/fs/super.c
index 69ce6c600968..b72f1d288e95 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -274,6 +274,7 @@ static void destroy_super_work(struct work_struct *work)
{
struct super_block *s = container_of(work, struct super_block,
destroy_work);
+ fsnotify_sb_free(s);
security_sb_free(s);
put_user_ns(s->s_user_ns);
kfree(s->s_subtype);
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 7f1ab8264e41..4dd6143db271 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -576,6 +576,7 @@ extern int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data
extern void __fsnotify_inode_delete(struct inode *inode);
extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
extern void fsnotify_sb_delete(struct super_block *sb);
+extern void fsnotify_sb_free(struct super_block *sb);
extern u32 fsnotify_get_cookie(void);
static inline __u32 fsnotify_parent_needed_mask(__u32 mask)
@@ -880,6 +881,9 @@ static inline void __fsnotify_vfsmount_delete(struct vfsmount *mnt)
static inline void fsnotify_sb_delete(struct super_block *sb)
{}
+static inline void fsnotify_sb_free(struct super_block *sb)
+{}
+
static inline void fsnotify_update_flags(struct dentry *dentry)
{}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fsnotify: fix UAF from FS_ERROR event on a shutting down filesystem
2024-04-16 18:14 [PATCH] fsnotify: fix UAF from FS_ERROR event on a shutting down filesystem Amir Goldstein
@ 2024-04-17 10:05 ` Jan Kara
2024-04-17 11:35 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2024-04-17 10:05 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Jan Kara, Hillf Danton, Christian Brauner, linux-fsdevel
On Tue 16-04-24 21:14:52, Amir Goldstein wrote:
> Protect against use after free when filesystem calls fsnotify_sb_error()
> during fs shutdown.
>
> Move freeing of sb->s_fsnotify_info to destroy_super_work(), because it
> may be accessed from fs shutdown context.
>
> Reported-by: syzbot+5e3f9b2a67b45f16d4e6@syzkaller.appspotmail.com
> Suggested-by: Jan Kara <jack@suse.cz>
> Link: https://lore.kernel.org/linux-fsdevel/20240416173211.4lnmgctyo4jn5fha@quack3/
> Fixes: 07a3b8d0bf72 ("fsnotify: lazy attach fsnotify_sb_info state to sb")
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Thanks! Added to my tree.
Honza
> ---
> fs/notify/fsnotify.c | 6 +++++-
> fs/super.c | 1 +
> include/linux/fsnotify_backend.h | 4 ++++
> 3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
> index 2ae965ef37e8..ff69ae24c4e8 100644
> --- a/fs/notify/fsnotify.c
> +++ b/fs/notify/fsnotify.c
> @@ -103,7 +103,11 @@ void fsnotify_sb_delete(struct super_block *sb)
> WARN_ON(fsnotify_sb_has_priority_watchers(sb, FSNOTIFY_PRIO_CONTENT));
> WARN_ON(fsnotify_sb_has_priority_watchers(sb,
> FSNOTIFY_PRIO_PRE_CONTENT));
> - kfree(sbinfo);
> +}
> +
> +void fsnotify_sb_free(struct super_block *sb)
> +{
> + kfree(sb->s_fsnotify_info);
> }
>
> /*
> diff --git a/fs/super.c b/fs/super.c
> index 69ce6c600968..b72f1d288e95 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -274,6 +274,7 @@ static void destroy_super_work(struct work_struct *work)
> {
> struct super_block *s = container_of(work, struct super_block,
> destroy_work);
> + fsnotify_sb_free(s);
> security_sb_free(s);
> put_user_ns(s->s_user_ns);
> kfree(s->s_subtype);
> diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
> index 7f1ab8264e41..4dd6143db271 100644
> --- a/include/linux/fsnotify_backend.h
> +++ b/include/linux/fsnotify_backend.h
> @@ -576,6 +576,7 @@ extern int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data
> extern void __fsnotify_inode_delete(struct inode *inode);
> extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
> extern void fsnotify_sb_delete(struct super_block *sb);
> +extern void fsnotify_sb_free(struct super_block *sb);
> extern u32 fsnotify_get_cookie(void);
>
> static inline __u32 fsnotify_parent_needed_mask(__u32 mask)
> @@ -880,6 +881,9 @@ static inline void __fsnotify_vfsmount_delete(struct vfsmount *mnt)
> static inline void fsnotify_sb_delete(struct super_block *sb)
> {}
>
> +static inline void fsnotify_sb_free(struct super_block *sb)
> +{}
> +
> static inline void fsnotify_update_flags(struct dentry *dentry)
> {}
>
> --
> 2.34.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fsnotify: fix UAF from FS_ERROR event on a shutting down filesystem
2024-04-16 18:14 [PATCH] fsnotify: fix UAF from FS_ERROR event on a shutting down filesystem Amir Goldstein
2024-04-17 10:05 ` Jan Kara
@ 2024-04-17 11:35 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2024-04-17 11:35 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Jan Kara, Hillf Danton, linux-fsdevel
On Tue, Apr 16, 2024 at 09:14:52PM +0300, Amir Goldstein wrote:
> Protect against use after free when filesystem calls fsnotify_sb_error()
> during fs shutdown.
>
> Move freeing of sb->s_fsnotify_info to destroy_super_work(), because it
> may be accessed from fs shutdown context.
>
> Reported-by: syzbot+5e3f9b2a67b45f16d4e6@syzkaller.appspotmail.com
> Suggested-by: Jan Kara <jack@suse.cz>
> Link: https://lore.kernel.org/linux-fsdevel/20240416173211.4lnmgctyo4jn5fha@quack3/
> Fixes: 07a3b8d0bf72 ("fsnotify: lazy attach fsnotify_sb_info state to sb")
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
Reviewed-by: Christian Brauner <brauner@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-17 11:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-16 18:14 [PATCH] fsnotify: fix UAF from FS_ERROR event on a shutting down filesystem Amir Goldstein
2024-04-17 10:05 ` Jan Kara
2024-04-17 11:35 ` Christian Brauner
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.