* [PATCH] gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole
@ 2026-11-16 18:00 William Chuang
2026-11-16 22:08 ` Andreas Gruenbacher
0 siblings, 1 reply; 3+ messages in thread
From: William Chuang @ 2026-11-16 18:00 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: gfs2, linux-kernel, William Chuang, syzbot+5a5f492ccae698fd7434, stable
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@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5a5f492ccae698fd7434
Cc: stable@vger.kernel.org
Signed-off-by: William Chuang <founder@logarcheon.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH] gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole
2026-11-16 18:00 [PATCH] gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole William Chuang
@ 2026-11-16 22:08 ` Andreas Gruenbacher
0 siblings, 0 replies; 3+ messages in thread
From: Andreas Gruenbacher @ 2026-11-16 22:08 UTC (permalink / raw)
To: William Chuang
Cc: Andreas Gruenbacher, gfs2, linux-kernel,
syzbot+5a5f492ccae698fd7434, stable
On Mon, Nov 16, 2026 at 7:01 PM William Chuang <founder@logarcheon.com> wrote:
> 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@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=5a5f492ccae698fd7434
> Cc: stable@vger.kernel.org
> Signed-off-by: William Chuang <founder@logarcheon.com>
Thanks.
Could you please replace this with the following fix and resend?
Andreas
--
gfs2_seek_data() and gfs2_seek_hole() call gfs2_glock_nq_init(), and
independent of the outcome, they call gfs2_glock_dq_uninit(). When the
gfs2_glock_nq() call in gfs2_glock_nq_init() fails, gfs2_glock_nq_init()
returns with an error code and gh.gh_gl is set NULL. This causes a NULL
pointer dereference in gfs2_glock_dq().
Fix that by only calling gfs2_glock_dq_uninit() when
gfs2_glock_nq_init() succeeds.
Fixes: 3a27411cb4bc ("gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap")
Reported-by: syzbot+5a5f492ccae698fd7434@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5a5f492ccae698fd7434
Cc: stable@vger.kernel.org
Signed-off-by: William Chuang <founder@logarcheon.com>
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 2c2dc459c037..d4678e4832b3 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -2253,9 +2253,11 @@ loff_t gfs2_seek_data(struct file *file, loff_t offset)
inode_lock_shared(inode);
ret = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &gh);
- if (!ret)
- ret = iomap_seek_data(inode, offset, &gfs2_iomap_ops);
+ if (ret)
+ goto out;
+ ret = iomap_seek_data(inode, offset, &gfs2_iomap_ops);
gfs2_glock_dq_uninit(&gh);
+out:
inode_unlock_shared(inode);
if (ret < 0)
@@ -2272,9 +2274,11 @@ loff_t gfs2_seek_hole(struct file *file, loff_t offset)
inode_lock_shared(inode);
ret = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &gh);
- if (!ret)
- ret = iomap_seek_hole(inode, offset, &gfs2_iomap_ops);
+ if (ret)
+ goto out;
+ ret = iomap_seek_hole(inode, offset, &gfs2_iomap_ops);
gfs2_glock_dq_uninit(&gh);
+out:
inode_unlock_shared(inode);
if (ret < 0)
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <20261116175346.44221-1-founder@logarcheon.com>]
* Re: [PATCH] gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole
[not found] <20261116175346.44221-1-founder@logarcheon.com>
@ 2026-11-16 17:54 ` syzbot
0 siblings, 0 replies; 3+ messages in thread
From: syzbot @ 2026-11-16 17:54 UTC (permalink / raw)
To: founder; +Cc: founder, syzkaller-bugs, linux-kernel
> #syz test
Patch testing via #syz test is temporarily disabled.
See https://github.com/google/syzkaller/issues/8122 for details.
>
> 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()).
>
> Reported-by: syzbot+5a5f492ccae698fd7434@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=5a5f492ccae698fd7434
> Signed-off-by: William Chuang <founder@logarcheon.com>
> ---
> 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 75fb1a0..4110b2d 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
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-16 22:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 18:00 [PATCH] gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole William Chuang
2026-11-16 22:08 ` Andreas Gruenbacher
[not found] <20261116175346.44221-1-founder@logarcheon.com>
2026-11-16 17:54 ` syzbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®