gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole
Subsystems (2)
PATCH 1/1 gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole
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()).
--- fs/gfs2/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/gfs2/inode.c +4 -2
@@ -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 )
Signature · 1 line
2.43.0
Andreas Gruenbacher
maintainerPATCH 1/1 gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole
Quoted 13 lines · William Chuang
When the filesystem has been withdrawn,
gfs2_glock_nq()returns-EIOwithout queuing the holder, andgfs2_glock_nq_init()then callsgfs2_holder_uninit(), which sets gh.gh_gl to NULL.
gfs2_seek_data()andgfs2_seek_hole()callgfs2_glock_dq_uninit()unconditionally, so in that casegfs2_glock_dq()dereferences a NULL glock when it takesgl->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()andgfs2_getattr()).
Quoted 5 lines
Fixes 3a27411cb4bc ("gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap")Reported-by [email protected]Signed-off-by William Chuang <[email protected]>
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.
fs/gfs2/inode.c +8 -4
@@ -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 )
PATCH v2 1/1 gfs2: Fix NULL pointer dereference in gfs2_seek_data/gfs2_seek_hole
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.
---
v2: Adopt Andreas Gruenbacher's version of the fix -- skip
gfs2_glock_dq_uninit() via goto out when gfs2_glock_nq_init() fails, rather than guarding the dequeue with gfs2_holder_initialized(); reword the commit message to match. v1 posted at
https://lore.kernel.org/r/[email protected]
fs/gfs2/inode.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/gfs2/inode.c +8 -4
@@ -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 )
Signature · 1 line
2.43.0
Quoted 58 lines · William Chuang
gfs2_seek_data()andgfs2_seek_hole()callgfs2_glock_nq_init(), and independent of the outcome, they callgfs2_glock_dq_uninit(). When thegfs2_glock_nq()call ingfs2_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 ingfs2_glock_dq().Fix that by only calling
gfs2_glock_dq_uninit()whengfs2_glock_nq_init()succeeds.Fixes 3a27411cb4bc ("gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap")Reported-by [email protected]Suggested-by Andreas Gruenbacher <[email protected]>Signed-off-by William Chuang <[email protected]>---
v2: Adopt Andreas Gruenbacher's version of the fix -- skip
gfs2_glock_dq_uninit()viagoto outwhengfs2_glock_nq_init()fails, rather than guarding the dequeue withgfs2_holder_initialized(); reword the commit message to match. v1 posted at
https://lore.kernel.org/r/[email protected]fs/gfs2/inode.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)fs/gfs2/inode.c +8
-5@@ -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 ) --
Quoted 2 lines
2.43.0
Applied.
Thanks,
Andreas