From mboxrd@z Thu Jan 1 00:00:00 1970 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 B55C721B90F for ; Wed, 26 Feb 2025 02:27:38 +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=1740536858; cv=none; b=G0pUmX5xrkUdiqLxIAQsHm6SrL+Xcei++huU2tdeYa9EiQSJx86nV1Oi7dxoaxLXN4UmYW8A6hezlyxw5BgYBrXll6yFZxNkbV85yAaRRpV9m6zQhX6hTnaaPaPLxU8xVX0C5fazNZL+k6ztiukeimMsTqLy3AK0jDkmwRf3Sog= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740536858; c=relaxed/simple; bh=6BF4AzGpsWzwtl+NzjDqcmbh+IGcL+C8PctUDCjDHB4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=c9dXhcwbqWAkf6fDUMsSlbd3lQ8BWxLnQEJxVEZJ4XqPL9pY4p7Sm2ByxZJoyRLknHhZ8zdBmzLXl5aZimKPQ7glWHrJAKlPuvyfkZ6skC4NaCtfD5SEWVqbHRf3rV6I9HZ9HO36Pb+JRKGM4WRwuYck2r8PTnZfO5PUoJqr46Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=U8W4Ak+x; 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="U8W4Ak+x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 820A3C4CEE8; Wed, 26 Feb 2025 02:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1740536858; bh=6BF4AzGpsWzwtl+NzjDqcmbh+IGcL+C8PctUDCjDHB4=; h=From:To:Cc:Subject:Date:Reply-to:From; b=U8W4Ak+x37s5miRqGbKT7zibPzy/ubYgmsJZ749Z8cJE61YTsXCGkr0P9ktb3wb0E 5qcgAYDqKECjqdfWR9HPMrwTungtBOp9TcvHlAg5Wz4Ip6kXyumCbKcHIvW4WpwemK sUSwVChy++K20jJh2phYK6EuKMUA9ZLfrO+rYRMA= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-49702: btrfs: fix hang during unmount when block group reclaim task is running Date: Wed, 26 Feb 2025 03:24:25 +0100 Message-ID: <2025022629-CVE-2022-49702-4b46@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=6513; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=6BF4AzGpsWzwtl+NzjDqcmbh+IGcL+C8PctUDCjDHB4=; b=owGbwMvMwCRo6H6F97bub03G02pJDOn7qp6+7A7g9+q8v+HciieyV7bvnZHa/jXp+SSrkz3cQ lx6L22XdsSyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEqq8yLDjmyR+UwPg5OLlp +sv913NlbXNMPBnmSgcICh/lPcyrkvxPqTOu19Nk5ZVEAA== 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 hang during unmount when block group reclaim task is running When we start an unmount, at close_ctree(), if we have the reclaim task running and in the middle of a data block group relocation, we can trigger a deadlock when stopping an async reclaim task, producing a trace like the following: [629724.498185] task:kworker/u16:7 state:D stack: 0 pid:681170 ppid: 2 flags:0x00004000 [629724.499760] Workqueue: events_unbound btrfs_async_reclaim_metadata_space [btrfs] [629724.501267] Call Trace: [629724.501759] [629724.502174] __schedule+0x3cb/0xed0 [629724.502842] schedule+0x4e/0xb0 [629724.503447] btrfs_wait_on_delayed_iputs+0x7c/0xc0 [btrfs] [629724.504534] ? prepare_to_wait_exclusive+0xc0/0xc0 [629724.505442] flush_space+0x423/0x630 [btrfs] [629724.506296] ? rcu_read_unlock_trace_special+0x20/0x50 [629724.507259] ? lock_release+0x220/0x4a0 [629724.507932] ? btrfs_get_alloc_profile+0xb3/0x290 [btrfs] [629724.508940] ? do_raw_spin_unlock+0x4b/0xa0 [629724.509688] btrfs_async_reclaim_metadata_space+0x139/0x320 [btrfs] [629724.510922] process_one_work+0x252/0x5a0 [629724.511694] ? process_one_work+0x5a0/0x5a0 [629724.512508] worker_thread+0x52/0x3b0 [629724.513220] ? process_one_work+0x5a0/0x5a0 [629724.514021] kthread+0xf2/0x120 [629724.514627] ? kthread_complete_and_exit+0x20/0x20 [629724.515526] ret_from_fork+0x22/0x30 [629724.516236] [629724.516694] task:umount state:D stack: 0 pid:719055 ppid:695412 flags:0x00004000 [629724.518269] Call Trace: [629724.518746] [629724.519160] __schedule+0x3cb/0xed0 [629724.519835] schedule+0x4e/0xb0 [629724.520467] schedule_timeout+0xed/0x130 [629724.521221] ? lock_release+0x220/0x4a0 [629724.521946] ? lock_acquired+0x19c/0x420 [629724.522662] ? trace_hardirqs_on+0x1b/0xe0 [629724.523411] __wait_for_common+0xaf/0x1f0 [629724.524189] ? usleep_range_state+0xb0/0xb0 [629724.524997] __flush_work+0x26d/0x530 [629724.525698] ? flush_workqueue_prep_pwqs+0x140/0x140 [629724.526580] ? lock_acquire+0x1a0/0x310 [629724.527324] __cancel_work_timer+0x137/0x1c0 [629724.528190] close_ctree+0xfd/0x531 [btrfs] [629724.529000] ? evict_inodes+0x166/0x1c0 [629724.529510] generic_shutdown_super+0x74/0x120 [629724.530103] kill_anon_super+0x14/0x30 [629724.530611] btrfs_kill_super+0x12/0x20 [btrfs] [629724.531246] deactivate_locked_super+0x31/0xa0 [629724.531817] cleanup_mnt+0x147/0x1c0 [629724.532319] task_work_run+0x5c/0xa0 [629724.532984] exit_to_user_mode_prepare+0x1a6/0x1b0 [629724.533598] syscall_exit_to_user_mode+0x16/0x40 [629724.534200] do_syscall_64+0x48/0x90 [629724.534667] entry_SYSCALL_64_after_hwframe+0x44/0xae [629724.535318] RIP: 0033:0x7fa2b90437a7 [629724.535804] RSP: 002b:00007ffe0b7e4458 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6 [629724.536912] RAX: 0000000000000000 RBX: 00007fa2b9182264 RCX: 00007fa2b90437a7 [629724.538156] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000555d6cf20dd0 [629724.539053] RBP: 0000555d6cf20ba0 R08: 0000000000000000 R09: 00007ffe0b7e3200 [629724.539956] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 [629724.540883] R13: 0000555d6cf20dd0 R14: 0000555d6cf20cb0 R15: 0000000000000000 [629724.541796] This happens because: 1) Before entering close_ctree() we have the async block group reclaim task running and relocating a data block group; 2) There's an async metadata (or data) space reclaim task running; 3) We enter close_ctree() and park the cleaner kthread; 4) The async space reclaim task is at flush_space() and runs all the existing delayed iputs; 5) Before the async space reclaim task calls btrfs_wait_on_delayed_iputs(), the block group reclaim task which is doing the data block group relocation, creates a delayed iput at replace_file_extents() (called when COWing leaves that have file extent items pointing to relocated data extents, during the merging phase of relocation roots); 6) The async reclaim space reclaim task blocks at btrfs_wait_on_delayed_iputs(), since we have a new delayed iput; 7) The task at close_ctree() then calls cancel_work_sync() to stop the async space reclaim task, but it blocks since that task is waiting for the delayed iput to be run; 8) The delayed iput is never run because the cleaner kthread is parked, and no one else runs delayed iputs, resulting in a hang. So fix this by stopping the async block group reclaim task before we park the cleaner kthread. The Linux kernel CVE team has assigned CVE-2022-49702 to this issue. Affected and fixed versions =========================== Issue introduced in 5.13 with commit 18bb8bbf13c1839b43c9e09e76d397b753989af2 and fixed in 5.15.51 with commit 341d33128a940c6634175dcb6ca92dc454cfa7d2 Issue introduced in 5.13 with commit 18bb8bbf13c1839b43c9e09e76d397b753989af2 and fixed in 5.18.8 with commit 9fadb11f1295289e0da4d3342ecb6b92c1c99540 Issue introduced in 5.13 with commit 18bb8bbf13c1839b43c9e09e76d397b753989af2 and fixed in 5.19 with commit 31e70e527806c546a72262f2fc3d982ee23c42d3 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-2022-49702 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/disk-io.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/341d33128a940c6634175dcb6ca92dc454cfa7d2 https://git.kernel.org/stable/c/9fadb11f1295289e0da4d3342ecb6b92c1c99540 https://git.kernel.org/stable/c/31e70e527806c546a72262f2fc3d982ee23c42d3