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 3427916CD0A for ; Wed, 21 Aug 2024 06:12:55 +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=1724220775; cv=none; b=GLVOagt8WqoovKurMoiI477WkLAjAu8IdclnefrYH9Y7o/kZScFA6WqRnUlfKDhNBq11g4q+bNHmv2LhnT587iMfEcTX+z3O9sqHDRPcYred8EhC8yrxyAMhsTBm51fqv+A9+JaQcKQ23vx+/CCefimJnPCFHlK070APTvzuh7M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724220775; c=relaxed/simple; bh=H79svqtEzxvBYEj1DE9gC8nclvApmKE3TT2xkhm8QIs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dQUblkNOTKWx5lR3c/F2FqkRCv+0HHIcUETuUgt5ajQtMcZ6qKHGT7LMJltm6yXBAVQgq6EMBtXKVNqIjDJV8OJMHRDbecslTV6HxVyjW83jQY5YV/L998rlOEObK6gGv5AMoFl97XjL+BKWdfU857NtJc4NInfTKGzxm1DlQI4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qatH9DLf; 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="qatH9DLf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8947C32782; Wed, 21 Aug 2024 06:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1724220775; bh=H79svqtEzxvBYEj1DE9gC8nclvApmKE3TT2xkhm8QIs=; h=From:To:Cc:Subject:Date:Reply-to:From; b=qatH9DLfnbSY4UbuFXuYGFDU1C05LWZ63kmYITTcbo78A5xsY13j5bNqc36uX3usn 5kVmTdyS1hKjWEk8Y4Nv0yvKe5QSBZ+gY9Bl0Dq3W6YW7kYdl8nLed5cxyinKRCw96 5HlGhPnBktO6N4hYKgVG6hb7mZzQaLF4m0h2fKAI= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2023-52896: btrfs: fix race between quota rescan and disable leading to NULL pointer deref Date: Wed, 21 Aug 2024 14:11:37 +0800 Message-ID: <2024082112-CVE-2023-52896-d795@gregkh> X-Mailer: git-send-email 2.46.0 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=5520; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=H79svqtEzxvBYEj1DE9gC8nclvApmKE3TT2xkhm8QIs=; b=owGbwMvMwCRo6H6F97bub03G02pJDGlHWxn+1VRV1Z1Ofrd1yXKGLPazYjlnFudtKN+164TXZ ObLmfMlOmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAi5goMC44f4z3EcPyy/66V 9c/Xa5y7kDKt1o9hrsTew/+/RsfzNR1/LSaVqHEn8aLHNgA= 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 race between quota rescan and disable leading to NULL pointer deref If we have one task trying to start the quota rescan worker while another one is trying to disable quotas, we can end up hitting a race that results in the quota rescan worker doing a NULL pointer dereference. The steps for this are the following: 1) Quotas are enabled; 2) Task A calls the quota rescan ioctl and enters btrfs_qgroup_rescan(). It calls qgroup_rescan_init() which returns 0 (success) and then joins a transaction and commits it; 3) Task B calls the quota disable ioctl and enters btrfs_quota_disable(). It clears the bit BTRFS_FS_QUOTA_ENABLED from fs_info->flags and calls btrfs_qgroup_wait_for_completion(), which returns immediately since the rescan worker is not yet running. Then it starts a transaction and locks fs_info->qgroup_ioctl_lock; 4) Task A queues the rescan worker, by calling btrfs_queue_work(); 5) The rescan worker starts, and calls rescan_should_stop() at the start of its while loop, which results in 0 iterations of the loop, since the flag BTRFS_FS_QUOTA_ENABLED was cleared from fs_info->flags by task B at step 3); 6) Task B sets fs_info->quota_root to NULL; 7) The rescan worker tries to start a transaction and uses fs_info->quota_root as the root argument for btrfs_start_transaction(). This results in a NULL pointer dereference down the call chain of btrfs_start_transaction(). The stack trace is something like the one reported in Link tag below: general protection fault, probably for non-canonical address 0xdffffc0000000041: 0000 [#1] PREEMPT SMP KASAN KASAN: null-ptr-deref in range [0x0000000000000208-0x000000000000020f] CPU: 1 PID: 34 Comm: kworker/u4:2 Not tainted 6.1.0-syzkaller-13872-gb6bb9676f216 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022 Workqueue: btrfs-qgroup-rescan btrfs_work_helper RIP: 0010:start_transaction+0x48/0x10f0 fs/btrfs/transaction.c:564 Code: 48 89 fb 48 (...) RSP: 0018:ffffc90000ab7ab0 EFLAGS: 00010206 RAX: 0000000000000041 RBX: 0000000000000208 RCX: ffff88801779ba80 RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000 RBP: dffffc0000000000 R08: 0000000000000001 R09: fffff52000156f5d R10: fffff52000156f5d R11: 1ffff92000156f5c R12: 0000000000000000 R13: 0000000000000001 R14: 0000000000000001 R15: 0000000000000003 FS: 0000000000000000(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2bea75b718 CR3: 000000001d0cc000 CR4: 00000000003506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: btrfs_qgroup_rescan_worker+0x3bb/0x6a0 fs/btrfs/qgroup.c:3402 btrfs_work_helper+0x312/0x850 fs/btrfs/async-thread.c:280 process_one_work+0x877/0xdb0 kernel/workqueue.c:2289 worker_thread+0xb14/0x1330 kernel/workqueue.c:2436 kthread+0x266/0x300 kernel/kthread.c:376 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308 Modules linked in: So fix this by having the rescan worker function not attempt to start a transaction if it didn't do any rescan work. The Linux kernel CVE team has assigned CVE-2023-52896 to this issue. Affected and fixed versions =========================== Issue introduced in 5.4.178 with commit 26b3901d20bf and fixed in 5.4.230 with commit 89ac597e3e80 Issue introduced in 5.10.99 with commit 32747e01436a and fixed in 5.10.165 with commit 3bd433748571 Issue introduced in 5.15.22 with commit 89d4cca583fc and fixed in 5.15.90 with commit 64287cd456a2 Issue introduced in 5.17 with commit e804861bd4e6 and fixed in 6.1.8 with commit 1004fc90f0d7 Issue introduced in 5.17 with commit e804861bd4e6 and fixed in 6.2 with commit b7adbf9ada35 Issue introduced in 5.16.8 with commit 31198e58c09e 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-2023-52896 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/qgroup.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/89ac597e3e807b91e2ebd6a7c36fec7b97290233 https://git.kernel.org/stable/c/3bd43374857103ba3cac751d6d4afa8d83b5d92a https://git.kernel.org/stable/c/64287cd456a22373053998c1fccf14b651e9cbbd https://git.kernel.org/stable/c/1004fc90f0d79a4b7d9e3d432729914f472f9ad1 https://git.kernel.org/stable/c/b7adbf9ada3513d2092362c8eac5cddc5b651f5c