# CVE-2021-46958: btrfs: fix race between transaction aborts and fsyncs leading to use-after-free

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** HIGH 7.8
- **CVSS:** 7.8 (v3.1, CNA) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`
- **CVSS metrics:** Attack vector: Local; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: High; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Not remotely exploitable (local or adjacent access needed)
- **EPSS:** 0.24% (percentile 10, 2026-11-26)
- **CWE:** CWE-416
- **Published:** 2024-02-27T18:46:59.315Z
- **Modified:** 2026-08-05T08:45:13.853Z

## Who should check

- Anyone running Linux \>= ef67963dac255b293e19815ea3d440567be4626f, \< a4794be7b00b7eda4b45fffd283ab7d76df7e5d6; \>= ef67963dac255b293e19815ea3d440567be4626f, \< 633f7f216663587f17601eaa1cf2ac3d5654874c; \>= ef67963dac255b293e19815ea3d440567be4626f, \< e2da98788369bfba1138bada72765c47989a4338; \>= ef67963dac255b293e19815ea3d440567be4626f, \< 061dde8245356d8864d29e25207aa4daa0be4d3c
- Anyone running Linux 5.7

## Description

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

btrfs: fix race between transaction aborts and fsyncs leading to use-after-free

There is a race between a task aborting a transaction during a commit,
a task doing an fsync and the transaction kthread, which leads to an
use-after-free of the log root tree. When this happens, it results in a
stack trace like the following:

  BTRFS info (device dm-0): forced readonly
  BTRFS warning (device dm-0): Skipping commit of aborted transaction.
  BTRFS: error (device dm-0) in cleanup\_transaction:1958: errno=-5 IO failure
  BTRFS warning (device dm-0): lost page write due to IO error on /dev/mapper/error-test (-5)
  BTRFS warning (device dm-0): Skipping commit of aborted transaction.
  BTRFS warning (device dm-0): direct IO failed ino 261 rw 0,0 sector 0xa4e8 len 4096 err no 10
  BTRFS error (device dm-0): error writing primary super block to device 1
  BTRFS warning (device dm-0): direct IO failed ino 261 rw 0,0 sector 0x12e000 len 4096 err no 10
  BTRFS warning (device dm-0): direct IO failed ino 261 rw 0,0 sector 0x12e008 len 4096 err no 10
  BTRFS warning (device dm-0): direct IO failed ino 261 rw 0,0 sector 0x12e010 len 4096 err no 10
  BTRFS: error (device dm-0) in write\_all\_supers:4110: errno=-5 IO failure (1 errors while writing supers)
  BTRFS: error (device dm-0) in btrfs\_sync\_log:3308: errno=-5 IO failure
  general protection fault, probably for non-canonical address 0x6b6b6b6b6b6b6b68: 0000 \[\#1\] PREEMPT SMP DEBUG\_PAGEALLOC PTI
  CPU: 2 PID: 2458471 Comm: fsstress Not tainted 5.12.0-rc5-btrfs-next-84 \#1
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
  RIP: 0010:\_\_mutex\_lock+0x139/0xa40
  Code: c0 74 19 (...)
  RSP: 0018:ffff9f18830d7b00 EFLAGS: 00010202
  RAX: 6b6b6b6b6b6b6b68 RBX: 0000000000000001 RCX: 0000000000000002
  RDX: ffffffffb9c54d13 RSI: 0000000000000000 RDI: 0000000000000000
  RBP: ffff9f18830d7bc0 R08: 0000000000000000 R09: 0000000000000000
  R10: ffff9f18830d7be0 R11: 0000000000000001 R12: ffff8c6cd199c040
  R13: ffff8c6c95821358 R14: 00000000fffffffb R15: ffff8c6cbcf01358
  FS:  00007fa9140c2b80(0000) GS:ffff8c6fac600000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: 00007fa913d52000 CR3: 000000013d2b4003 CR4: 0000000000370ee0
  DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
  DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
  Call Trace:
   ? \_\_btrfs\_handle\_fs\_error+0xde/0x146 \[btrfs\]
   ? btrfs\_sync\_log+0x7c1/0xf20 \[btrfs\]
   ? btrfs\_sync\_log+0x7c1/0xf20 \[btrfs\]
   btrfs\_sync\_log+0x7c1/0xf20 \[btrfs\]
   btrfs\_sync\_file+0x40c/0x580 \[btrfs\]
   do\_fsync+0x38/0x70
   \_\_x64\_sys\_fsync+0x10/0x20
   do\_syscall\_64+0x33/0x80
   entry\_SYSCALL\_64\_after\_hwframe+0x44/0xae
  RIP: 0033:0x7fa9142a55c3
  Code: 8b 15 09 (...)
  RSP: 002b:00007fff26278d48 EFLAGS: 00000246 ORIG\_RAX: 000000000000004a
  RAX: ffffffffffffffda RBX: 0000563c83cb4560 RCX: 00007fa9142a55c3
  RDX: 00007fff26278cb0 RSI: 00007fff26278cb0 RDI: 0000000000000005
  RBP: 0000000000000005 R08: 0000000000000001 R09: 00007fff26278d5c
  R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000340
  R13: 00007fff26278de0 R14: 00007fff26278d96 R15: 0000563c83ca57c0
  Modules linked in: btrfs dm\_zero dm\_snapshot dm\_thin\_pool (...)
  ---\[ end trace ee2f1b19327d791d \]---

The steps that lead to this crash are the following:

1) We are at transaction N;

2) We have two tasks with a transaction handle attached to transaction N.
   Task A and Task B. Task B is doing an fsync;

3) Task B is at btrfs\_sync\_log(), and has saved fs\_info-\>log\_root\_tree
   into a local variable named 'log\_root\_tree' at the top of
   btrfs\_sync\_log(). Task B is about to call write\_all\_supers(), but
   before that...

4) Task A calls btrfs\_commit\_transaction(), and after it sets the
   transaction state to TRANS\_STATE\_COMMIT\_START, an error happens before
   it w
---truncated---

## Affected and fixed versions

- Linux: \>= ef67963dac255b293e19815ea3d440567be4626f, \< a4794be7b00b7eda4b45fffd283ab7d76df7e5d6; \>= ef67963dac255b293e19815ea3d440567be4626f, \< 633f7f216663587f17601eaa1cf2ac3d5654874c; \>= ef67963dac255b293e19815ea3d440567be4626f, \< e2da98788369bfba1138bada72765c47989a4338; \>= ef67963dac255b293e19815ea3d440567be4626f, \< 061dde8245356d8864d29e25207aa4daa0be4d3c (cvelist)
- Linux: 5.7 (cvelist)

## Mitigation

- Upgrade Linux to 061dde8245356d8864d29e25207aa4daa0be4d3c or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2021-46958. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2021-46958.md
Affected: Linux >= ef67963dac255b293e19815ea3d440567be4626f, < a4794be7b00b7eda4b45fffd283ab7d76df7e5d6; >= ef67963dac255b293e19815ea3d440567be4626f, < 633f7f216663587f17601eaa1cf2ac3d5654874c; >= ef67963dac255b293e19815ea3d440567be4626f, < e2da98788369bfba1138bada72765c47989a4338; >= ef67963dac255b293e19815…
Fixed in: Linux 633f7f216663587f17601eaa1cf2ac3d5654874c, Linux 061dde8245356d8864d29e25207aa4daa0be4d3c

Steps:
1. Search this machine and project for Linux: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2021-46958 being exploited?

There is no confirmed exploitation: CVE-2021-46958 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.24% chance of exploitation in the next 30 days (as of 2026-11-26).

### How serious is CVE-2021-46958?

High: CVSS 7.8 (v3.1, scored by CNA). Not remotely exploitable (local or adjacent access needed).

### Which versions are affected by CVE-2021-46958?

Linux \>= ef67963dac255b293e19815ea3d440567be4626f, \< a4794be7b00b7eda4b45fffd283ab7d76df7e5d6; \>= ef67963dac255b293e19815ea3d440567be4626f, \< 633f7f216663587f17601eaa1cf2ac3d5654874c; \>= ef67963dac255b293e19815ea3d440567be4626f, \< e2da98788369bfba1138bada72765c47989a4338; \>= ef67963dac255b293e19815ea3d440567be4626f, \< 061dde8245356d8864d29e25207aa4daa0be4d3c; Linux 5.7.

### Is there a fix for CVE-2021-46958?

Yes. Fixed in Linux 633f7f216663587f17601eaa1cf2ac3d5654874c, Linux 061dde8245356d8864d29e25207aa4daa0be4d3c. Upgrade Linux to 061dde8245356d8864d29e25207aa4daa0be4d3c or later.

### How do I check if I'm affected by CVE-2021-46958?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- patch: <https://git.kernel.org/stable/c/a4794be7b00b7eda4b45fffd283ab7d76df7e5d6>
- patch: <https://git.kernel.org/stable/c/633f7f216663587f17601eaa1cf2ac3d5654874c>
- patch: <https://git.kernel.org/stable/c/e2da98788369bfba1138bada72765c47989a4338>
- patch: <https://git.kernel.org/stable/c/061dde8245356d8864d29e25207aa4daa0be4d3c>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2021-46958>

HTML: <https://flawdb.com/CVE-2021-46958> · JSON: <https://flawdb.com/api/v1/entries/CVE-2021-46958>
