mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gfs2: free loaded journal descriptors when gfs2_jindex_hold() fails
@ 2026-12-06 12:04 Jiaming Zhang
  0 siblings, 0 replies; only message in thread
From: Jiaming Zhang @ 2026-12-06 12:04 UTC (permalink / raw)
  To: Andreas Gruenbacher, gfs2
  Cc: David Teigland, linux-kernel, Jiaming Zhang, stable

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@mail.gmail.com/
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:Gemini
Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-06 12:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06 12:04 [PATCH] gfs2: free loaded journal descriptors when gfs2_jindex_hold() fails Jiaming Zhang

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®