CVE-2021-47011: mm: memcontrol: slab: fix obtain a reference to a freeing memcg

Published Feb 28, 2024
·
Updated

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

mm: memcontrol: slab: fix obtain a reference to a freeing memcg

Patch series "Use objcgroup APIs to charge kmem pages", v5.

Since Roman's series "The new cgroup slab memory controller" applied. All slab objects are charged with the new APIs of objcgroup. The new APIs introduce a struct objcgroup to charge slab objects. It prevents long-living objects from pinning the original memory cgroup in the memory. But there are still some corner objects (e.g. allocations larger than order-1 page on SLUB) which are not charged with the new APIs. Those objects (include the pages which are allocated from buddy allocator directly) are charged as kmem pages which still hold a reference to the memory cgroup.

E.g. We know that the kernel stack is charged as kmem pages because the size of the kernel stack can be greater than 2 pages (e.g. 16KB on x8664 or arm64). If we create a thread (suppose the thread stack is charged to memory cgroup A) and then move it from memory cgroup A to memory cgroup B. Because the kernel stack of the thread hold a reference to the memory cgroup A. The thread can pin the memory cgroup A in the memory even if we remove the cgroup A. If we want to see this scenario by using the following script. We can see that the system has added 500 dying cgroups (This is not a real world issue, just a script to show that the large kmallocs are charged as kmem pages which can pin the memory cgroup in the memory).

#!/bin/bash

cat /proc/cgroups | grep memory

cd /sys/fs/cgroup/memory echo 1 > memory.movechargeatimmigrate

for i in range{1..500} do mkdir kmemtest echo $$ > kmemtest/cgroup.procs sleep 3600 & echo $$ > cgroup.procs echo cat kmemtest/cgroup.procs > cgroup.procs rmdir kmemtest done

cat /proc/cgroups | grep memory

This patchset aims to make those kmem pages to drop the reference to memory cgroup by using the APIs of objcgroup. Finally, we can see that the number of the dying cgroups will not increase if we run the above test script.

This patch (of 7):

The rcureadlock/unlock only can guarantee that the memcg will not be freed, but it cannot guarantee the success of cssget (which is in the refillstock when cached memcg changed) to memcg.

rcureadlock() memcg = objcgroupmemcg(old) memcgkmemuncharge(memcg) refillstock(memcg) if (stock->cached != memcg) // cssget can change the ref counter from 0 back to 1. cssget(&memcg->css) rcureadunlock()

This fix is very like the commit:

eefbfa7fd678 ("mm: memcg/slab: fix use after free in objcgroupcharge")

Fix this by holding a reference to the memcg which is passed to the memcgkmemuncharge() before calling memcgkmemuncharge().

Affected Software

3 affected components
Linux Linux kernel>=5.10.11<5.10.37
Linux Linux kernel>=5.11<5.11.21
Linux Linux kernel>=5.12<5.12.4

Event History

Feb 28, 2024
CVE Published
via MITRE·08:13 AM
Data Sourced
via MITRE·08:13 AM
DescriptionSeverity
Data Sourced
via NVD·09:15 AM
RemedyDescriptionSeverityAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2021-47011?

CVE-2021-47011 has been classified as a medium severity vulnerability in the Linux kernel.

2

How do I fix CVE-2021-47011?

To fix CVE-2021-47011, update your Linux kernel to a version that includes the patches addressing this vulnerability.

3

Which versions of Linux kernel are affected by CVE-2021-47011?

CVE-2021-47011 affects Linux kernel versions between 5.10.11 and 5.10.37, 5.11 and 5.11.21, and 5.12 and 5.12.4.

4

What type of vulnerability is CVE-2021-47011?

CVE-2021-47011 is a memory management vulnerability specific to the memory control subsystem of the Linux kernel.

5

Is CVE-2021-47011 being actively exploited?

As of now, there are no known active exploits for CVE-2021-47011, but it is essential to apply the updates promptly to mitigate any risk.

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