# CVE-2021-47585: btrfs: fix memory leak in \_\_add\_inode\_ref()

> 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.30% (percentile 16, 2026-11-26)
- **CWE:** CWE-401
- **Published:** 2024-06-19T14:53:50.780Z
- **Modified:** 2026-06-17T04:17:49.000Z

## Who should check

- Anyone running Linux \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< 005d9292b5b2e71a009f911bd85d755009b37242; \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< 493ff661d434d6bdf02e3a21adae04d7a0b4265d; \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< f35838a6930296fc1988764cfa54cb3f705c0665
- Anyone running Linux 5.5

## Description

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

btrfs: fix memory leak in \_\_add\_inode\_ref()

Line 1169 (\#3) allocates a memory chunk for victim\_name by kmalloc(),
but  when the function returns in line 1184 (\#4) victim\_name allocated
by line 1169 (\#3) is not freed, which will lead to a memory leak.
There is a similar snippet of code in this function as allocating a memory
chunk for victim\_name in line 1104 (\#1) as well as releasing the memory
in line 1116 (\#2).

We should kfree() victim\_name when the return value of backref\_in\_log()
is less than zero and before the function returns in line 1184 (\#4).

1057 static inline int \_\_add\_inode\_ref(struct btrfs\_trans\_handle \*trans,
1058 				  struct btrfs\_root \*root,
1059 				  struct btrfs\_path \*path,
1060 				  struct btrfs\_root \*log\_root,
1061 				  struct btrfs\_inode \*dir,
1062 				  struct btrfs\_inode \*inode,
1063 				  u64 inode\_objectid, u64 parent\_objectid,
1064 				  u64 ref\_index, char \*name, int namelen,
1065 				  int \*search\_done)
1066 {

1104 	victim\_name = kmalloc(victim\_name\_len, GFP\_NOFS);
	// \#1: kmalloc (victim\_name-1)
1105 	if (!victim\_name)
1106 		return -ENOMEM;

1112	ret = backref\_in\_log(log\_root, &search\_key,
1113			parent\_objectid, victim\_name,
1114			victim\_name\_len);
1115	if (ret \< 0) {
1116		kfree(victim\_name); // \#2: kfree (victim\_name-1)
1117		return ret;
1118	} else if (!ret) {

1169 	victim\_name = kmalloc(victim\_name\_len, GFP\_NOFS);
	// \#3: kmalloc (victim\_name-2)
1170 	if (!victim\_name)
1171 		return -ENOMEM;

1180 	ret = backref\_in\_log(log\_root, &search\_key,
1181 			parent\_objectid, victim\_name,
1182 			victim\_name\_len);
1183 	if (ret \< 0) {
1184 		return ret; // \#4: missing kfree (victim\_name-2)
1185 	} else if (!ret) {

1241 	return 0;
1242 }

## Affected and fixed versions

- Linux: \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< 005d9292b5b2e71a009f911bd85d755009b37242; \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< 493ff661d434d6bdf02e3a21adae04d7a0b4265d; \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< f35838a6930296fc1988764cfa54cb3f705c0665 (cvelist)
- Linux: 5.5 (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-47585. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2021-47585.md
Affected: Linux >= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, < 005d9292b5b2e71a009f911bd85d755009b37242; >= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, < 493ff661d434d6bdf02e3a21adae04d7a0b4265d; >= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, < f35838a6930296fc1988764cfa54cb3f705c0665; Linux 5.5
Fixed in: Linux 005d9292b5b2e71a009f911bd85d755009b37242, Linux 493ff661d434d6bdf02e3a21adae04d7a0b4265d

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

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

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

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

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

Linux \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< 005d9292b5b2e71a009f911bd85d755009b37242; \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< 493ff661d434d6bdf02e3a21adae04d7a0b4265d; \>= d3316c8233bb05e0dd855d30aac347bb8ad76ee4, \< f35838a6930296fc1988764cfa54cb3f705c0665; Linux 5.5.

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

Yes. Fixed in Linux 005d9292b5b2e71a009f911bd85d755009b37242, Linux 493ff661d434d6bdf02e3a21adae04d7a0b4265d. No fix listed yet: follow the vendor advisory.

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

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/005d9292b5b2e71a009f911bd85d755009b37242>
- patch: <https://git.kernel.org/stable/c/493ff661d434d6bdf02e3a21adae04d7a0b4265d>
- patch: <https://git.kernel.org/stable/c/f35838a6930296fc1988764cfa54cb3f705c0665>

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

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