From nobody Thu Apr 9 17:58:06 2026 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (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 0ADD84EA39E for ; Tue, 3 Mar 2026 18:02:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772560925; cv=none; b=na86YUSbJVvLm0RIBb6L1R/1kAfnYa5jVsx3SyI6tO2XNEIRnXYri3Z6cBNHBXQ0YwjJdZLJ021RJHvriKb9L2NCYiHSXY76se+/FTD9eutM38ZnEid/XXn2DVldYKt1JGzOT3quwCY9ljGmqabtIf+qrDYWV+KsN/UW2C51JpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772560925; c=relaxed/simple; bh=/IXmo69Qqppsb0Rguh1puUkOgy5dR4pABTlr/a1NR3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z632F9IakCiGqHslKb35QdwLpT5o6t3hy9x4NTUFMRVQXT6u9LUThUKOE7+0V6KrxoZwi/YG8PO9l5wdTrOMQ3N9TW42a21ZdZWxwCQbyZD7FrouAhhRvZEK4Zkkmweh78Y8hvF4EYma/bwStKE19EpB7gL/q86ID+tk8SAyKcM= 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=LFOFwRvB; arc=none smtp.client-ip=74.125.82.41 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="LFOFwRvB" Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-1270adc5121so7469792c88.0 for ; Tue, 03 Mar 2026 10:02:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772560923; x=1773165723; 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=nYGdbxnOx3otBr6PvYVC6d9nFh0rDHzCPxy+MS19bo0=; b=LFOFwRvBxGNJHCcQtPfFkMFQB3KqM9Ww+dsksJf5cpVYxcHoawXjL4XINR/5aGSl2I yfwUbnpg8WqVlF5y5SPIDThtzFeZI4kCKnvXkPBXs4LPtBSWdJKTUNoIEBmLR9fBPJhO i0jtvhtstywHJeqY9xraoV+YtOSe4KCS/gJLkMen0q/WgU09A9BoS/UjpkmYixoiOg2s QX7RJlpQgfTil6AavMDkALf9otTMne6LkQgdq1laPbMOhFFPKFrkgot40PtL+cjD7Yj3 85Fvze2u+Z/MRysy9g6nzNo1YBFIaswzH22DnPO4Z+WUKgPb9kdMv7VOn8dJR1nnd8EB uONw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772560923; x=1773165723; 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=nYGdbxnOx3otBr6PvYVC6d9nFh0rDHzCPxy+MS19bo0=; b=gkgO7Yahs2khfFL3+ZsrGurrmm2+1mv0ssQuhAL03V/d0H1OI+Md6i0Ic9Yc3eEj4X Hyg7ANYGXfsFLHA+wNR2BSmcP+svKsdr6hekO3PiQ36KRds3fapiP7M/GjsFEnWoTpVD 1IK+8o6T2A/2WhBQAgnkKJAQjLKUo4WkysFOd6gewy4b7bbUMmqPTw1Kgybhk1zhF2B7 +zsX/piyJvmcgyd1Q9082YGvMLgzuIoMSJWzV1dk1CAGYVL+rWirscsUcY5hukhsJEU+ gFTEdXntZe9Nh9C1xmyYMwGnGBtHqq9F6Lh4bbw86Q6e9lJHUJvDeGaNHm6RHU3dzB/l gsAw== X-Forwarded-Encrypted: i=1; AJvYcCXUNlnNNuwR0mvX2KgA87yJWgk6JlYsEbZT+yH4E48bC/xu2LmSbwjjQgmU+9XtdVf21r3xKMhDdgi4ecE=@vger.kernel.org X-Gm-Message-State: AOJu0YyxTlOabIySR+NYwv66ZS+/gNH53Fd6i1FNdsLxof+vxOdJRfTr uQ89HYZkplwRlkL58PDs726xppAmUm7o6Qp78+QEwGLM08c/X+Qve9+I X-Gm-Gg: ATEYQzx7eqyhvGAIWgqXgHE8TP98K209tote4P9zsEWHWUBZPU7w7S295l3f/tgernH b1iGgCSlAAyQ1ZH4g9ym7heb8PoPUxqkvq2/rky5+tSpIylH6KgnSWxmOX5EOWCAghRW4z/i3iH y1jcV7xaWNsovgUbKEROK9XC4axM0afYYcti6c5dQ8WtIxCQsZDz1btN2nJuSd9ir7oMzwcVkhw 5msN/kxNQ68MhBAb9WQCLpat3zCx2iUy9WcnlFXnODnp38LWJVtjeALPRDVVbQ4Hbsk7nm5EG02 QC/DaItV7HTRt0MF+uRIP0/cuCNiZDtmqLmWR8sPAb5jTLXCI+91TH+pSoWTHmHfV+IWlebKQwj m/yJbYuaBG4KLCvzagHUTjcC15+3AjBlK/YCQ9iRtE2mu+j0/E4vpWc1kqRdcU4np63FshEt2SQ U5h2DjDd1cP1p85OrDX9+tlYL1wfg/8fawiJMMpWyTa68mI+1eO9ncTPVIpnu6dRsHHinMZ1jLH 5z8pwdHotH9KQcn800/BJTUe2bwxWUoSHg78wlwMmMq4tKMry0BrdQ9OT7s5Wulqi7oZuNFQ+/0 X-Received: by 2002:a05:7300:6ca8:b0:2be:aa:9a4a with SMTP id 5a478bee46e88-2be00aa9ba5mr3428751eec.0.1772560923094; Tue, 03 Mar 2026 10:02:03 -0800 (PST) Received: from arch.guest.box.net ([8.39.49.136]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdfba0df2fsm9506612eec.7.2026.03.03.10.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2026 10:02:02 -0800 (PST) From: Milos Nikic To: jack@suse.cz Cc: tytso@mit.edu, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Milos Nikic , Zhang Yi , Andreas Dilger Subject: [PATCH v4 1/2] jbd2: gracefully abort instead of panicking on unlocked buffer Date: Tue, 3 Mar 2026 10:01:56 -0800 Message-ID: <20260303180157.53061-2-nikic.milos@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260303180157.53061-1-nikic.milos@gmail.com> References: <20260303180157.53061-1-nikic.milos@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" In jbd2_journal_get_create_access(), if the caller passes an unlocked buffer, the code currently triggers a fatal J_ASSERT. While an unlocked buffer here is a clear API violation and a bug in the caller, crashing the entire system is an overly severe response. It brings down the whole machine for a localized filesystem inconsistency. Replace the J_ASSERT with a WARN_ON_ONCE to capture the offending caller's stack trace, and return an error (-EINVAL). This allows the journal to gracefully abort the transaction, protecting data integrity without causing a kernel panic. Signed-off-by: Milos Nikic Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Andreas Dilger --- fs/jbd2/transaction.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index dca4b5d8aaaa..04d17a5f2a82 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -1302,7 +1302,12 @@ int jbd2_journal_get_create_access(handle_t *handle,= struct buffer_head *bh) goto out; } =20 - J_ASSERT_JH(jh, buffer_locked(jh2bh(jh))); + if (WARN_ON_ONCE(!buffer_locked(jh2bh(jh)))) { + err =3D -EINVAL; + spin_unlock(&jh->b_state_lock); + jbd2_journal_abort(journal, err); + goto out; + } =20 if (jh->b_transaction =3D=3D NULL) { /* --=20 2.53.0 From nobody Thu Apr 9 17:58:06 2026 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 3CD6F377EB3 for ; Tue, 3 Mar 2026 18:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772560927; cv=none; b=IAYehNzP+HbT60YG+oGyk/aSU+wLob01t1IpO3OW0w7FaY6sOuenB2MBZ9ZjU3sIjvn6Q4TcgWxcCqhvpS7yLhe+/32n8ojmK54ZF9mp7j9Y6JJPhXsKWWsdE5KRZWeqmGXHjR2+Sw4j0RtJ2Ks2c0gcIB81pJuBWyeiq0QmiCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772560927; c=relaxed/simple; bh=+qGADK3hc8JKCWj7GguvVBLxpYgnyMyBrv5MYiGxtCw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dldhlb0fPkNsh9+mYlyofsxc3e5V3VvHktis2k3IE3VN5Rr4rStfPYUQ6+TZwaQMynodV5jlNytNsvyUpVzfkyO5CL1dFvOfPYa3E9EkTzo/N0W2RCul9KpKw2D26yI8bU8V5jreD3dnI6/MBHgt6Z0gxeykTp4F9pl2A9Sn86s= 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=S2nY9GbK; arc=none smtp.client-ip=74.125.82.54 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="S2nY9GbK" Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-1273349c56bso7210317c88.0 for ; Tue, 03 Mar 2026 10:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772560925; x=1773165725; 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=lDaZthny2THuP7ev8syfJWkMisufRuRYdnb675O2Q98=; b=S2nY9GbKNZVyzqT/I69R2PUe8eaiP7SNkzrIvFP6Q9L+W6TatUrGV2FzTWT0kusXnC zPtiHaAgLmaVJf9OlceDPzj1nVVzMr2TJKmsHTdhGg2NZA7i9cEZonQspM8eCU4mbXrq icksx+tq1XKjFKs81k4yDTChRGlD7uwmNDBx/8jo99weU/wlQHAPimlu/eGg/EP7pCwJ hdzZVfcLDehSNPjsXsO55CLUMSPyBq6o+AwACJSzdz074JUfjuwsKqFW13XpI62Bs2q0 lEH5YmTZ7ISN+MaPuHlsv0RqPjEIxtChRS3PUs3C5Y6XTWnsbH+37wQxyQCxx+mXuScR xaGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772560925; x=1773165725; 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=lDaZthny2THuP7ev8syfJWkMisufRuRYdnb675O2Q98=; b=Ihu2O4+MLwpgTvHi6jWqHf72un/xFMCNkUH6YNV+u26Ja+5lWu2Y1FcKccL/jVH8xB D7puvZJxzDoIdf4BYCAjTC+QGGSVx3VPQR01NCjzdY7tsnUbf6b0YaUeXR8gNewg643g Ydt6tgdFj0mOWD2+c/8GBo/J4ZjcGs12cgveVDtwYlLv0BMWE5GXDCvE/1BHeyhf1upo Sqa4wgr5qKsvdSt81rrf0/bvBNukN1PuruefaAGCdRlClJLzb3X5t56BQGVj5VnNKA2g Fn8eGBq5UxIztcyiRpvnpgJY0mbQdYUAm2aRft/0lKilxBnAzQY4KUJRxPTFzRMoBN0J 8KFw== X-Forwarded-Encrypted: i=1; AJvYcCU6yPHxqmFIXAAZEKRVO3/MlWmUKe0W4ko18GimpuTiLawJ8yJeqrbUHm+zVdtfQ4Yulwa1ZSy+PFmK3b0=@vger.kernel.org X-Gm-Message-State: AOJu0YwRYP0tj67ewfCwk0nbG0TzGeoRbIdL7iQAbj7L4DdHDuzONudB o44ff6zGtueDYd+sg2jsF1gVsjyVtCEbKUxZBYz1He3ltqKSG8SkDiMLR8hoDQ== X-Gm-Gg: ATEYQzz2XDyxGHHzZaKUMm35QQs/c90JQCi3clqcI2g9fkR3fCGq8jIB8XcDNMzrBek yAprBwLwpPHVDWXrfCiXliR/+wpOFcihClkUsOMBoFsPv7LtvRRezMFWj7pcPNGPzYB9z7oKAMa btxjkh4yRYZv2yHOdW25JHLURws9Y8BmCnJNfoyHGXrZpRjs7ySK0FDmwn8yGxJXBNKfc8t8CiI cJNz56CHopbyX1JaMjGLGFEg2FpnT+gxh3IDhx88aGGAtZ8p5O15QO2uca9WBkAG/Q6xph4sL4M b17YRlm4g3Gk4rlxrlog2GrPdKjW8GglOYwCrukSmYdzzAY9xWAoqONqghILpi+mkIL7PPo9fNC KxugGt//vT1rFL8Q2jG/sfX1ePdXUQxZRIMPbqcTOwZI+sabgrQEL0at9engeN3pXW7ib8XYn7Q IyaBAcoFtL0BYs0VOkr1s0Z1fvHQwoVDs4qkTIOyoNXDgDvuv1wsu58svw2MeC54lbbswqS7QoB bgzdcTt8WF0XAwb4B3BjrjyZq7IGb2laiUdG5qZlwK61jBgrQ0widaWONDGkAdStQDE3QtxoiZV X-Received: by 2002:a05:693c:4084:b0:2ba:9115:2fab with SMTP id 5a478bee46e88-2bde1bb8214mr4781726eec.12.1772560924929; Tue, 03 Mar 2026 10:02:04 -0800 (PST) Received: from arch.guest.box.net ([8.39.49.136]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdfba0df2fsm9506612eec.7.2026.03.03.10.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2026 10:02:04 -0800 (PST) From: Milos Nikic To: jack@suse.cz Cc: tytso@mit.edu, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Milos Nikic Subject: [PATCH v4 2/2] jbd2: gracefully abort on transaction state corruptions Date: Tue, 3 Mar 2026 10:01:57 -0800 Message-ID: <20260303180157.53061-3-nikic.milos@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260303180157.53061-1-nikic.milos@gmail.com> References: <20260303180157.53061-1-nikic.milos@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" Auditing the jbd2 codebase reveals several legacy J_ASSERT calls that enforce internal state machine invariants (e.g., verifying jh->b_transaction or jh->b_next_transaction pointers). When these invariants are broken, the journal is in a corrupted state. However, triggering a fatal panic brings down the entire system for a localized filesystem error. This patch targets a specific class of these asserts: those residing inside functions that natively return integer error codes, booleans, or error pointers. It replaces the hard J_ASSERTs with WARN_ON_ONCE to capture the offending stack trace, safely drops any held locks, gracefully aborts the journal, and returns -EINVAL. This prevents a catastrophic kernel panic while ensuring the corrupted journal state is safely contained and upstream callers (like ext4 or ocfs2) can gracefully handle the aborted handle. Functions modified in fs/jbd2/transaction.c: - jbd2__journal_start() - do_get_write_access() - jbd2_journal_dirty_metadata() - jbd2_journal_forget() - jbd2_journal_try_to_free_buffers() - jbd2_journal_file_inode() Signed-off-by: Milos Nikic Reviewed-by: Andreas Dilger > Reviewed-by: Jan Kara Reviewed-by: Zhang Yi --- fs/jbd2/transaction.c | 112 ++++++++++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 26 deletions(-) diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 04d17a5f2a82..bae6c99d635c 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -474,7 +474,8 @@ handle_t *jbd2__journal_start(journal_t *journal, int n= blocks, int rsv_blocks, return ERR_PTR(-EROFS); =20 if (handle) { - J_ASSERT(handle->h_transaction->t_journal =3D=3D journal); + if (WARN_ON_ONCE(handle->h_transaction->t_journal !=3D journal)) + return ERR_PTR(-EINVAL); handle->h_ref++; return handle; } @@ -1036,7 +1037,13 @@ do_get_write_access(handle_t *handle, struct journal= _head *jh, */ if (!jh->b_transaction) { JBUFFER_TRACE(jh, "no transaction"); - J_ASSERT_JH(jh, !jh->b_next_transaction); + if (WARN_ON_ONCE(jh->b_next_transaction)) { + spin_unlock(&jh->b_state_lock); + unlock_buffer(bh); + error =3D -EINVAL; + jbd2_journal_abort(journal, error); + goto out; + } JBUFFER_TRACE(jh, "file as BJ_Reserved"); /* * Make sure all stores to jh (b_modified, b_frozen_data) are @@ -1069,13 +1076,27 @@ do_get_write_access(handle_t *handle, struct journa= l_head *jh, */ if (jh->b_frozen_data) { JBUFFER_TRACE(jh, "has frozen data"); - J_ASSERT_JH(jh, jh->b_next_transaction =3D=3D NULL); + if (WARN_ON_ONCE(jh->b_next_transaction)) { + spin_unlock(&jh->b_state_lock); + error =3D -EINVAL; + jbd2_journal_abort(journal, error); + goto out; + } goto attach_next; } =20 JBUFFER_TRACE(jh, "owned by older transaction"); - J_ASSERT_JH(jh, jh->b_next_transaction =3D=3D NULL); - J_ASSERT_JH(jh, jh->b_transaction =3D=3D journal->j_committing_transactio= n); + if (WARN_ON_ONCE(jh->b_next_transaction || + jh->b_transaction !=3D + journal->j_committing_transaction)) { + pr_err("JBD2: %s: assertion failure: b_next_transaction=3D%p b_transacti= on=3D%p j_committing_transaction=3D%p\n", + journal->j_devname, jh->b_next_transaction, + jh->b_transaction, journal->j_committing_transaction); + spin_unlock(&jh->b_state_lock); + error =3D -EINVAL; + jbd2_journal_abort(journal, error); + goto out; + } =20 /* * There is one case we have to be very careful about. If the @@ -1496,7 +1517,7 @@ void jbd2_buffer_abort_trigger(struct journal_head *j= h, int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh) { transaction_t *transaction =3D handle->h_transaction; - journal_t *journal; + journal_t *journal =3D transaction->t_journal; struct journal_head *jh; int ret =3D 0; =20 @@ -1520,8 +1541,14 @@ int jbd2_journal_dirty_metadata(handle_t *handle, st= ruct buffer_head *bh) if (data_race(jh->b_transaction !=3D transaction && jh->b_next_transaction !=3D transaction)) { spin_lock(&jh->b_state_lock); - J_ASSERT_JH(jh, jh->b_transaction =3D=3D transaction || - jh->b_next_transaction =3D=3D transaction); + if (WARN_ON_ONCE(jh->b_transaction !=3D transaction && + jh->b_next_transaction !=3D transaction)) { + pr_err("JBD2: %s: assertion failure: b_transaction=3D%p transaction=3D%= p b_next_transaction=3D%p\n", + journal->j_devname, jh->b_transaction, + transaction, jh->b_next_transaction); + ret =3D -EINVAL; + goto out_unlock_bh; + } spin_unlock(&jh->b_state_lock); } if (data_race(jh->b_modified =3D=3D 1)) { @@ -1531,13 +1558,15 @@ int jbd2_journal_dirty_metadata(handle_t *handle, s= truct buffer_head *bh) spin_lock(&jh->b_state_lock); if (jh->b_transaction =3D=3D transaction && jh->b_jlist !=3D BJ_Metadata) - pr_err("JBD2: assertion failure: h_type=3D%u " - "h_line_no=3D%u block_no=3D%llu jlist=3D%u\n", + pr_err("JBD2: assertion failure: h_type=3D%u h_line_no=3D%u block_no= =3D%llu jlist=3D%u\n", handle->h_type, handle->h_line_no, (unsigned long long) bh->b_blocknr, jh->b_jlist); - J_ASSERT_JH(jh, jh->b_transaction !=3D transaction || - jh->b_jlist =3D=3D BJ_Metadata); + if (WARN_ON_ONCE(jh->b_transaction =3D=3D transaction && + jh->b_jlist !=3D BJ_Metadata)) { + ret =3D -EINVAL; + goto out_unlock_bh; + } spin_unlock(&jh->b_state_lock); } goto out; @@ -1557,8 +1586,6 @@ int jbd2_journal_dirty_metadata(handle_t *handle, str= uct buffer_head *bh) goto out_unlock_bh; } =20 - journal =3D transaction->t_journal; - if (jh->b_modified =3D=3D 0) { /* * This buffer's got modified and becoming part @@ -1636,7 +1663,10 @@ int jbd2_journal_dirty_metadata(handle_t *handle, st= ruct buffer_head *bh) } =20 /* That test should have eliminated the following case: */ - J_ASSERT_JH(jh, jh->b_frozen_data =3D=3D NULL); + if (WARN_ON_ONCE(jh->b_frozen_data)) { + ret =3D -EINVAL; + goto out_unlock_bh; + } =20 JBUFFER_TRACE(jh, "file as BJ_Metadata"); spin_lock(&journal->j_list_lock); @@ -1675,6 +1705,7 @@ int jbd2_journal_forget(handle_t *handle, struct buff= er_head *bh) int err =3D 0; int was_modified =3D 0; int wait_for_writeback =3D 0; + int abort_journal =3D 0; =20 if (is_handle_aborted(handle)) return -EROFS; @@ -1708,7 +1739,11 @@ int jbd2_journal_forget(handle_t *handle, struct buf= fer_head *bh) jh->b_modified =3D 0; =20 if (jh->b_transaction =3D=3D transaction) { - J_ASSERT_JH(jh, !jh->b_frozen_data); + if (WARN_ON_ONCE(jh->b_frozen_data)) { + err =3D -EINVAL; + abort_journal =3D 1; + goto drop; + } =20 /* If we are forgetting a buffer which is already part * of this transaction, then we can just drop it from @@ -1747,8 +1782,11 @@ int jbd2_journal_forget(handle_t *handle, struct buf= fer_head *bh) } spin_unlock(&journal->j_list_lock); } else if (jh->b_transaction) { - J_ASSERT_JH(jh, (jh->b_transaction =3D=3D - journal->j_committing_transaction)); + if (WARN_ON_ONCE(jh->b_transaction !=3D journal->j_committing_transactio= n)) { + err =3D -EINVAL; + abort_journal =3D 1; + goto drop; + } /* However, if the buffer is still owned by a prior * (committing) transaction, we can't drop it yet... */ JBUFFER_TRACE(jh, "belongs to older transaction"); @@ -1766,7 +1804,11 @@ int jbd2_journal_forget(handle_t *handle, struct buf= fer_head *bh) jh->b_next_transaction =3D transaction; spin_unlock(&journal->j_list_lock); } else { - J_ASSERT(jh->b_next_transaction =3D=3D transaction); + if (WARN_ON_ONCE(jh->b_next_transaction !=3D transaction)) { + err =3D -EINVAL; + abort_journal =3D 1; + goto drop; + } =20 /* * only drop a reference if this transaction modified @@ -1812,6 +1854,8 @@ int jbd2_journal_forget(handle_t *handle, struct buff= er_head *bh) drop: __brelse(bh); spin_unlock(&jh->b_state_lock); + if (abort_journal) + jbd2_journal_abort(journal, err); if (wait_for_writeback) wait_on_buffer(bh); jbd2_journal_put_journal_head(jh); @@ -2136,7 +2180,8 @@ bool jbd2_journal_try_to_free_buffers(journal_t *jour= nal, struct folio *folio) struct buffer_head *bh; bool ret =3D false; =20 - J_ASSERT(folio_test_locked(folio)); + if (WARN_ON_ONCE(!folio_test_locked(folio))) + return false; =20 head =3D folio_buffers(folio); bh =3D head; @@ -2651,6 +2696,8 @@ static int jbd2_journal_file_inode(handle_t *handle, = struct jbd2_inode *jinode, { transaction_t *transaction =3D handle->h_transaction; journal_t *journal; + int err =3D 0; + int abort_transaction =3D 0; =20 if (is_handle_aborted(handle)) return -EROFS; @@ -2685,20 +2732,33 @@ static int jbd2_journal_file_inode(handle_t *handle= , struct jbd2_inode *jinode, /* On some different transaction's list - should be * the committing one */ if (jinode->i_transaction) { - J_ASSERT(jinode->i_next_transaction =3D=3D NULL); - J_ASSERT(jinode->i_transaction =3D=3D - journal->j_committing_transaction); + if (WARN_ON_ONCE(jinode->i_next_transaction || + jinode->i_transaction !=3D + journal->j_committing_transaction)) { + pr_err("JBD2: %s: assertion failure: i_next_transaction=3D%p i_transact= ion=3D%p j_committing_transaction=3D%p\n", + journal->j_devname, jinode->i_next_transaction, + jinode->i_transaction, + journal->j_committing_transaction); + err =3D -EINVAL; + abort_transaction =3D 1; + goto done; + } jinode->i_next_transaction =3D transaction; goto done; } /* Not on any transaction list... */ - J_ASSERT(!jinode->i_next_transaction); + if (WARN_ON_ONCE(jinode->i_next_transaction)) { + err =3D -EINVAL; + abort_transaction =3D 1; + goto done; + } jinode->i_transaction =3D transaction; list_add(&jinode->i_list, &transaction->t_inode_list); done: spin_unlock(&journal->j_list_lock); - - return 0; + if (abort_transaction) + jbd2_journal_abort(journal, err); + return err; } =20 int jbd2_journal_inode_ranged_write(handle_t *handle, --=20 2.53.0