CVE-2022-50067

Source
https://nvd.nist.gov/vuln/detail/CVE-2022-50067
Import Source
https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2022-50067.json
JSON Data
https://api.osv.dev/v1/vulns/CVE-2022-50067
Downstream
Related
Published
2025-06-18T11:02:13.127Z
Modified
2025-12-23T21:43:11.100604Z
Summary
btrfs: unset reloc control if transaction commit fails in prepare_to_relocate()
Details

In the Linux kernel, the following vulnerability has been resolved:

btrfs: unset reloc control if transaction commit fails in preparetorelocate()

In btrfsrelocateblockgroup(), the rc is allocated. Then btrfsrelocateblockgroup() calls

relocateblockgroup() preparetorelocate() setreloccontrol()

that assigns rc to the variable fsinfo->relocctl. When preparetorelocate() returns, it calls

btrfscommittransaction() btrfsstartdirtyblockgroups() btrfsallocpath() kmemcachezalloc()

which may fail for example (or other errors could happen). When the failure occurs, btrfsrelocateblockgroup() detects the error and frees rc and doesn't set fsinfo->relocctl to NULL. After that, in btrfsinitrelocroot(), rc is retrieved from fsinfo->relocctl and then used, which may cause a use-after-free bug.

This possible bug can be triggered by calling btrfsioctlbalance() before calling btrfsioctldefrag().

To fix this possible bug, in preparetorelocate(), check if btrfscommittransaction() fails. If the failure occurs, unsetreloccontrol() is called to set fsinfo->relocctl to NULL.

The error log in our fault-injection testing is shown as follows:

[ 58.751070] BUG: KASAN: use-after-free in btrfsinitrelocroot+0x7ca/0x920 [btrfs] ... [ 58.753577] Call Trace: ... [ 58.755800] kasanreport+0x45/0x60 [ 58.756066] btrfsinitrelocroot+0x7ca/0x920 [btrfs] [ 58.757304] recordrootintrans+0x792/0xa10 [btrfs] [ 58.757748] btrfsrecordrootintrans+0x463/0x4f0 [btrfs] [ 58.758231] starttransaction+0x896/0x2950 [btrfs] [ 58.758661] btrfsdefragroot+0x250/0xc00 [btrfs] [ 58.759083] btrfsioctldefrag+0x467/0xa00 [btrfs] [ 58.759513] btrfsioctl+0x3c95/0x114e0 [btrfs] ... [ 58.768510] Allocated by task 23683: [ 58.768777] _kasankmalloc+0xb5/0xf0 [ 58.769069] _kmalloc+0x227/0x3d0 [ 58.769325] allocreloccontrol+0x10a/0x3d0 [btrfs] [ 58.769755] btrfsrelocateblockgroup+0x7aa/0x1e20 [btrfs] [ 58.770228] btrfsrelocatechunk+0xf1/0x760 [btrfs] [ 58.770655] _btrfsbalance+0x1326/0x1f10 [btrfs] [ 58.771071] btrfsbalance+0x3150/0x3d30 [btrfs] [ 58.771472] btrfsioctlbalance+0xd84/0x1410 [btrfs] [ 58.771902] btrfsioctl+0x4caa/0x114e0 [btrfs] ... [ 58.773337] Freed by task 23683: ... [ 58.774815] kfree+0xda/0x2b0 [ 58.775038] freereloccontrol+0x1d6/0x220 [btrfs] [ 58.775465] btrfsrelocateblockgroup+0x115c/0x1e20 [btrfs] [ 58.775944] btrfsrelocatechunk+0xf1/0x760 [btrfs] [ 58.776369] _btrfsbalance+0x1326/0x1f10 [btrfs] [ 58.776784] btrfsbalance+0x3150/0x3d30 [btrfs] [ 58.777185] btrfsioctlbalance+0xd84/0x1410 [btrfs] [ 58.777621] btrfs_ioctl+0x4caa/0x114e0 [btrfs] ...

Database specific
{
    "cna_assigner": "Linux",
    "osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2022/50xxx/CVE-2022-50067.json"
}
References

Affected packages

Git / git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

Affected ranges

Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
1a5353475df8fcaf200fecc9e961a3900d15e891
Fixed
ff0e8ed8dfb584575cffc1561f17a1d094e8565b
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
499d29bf151951399367ba83645abfdb429a3af9
Fixed
dcb11fe0a0a9cca2b7425191b9bf30dc29f2ad0f
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
4223d91ca1b5bf3928e5722c3c6b3fdb49250ab3
Fixed
8e546674031fc1576da501e27a8fd165222e5a37
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
6f371623f315c26100e603c2e8837cdbe130f9e0
Fixed
b60e862e133f646f19023ece1d476d630a660de1
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
fb686c6824dd6294ca772b92424b8fba666e7d00
Fixed
78f8c2370e3d33e35f23bdc648653d779aeacb6e
Fixed
5d741afed0bac206640cc64d77b97853283cf719
Fixed
85f02d6c856b9f3a0acf5219de6e32f58b9778eb

Affected versions

v5.*

v5.12
v5.13
v5.13-rc1
v5.13-rc2
v5.13-rc3
v5.13-rc4
v5.13-rc5
v5.13-rc6
v5.13-rc7
v5.14
v5.14-rc1
v5.14-rc2
v5.14-rc3
v5.14-rc4
v5.14-rc5
v5.14-rc6
v5.14-rc7
v5.15
v5.15-rc1
v5.15-rc2
v5.15-rc3
v5.15-rc4
v5.15-rc5
v5.15-rc6
v5.15-rc7
v5.15.1
v5.15.10
v5.15.11
v5.15.12
v5.15.13
v5.15.14
v5.15.15
v5.15.16
v5.15.17
v5.15.18
v5.15.19
v5.15.2
v5.15.20
v5.15.21
v5.15.22
v5.15.23
v5.15.24
v5.15.25
v5.15.26
v5.15.27
v5.15.28
v5.15.29
v5.15.3
v5.15.30
v5.15.31
v5.15.32
v5.15.33
v5.15.34
v5.15.35
v5.15.36
v5.15.37
v5.15.38
v5.15.39
v5.15.4
v5.15.40
v5.15.41
v5.15.42
v5.15.43
v5.15.44
v5.15.45
v5.15.46
v5.15.47
v5.15.48
v5.15.49
v5.15.5
v5.15.50
v5.15.51
v5.15.52
v5.15.53
v5.15.54
v5.15.55
v5.15.56
v5.15.57
v5.15.58
v5.15.59
v5.15.6
v5.15.60
v5.15.61
v5.15.62
v5.15.7
v5.15.8
v5.15.9
v5.16
v5.16-rc1
v5.16-rc2
v5.16-rc3
v5.16-rc4
v5.16-rc5
v5.16-rc6
v5.16-rc7
v5.16-rc8
v5.17
v5.17-rc1
v5.17-rc2
v5.17-rc3
v5.17-rc4
v5.17-rc5
v5.17-rc6
v5.17-rc7
v5.17-rc8
v5.18
v5.18-rc1
v5.18-rc2
v5.18-rc3
v5.18-rc4
v5.18-rc5
v5.18-rc6
v5.18-rc7
v5.19
v5.19-rc1
v5.19-rc2
v5.19-rc3
v5.19-rc4
v5.19-rc5
v5.19-rc6
v5.19-rc7
v5.19-rc8
v5.19.1
v5.19.2
v5.19.3

Database specific

source

"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2022-50067.json"

Linux / Kernel

Package

Name
Kernel

Affected ranges

Type
ECOSYSTEM
Events
Introduced
5.13.0
Fixed
5.15.63
Type
ECOSYSTEM
Events
Introduced
5.16.0
Fixed
5.19.4

Database specific

source

"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2022-50067.json"