From nobody Sun Feb 8 10:30:00 2026 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B4CD4FAEDB for ; Thu, 8 Jan 2026 14:20:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767882005; cv=none; b=DZB4r/Y5qC/ZLxCbmNKpISVMihusZ4l+khq9/4P7+cvOznxhNMvrrlLuHdtSmeUOmjnhXY/C9qJTBCeXxrMpqT1m2gui0rWuYpyn9Vn2qBuGKlWFVkxKyvi/RiH8FaBO07MbO3wBb8+RGoR92ymB+C4tiASb8dGZK//yTpN1/4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767882005; c=relaxed/simple; bh=HaEnV4ehoraqs2JDYMtCzb/1LxR89HWES5hD+j3POUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sdujd4hXREPrgsOo1Pi9eEZto5S331qKE7yztazGDL8e8+SxDfsNB3+1yhw0JRqCh2n9XOw21ZzASIyDXm/vY6M1ESDasS+04NfTC5RrACb5HRvtqsqibGxA/L3jZGUo7QYo6f6kvjWhSOs82RFjmUkJ7PGvSagkK3g57/abgpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=h4rdmPwS; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h4rdmPwS" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-64b608ffca7so4866391a12.3 for ; Thu, 08 Jan 2026 06:20:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767882001; x=1768486801; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XFU8Ih7hrSkurdKWhD1ijhVh4ZiAsNV6HLiabVokPfk=; b=h4rdmPwSM/dJm8SHZbvEiAJ5h1VIPfesNt2fsN9eR6iTf7JXutfl9m007AjMg6CHGp MkTaH0ohAZ3FaROKUniiMKOpi5DesOLo6iIYjuFyOQpG14uHL+RkH1QPlXVp7irJclEG e5+Jb+RdsIRTo8q8Cq8bc7XUOxJqljp6dbGCuEy8YhtfkUtvmesX5vosHbsfH4Ct1nbo Z2YBaKKhoj29zbdGofH+Pi9Bo2FiBL5G+YugXkpYoj8WLhAbbiycoxa18wCVaCO0ykaJ CBR35D7xrDvsBP6hF+EhwqZ38Hq/AC3K0lcEsmUqPRf+Fq76UX4aD3U2B6rEsY5C9K5s D8Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767882001; x=1768486801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=XFU8Ih7hrSkurdKWhD1ijhVh4ZiAsNV6HLiabVokPfk=; b=S7mVyHlz4Q2Qws4I4/juNY/OuYpC4vewce66k+0l1mCQXLMkoH2mSa6b7aMAAVrg0r 3VjdWd3WJNCPIgWZgSGxLS35qZLjrV8YyjH8hWnpSY/EDE1v6SPm3gql68sRLfFUvyT7 jUsko0cVuvHPoDfaTTBQg4TTxHOSGIN4l6lKVGMcOQIuBRymkigtncxgqrWmc1EsaxUr mMCr0G3IduSC26V24eInVVlsc2SLI3tnfEmoHnSF3Mmsd6izhS0ljOOxku+0qpBplKpa 1nzsiYhS3aCmG8+nclM03Zg6XwkCm4hpGB6BgEsmRIg8xzDvOK5x3KY+Wk0OTQIXgwQM 5H1Q== X-Forwarded-Encrypted: i=1; AJvYcCXrSXWmvhKRh/t1LJ6yTfOfknOM3tPQ6B7QsYbGVjdHTW6uA76vBJk5L6VBfzWF6sUVpJIjk5cQaR+GxFM=@vger.kernel.org X-Gm-Message-State: AOJu0YyZ39z1eDsHkQPmX5rvAaq33ZBD4Xtj/jQ+ivhB50F8yjGKMXLk TahhmTld6F4mt2ua0o26oaTWphliQaipKeVOrvDXzf6mwKUKk2bLwoQmocQ5zvJi X-Gm-Gg: AY/fxX6hXObSGFOgZ1MapBPMBxYECgKgPy2mHnmC9FN2ociFlVNNz/Hm8czp7iCYcwC TXmVIjHBM0mQ3q3kXF6+SvS3QGMfVny172vzwjitv0bNJzB2JPpsv6aUCeC/bK9mqpi7qh3xcDE gkT3J1R+t550Vo6q4rrRZTyAWRePSKLNiwRKX6E7T44l8e0rBxBMK+TUDxgIhOvDxo462CR0htU QHX8wf+JGGLBOnpOXiYVIZ4pRibCxOJrdrxJICvne14ZEwWL6EAqk07TvqQDI36DLFB4BlghIxe RMn34nPLXaX4tnfez7Pn8XqpM3AJ93sd4TJSaSId6E4uvchh2F08ogqmfU9k+LbIUILXPDG1Ev2 MbBGnFkwt6/9Tfb4eUuh8/vJx3tihV6jlzUHqPV5n0FHyMUAi7y7lyLAHIBhe1Rxu6w3JpRU5nu JSqLUJc/xgpnt0Kg== X-Google-Smtp-Source: AGHT+IFdshrgPVcptLCLWBEfjJcbNevKZB5kL0eUZhIYHdklA2hZ6/zmV6PqAkBXH1owpYsRHn2iFQ== X-Received: by 2002:a17:907:9704:b0:b83:13c3:d495 with SMTP id a640c23a62f3a-b8445345cafmr632272866b.37.1767882000645; Thu, 08 Jan 2026 06:20:00 -0800 (PST) Received: from prometheus ([85.11.110.37]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b842a235c0fsm818034766b.9.2026.01.08.06.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jan 2026 06:19:59 -0800 (PST) From: Szymon Wilczek To: ocfs2-devel@lists.linux.dev Cc: joseph.qi@linux.alibaba.com, mark@fasheh.com, jlbec@evilplan.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, akpm@linux-foundation.org, Szymon Wilczek , syzbot+51244a05705883616c95@syzkaller.appspotmail.com Subject: [PATCH v2] ocfs2: fix circular locking dependency in ocfs2_acquire_dquot Date: Thu, 8 Jan 2026 15:19:31 +0100 Message-ID: <20260108141931.67110-1-swilczek.lx@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251227174251.121668-1-swilczek.lx@gmail.com> References: <20251227174251.121668-1-swilczek.lx@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move ocfs2_extend_no_holes() and ocfs2_start_trans() to execute before ocfs2_lock_global_qf() to fix a circular locking dependency reported by syzbot. The issue occurs because ocfs2_start_trans() acquires sb_internal (via sb_start_intwrite) while already holding quota file locks (ip_alloc_sem and sysfile_lock_key). This conflicts with freeze/dismount paths that acquire sb_internal first, creating the following circular dependency: sb_internal -> sysfile_lock_key -> ip_alloc_sem (freeze/dismount) ip_alloc_sem -> sysfile_lock_key -> sb_internal (quota acquire) Fix this by reordering the operations: 1. Speculatively extend quota file (uses need_alloc estimate) 2. Start transaction 3. Acquire global quota file lock 4. Perform quota operations 5. Release lock 6. Commit transaction This ensures sb_internal is acquired before quota file locks, matching the expected kernel lock order. Reported-by: syzbot+51244a05705883616c95@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug\?extid\=3D51244a05705883616c95 Signed-off-by: Szymon Wilczek --- fs/ocfs2/quota_global.c | 49 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c index e85b1ccf81be..95bb901820cf 100644 --- a/fs/ocfs2/quota_global.c +++ b/fs/ocfs2/quota_global.c @@ -821,13 +821,35 @@ static int ocfs2_acquire_dquot(struct dquot *dquot) trace_ocfs2_acquire_dquot(from_kqid(&init_user_ns, dquot->dq_id), type); mutex_lock(&dquot->dq_lock); + + /* + * Speculatively extend quota file before acquiring any locks or + * starting transaction to avoid lock inversion. sb_start_intwrite + * (via ocfs2_start_trans) ranks above quota file locks. + */ + if (need_alloc) { + WARN_ON(journal_current_handle()); + status =3D ocfs2_extend_no_holes(gqinode, NULL, + i_size_read(gqinode) + (need_alloc << sb->s_blocksize_bits), + i_size_read(gqinode)); + if (status < 0) + goto out; + } + + handle =3D ocfs2_start_trans(osb, + ocfs2_calc_global_qinit_credits(sb, type)); + if (IS_ERR(handle)) { + status =3D PTR_ERR(handle); + goto out; + } + /* * We need an exclusive lock, because we're going to update use count * and instantiate possibly new dquot structure */ status =3D ocfs2_lock_global_qf(info, 1); if (status < 0) - goto out; + goto out_trans; status =3D ocfs2_qinfo_lock(info, 0); if (status < 0) goto out_dq; @@ -843,29 +865,12 @@ static int ocfs2_acquire_dquot(struct dquot *dquot) OCFS2_DQUOT(dquot)->dq_use_count++; OCFS2_DQUOT(dquot)->dq_origspace =3D dquot->dq_dqb.dqb_curspace; OCFS2_DQUOT(dquot)->dq_originodes =3D dquot->dq_dqb.dqb_curinodes; - if (!dquot->dq_off) { /* No real quota entry? */ + if (!dquot->dq_off) /* No real quota entry? */ ex =3D 1; - /* - * Add blocks to quota file before we start a transaction since - * locking allocators ranks above a transaction start - */ - WARN_ON(journal_current_handle()); - status =3D ocfs2_extend_no_holes(gqinode, NULL, - i_size_read(gqinode) + (need_alloc << sb->s_blocksize_bits), - i_size_read(gqinode)); - if (status < 0) - goto out_dq; - } =20 - handle =3D ocfs2_start_trans(osb, - ocfs2_calc_global_qinit_credits(sb, type)); - if (IS_ERR(handle)) { - status =3D PTR_ERR(handle); - goto out_dq; - } status =3D ocfs2_qinfo_lock(info, ex); if (status < 0) - goto out_trans; + goto out_dq; status =3D qtree_write_dquot(&info->dqi_gi, dquot); if (ex && info_dirty(sb_dqinfo(sb, type))) { err =3D __ocfs2_global_write_info(sb, type); @@ -873,10 +878,10 @@ static int ocfs2_acquire_dquot(struct dquot *dquot) status =3D err; } ocfs2_qinfo_unlock(info, ex); -out_trans: - ocfs2_commit_trans(osb, handle); out_dq: ocfs2_unlock_global_qf(info, 1); +out_trans: + ocfs2_commit_trans(osb, handle); if (status < 0) goto out; =20 --=20 2.52.0