CVE-2021-47505: aio: fix use-after-free due to missing POLLFREE handling
In the Linux kernel, the following vulnerability has been resolved:
aio: fix use-after-free due to missing POLLFREE handling
signalfdpoll() and binderpoll() are special in that they use a waitqueue whose lifetime is the current task, rather than the struct file as is normally the case. This is okay for blocking polls, since a blocking poll occurs within one task; however, non-blocking polls require another solution. This solution is for the queue to be cleared before it is freed, by sending a POLLFREE notification to all waiters.
Unfortunately, only eventpoll handles POLLFREE. A second type of non-blocking poll, aio poll, was added in kernel v4.18, and it doesn't handle POLLFREE. This allows a use-after-free to occur if a signalfd or binder fd is polled with aio poll, and the waitqueue gets freed.
Fix this by making aio poll handle POLLFREE.
A patch by Ramji Jiyani <ramjiyani@google.com> (https://lore.kernel.org/r/20211027011834.2497484-1-ramjiyani@google.com) tried to do this by making aiopollwake() always complete the request inline if POLLFREE is seen. However, that solution had two bugs. First, it introduced a deadlock, as it unconditionally locked the aio context while holding the waitqueue lock, which inverts the normal locking order. Second, it didn't consider that POLLFREE notifications are missed while the request has been temporarily de-queued.
The second problem was solved by my previous patch. This patch then properly fixes the use-after-free by handling POLLFREE in a deadlock-free way. It does this by taking advantage of the fact that freeing of the waitqueue is RCU-delayed, similar to what eventpoll does.
Other sources
In the Linux kernel, the following vulnerability has been resolved:
aio: fix use-after-free due to missing POLLFREE handling
The Linux kernel CVE team has assigned CVE-2021-47505 to this issue.
Upstream advisory: https://lore.kernel.org/linux-cve-announce/2024052452-CVE-2021-47505-427f@gregkh/T
— Red Hat
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
redhat/kernelto a version that resolves this vulnerability.Fixed in 4.19.221 - Upgrade
Upgrade
redhat/kernelto a version that resolves this vulnerability.Fixed in 5.4.165 - Upgrade
Upgrade
redhat/kernelto a version that resolves this vulnerability.Fixed in 5.10.85 - Upgrade
Upgrade
redhat/kernelto a version that resolves this vulnerability.Fixed in 5.15.8 - Upgrade
Upgrade
redhat/kernelto a version that resolves this vulnerability.Fixed in 5.16 - Upgrade
Upgrade
linux kernel aioto a version that resolves this vulnerability.Fixed in v4.18Patch CVE-2021-47505 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Patch CVE-2021-47505 - Configuration
Fix CVE-2021-47505 by ensuring aio poll/wake correctly handles POLLFREE (e.g., inline handling when POLLFREE is seen) so waiters are notified before the waitqueue is freed, preventing a use-after-free.
aio_poll_wake / POLLFREE handling POLLFREE notification handling = enable
Event History
Frequently Asked Questions
What is the severity of CVE-2021-47505?
CVE-2021-47505 is considered a medium severity vulnerability in the Linux kernel.
How do I fix CVE-2021-47505?
To fix CVE-2021-47505, upgrade the Linux kernel to versions 4.19.221, 5.4.165, 5.10.85, 5.15.8, or 5.16.
Which systems are affected by CVE-2021-47505?
CVE-2021-47505 affects various Linux kernel versions between 4.18 and 5.16-rc4.
What type of vulnerability is CVE-2021-47505?
CVE-2021-47505 is a use-after-free vulnerability due to missing POLLFREE handling in the Linux kernel.
Is CVE-2021-47505 remotely exploitable?
CVE-2021-47505 can potentially be exploited locally, as it relates to the handling of specific kernel functions.