From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796389099; b=GcE+qSr+Wh5yixROCvcF1AgQbgQiCq453VjkI0Jmop3qFRAF1i9PVhNy4UzBLPKFRw9A qUnReam4g6vfGqrXuuLDhfxIM2yFKB2jbqdPiuegtZCggdgINT60kf9vydfJFbKp1h4ji XUYa3JkJMBHXDkb0SuaHiDqEFA8owK/MQv0z8KTdMP1UyCae3Om5SAuentsPeYARYb97E 5RdFYqgosQB6R84amN6FEG9KlMJP6oeSme2HtWLOPHIXzAJQ8hcdltKfJ93w0rM1pZBn9 epQsOOk5Co68tBTybVu5qL0yWq0a0BmlglERx0QiH21KN0pV3obCB1OqD6eQdUQrLQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389099; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=qk5nKZza3+NoEE4RHv0qiTFI0WwDB1yxDE28B8YtqFI=; b=Nqz2q87wQGpfH8v51lPBpwWRgzsB6Q8Gs+HY6/UMf/N60BJIE7kUHMuUzzrkkfMV6Oib Z30xAmM3jJhVF12w9ds21+utsw4VE5QcVb47+okTKvDjMlHT3uT7VFaEm9/wWKfsaZs04 xlSh5GLk7p9tbVWFQ0LzsJUIgknQ7gIHJaJp8IYQedPRGMz+i+ohSAwjFbkhKjSSX/2IZ 8Z0XVNXZBvACDjo+GIvuYhNa+Bp6eFkkgdPwdGfFPlxTUDGCPNJVQRMo6i+8Zwy4nGh19 uKuN+iOhUDB+NVE6LeDnvhnCrxZ8jlQLu/BslpDy+vQr3GQGkLcuHlUjJVDHrloX66Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vxi8inhY; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21DAC606A32F; Fri, 4 Dec 2026 12:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vxi8inhY Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B1C01F00897; Fri, 4 Dec 2026 12:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389098; bh=qk5nKZza3+NoEE4RHv0qiTFI0WwDB1yxDE28B8YtqFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vxi8inhYU41/BDXRRIh1Z/gWS3+l5AgArOJBWAAcaueMzSheQ470mHNWafY1i7aaP 15XRD0HFqB33dpRhS27gQyr4x6yPVJh9suA2ATstpinypFUy7laMA598GRdJtyE1+l 0JL9zvJj0/h1v56N/nFuHG1nq71GHgplk63tuhYY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Christian=20G=C3=B6ttsche?= , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 6.1 0865/1059] jbd2: set JBD2_LOADED under j_state_lock Date: Fri, 4 Dec 2026 19:06:36 +0900 Message-ID: <20261204100706.427787887@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Göttsche [ Upstream commit 40e53dad45a92e932156de23a69c991f3e2512c9 ] j_flags is protected by j_state_lock, with only quick racy checks done without it. jbd2_journal_load() however sets JBD2_LOADED with a plain read-modify-write after journal_reset() has already started kjournald2, which tests and may update j_flags under the lock. KCSAN reports this while mounting the root file system: BUG: KCSAN: data-race in jbd2_journal_load / kjournald2 write to 0xffff9c6b012c6000 of 8 bytes by task 1 on cpu 3: jbd2_journal_load+0x279/0x3c0 ext4_fill_super+0x34dc/0x5740 get_tree_bdev_flags+0x21d/0x340 ... read to 0xffff9c6b012c6000 of 8 bytes by task 77 on cpu 0: kjournald2+0xc8/0x3e0 kthread+0x1bd/0x200 ... value changed: 0x00000000000000a8 -> 0x00000000000000b8 A concurrent update of another flag, e.g. JBD2_ABORT, could be lost. Take j_state_lock when setting JBD2_LOADED, like the other writers of j_flags do. Fixes: 470decc613ab ("[PATCH] jbd2: initial copy of files from jbd") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Christian Göttsche Reviewed-by: Jan Kara Link: https://patch.msgid.link/20260928202159.2463182-1-cgoettsche@seltendoof.de Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/jbd2/journal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 4d26457f2e906..36c940001249e 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -2117,7 +2117,10 @@ int jbd2_journal_load(journal_t *journal) if (journal_reset(journal)) goto recovery_error; + /* kjournald2 is already running, see journal_reset(). */ + write_lock(&journal->j_state_lock); journal->j_flags |= JBD2_LOADED; + write_unlock(&journal->j_state_lock); return 0; recovery_error: -- 2.53.0