CVE-2024-56786: bpf: put bpf_link's program when link is safe to be deallocated
In the Linux kernel, the following vulnerability has been resolved:
bpf: put bpflink's program when link is safe to be deallocated
In general, BPF link's underlying BPF program should be considered to be reachable through attach hook -> link -> prog chain, and, pessimistically, we have to assume that as long as link's memory is not safe to free, attach hook's code might hold a pointer to BPF program and use it.
As such, it's not (generally) correct to put link's program early before waiting for RCU GPs to go through. More eager bpfprogput() that we currently do is mostly correct due to BPF program's release code doing similar RCU GP waiting, but as will be shown in the following patches, BPF program can be non-sleepable (and, thus, reliant on only "classic" RCU GP), while BPF link's attach hook can have sleepable semantics and needs to be protected by RCU Tasks Trace, and for such cases BPF link has to go through RCU Tasks Trace + "classic" RCU GPs before being deallocated. And so, if we put BPF program early, we might free BPF program before we free BPF link, leading to use-after-free situation.
So, this patch defers bpfprogput() until we are ready to perform bpflink's deallocation. At worst, this delays BPF program freeing by one extra RCU GP, but that seems completely acceptable. Alternatively, we'd need more elaborate ways to determine BPF hook, BPF link, and BPF program lifetimes, and how they relate to each other, which seems like an unnecessary complication.
Note, for most BPF links we still will perform eager bpfprogput() and link dealloc, so for those BPF links there are no observable changes whatsoever. Only BPF links that use deferred dealloc might notice slightly delayed freeing of BPF programs.
Also, to reduce code and logic duplication, extract program put + link dealloc logic into bpflinkdealloc() helper.
Other sources
In the Linux kernel, the following vulnerability has been resolved:
bpf: put bpflink's program when link is safe to be deallocated
The Linux kernel CVE team has assigned CVE-2024-56786 to this issue.
Upstream advisory: https://lore.kernel.org/linux-cve-announce/2025010808-CVE-2024-56786-1f56@gregkh/T
— Red Hat
Rejected reason: This CVE ID has been rejected or withdrawn by its CVE Numbering Authority.
— NVD
This CVE was automatically created from a reference found in an email or other text. If you are reading this, then this CVE entry is probably erroneous, since this text should be replaced by the official CVE description automatically.
— Launchpad
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
debian/linuxto a version that resolves this vulnerability.Fixed in 6.12.27-1
Event History
Frequently Asked Questions
What is the severity of CVE-2024-56786?
The severity of CVE-2024-56786 is classified as a high vulnerability due to potential impacts on the Linux kernel's BPF program management.
How do I fix CVE-2024-56786?
To fix CVE-2024-56786, update the Linux kernel to version 6.6.67 or later for versions before 6.12.6.
Which versions of Linux Kernel are affected by CVE-2024-56786?
CVE-2024-56786 affects Linux Kernel versions prior to 6.6.67 and between 6.7 and 6.12.5.
What components are impacted by CVE-2024-56786?
CVE-2024-56786 impacts the BPF link's program management within the Linux kernel.
Is there a workaround for CVE-2024-56786?
Currently, the best approach to mitigate CVE-2024-56786 is to apply the latest updates to the Linux kernel, as no specific workaround is provided.