# CVE-2021-46987: btrfs: fix deadlock when cloning inline extents and using qgroups

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

- **Severity:** MEDIUM 5.5
- **CVSS:** 5.5 (v3.1, NVD) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H`
- **CVSS metrics:** Attack vector: Local; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: None; Integrity impact: None; 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.18% (percentile 5, 2026-11-26)
- **CWE:** CWE-667
- **Published:** 2024-02-28T08:13:14.690Z
- **Modified:** 2026-06-17T04:16:05.287Z

## Who should check

- Anyone running Linux \>= c53e9653605dbf708f5be02902de51831be4b009, \< f8fbbd06fab9b75dcd68d850fe318ac3bc128974; \>= c53e9653605dbf708f5be02902de51831be4b009, \< d5347827d0b4b2250cbce6eccaa1c81dc78d8651; \>= c53e9653605dbf708f5be02902de51831be4b009, \< 96157707c0420e3d3edfe046f1cc797fee117ade; \>= c53e9653605dbf708f5be02902de51831be4b009, \< f9baa501b4fd6962257853d46ddffbc21f27e344; 36af2de520cca7c37974cc4944b47850f6c460ee; \>= 5.4.141, \< 5.5
- Anyone running Linux 5.9

## Description

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

btrfs: fix deadlock when cloning inline extents and using qgroups

There are a few exceptional cases where cloning an inline extent needs to
copy the inline extent data into a page of the destination inode.

When this happens, we end up starting a transaction while having a dirty
page for the destination inode and while having the range locked in the
destination's inode iotree too. Because when reserving metadata space
for a transaction we may need to flush existing delalloc in case there is
not enough free space, we have a mechanism in place to prevent a deadlock,
which was introduced in commit 3d45f221ce627d ("btrfs: fix deadlock when
cloning inline extent and low on free metadata space").

However when using qgroups, a transaction also reserves metadata qgroup
space, which can also result in flushing delalloc in case there is not
enough available space at the moment. When this happens we deadlock, since
flushing delalloc requires locking the file range in the inode's iotree
and the range was already locked at the very beginning of the clone
operation, before attempting to start the transaction.

When this issue happens, stack traces like the following are reported:

  \[72747.556262\] task:kworker/u81:9   state:D stack:    0 pid:  225 ppid:     2 flags:0x00004000
  \[72747.556268\] Workqueue: writeback wb\_workfn (flush-btrfs-1142)
  \[72747.556271\] Call Trace:
  \[72747.556273\]  \_\_schedule+0x296/0x760
  \[72747.556277\]  schedule+0x3c/0xa0
  \[72747.556279\]  io\_schedule+0x12/0x40
  \[72747.556284\]  \_\_lock\_page+0x13c/0x280
  \[72747.556287\]  ? generic\_file\_readonly\_mmap+0x70/0x70
  \[72747.556325\]  extent\_write\_cache\_pages+0x22a/0x440 \[btrfs\]
  \[72747.556331\]  ? \_\_set\_page\_dirty\_nobuffers+0xe7/0x160
  \[72747.556358\]  ? set\_extent\_buffer\_dirty+0x5e/0x80 \[btrfs\]
  \[72747.556362\]  ? update\_group\_capacity+0x25/0x210
  \[72747.556366\]  ? cpumask\_next\_and+0x1a/0x20
  \[72747.556391\]  extent\_writepages+0x44/0xa0 \[btrfs\]
  \[72747.556394\]  do\_writepages+0x41/0xd0
  \[72747.556398\]  \_\_writeback\_single\_inode+0x39/0x2a0
  \[72747.556403\]  writeback\_sb\_inodes+0x1ea/0x440
  \[72747.556407\]  \_\_writeback\_inodes\_wb+0x5f/0xc0
  \[72747.556410\]  wb\_writeback+0x235/0x2b0
  \[72747.556414\]  ? get\_nr\_inodes+0x35/0x50
  \[72747.556417\]  wb\_workfn+0x354/0x490
  \[72747.556420\]  ? newidle\_balance+0x2c5/0x3e0
  \[72747.556424\]  process\_one\_work+0x1aa/0x340
  \[72747.556426\]  worker\_thread+0x30/0x390
  \[72747.556429\]  ? create\_worker+0x1a0/0x1a0
  \[72747.556432\]  kthread+0x116/0x130
  \[72747.556435\]  ? kthread\_park+0x80/0x80
  \[72747.556438\]  ret\_from\_fork+0x1f/0x30

  \[72747.566958\] Workqueue: btrfs-flush\_delalloc btrfs\_work\_helper \[btrfs\]
  \[72747.566961\] Call Trace:
  \[72747.566964\]  \_\_schedule+0x296/0x760
  \[72747.566968\]  ? finish\_wait+0x80/0x80
  \[72747.566970\]  schedule+0x3c/0xa0
  \[72747.566995\]  wait\_extent\_bit.constprop.68+0x13b/0x1c0 \[btrfs\]
  \[72747.566999\]  ? finish\_wait+0x80/0x80
  \[72747.567024\]  lock\_extent\_bits+0x37/0x90 \[btrfs\]
  \[72747.567047\]  btrfs\_invalidatepage+0x299/0x2c0 \[btrfs\]
  \[72747.567051\]  ? find\_get\_pages\_range\_tag+0x2cd/0x380
  \[72747.567076\]  \_\_extent\_writepage+0x203/0x320 \[btrfs\]
  \[72747.567102\]  extent\_write\_cache\_pages+0x2bb/0x440 \[btrfs\]
  \[72747.567106\]  ? update\_load\_avg+0x7e/0x5f0
  \[72747.567109\]  ? enqueue\_entity+0xf4/0x6f0
  \[72747.567134\]  extent\_writepages+0x44/0xa0 \[btrfs\]
  \[72747.567137\]  ? enqueue\_task\_fair+0x93/0x6f0
  \[72747.567140\]  do\_writepages+0x41/0xd0
  \[72747.567144\]  \_\_filemap\_fdatawrite\_range+0xc7/0x100
  \[72747.567167\]  btrfs\_run\_delalloc\_work+0x17/0x40 \[btrfs\]
  \[72747.567195\]  btrfs\_work\_helper+0xc2/0x300 \[btrfs\]
  \[72747.567200\]  process\_one\_work+0x1aa/0x340
  \[72747.567202\]  worker\_thread+0x30/0x390
  \[72747.567205\]  ? create\_worker+0x1a0/0x1a0
  \[72747.567208\]  kthread+0x116/0x130
  \[72747.567211\]  ? kthread\_park+0x80/0x80
  \[72747.567214\]  ret\_from\_fork+0x1f/0x30

  \[72747.569686\] task:fsstress        state:D stack:    
---truncated---

## Affected and fixed versions

- Linux: \>= c53e9653605dbf708f5be02902de51831be4b009, \< f8fbbd06fab9b75dcd68d850fe318ac3bc128974; \>= c53e9653605dbf708f5be02902de51831be4b009, \< d5347827d0b4b2250cbce6eccaa1c81dc78d8651; \>= c53e9653605dbf708f5be02902de51831be4b009, \< 96157707c0420e3d3edfe046f1cc797fee117ade; \>= c53e9653605dbf708f5be02902de51831be4b009, \< f9baa501b4fd6962257853d46ddffbc21f27e344; 36af2de520cca7c37974cc4944b47850f6c460ee; \>= 5.4.141, \< 5.5 (cvelist)
- Linux: 5.9 (cvelist)

## Mitigation

- Upgrade Linux to 5.5 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-46987. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2021-46987.md
Affected: Linux >= c53e9653605dbf708f5be02902de51831be4b009, < f8fbbd06fab9b75dcd68d850fe318ac3bc128974; >= c53e9653605dbf708f5be02902de51831be4b009, < d5347827d0b4b2250cbce6eccaa1c81dc78d8651; >= c53e9653605dbf708f5be02902de51831be4b009, < 96157707c0420e3d3edfe046f1cc797fee117ade; >= c53e9653605dbf708f5be02…
Fixed in: Linux 96157707c0420e3d3edfe046f1cc797fee117ade, Linux 5.5

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-46987 being exploited?

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

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

Medium: CVSS 5.5 (v3.1, scored by NVD). Not remotely exploitable (local or adjacent access needed).

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

Linux \>= c53e9653605dbf708f5be02902de51831be4b009, \< f8fbbd06fab9b75dcd68d850fe318ac3bc128974; \>= c53e9653605dbf708f5be02902de51831be4b009, \< d5347827d0b4b2250cbce6eccaa1c81dc78d8651; \>= c53e9653605dbf708f5be02902de51831be4b009, \< 96157707c0420e3d3edfe046f1cc797fee117ade; \>= c53e9653605dbf708f5be02902de51831be4b009, \< f9baa501b4fd6962257853d46ddffbc21f27e344; 36af2de520cca7c37974cc4944b47850f6c460ee; \>= 5.4.141, \< 5.5; Linux 5.9.

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

Yes. Fixed in Linux 96157707c0420e3d3edfe046f1cc797fee117ade, Linux 5.5. Upgrade Linux to 5.5 or later.

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

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/d5347827d0b4b2250cbce6eccaa1c81dc78d8651>
- patch: <https://git.kernel.org/stable/c/96157707c0420e3d3edfe046f1cc797fee117ade>
- patch: <https://git.kernel.org/stable/c/f9baa501b4fd6962257853d46ddffbc21f27e344>
- other: <https://git.kernel.org/stable/c/f8fbbd06fab9b75dcd68d850fe318ac3bc128974>
- other: <https://lists.debian.org/debian-lts-announce/2025/10/msg00007.html>

## 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-46987>

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