CVE-2024-41010: bpf: Fix too early release of tcx_entry
In the Linux kernel, the following vulnerability has been resolved:
bpf: Fix too early release of tcxentry
Pedro Pinto and later independently also Hyunwoo Kim and Wongi Lee reported an issue that the tcxentry can be released too early leading to a use after free (UAF) when an active old-style ingress or clsact qdisc with a shared tc block is later replaced by another ingress or clsact instance.
Essentially, the sequence to trigger the UAF (one example) can be as follows:
1. A network namespace is created 2. An ingress qdisc is created. This allocates a tcxentry, and &tcxentry->miniq is stored in the qdisc's miniqp->pminiq. At the same time, a tcf block with index 1 is created. 3. chain0 is attached to the tcf block. chain0 must be connected to the block linked to the ingress qdisc to later reach the function tcfchain0headchangecbdel() which triggers the UAF. 4. Create and graft a clsact qdisc. This causes the ingress qdisc created in step 1 to be removed, thus freeing the previously linked tcxentry:
rtnetlinkrcvmsg() => tcmodifyqdisc() => qdisccreate() => clsactinit() [a] => qdiscgraft() => qdiscdestroy() => qdiscdestroy() => ingressdestroy() [b] => tcxentryfree() => kfreercu() // tcxentry freed
5. Finally, the network namespace is closed. This registers the cleanupnet worker, and during the process of releasing the remaining clsact qdisc, it accesses the tcxentry that was already freed in step 4, causing the UAF to occur:
cleanupnet() => opsexitlist() => defaultdeviceexitbatch() => unregisternetdevicemany() => unregisternetdevicemanynotify() => devshutdown() => qdiscput() => clsactdestroy() [c] => tcfblockputext() => tcfchain0headchangecbdel() => tcfchainheadchangeitem() => clsactchainheadchange() => miniqdiscpairswap() // UAF
There are also other variants, the gist is to add an ingress (or clsact) qdisc with a specific shared block, then to replace that qdisc, waiting for the tcxentry kfreercu() to be executed and subsequently accessing the current active qdisc's miniq one way or another.
The correct fix is to turn the miniqactive boolean into a counter. What can be observed, at step 2 above, the counter transitions from 0->1, at step [a] from 1->2 (in order for the miniq object to remain active during the replacement), then in [b] from 2->1 and finally [c] 1->0 with the eventual release. The reference counter in general ranges from [0,2] and it does not need to be atomic since all access to the counter is protected by the rtnl mutex. With this in place, there is no longer a UAF happening and the tcxentry is freed at the correct time.
Other sources
In the Linux kernel, the following vulnerability has been resolved:
bpf: Fix too early release of tcxentry
The Linux kernel CVE team has assigned CVE-2024-41010 to this issue.
Upstream advisory: https://lore.kernel.org/linux-cve-announce/2024071718-CVE-2024-41010-9042@gregkh/T
— Red Hat
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
debian/linuxto a version that resolves this vulnerability.Fixed in 5.10.223-1Fixed in 5.10.234-1Fixed in 6.1.129-1Fixed in 6.1.135-1Fixed in 6.12.22-1Fixed in 6.12.25-1 - Upgrade
Upgrade
redhat/kernelto a version that resolves this vulnerability.Fixed in 6.10 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Patch CVE-2024-41010 - Configuration
Apply the fix that turns the miniq_active boolean into a reference counter for tcx_entry (miniq object in qdisc miniqp->p_miniq), so tcx_entry is not released too early; ensure counter accesses are protected by the rtnl mutex (no need for atomic).
Linux kernel bpf tcx_entry lifetime management miniq_active = convert boolean to counter with transitions 0->1, 1->2, 2->1, 1->0 protected by rtnl mutex
Event History
Frequently Asked Questions
What is the severity of CVE-2024-41010?
CVE-2024-41010 has a moderate severity rating due to the potential for a use after free vulnerability in the Linux kernel.
Which versions of the Linux kernel are affected by CVE-2024-41010?
CVE-2024-41010 affects specific versions of the Linux kernel including those between 6.7 and 6.9.10 and those between 6.6 and 6.6.41.
How do I fix CVE-2024-41010?
To fix CVE-2024-41010, upgrade your Linux kernel to versions 5.10.223-1, 5.10.226-1, 6.1.119-1, 6.1.123-1, 6.12.10-1, or 6.12.11-1.
What is a use after free vulnerability related to CVE-2024-41010?
A use after free vulnerability occurs when a program continues to use a memory resource after it has been freed, potentially leading to program crashes or security breaches.
Who reported CVE-2024-41010?
CVE-2024-41010 was reported by Pedro Pinto, Hyunwoo Kim, and Wongi Lee.