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=1796382000; b=PhQew0EF+P1GjPcS5tqGS9HlKnp6nLc0ady4CQCrf/+mvv0BIVCYsUAxBzU7xNZ6z0Ye 5q3QcEvpE+h35tkq9Wj23RN0IZC5ZWTtw4pwiik9+UmKUras+eHKtreIibpMDdStxV3U7 KxxRIyPDOtSaCFjafwQDE1tSvLeghzkxn4/KDOX3HKdKV2uYSs8Oic/bGRwO5Zt/8HeCM 4xtedw2XdBoYUB2JE9zYgDCOVil2XKOBo9NP5m6AJGOm4p9V5Ox9YP3CRk+o+vegJbA7w erYBDykff5JOPzaAZduuBQZX2AUdjfinYNzI6KTWKsfBNTeM9Aas1RPOAEuD/CkSu5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382000; 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=lhOAw17r/y958pIRVJG2pMKtP38NWDKUrIFwGrbwUkM=; b=Kh0CbLQcPdOKdPOsv7aOWvns3chMb5rSLekmbQEZK87IYdm07ODOgOputMfT7up9oabL 5S7tfOzlwoJ9iR+BYw9ZEDXhsoILu0J4n32l9gcfYiCu8jPj11GU+P19ihJKgSjlbbOKg WPiDp9+jDGa6/ISHxaf3Wheet54B5BPY6GetSmlXQUYCEnEcgtVK5P1nPrgrrbxtec1Gz Mfk+TXb28gDuWyTEitvu1HAmfbMExnC6xL6F9Tk8SwEyMcPCGLakGCIBdCMezVLZUlzlb FNZYC2X6K6ntW0JTJXcJd10CbxZmFsXwoOy2sTl2gkcJAzTiAs81l057y5UI+Lgvy3A== 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="UTWo/9ca"; 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 4F87E606A32C; Fri, 4 Dec 2026 11:00:00 +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=UTWo/9ca Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8EC51F00939; Fri, 4 Dec 2026 10:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382000; bh=lhOAw17r/y958pIRVJG2pMKtP38NWDKUrIFwGrbwUkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UTWo/9cafHalDOFmwhfP/mv/8hePvoG7aTHfbndeq56RY++w7fGcRO4H21hRHvDW0 YxvPoKG8pN+yvQFe4ZZ4fXky5SfGUwxDQhpHbh9UkvN0nVm5Lz1nO7x665M9iXlCeh 1CnzVG5zZRPBZR5zUEWi1DxW3Xoc85ErslacX61U= 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.18 264/703] jbd2: set JBD2_LOADED under j_state_lock Date: Fri, 4 Dec 2026 19:02:43 +0900 Message-ID: <20261204100634.809510401@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 1184dbad43e57..ae6eebe40c9de 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -2102,7 +2102,10 @@ int jbd2_journal_load(journal_t *journal) return err; } + /* 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; } -- 2.53.0