[PATCH] gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole

From: William Chuang

Date: Mon Nov 16 2026 - 13:00:32 EST


When the filesystem has been withdrawn, gfs2_glock_nq() returns -EIO
without queuing the holder, and gfs2_glock_nq_init() then calls
gfs2_holder_uninit(), which sets gh.gh_gl to NULL.

gfs2_seek_data() and gfs2_seek_hole() call gfs2_glock_dq_uninit()
unconditionally, so in that case gfs2_glock_dq() dereferences a NULL
glock when it takes gl->gl_lockref.lock, causing a general protection
fault.

Only release the holder when it was successfully acquired, matching the
pattern already used elsewhere in this file (such as gfs2_fiemap() and
gfs2_getattr()).

Fixes: 3a27411cb4bc ("gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap")
Reported-by: syzbot+5a5f492ccae698fd7434@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=5a5f492ccae698fd7434
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: William Chuang <founder@xxxxxxxxxxxxxx>
---
fs/gfs2/inode.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 75fb1a0c91425..4110b2d0b549c 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -2255,7 +2255,8 @@ loff_t gfs2_seek_data(struct file *file, loff_t offset)
ret = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &gh);
if (!ret)
ret = iomap_seek_data(inode, offset, gfs2_iomap_next);
- gfs2_glock_dq_uninit(&gh);
+ if (gfs2_holder_initialized(&gh))
+ gfs2_glock_dq_uninit(&gh);
inode_unlock_shared(inode);

if (ret < 0)
@@ -2274,7 +2275,8 @@ loff_t gfs2_seek_hole(struct file *file, loff_t offset)
ret = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &gh);
if (!ret)
ret = iomap_seek_hole(inode, offset, gfs2_iomap_next);
- gfs2_glock_dq_uninit(&gh);
+ if (gfs2_holder_initialized(&gh))
+ gfs2_glock_dq_uninit(&gh);
inode_unlock_shared(inode);

if (ret < 0)
--
2.43.0