[PATCH] gfs2: free loaded journal descriptors when gfs2_jindex_hold() fails
From: Jiaming Zhang
Date: Sun Dec 06 2026 - 07:04:49 EST
GFS2 caches inode metadata in per-glock address spaces whose glocks
hold raw pointers back to struct gfs2_sbd (sdp), so every glock address
space must be torn down before free_sbd() frees sdp. During mount,
init_journal() assumes gfs2_jindex_hold() leaves nothing on
sd_jindex_list on error:
error = gfs2_jindex_hold(sdp, &ji_gh);
if (error) {
fs_err(sdp, "can't read journal index: %d\n", error);
goto fail;
}
gfs2_jindex_hold() loops over "journal0", "journal1", ... in jindex,
looking up each inode via gfs2_lookupi() and appending a struct
gfs2_jdesc to sdp->sd_jindex_list. If an earlier journal succeeds and
caches a metadata folio while a later journal fails lookup (e.g. -EIO),
gfs2_jindex_hold() returns an error with the earlier entry still queued.
Jumping to fail skips fail_jindex and gfs2_jindex_free(sdp), leaving
the loaded journal inode, its glock address space, and its cached
metadata folio alive past gfs2_fill_super()'s free_sbd(sdp) call.
When memory reclaim later evicts that folio, gfs2_release_folio()
recovers the freed sdp via gfs2_mapping2sbd() and calls
spin_lock(&sdp->sd_log_lock), causing a slab-use-after-free read (3168
bytes into kmalloc-8k). Triggering this requires mounting a crafted
GFS2 image (CAP_SYS_ADMIN) followed by memory reclaim.
Jump to fail_jindex on gfs2_jindex_hold() error in init_journal() and
remove the now-unused fail label, so gfs2_jindex_free(sdp) releases any
already-loaded journal descriptors and their glock address spaces before
free_sbd().
Fixes: b3b94faa5fe5 ("[GFS2] The core of GFS2")
Closes: https://lore.kernel.org/lkml/CANypQFYTi2tsHRJX2i=KMvSXy29ow5v9xj90cB3a5B-Jd5bygg@xxxxxxxxxxxxxx/
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: Antigravity:Gemini
Signed-off-by: Jiaming Zhang <r772577952@xxxxxxxxx>
---
fs/gfs2/ops_fstype.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 6ec47376aecf..cb1b8ab65bb8 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -713,7 +713,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
error = gfs2_jindex_hold(sdp, &ji_gh);
if (error) {
fs_err(sdp, "can't read journal index: %d\n", error);
- goto fail;
+ goto fail_jindex;
}
error = -EUSERS;
@@ -826,7 +826,6 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
gfs2_jindex_free(sdp);
if (gfs2_holder_initialized(&ji_gh))
gfs2_glock_dq_uninit(&ji_gh);
-fail:
iput(sdp->sd_jindex);
return error;
}
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.43.0