From: Jiaming Zhang <r772577952@gmail.com>
To: Andreas Gruenbacher <agruenba@redhat.com>, gfs2@lists.linux.dev
Cc: linux-kernel@vger.kernel.org,
Jiaming Zhang <r772577952@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] gfs2: validate quota inode mode and jdata flag at mount time
Date: Sun, 6 Dec 2026 20:13:33 +0800 [thread overview]
Message-ID: <20261206121333.492868-1-r772577952@gmail.com> (raw)
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
reply other threads:[~2026-12-06 12:13 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=20261206121333.492868-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 \
/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®