mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiaming Zhang <r772577952@gmail.com>
To: Andreas Gruenbacher <agruenba@redhat.com>, gfs2@lists.linux.dev
Cc: David Teigland <teigland@redhat.com>,
	linux-kernel@vger.kernel.org,
	Jiaming Zhang <r772577952@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] gfs2: free loaded journal descriptors when gfs2_jindex_hold() fails
Date: Sun,  6 Dec 2026 20:04:36 +0800	[thread overview]
Message-ID: <20261206120436.487394-1-r772577952@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-06 12:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206120436.487394-1-r772577952@gmail.com \
    --to=r772577952@gmail.com \
    --cc=agruenba@redhat.com \
    --cc=gfs2@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=teigland@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®