Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03F7510E3 for ; Tue, 30 Jul 2024 07:48:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722325715; cv=none; b=FoRTdy5LrOYL/+/14xK6Pj6P1oRUe2mTTlzVXfqd5e5Hdv4Dm02bG8n7k2UMeZgWait/cQAEYLUhVI2p21POGfhuo5HZMOc7/fwFhtRd2E8j7RgW1hzce8B8/u+3qUv29Ev/r4U3FliOTlyYyX6oCneDyBT3gTlhyuU/W3DXII0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722325715; c=relaxed/simple; bh=Vw52Dvy/In8aCkPimb1GTz+Fu74hF0vKrFk5w/FNcnY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=K/STrfmRBp8B/1WTw+/9yXhNo8uRbaqZKZPV2lHO9zsX6qKoL2yyWbNMhWwbWEk7cCvEiD3O06Lj432t3A98ONRT56+BKIGgZ8VtivBLof5DXavfdm3zSarwVpilDT/eNXGhMREemUsPDUKdgEx2ndgqmVP5Oa8aB6WryuUMpbA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nDJnXaBF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="nDJnXaBF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 242F9C4AF0B; Tue, 30 Jul 2024 07:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722325714; bh=Vw52Dvy/In8aCkPimb1GTz+Fu74hF0vKrFk5w/FNcnY=; h=From:To:Cc:Subject:Date:Reply-to:From; b=nDJnXaBFl8AuHCKWV8XVqXxaJz13327B7GsuyKO5EtUvItTQNa/Ouy93F/VIQ7UWj GWWvJFRjnRPeLZuLB7f/4Vf1+H2nlAz8c2COH0G5kV6VB//AsPIXCnzuLKReyqw84a HI9YUvcUkQThwGbzypo8MIGMV7d/73VtRAzyukuA= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-42103: btrfs: fix adding block group to a reclaim list and the unused list during reclaim Date: Tue, 30 Jul 2024 09:47:21 +0200 Message-ID: <2024073019-CVE-2024-42103-9e8c@gregkh> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=5987; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=Vw52Dvy/In8aCkPimb1GTz+Fu74hF0vKrFk5w/FNcnY=; b=owGbwMvMwCRo6H6F97bub03G02pJDGkrZrWftBbZwSVmMWNifdcTyRaZNyG3jysoT7efdGmJ/ slZd+PedcSyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEkk4wzM+5uWqy39ntQQ7p veF5G2Zsf5m8fgnDgknsr/86h66bkeduN6/p7eqFp7KusAEA X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: btrfs: fix adding block group to a reclaim list and the unused list during reclaim There is a potential parallel list adding for retrying in btrfs_reclaim_bgs_work and adding to the unused list. Since the block group is removed from the reclaim list and it is on a relocation work, it can be added into the unused list in parallel. When that happens, adding it to the reclaim list will corrupt the list head and trigger list corruption like below. Fix it by taking fs_info->unused_bgs_lock. [177.504][T2585409] BTRFS error (device nullb1): error relocating ch= unk 2415919104 [177.514][T2585409] list_del corruption. next->prev should be ff1100= 0344b119c0, but was ff11000377e87c70. (next=3Dff110002390cd9c0) [177.529][T2585409] ------------[ cut here ]------------ [177.537][T2585409] kernel BUG at lib/list_debug.c:65! [177.545][T2585409] Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN NOPTI [177.555][T2585409] CPU: 9 PID: 2585409 Comm: kworker/u128:2 Tainted: G W 6.10.0-rc5-kts #1 [177.568][T2585409] Hardware name: Supermicro SYS-520P-WTR/X12SPW-TF, BIOS 1.2 02/14/2022 [177.579][T2585409] Workqueue: events_unbound btrfs_reclaim_bgs_work[btrfs] [177.589][T2585409] RIP: 0010:__list_del_entry_valid_or_report.cold+0x70/0x72 [177.624][T2585409] RSP: 0018:ff11000377e87a70 EFLAGS: 00010286 [177.633][T2585409] RAX: 000000000000006d RBX: ff11000344b119c0 RCX:0000000000000000 [177.644][T2585409] RDX: 000000000000006d RSI: 0000000000000008 RDI:ffe21c006efd0f40 [177.655][T2585409] RBP: ff110002e0509f78 R08: 0000000000000001 R09:ffe21c006efd0f08 [177.665][T2585409] R10: ff11000377e87847 R11: 0000000000000000 R12:ff110002390cd9c0 [177.676][T2585409] R13: ff11000344b119c0 R14: ff110002e0508000 R15:dffffc0000000000 [177.687][T2585409] FS: 0000000000000000(0000) GS:ff11000fec880000(0000) knlGS:0000000000000000 [177.700][T2585409] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [177.709][T2585409] CR2: 00007f06bc7b1978 CR3: 0000001021e86005 CR4:0000000000771ef0 [177.720][T2585409] DR0: 0000000000000000 DR1: 0000000000000000 DR2:0000000000000000 [177.731][T2585409] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7:0000000000000400 [177.742][T2585409] PKRU: 55555554 [177.748][T2585409] Call Trace: [177.753][T2585409] [177.759][T2585409] ? __die_body.cold+0x19/0x27 [177.766][T2585409] ? die+0x2e/0x50 [177.772][T2585409] ? do_trap+0x1ea/0x2d0 [177.779][T2585409] ? __list_del_entry_valid_or_report.cold+0x70/0x72 [177.788][T2585409] ? do_error_trap+0xa3/0x160 [177.795][T2585409] ? __list_del_entry_valid_or_report.cold+0x70/0x72 [177.805][T2585409] ? handle_invalid_op+0x2c/0x40 [177.812][T2585409] ? __list_del_entry_valid_or_report.cold+0x70/0x72 [177.820][T2585409] ? exc_invalid_op+0x2d/0x40 [177.827][T2585409] ? asm_exc_invalid_op+0x1a/0x20 [177.834][T2585409] ? __list_del_entry_valid_or_report.cold+0x70/0x72 [177.843][T2585409] btrfs_delete_unused_bgs+0x3d9/0x14c0 [btrfs] There is a similar retry_list code in btrfs_delete_unused_bgs(), but it is safe, AFAICS. Since the block group was in the unused list, the used bytes should be 0 when it was added to the unused list. Then, it checks block_group->{used,reserved,pinned} are still 0 under the block_group->lock. So, they should be still eligible for the unused list, not the reclaim list. The reason it is safe there it's because because we're holding space_info->groups_sem in write mode. That means no other task can allocate from the block group, so while we are at deleted_unused_bgs() it's not possible for other tasks to allocate and deallocate extents from the block group, so it can't be added to the unused list or the reclaim list by anyone else. The bug can be reproduced by btrfs/166 after a few rounds. In practice this can be hit when relocation cannot find more chunk space and ends with ENOSPC. The Linux kernel CVE team has assigned CVE-2024-42103 to this issue. Affected and fixed versions =========================== Issue introduced in 5.15.162 with commit 2311fd03027d and fixed in 5.15.163 with commit 522b39bd7163 Issue introduced in 6.1.96 with commit 15cb476ceb7d and fixed in 6.1.98 with commit aa1d8cc0cc50 Issue introduced in 6.6.36 with commit bf1e8c21f2be and fixed in 6.6.39 with commit f8e960be923f Issue introduced in 6.9.7 with commit ab58fe210c40 and fixed in 6.9.9 with commit 326fa14549d7 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2024-42103 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: fs/btrfs/block-group.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/522b39bd7163e8dc49f8cf10b9b782218ac48746 https://git.kernel.org/stable/c/aa1d8cc0cc500e06b316cd6732d4e6c1388fe33c https://git.kernel.org/stable/c/f8e960be923f74a273c62478c9cab9523936752b https://git.kernel.org/stable/c/326fa14549d7969ef80d3f5beea5470cd1c8e67f https://git.kernel.org/stable/c/48f091fd50b2eb33ae5eaea9ed3c4f81603acf38