From nobody Tue Mar 3 03:21:04 2026 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 9269E382364 for ; Mon, 2 Mar 2026 21:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487276; cv=none; b=IV2bJXHfg/pBz6GWz0uXLoN9N6s7lBEnYsIj7xNCtJIIZkC5cS8AeK1RylwaU7KeaqD7D6/i4gSvdCw8RlUNB7HN7LPMqWgHOd8fqesNY6SrjetcBNwWee3JMY9v8ieW/o8VcgybGpP2iBGkj3fzSO2+z+L90Youhwr5KrpArIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487276; c=relaxed/simple; bh=VTv6p9V1KuY3NuOQ/g19x6YUh6QjpeorFmtw98a94Do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qu6nE7j6jIRNX7Xoem7NsaOxlfLKuKk2TnEv7rjrPBR/ikA2cDvXWrV2J7F5SSBZFVWnk79nc2spbmbCl19+QEpno3x6YvUX4ReFHrahPfDALEhbotkNoMU2R2F05W+6yy8V/4Mrnk4Bjjqjc+9nKqfrUaiAGHuh2Gpy/BCvWuI= 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=F4TeNGza; arc=none smtp.client-ip=74.125.82.170 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="F4TeNGza" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-2be1ab1fa7dso594750eec.0 for ; Mon, 02 Mar 2026 13:34:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772487275; x=1773092075; 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=dex6BTSk/FD4IJdE9hg782BTunzN70oc+BYZl89/r7o=; b=F4TeNGzaP+0QRL5KFTTu8RSVBaeFeELUm9vGR+zBmAiw3ntAgPpG4C3L7GhI8eIOIu hOf4EYMHZGlr+3VRRYqV6P2+aKgv6yjJwD3/gAu/5cUb9v7lmA7iOjJRVHANrKVgQV6l Ln9sdjor9qOIlwhp230/iEhntiOcMEBFgb3KqFoGKZD/fDskKxZjQ++clvSoDMQb5fuE o0zCBcdk4PgsFO5bgwK1eauGIL4N2ZZi/yyLDUEskK/fSMLPMkPgbCA8dpqShrVS6yK+ St0xz4EBbhGvkFI2IaXA9HxTRNOzV85zPiy/IVrcy4k1lQiTVuBCXUlGZmaW7uHykc2p ATeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772487275; x=1773092075; 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=dex6BTSk/FD4IJdE9hg782BTunzN70oc+BYZl89/r7o=; b=NVGhBMTgojduira0QhgPXPdrSctq0tJBdOFk+GRcBxOgnLJYjP/fSi/qAxw6OGPnRq hAuZVH+nnX+5n32JPjgQpHBwv04VtXXT90XIh3DjyliaBDwA6a/DEg5jWKMNgVJ/Nbhp YqeH5T2qUe8EOGxHbC8REBEz74gTcw1gKCkGujnOqRwGKkKeaQ5Vph+MWczC1qu3T0UF Di8y9rDFuN3k+91xt50Ba3Bp+GIzYZmDC1ofpHvztdQX6y3DhJSnV+m96LWFP/ZLFlTB WHcTtK5N/0nNpfQrUTRbY+vqnfaew4uOb9GZFZFwhCg4reDMDY9GHqx03FgkK1neCM66 GYqg== X-Forwarded-Encrypted: i=1; AJvYcCUuuAsAxFmXPwKAluqjr+D23a1iOntPmqatJfue+dqErO0gu0XEbNyj1MoNF/s4BXXjWNTQZcf5TCeymBA=@vger.kernel.org X-Gm-Message-State: AOJu0YwfmkqWNXzowCnoTuq2e29s547LG1svhexpzykB8BZookkthaQS mQ7nLxsk5aJX+SH6LKUhTsiEQp1HC8sgX2DDRK47VllImrk/nDugSU/O X-Gm-Gg: ATEYQzz07umXVwP3NZDlcs8ZTnecftSVMmT/2ZIYGpNnlW41fdTNDU53U//FUQT7VEt ZA65VuQNbAOir5KWhcPKYjsZwsKzzQfoxkgAoonsf5NwR0F6bl+8B+OcdYZJ+XblLNX3ZbC+83C X7cfGv7M+d2DPvWFJOA+ZNxDLOedZNznnn45NIuNTkXATfuIGTE8Dx+RKMjoYIUKFP/DVZpF90s m2EjDXl7NKYHZAD4BbOzoEtUeXIqlmT5SmoSHJTdbf4jhWQOAWWyzIZ496dmSFEFtK/wc5Ez+GZ kfei0YR8VFITIBEDzG2A0VyGaV6cRSkQLSH3qGBcARg2qt70fTFINU3XT5bafYhblsM/nwHFgVs +YvUjofeIG+YWQ4wExPKprfJuKYoq/3SPRAu9vcnikkBC9+CAewzc0Ht+e8+SeTqhcD3xi3Za5g RwdF2q+ow7pls8upEWIFT4VoQLxkQCWo+8diREEd/aO6xVj2rzcd11WT1xIFR+lecIbIEQn05kl PU626/ODaC061MO6baEdei7SK7rY+9WjRulN6nVfs1LVBHdelR2VOetSLS4x88BuLNBgrX1al9W aQx5SXLPi2elUjGBVRLnCnIOdNPadd5d70G7bSA= X-Received: by 2002:a05:7022:4381:b0:11a:51f9:daf with SMTP id a92af1059eb24-1278fc56a82mr7378968c88.14.1772487274540; Mon, 02 Mar 2026 13:34:34 -0800 (PST) Received: from arch.lan (c-98-51-119-100.hsd1.ca.comcast.net. [98.51.119.100]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12789a52ab0sm20032605c88.15.2026.03.02.13.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 13:34:34 -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 Subject: [PATCH v2 1/2] jbd2: gracefully abort instead of panicking on unlocked buffer Date: Mon, 2 Mar 2026 13:34:24 -0800 Message-ID: <20260302213425.273187-2-nikic.milos@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302213425.273187-1-nikic.milos@gmail.com> References: <20260302213425.273187-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 --- 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 Tue Mar 3 03:21:04 2026 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (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 4A46E38238C for ; Mon, 2 Mar 2026 21:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487280; cv=none; b=YTIhcThGJ4QCsHpeVa5sP87IFHzPEP5Ah1+DGXMxoH9Tb10uQeiRRtTnVj/L4j4Y7y3mxpKuI8r6W63R+eB94Y0L8QwwFqlMjo0KaKlP7CuZLIn0F669By8PeFLz5E4FBPyKdkW3TRyq6FXARykDyXH5ff9GTiYudUOoHcqld6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487280; c=relaxed/simple; bh=2w4NYmNXC6W52+BIHCjdUycts2WYUcggQH+JBNiF3n8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gdfHd2niFTZeIR0NaEn8LCR+egv9+UoL2CakbTg43P0+3QHuwcg1TRyURcBRRe+iQGes6PcnfmymgJUMizr9tHjN4rI0C12cD+n97/BF9phkKYtXMCtGdmlpIxrDz9zr3YBNRkuYGZkRrVuI49Ir5b3f+zRXbZF5cGcvQ3wHD/o= 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=gr5HHC1x; arc=none smtp.client-ip=74.125.82.45 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="gr5HHC1x" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-12713e56abdso2979719c88.1 for ; Mon, 02 Mar 2026 13:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772487278; x=1773092078; 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=MWiykqLPzQ0xTr9Kr/6ehg+AMSjO73dUzFgcIu/BQ7Q=; b=gr5HHC1x3VJoLIRJ2IRTbXmgJJSE9n/S4H1nau267HZydpHJLIl/S315Dd1C1R5O8p HQHTrCFU+87nQgZGR6vOvFq/Kmr1GHxSdoqaWSlRNfi/9cXTEFs6tmDpuLX5kwJhRzWS C5vQaw8iBSdkXLiF84D0FU60QSTGyXK7qPu4WpP29By89cY9T1VSwFAbTr6o+drMLYiK YwS0LP36YVg3ndOOYxdSD4nl8eD4quDxXAKPF1MFc1SU6M6ht5SHyV8FFYqR8VwzkgNN ZjOC3OrNkyIdGPkMnHCulTmw8Ek3TaHCaBjC4d+KowxKn5H9RjS6isTmXpmKu5kIQFVH kM8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772487278; x=1773092078; 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=MWiykqLPzQ0xTr9Kr/6ehg+AMSjO73dUzFgcIu/BQ7Q=; b=qZh8WeWjk5Rgu7tl2LSIkwxhnQ7TZFqpWxJ1pqqi29VP3g8ntDZAw9MVfS70UFIRZg HAJzR334uxtOOHdkXdhTTSQd57ad6VsFY2jLxDquYMbgzqWB2tlGSqaf+ufjsRfF7Nck SOrM+/lqxPeGNuInqeBLGRGT/YkGh4giwLAvhhbUwiqH4ef5qVSEpWM0XwMy4gqyAESD SW7UBnTVtlyTUlLGkH5Pf0jF+OBa3AVoApwX3Lx2cOJEpWwTNm+LUdouX6VRce8PFIzB 7R0tg6rNF7pP3RDD0CYVR1OYehz8svkxTAazyB2Xo9DFZ+6SyAhzAT5UbFBzR1pp6uwv ZOJg== X-Forwarded-Encrypted: i=1; AJvYcCWP6Gu17NR43v8ROtLdcu+wafhC6m8s5zPRnTQ6VFA/ly8B2TiYklvoe0gxREXaLZxuIBmjzwyNUsry/Pk=@vger.kernel.org X-Gm-Message-State: AOJu0YwNvSp63u4ms9t29xotPo0w1wVhVICyULfYU5E1Q9vfdfEgScEw SCkXhMpMBC0Cb5xY4KTisXUa1F0j8mMLJCnXDgVRuwKknO8lGqWsMK6L X-Gm-Gg: ATEYQzwqUP3QRqpQ5gwAEZw+FvQZdb5cC1N5xEND9WEwHnZ9O08oa9ZgPtnEs3Gc8vt NpqdXrRRSHUDPxvlknpMfQtEinL5sesMfeUxtqIX2cdwi+zVlPOI/hFsR0Xsh7RiQ28VT/v4M1w +sTwDqonFsdULavKTmgt5BZJj2mWarWDL2JXgYBTomNLKXOYu+r+36q1rgQiB9hE4wTey2Gqltl nT3AB5ScunrFUeXNTFYTy13TZ5PFIjipeAtwEwnXXrGPRL2UHqdVzjPBRZYMgyYAkmOQvCUkG+Z fUc0Jz4cbIGTa2lgfMH/jREPLHpEGIPtft2UOgIFbl09Tp5pjG/1JIl4rWtwqDzCnjqnK2Kp4pU c8YeOPZJVFbOl6YO5FZTcFQ6LXTAMdsLKhPrxsZ7kI0cTCV/EBmo+n8L/FyIZyGvcS+gV7ld8oE qDYDuylGz0lT/MSAb2s56KkuuO5MjWyyDPFIkqVNmAWWaW6OJuTT8x4GzE5gX6s9yKzFvVEdMWd 0gy1QxPQdXHgyDCwnY9ekWIZ4sQXzfsxcrP1sft35H4bLaRrLNgCN3LDhtp0ReckcQ+glWAnw1G VMAhZTAHxsAJPEnvyjCGHWr97j4O X-Received: by 2002:a05:7022:ba0:b0:119:e569:f86c with SMTP id a92af1059eb24-1278f79f1fcmr5552563c88.9.1772487278309; Mon, 02 Mar 2026 13:34:38 -0800 (PST) Received: from arch.lan (c-98-51-119-100.hsd1.ca.comcast.net. [98.51.119.100]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12789a52ab0sm20032605c88.15.2026.03.02.13.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 13:34:37 -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 v2 2/2] jbd2: gracefully abort on transaction state corruptions Date: Mon, 2 Mar 2026 13:34:25 -0800 Message-ID: <20260302213425.273187-3-nikic.milos@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302213425.273187-1-nikic.milos@gmail.com> References: <20260302213425.273187-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 > --- fs/jbd2/transaction.c | 95 +++++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 21 deletions(-) diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 04d17a5f2a82..85e9338ed999 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,24 @@ 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)) { + 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 @@ -1520,8 +1538,11 @@ 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)) { + ret =3D -EINVAL; + goto out_unlock_bh; + } spin_unlock(&jh->b_state_lock); } if (data_race(jh->b_modified =3D=3D 1)) { @@ -1536,8 +1557,11 @@ int jbd2_journal_dirty_metadata(handle_t *handle, st= ruct buffer_head *bh) 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; @@ -1636,7 +1660,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 +1702,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 +1736,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 +1779,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 +1801,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 +1851,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 +2177,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 +2693,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 +2729,29 @@ 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)) { + 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