CVE-2026-138895: mm: hugetlb: drop refcount before freeing on memcg charge failure
In the Linux kernel, the following vulnerability has been resolved:
mm: hugetlb: drop refcount before freeing on memcg charge failure
When memcgroupchargehugetlb(folio, gfp) returns -ENOMEM, the folio has its refcount set to 1 via foliorefunfreeze(folio, 1).
The error path calls freehugefolio(folio) directly, which expects a refcount of 0. Hence, VMBUGONFOLIO(foliorefcount(folio), folio) is triggered.
Even with CONFIGDEBUGVM disabled, returning a folio with refcount 1 to the freelist can corrupt allocator state later.
Use folioput(folio) instead of freehugefolio(folio) to properly drop the reference before freeing it.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
On the mem_cgroup_charge_hugetlb(folio, gfp) -ENOMEM error path, use folio_put(folio) instead of free_huge_folio(folio) to drop the reference before freeing the folio.
Event History
Frequently Asked Questions
What condition is required to trigger the faulty error path?
The hugetlb memory-cgroup charge for a folio must fail with -ENOMEM. In that case, the folio has been restored to a reference count of 1 before the error path attempts to free it.
Is this issue limited to kernels built with CONFIG_DEBUG_VM?
No. With CONFIG_DEBUG_VM enabled, the invalid nonzero reference count triggers VM_BUG_ON_FOLIO. Without it, the folio can be returned to the freelist with a reference count of 1, potentially corrupting allocator state later.
What does the resolved change do?
It replaces the direct free_huge_folio(folio) call in this error path with folio_put(folio). This drops the restored reference before the folio is freed.