# CVE-2021-47508: btrfs: free exchange changeset on failures

> 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.27% (percentile 12, 2026-11-26)
- **CWE:** CWE-401
- **Published:** 2024-05-24T15:01:54.048Z
- **Modified:** 2026-06-17T04:17:39.253Z

## Who should check

- Anyone running Linux \>= 364ecf3651e0862152c8b340d7cb3021dc0122c7, \< ca06c5cb1b6dbfe67655b33c02fc394d65824519; \>= 364ecf3651e0862152c8b340d7cb3021dc0122c7, \< da5e817d9d75422eaaa05490d0b9a5e328fc1a51
- Anyone running Linux 4.13

## Description

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

btrfs: free exchange changeset on failures

Fstests runs on my VMs have show several kmemleak reports like the following.

  unreferenced object 0xffff88811ae59080 (size 64):
    comm "xfs\_io", pid 12124, jiffies 4294987392 (age 6.368s)
    hex dump (first 32 bytes):
      00 c0 1c 00 00 00 00 00 ff cf 1c 00 00 00 00 00  ................
      90 97 e5 1a 81 88 ff ff 90 97 e5 1a 81 88 ff ff  ................
    backtrace:
      \[\<00000000ac0176d2\>\] ulist\_add\_merge+0x60/0x150 \[btrfs\]
      \[\<0000000076e9f312\>\] set\_state\_bits+0x86/0xc0 \[btrfs\]
      \[\<0000000014fe73d6\>\] set\_extent\_bit+0x270/0x690 \[btrfs\]
      \[\<000000004f675208\>\] set\_record\_extent\_bits+0x19/0x20 \[btrfs\]
      \[\<00000000b96137b1\>\] qgroup\_reserve\_data+0x274/0x310 \[btrfs\]
      \[\<0000000057e9dcbb\>\] btrfs\_check\_data\_free\_space+0x5c/0xa0 \[btrfs\]
      \[\<0000000019c4511d\>\] btrfs\_delalloc\_reserve\_space+0x1b/0xa0 \[btrfs\]
      \[\<000000006d37e007\>\] btrfs\_dio\_iomap\_begin+0x415/0x970 \[btrfs\]
      \[\<00000000fb8a74b8\>\] iomap\_iter+0x161/0x1e0
      \[\<0000000071dff6ff\>\] \_\_iomap\_dio\_rw+0x1df/0x700
      \[\<000000002567ba53\>\] iomap\_dio\_rw+0x5/0x20
      \[\<0000000072e555f8\>\] btrfs\_file\_write\_iter+0x290/0x530 \[btrfs\]
      \[\<000000005eb3d845\>\] new\_sync\_write+0x106/0x180
      \[\<000000003fb505bf\>\] vfs\_write+0x24d/0x2f0
      \[\<000000009bb57d37\>\] \_\_x64\_sys\_pwrite64+0x69/0xa0
      \[\<000000003eba3fdf\>\] do\_syscall\_64+0x43/0x90

In case brtfs\_qgroup\_reserve\_data() or btrfs\_delalloc\_reserve\_metadata()
fail the allocated extent\_changeset will not be freed.

So in btrfs\_check\_data\_free\_space() and btrfs\_delalloc\_reserve\_space()
free the allocated extent\_changeset to get rid of the allocated memory.

The issue currently only happens in the direct IO write path, but only
after 65b3c08606e5 ("btrfs: fix ENOSPC failure when attempting direct IO
write into NOCOW range"), and also at defrag\_one\_locked\_target(). Every
other place is always calling extent\_changeset\_free() even if its call
to btrfs\_delalloc\_reserve\_space() or btrfs\_check\_data\_free\_space() has
failed.

## Affected and fixed versions

- Linux: \>= 364ecf3651e0862152c8b340d7cb3021dc0122c7, \< ca06c5cb1b6dbfe67655b33c02fc394d65824519; \>= 364ecf3651e0862152c8b340d7cb3021dc0122c7, \< da5e817d9d75422eaaa05490d0b9a5e328fc1a51 (cvelist)
- Linux: 4.13 (cvelist)

## Mitigation

- No fix listed yet: follow the vendor advisory.

## Check your systems with an agent

Paste this into a coding agent:

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

Details: https://flawdb.com/CVE-2021-47508.md
Affected: Linux >= 364ecf3651e0862152c8b340d7cb3021dc0122c7, < ca06c5cb1b6dbfe67655b33c02fc394d65824519; >= 364ecf3651e0862152c8b340d7cb3021dc0122c7, < da5e817d9d75422eaaa05490d0b9a5e328fc1a51; Linux 4.13
Fixed in: no fixed version listed yet

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

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

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

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

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

Linux \>= 364ecf3651e0862152c8b340d7cb3021dc0122c7, \< ca06c5cb1b6dbfe67655b33c02fc394d65824519; \>= 364ecf3651e0862152c8b340d7cb3021dc0122c7, \< da5e817d9d75422eaaa05490d0b9a5e328fc1a51; Linux 4.13.

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

No fixed version is listed in the sources yet. No fix listed yet: follow the vendor advisory.

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

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/ca06c5cb1b6dbfe67655b33c02fc394d65824519>
- patch: <https://git.kernel.org/stable/c/da5e817d9d75422eaaa05490d0b9a5e328fc1a51>

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

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