{"id":74077,"date":"2025-11-21T13:49:44","date_gmt":"2025-11-21T10:19:44","guid":{"rendered":"https:\/\/afaghhosting.net\/blog\/cve-2025-40209-btrfs-fix-memory-leak-of-qgroup_list-in-btrfs_add_qgroup_relation\/"},"modified":"2025-11-21T13:49:44","modified_gmt":"2025-11-21T10:19:44","slug":"cve-2025-40209-btrfs-fix-memory-leak-of-qgroup_list-in-btrfs_add_qgroup_relation","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/cve-2025-40209-btrfs-fix-memory-leak-of-qgroup_list-in-btrfs_add_qgroup_relation\/","title":{"rendered":"CVE-2025-40209 &#8211; btrfs: fix memory leak of qgroup_list in btrfs_add_qgroup_relation"},"content":{"rendered":"<p>CVE ID : CVE-2025-40209<\/p>\n<p>Published :  Nov. 21, 2025, 10:19 a.m. | 56\u00a0minutes ago<\/p>\n<p>Description : In the Linux kernel, the following vulnerability has been resolved:<\/p>\n<p>btrfs: fix memory leak of qgroup_list in btrfs_add_qgroup_relation<\/p>\n<p>When btrfs_add_qgroup_relation() is called with invalid qgroup levels<br \/>\n(src &gt;= dst), the function returns -EINVAL directly without freeing the<br \/>\npreallocated qgroup_list structure passed by the caller. This causes a<br \/>\nmemory leak because the caller unconditionally sets the pointer to NULL<br \/>\nafter the call, preventing any cleanup.<\/p>\n<p>The issue occurs because the level validation check happens before the<br \/>\nmutex is acquired and before any error handling path that would free<br \/>\nthe prealloc pointer. On this early return, the cleanup code at the<br \/>\n&#8216;out&#8217; label (which includes kfree(prealloc)) is never reached.<\/p>\n<p>In btrfs_ioctl_qgroup_assign(), the code pattern is:<\/p>\n<p>    prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL);<br \/>\n    ret = btrfs_add_qgroup_relation(trans, sa-&gt;src, sa-&gt;dst, prealloc);<br \/>\n    prealloc = NULL;  \/\/ Always set to NULL regardless of return value<br \/>\n    &#8230;<br \/>\n    kfree(prealloc);  \/\/ This becomes kfree(NULL), does nothing<\/p>\n<p>When the level check fails, &#8216;prealloc&#8217; is never freed by either the<br \/>\ncallee or the caller, resulting in a 64-byte memory leak per failed<br \/>\noperation. This can be triggered repeatedly by an unprivileged user<br \/>\nwith access to a writable btrfs mount, potentially exhausting kernel<br \/>\nmemory.<\/p>\n<p>Fix this by freeing prealloc before the early return, ensuring prealloc<br \/>\nis always freed on all error paths.<\/p>\n<p>Severity: 0.0 | NA<\/p>\n<p>Visit the link for more details, such as CVSS details, affected products, timeline, and more&#8230;\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CVE ID : CVE-2025-40209 Published : Nov. 21, 2025, 10:19 a.m. | 56\u00a0minutes ago Description : In the Linux kernel, the following vulnerability has been resolved: btrfs: fix memory leak of qgroup_list in btrfs_add_qgroup_relation When btrfs_add_qgroup_relation() is called with invalid qgroup levels (src &gt;= dst), the function returns -EINVAL directly without freeing the preallocated qgroup_list &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-74077","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/74077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=74077"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/74077\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=74077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=74077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=74077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}