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 326DF1D554 for ; Tue, 21 Jan 2025 12:19:26 +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=1737461966; cv=none; b=Vlydvi+q4cDw+qg1j0DktlDBH/KQ4C6xNybsEYN3uZ0XUFS4JqqbMLpJ4+8NxxFudL9+UxgEMgERiRKqu4qdxLSknDztQsUKWpipUYJ9F+PlK+k7Iy47LxgwO6T2+I05i36seisjDUbgIq7m2moFBsz6Uu78J4gcBcnIOc+QNVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737461966; c=relaxed/simple; bh=dlm8UtYeQp69ecOsnv0rROd5qkdg2+SbEXz23WaRaI4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IeXs0iLiDy8/GMaziQb3/rcnVe7XkR2f5wsf9sd0SLXynX9RvuqqLPZId7k/Pi1L9ywH/FLWY7uweEdCr/PEttorlrUDLlwNdIjgqL3et472Zys6bUnw7+rI8RsB2R1xNTxM4IFX0vZHLlRn8RmaGtOy+/E8oGrrrb+Swn2ptCQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Wtwb78jt; 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="Wtwb78jt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABFFFC4CEDF; Tue, 21 Jan 2025 12:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1737461966; bh=dlm8UtYeQp69ecOsnv0rROd5qkdg2+SbEXz23WaRaI4=; h=From:To:Cc:Subject:Date:Reply-to:From; b=Wtwb78jtVETrL874K8eEuEWtEjEdrPUC4sQTStP0ZOUf1B5d0vYZeenbdHlPiLC5O jHdN/RJj1TGof2WzrzsLrfWWCG+dgvSKAt3Y+PGVdcb8WgpyiE4A70h2O2P68LJNg4 wKUOMSRhEeJ3m0piIPokGGh5FDT7WdpyyfLI12Xg= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2025-21658: btrfs: avoid NULL pointer dereference if no valid extent tree Date: Tue, 21 Jan 2025 13:18:37 +0100 Message-ID: <2025012132-CVE-2025-21658-78d9@gregkh> X-Mailer: git-send-email 2.48.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=4073; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=dlm8UtYeQp69ecOsnv0rROd5qkdg2+SbEXz23WaRaI4=; b=owGbwMvMwCRo6H6F97bub03G02pJDOn9E2Zc4ZaaXtTJ+9J399UNJ1iP/92qEcO6g6V+YhDXD 7GMBf+9O2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiK4IZFpyULnspkrPq1Q6j KCbVaetS15j4xTDM4ZPLT1go3ev0ZOovSYH8mHM+N3nuAQA= 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: avoid NULL pointer dereference if no valid extent tree [BUG] Syzbot reported a crash with the following call trace: BTRFS info (device loop0): scrub: started on devid 1 BUG: kernel NULL pointer dereference, address: 0000000000000208 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 106e70067 P4D 106e70067 PUD 107143067 PMD 0 Oops: Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 1 UID: 0 PID: 689 Comm: repro Kdump: loaded Tainted: G O 6.13.0-rc4-custom+ #206 Tainted: [O]=OOT_MODULE Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS unknown 02/02/2022 RIP: 0010:find_first_extent_item+0x26/0x1f0 [btrfs] Call Trace: scrub_find_fill_first_stripe+0x13d/0x3b0 [btrfs] scrub_simple_mirror+0x175/0x260 [btrfs] scrub_stripe+0x5d4/0x6c0 [btrfs] scrub_chunk+0xbb/0x170 [btrfs] scrub_enumerate_chunks+0x2f4/0x5f0 [btrfs] btrfs_scrub_dev+0x240/0x600 [btrfs] btrfs_ioctl+0x1dc8/0x2fa0 [btrfs] ? do_sys_openat2+0xa5/0xf0 __x64_sys_ioctl+0x97/0xc0 do_syscall_64+0x4f/0x120 entry_SYSCALL_64_after_hwframe+0x76/0x7e [CAUSE] The reproducer is using a corrupted image where extent tree root is corrupted, thus forcing to use "rescue=all,ro" mount option to mount the image. Then it triggered a scrub, but since scrub relies on extent tree to find where the data/metadata extents are, scrub_find_fill_first_stripe() relies on an non-empty extent root. But unfortunately scrub_find_fill_first_stripe() doesn't really expect an NULL pointer for extent root, it use extent_root to grab fs_info and triggered a NULL pointer dereference. [FIX] Add an extra check for a valid extent root at the beginning of scrub_find_fill_first_stripe(). The new error path is introduced by 42437a6386ff ("btrfs: introduce mount option rescue=ignorebadroots"), but that's pretty old, and later commit b979547513ff ("btrfs: scrub: introduce helper to find and fill sector info for a scrub_stripe") changed how we do scrub. So for kernels older than 6.6, the fix will need manual backport. The Linux kernel CVE team has assigned CVE-2025-21658 to this issue. Affected and fixed versions =========================== Issue introduced in 5.11 with commit 42437a6386ffeaaf200731e73d723ea491f3fe7d and fixed in 6.6.72 with commit 24b85a8b0310e0144da9ab30be42e87e6476638a Issue introduced in 5.11 with commit 42437a6386ffeaaf200731e73d723ea491f3fe7d and fixed in 6.12.10 with commit aee5f69f3e6cd82bfefaca1b70b40b6cd8f3f784 Issue introduced in 5.11 with commit 42437a6386ffeaaf200731e73d723ea491f3fe7d and fixed in 6.13 with commit 6aecd91a5c5b68939cf4169e32bc49f3cd2dd329 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-2025-21658 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/scrub.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/24b85a8b0310e0144da9ab30be42e87e6476638a https://git.kernel.org/stable/c/aee5f69f3e6cd82bfefaca1b70b40b6cd8f3f784 https://git.kernel.org/stable/c/6aecd91a5c5b68939cf4169e32bc49f3cd2dd329