[PATCH v3 2/4] gfs2: protect statfs sync sysfs callback
From: Jiacheng Xu
Date: Sun Sep 20 2026 - 04:32:18 EST
The statfs_sync sysfs file remains accessible while gfs2_put_super()
releases sd_statfs_inode during unmount. A concurrent write can then
enter gfs2_statfs_sync() and dereference the released inode.
Serialize the sysfs callback with the superblock lifetime. Use a
non-blocking read lock so mount failure and unmount paths can remove
the sysfs files while holding s_umount for writing, and reject access
before the superblock becomes active.
Signed-off-by: Jiacheng Xu <stitch@xxxxxxxxxx>
---
fs/gfs2/sys.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 0d247299625c..fd6e8e34651d 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -229,6 +229,7 @@ static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf,
size_t len)
{
+ struct super_block *sb = sdp->sd_vfs;
int error, val;
if (!capable(CAP_SYS_ADMIN))
@@ -241,7 +242,12 @@ static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf,
if (val != 1)
return -EINVAL;
- gfs2_statfs_sync(sdp->sd_vfs, 0);
+ if (!super_trylock_shared_active(sb))
+ return -EAGAIN;
+
+ gfs2_statfs_sync(sb, 0);
+
+ super_unlock_active(sb);
return len;
}
--
2.51.0