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 6645A28A1D6 for ; Wed, 18 Jun 2025 11:08:37 +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=1750244917; cv=none; b=mZHZgTRjrSKelkIn2ycCJfc8U2kjKkYbdqgBNTXUbGYXSVfRzI/hlVutLpHXI/qR9EeW5mn1/rfqufdq3Ol0MQkIVRCVXe8tXczgI/0IDVfBWgbz3LGYkdj5uZpJAlqSsTgUwstKI3jkHPh0s1I/yL3vtwYs9hqrQDQf0zP/YxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750244917; c=relaxed/simple; bh=nMKhv6rLBpUZVPKcQOb7p+JoSnBEiYfMf6izAeLX4sc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VeG0rgBu7713wZYWzvBz068vQhvuamMM1DW0xsfX5yl21vST5JDAXaDPiUucLJ92KuqzpT+AZ9xeyalP3EzpI6VlZf1Q0Uu+S1me00/D9upNwBLhTgzZjeILfUN7R3TcDIva3nCviAvUM4zdyWywdBulmNkE4DtBpQZqu/UcPbQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=IXdyk0AI; 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="IXdyk0AI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7370C4CEF1; Wed, 18 Jun 2025 11:08:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750244917; bh=nMKhv6rLBpUZVPKcQOb7p+JoSnBEiYfMf6izAeLX4sc=; h=From:To:Cc:Subject:Date:Reply-to:From; b=IXdyk0AImlOODEsUMsIVbvB3pbJrhFc/7fRnp1kA/aVV00Gq47XdonZkLO+FxUm04 YMKUlXubk4e33nDggjLT8zp3c8MsPX2QAWNfcxl57Nc+G1maszpdshgE5P6wFMNgkx 7eHpISPRv2ED4ffbWatHfymcBf9+W5GBGdKXFTBU= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-50067: btrfs: unset reloc control if transaction commit fails in prepare_to_relocate() Date: Wed, 18 Jun 2025 13:02:12 +0200 Message-ID: <2025061852-CVE-2022-50067-a06c@gregkh> X-Mailer: git-send-email 2.49.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=5090; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=02Uh/X2Lf/6tKJ7uDON4df2MK0D1FfhqPVJMOg3xakg=; b=owGbwMvMwCRo6H6F97bub03G02pJDBlBc1Lm385Trvfd/pNFwT7S/HXllg/b71wwt08QMG5bf 2f+h6WSHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjARjUKG+bkf+U1WPPJ0OFuT OvfHj8r244o3VzHM02+8X3LaTj5Iz3Xb1IcxVnoHLskqAQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: btrfs: unset reloc control if transaction commit fails in prepare_to_relocate() In btrfs_relocate_block_group(), the rc is allocated. Then btrfs_relocate_block_group() calls relocate_block_group() prepare_to_relocate() set_reloc_control() that assigns rc to the variable fs_info->reloc_ctl. When prepare_to_relocate() returns, it calls btrfs_commit_transaction() btrfs_start_dirty_block_groups() btrfs_alloc_path() kmem_cache_zalloc() which may fail for example (or other errors could happen). When the failure occurs, btrfs_relocate_block_group() detects the error and frees rc and doesn't set fs_info->reloc_ctl to NULL. After that, in btrfs_init_reloc_root(), rc is retrieved from fs_info->reloc_ctl and then used, which may cause a use-after-free bug. This possible bug can be triggered by calling btrfs_ioctl_balance() before calling btrfs_ioctl_defrag(). To fix this possible bug, in prepare_to_relocate(), check if btrfs_commit_transaction() fails. If the failure occurs, unset_reloc_control() is called to set fs_info->reloc_ctl to NULL. The error log in our fault-injection testing is shown as follows: [ 58.751070] BUG: KASAN: use-after-free in btrfs_init_reloc_root+0x7ca/0x920 [btrfs] ... [ 58.753577] Call Trace: ... [ 58.755800] kasan_report+0x45/0x60 [ 58.756066] btrfs_init_reloc_root+0x7ca/0x920 [btrfs] [ 58.757304] record_root_in_trans+0x792/0xa10 [btrfs] [ 58.757748] btrfs_record_root_in_trans+0x463/0x4f0 [btrfs] [ 58.758231] start_transaction+0x896/0x2950 [btrfs] [ 58.758661] btrfs_defrag_root+0x250/0xc00 [btrfs] [ 58.759083] btrfs_ioctl_defrag+0x467/0xa00 [btrfs] [ 58.759513] btrfs_ioctl+0x3c95/0x114e0 [btrfs] ... [ 58.768510] Allocated by task 23683: [ 58.768777] ____kasan_kmalloc+0xb5/0xf0 [ 58.769069] __kmalloc+0x227/0x3d0 [ 58.769325] alloc_reloc_control+0x10a/0x3d0 [btrfs] [ 58.769755] btrfs_relocate_block_group+0x7aa/0x1e20 [btrfs] [ 58.770228] btrfs_relocate_chunk+0xf1/0x760 [btrfs] [ 58.770655] __btrfs_balance+0x1326/0x1f10 [btrfs] [ 58.771071] btrfs_balance+0x3150/0x3d30 [btrfs] [ 58.771472] btrfs_ioctl_balance+0xd84/0x1410 [btrfs] [ 58.771902] btrfs_ioctl+0x4caa/0x114e0 [btrfs] ... [ 58.773337] Freed by task 23683: ... [ 58.774815] kfree+0xda/0x2b0 [ 58.775038] free_reloc_control+0x1d6/0x220 [btrfs] [ 58.775465] btrfs_relocate_block_group+0x115c/0x1e20 [btrfs] [ 58.775944] btrfs_relocate_chunk+0xf1/0x760 [btrfs] [ 58.776369] __btrfs_balance+0x1326/0x1f10 [btrfs] [ 58.776784] btrfs_balance+0x3150/0x3d30 [btrfs] [ 58.777185] btrfs_ioctl_balance+0xd84/0x1410 [btrfs] [ 58.777621] btrfs_ioctl+0x4caa/0x114e0 [btrfs] ... The Linux kernel CVE team has assigned CVE-2022-50067 to this issue. Affected and fixed versions =========================== Fixed in 4.14.318 with commit ff0e8ed8dfb584575cffc1561f17a1d094e8565b Fixed in 4.19.286 with commit dcb11fe0a0a9cca2b7425191b9bf30dc29f2ad0f Fixed in 5.4.247 with commit 8e546674031fc1576da501e27a8fd165222e5a37 Fixed in 5.10.184 with commit b60e862e133f646f19023ece1d476d630a660de1 Fixed in 5.15.63 with commit 78f8c2370e3d33e35f23bdc648653d779aeacb6e Fixed in 5.19.4 with commit 5d741afed0bac206640cc64d77b97853283cf719 Fixed in 6.0 with commit 85f02d6c856b9f3a0acf5219de6e32f58b9778eb 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-50067 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/ff0e8ed8dfb584575cffc1561f17a1d094e8565b https://git.kernel.org/stable/c/dcb11fe0a0a9cca2b7425191b9bf30dc29f2ad0f https://git.kernel.org/stable/c/8e546674031fc1576da501e27a8fd165222e5a37 https://git.kernel.org/stable/c/b60e862e133f646f19023ece1d476d630a660de1 https://git.kernel.org/stable/c/78f8c2370e3d33e35f23bdc648653d779aeacb6e https://git.kernel.org/stable/c/5d741afed0bac206640cc64d77b97853283cf719 https://git.kernel.org/stable/c/85f02d6c856b9f3a0acf5219de6e32f58b9778eb