CVE-2025-40209: btrfs: fix memory leak of qgroup_list in btrfs_add_qgroup_relation

Published Nov 21, 2025
·
Updated

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

btrfs: fix memory leak of qgrouplist in btrfsaddqgrouprelation

When btrfsaddqgrouprelation() is called with invalid qgroup levels (src >= dst), the function returns -EINVAL directly without freeing the preallocated qgrouplist structure passed by the caller. This causes a memory leak because the caller unconditionally sets the pointer to NULL after the call, preventing any cleanup.

The issue occurs because the level validation check happens before the mutex is acquired and before any error handling path that would free the prealloc pointer. On this early return, the cleanup code at the 'out' label (which includes kfree(prealloc)) is never reached.

In btrfsioctlqgroupassign(), the code pattern is:

prealloc = kzalloc(sizeof(prealloc), GFPKERNEL); ret = btrfsaddqgrouprelation(trans, sa->src, sa->dst, prealloc); prealloc = NULL; // Always set to NULL regardless of return value ... kfree(prealloc); // This becomes kfree(NULL), does nothing

When the level check fails, 'prealloc' is never freed by either the callee or the caller, resulting in a 64-byte memory leak per failed operation. This can be triggered repeatedly by an unprivileged user with access to a writable btrfs mount, potentially exhausting kernel memory.

Fix this by freeing prealloc before the early return, ensuring prealloc is always freed on all error paths.

Affected Software

1 affected component
Linux Linux kernel (btrfs)

Event History

Nov 21, 2025
CVE Published
via MITRE·10:19 AM
Data Sourced
via MITRE·10:19 AM
Description
Data Sourced
via NVD·11:15 AM
Description
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2025-40209?

CVE-2025-40209 has been classified with a severity rating that indicates it poses a risk due to a memory leak in the btrfs component of the Linux kernel.

2

How do I fix CVE-2025-40209?

To mitigate CVE-2025-40209, users should update their Linux kernel to the latest version where the vulnerability has been patched.

3

What systems are affected by CVE-2025-40209?

CVE-2025-40209 affects systems running the Linux kernel that utilize the btrfs filesystem.

4

What is the impact of CVE-2025-40209?

The impact of CVE-2025-40209 includes a potential memory leak that can lead to increased memory consumption and performance degradation.

5

When was CVE-2025-40209 disclosed?

CVE-2025-40209 was disclosed in the context of a routine update addressing vulnerabilities in the Linux kernel.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203