mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gfs2: validate quota inode mode and jdata flag at mount time
@ 2026-12-06 12:13 Jiaming Zhang
  0 siblings, 0 replies; only message in thread
From: Jiaming Zhang @ 2026-12-06 12:13 UTC (permalink / raw)
  To: Andreas Gruenbacher, gfs2; +Cc: linux-kernel, Jiaming Zhang, stable

GFS2 assigns gfs2_jdata_aops (buffer_head-backed folio->private) to
regular inodes with GFS2_DIF_JDATA set and gfs2_aops (iomap-backed
folio->private, storing struct iomap_folio_state *) otherwise.  The
quota writer gfs2_write_buf_to_page() assumes the hidden "quota" system
inode always uses buffer heads:

	bh = folio_buffers(folio);
	if (!bh)
		bh = create_empty_buffers(folio, bsize, 0);

During mount, init_inodes() looks up sdp->sd_quota_inode without
instantiating it or validating its on-disk mode and flags.  Since
commit 2164f9b91869 ("gfs2: use iomap for buffered I/O in ordered and
writeback mode"), clearing GFS2_DIF_JDATA on the quota dinode makes
gfs2_set_aops() assign gfs2_aops instead of gfs2_jdata_aops.

During quota sync, gfs2_unstuffer_folio() queues the quota inode on
sd_log_ordered and gfs2_write_buf_to_page() attaches a buffer_head to
folio->private.  When do_sync() flushes the log, gfs2_ordered_write()
enters iomap_writepages() and iomap_clear_range_dirty(), casting that
buffer_head to struct iomap_folio_state and locking &ifs->state_lock.

Treating a buffer_head as a spinlock and dirty bitmap corrupts the
buffer_head and triggers BUG: spinlock bad magic (or a lockdep warning)
in iomap_clear_range_dirty().  Triggering this requires mounting a
crafted GFS2 image with quotas enabled (CAP_SYS_ADMIN) and performing
a quota-tracked write before unmount or quota sync.

Lock sdp->sd_quota_inode shared in init_inodes() so its on-disk mode
and flags are instantiated even when the directory entry carries DT_REG,
verify S_ISREG() and gfs2_is_jdata(), and reject corrupt images at
mount time with -EINVAL.

Fixes: 2164f9b91869 ("gfs2: use iomap for buffered I/O in ordered and writeback mode")
Closes: https://lore.kernel.org/lkml/CANypQFa2=8_kKc4KpY=tAdaDq+p8TyL-wtEQPEfp2aewCXbTjQ@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 | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 6ec47376aecf..62375d367cce 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -837,6 +837,7 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo)
 {
 	int error = 0;
 	struct inode *master = d_inode(sdp->sd_master_dir);
+	struct gfs2_holder q_gh;
 
 	if (undo)
 		goto fail_qinode;
@@ -862,6 +863,20 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo)
 		fs_err(sdp, "can't get quota file inode: %d\n", error);
 		goto fail_rindex;
 	}
+	error = gfs2_glock_nq_init(gfs2_inode_glock(sdp->sd_quota_inode),
+				   LM_ST_SHARED, 0, &q_gh);
+	if (error) {
+		fs_err(sdp, "can't lock quota file inode: %d\n", error);
+		goto fail_qinode;
+	}
+	if (!S_ISREG(sdp->sd_quota_inode->i_mode) ||
+	    !gfs2_is_jdata(GFS2_I(sdp->sd_quota_inode))) {
+		fs_err(sdp, "corrupt quota file inode\n");
+		error = -EINVAL;
+	}
+	gfs2_glock_dq_uninit(&q_gh);
+	if (error)
+		goto fail_qinode;
 	/*
 	 * i_rwsem on quota files is special. Since this inode is hidden system
 	 * file, we are safe to define locking ourselves.

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:13 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:13 [PATCH] gfs2: validate quota inode mode and jdata flag at mount time 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®