mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qing Zhang <diasyzhangqing@gmail.com>
To: Andreas Gruenbacher <agruenba@redhat.com>
Cc: gfs2@lists.linux.dev, linux-kernel@vger.kernel.org,
	syzbot+bad65435361712796381@syzkaller.appspotmail.com,
	diasyzhangqing@gmail.com, Qing Zhang <diasyzhang@tencent.com>
Subject: [PATCH] gfs2: Fix refcount of quota data restored at mount
Date: Wed,  4 Nov 2026 17:55:30 +0800	[thread overview]
Message-ID: <20261104095530.4178727-1-diasyzhang@tencent.com> (raw)
In-Reply-To: <683e2b6d.a00a0220.d8eae.005b.GAE@google.com>

gfs2_quota_init() resets the lockref count to 0 despite setting
QDF_CHANGE, which owns a reference released by do_qc().  Quota syncing
can therefore consume a concurrent user's reference, leaving the
count at 0 and triggering the assertion in __qd_hold().

Keep the initial reference from qd_alloc().  During cleanup, clear
the in-memory change and slot state and drop the QDF_CHANGE reference
for objects with no other references.  Leave the on-disk quota change
records untouched for recovery on the next mount.

Fixes: bb73ae8ff394 ("gfs2: Fix initial quota data refcount")
Reported-by: syzbot+bad65435361712796381@syzkaller.appspotmail.com
Closes: https://syzbot.appspot.com/bug?extid=bad65435361712796381
Signed-off-by: Qing Zhang <diasyzhang@tencent.com>
---
If QDF_CHANGE remains set at teardown, a concurrent sysfs quota_refresh
can make cleanup skip a restored object during remount-ro or unmount.
The last external put then leaves the QDF_CHANGE reference behind,
whereas before this patch it could dispose of the object with the
journal shut down.  Feedback on handling this reference safely would
be appreciated.

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

 fs/gfs2/quota.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index b2984fb7b35c..29eb7adc4284 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -1470,7 +1470,6 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
 			if (qd == NULL)
 				goto fail_brelse;
 
-			qd->qd_lockref.count = 0;
 			set_bit(QDF_CHANGE, &qd->qd_flags);
 			qd->qd_change = qc_change;
 			qd->qd_slot = slot;
@@ -1542,6 +1541,12 @@ void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
 	spin_lock(&qd_lock);
 	list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
 		spin_lock(&qd->qd_lockref.lock);
+		if (qd->qd_lockref.count == 1 &&
+		    test_and_clear_bit(QDF_CHANGE, &qd->qd_flags)) {
+			qd->qd_change = 0;
+			qd->qd_slot_ref = 0;
+			qd->qd_lockref.count = 0;
+		}
 		if (qd->qd_lockref.count != 0) {
 			spin_unlock(&qd->qd_lockref.lock);
 			continue;
-- 
2.43.7


  parent reply	other threads:[~2026-11-04  9:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-02 22:53 [syzbot] [gfs2?] kernel BUG in do_qc syzbot
2025-08-02 22:19 ` syzbot
2026-11-04  9:55 ` Qing Zhang [this message]
2026-11-04 10:23   ` syzbot

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=20261104095530.4178727-1-diasyzhang@tencent.com \
    --to=diasyzhangqing@gmail.com \
    --cc=agruenba@redhat.com \
    --cc=diasyzhang@tencent.com \
    --cc=gfs2@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+bad65435361712796381@syzkaller.appspotmail.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®