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 0C4A369D2B for ; Mon, 6 Jan 2025 16:21:11 +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=1736180473; cv=none; b=WmVKJAftvFNANAbH07oEUKYyUPy2i63qNaxy7HzFTkr+MnobOb5uHooyK3YypcUIKwYBV1DPD9rtOtrkqTG0ZkU6FDmfd3OEABuc46xnjx4NGBzUjvGyJD6sE7MOp9Y9G36M174uYrNoLfZ2+yoh1bE1uaHtpJyrs5x6fsqBtyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736180473; c=relaxed/simple; bh=mKEIXvGe3TaixWN+Gkjh5cPmk7vxYtJJ102NrNhyAo8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lu17qqlxjloiY5utjOPv53cn/aNOsC7R1lNHYZPOmiErUpJu8rpaTsV8zuGmOmNI+yYlMdJkMyH7kFPg5dnNeIwHOPUU4mKWzdXmn8lqdK6fjIDg5dJ6+wWcSZbZT2Hi4izOeNBDCiEzCM88Wv3I+cGZma3gNpfBqbmg6sZbJwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=l8dyW774; 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="l8dyW774" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34DEDC4CED2; Mon, 6 Jan 2025 16:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736180471; bh=mKEIXvGe3TaixWN+Gkjh5cPmk7vxYtJJ102NrNhyAo8=; h=From:To:Cc:Subject:Date:Reply-to:From; b=l8dyW774mgcYPFzoDKHTS7zQTeWMgIU71Hb6L05kjhmOhxt/1Cl7pk20PnS8vd6sA 8R/hlhPxAFG11fDiTPv0Vqhsq0LDe7bI5EjSaSn4TGm3ZTRTsb1MjO4IvdUnggtIiu Jdm/86D8enbtZ+KulwoUSTMAucNGvmBvevDpJ19M= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-56758: btrfs: check folio mapping after unlock in relocate_one_folio() Date: Mon, 6 Jan 2025 17:20:52 +0100 Message-ID: <2025010653-CVE-2024-56758-eeb6@gregkh> X-Mailer: git-send-email 2.47.1 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=4597; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=mKEIXvGe3TaixWN+Gkjh5cPmk7vxYtJJ102NrNhyAo8=; b=owGbwMvMwCRo6H6F97bub03G02pJDOk1TE/ZH8/9n1i5Sv+R3dwre323b7U4sZxvq+3JlKijx Tf/c3xs6YhlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJvNzKsODS2oiwU0byy51+ x7zaGOvxaeWEeA6GuTLfJrya4Vv0Y2KC2xS9lpurcjMf/wQA 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: check folio mapping after unlock in relocate_one_folio() When we call btrfs_read_folio() to bring a folio uptodate, we unlock the folio. The result of that is that a different thread can modify the mapping (like remove it with invalidate) before we call folio_lock(). This results in an invalid page and we need to try again. In particular, if we are relocating concurrently with aborting a transaction, this can result in a crash like the following: BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD 0 P4D 0 Oops: 0000 [#1] SMP CPU: 76 PID: 1411631 Comm: kworker/u322:5 Workqueue: events_unbound btrfs_reclaim_bgs_work RIP: 0010:set_page_extent_mapped+0x20/0xb0 RSP: 0018:ffffc900516a7be8 EFLAGS: 00010246 RAX: ffffea009e851d08 RBX: ffffea009e0b1880 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffc900516a7b90 RDI: ffffea009e0b1880 RBP: 0000000003573000 R08: 0000000000000001 R09: ffff88c07fd2f3f0 R10: 0000000000000000 R11: 0000194754b575be R12: 0000000003572000 R13: 0000000003572fff R14: 0000000000100cca R15: 0000000005582fff FS: 0000000000000000(0000) GS:ffff88c07fd00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 000000407d00f002 CR4: 00000000007706f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: ? __die+0x78/0xc0 ? page_fault_oops+0x2a8/0x3a0 ? __switch_to+0x133/0x530 ? wq_worker_running+0xa/0x40 ? exc_page_fault+0x63/0x130 ? asm_exc_page_fault+0x22/0x30 ? set_page_extent_mapped+0x20/0xb0 relocate_file_extent_cluster+0x1a7/0x940 relocate_data_extent+0xaf/0x120 relocate_block_group+0x20f/0x480 btrfs_relocate_block_group+0x152/0x320 btrfs_relocate_chunk+0x3d/0x120 btrfs_reclaim_bgs_work+0x2ae/0x4e0 process_scheduled_works+0x184/0x370 worker_thread+0xc6/0x3e0 ? blk_add_timer+0xb0/0xb0 kthread+0xae/0xe0 ? flush_tlb_kernel_range+0x90/0x90 ret_from_fork+0x2f/0x40 ? flush_tlb_kernel_range+0x90/0x90 ret_from_fork_asm+0x11/0x20 This occurs because cleanup_one_transaction() calls destroy_delalloc_inodes() which calls invalidate_inode_pages2() which takes the folio_lock before setting mapping to NULL. We fail to check this, and subsequently call set_extent_mapping(), which assumes that mapping != NULL (in fact it asserts that in debug mode) Note that the "fixes" patch here is not the one that introduced the race (the very first iteration of this code from 2009) but a more recent change that made this particular crash happen in practice. The Linux kernel CVE team has assigned CVE-2024-56758 to this issue. Affected and fixed versions =========================== Issue introduced in 6.6 with commit e7f1326cc24e22b38afc3acd328480a1183f9e79 and fixed in 6.12.8 with commit d508e56270389b3a16f5b3cf247f4eb1bbad1578 Issue introduced in 6.6 with commit e7f1326cc24e22b38afc3acd328480a1183f9e79 and fixed in 6.13-rc5 with commit 3e74859ee35edc33a022c3f3971df066ea0ca6b9 Issue introduced in 6.1.54 with commit 08daa38ca212d87f77beae839bc9be71079c7abf Issue introduced in 6.5.4 with commit 9d1e020ed9649cf140fcfafd052cfdcce9e9d67d 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-56758 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/relocation.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/d508e56270389b3a16f5b3cf247f4eb1bbad1578 https://git.kernel.org/stable/c/3e74859ee35edc33a022c3f3971df066ea0ca6b9