CVE-2024-26737
Severity CVSS v4.0:
Pending analysis
Type:
CWE-416
Use After Free
Publication date:
03/04/2024
Last modified:
04/04/2025
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
bpf: Fix racing between bpf_timer_cancel_and_free and bpf_timer_cancel<br />
<br />
The following race is possible between bpf_timer_cancel_and_free<br />
and bpf_timer_cancel. It will lead a UAF on the timer->timer.<br />
<br />
bpf_timer_cancel();<br />
spin_lock();<br />
t = timer->time;<br />
spin_unlock();<br />
<br />
bpf_timer_cancel_and_free();<br />
spin_lock();<br />
t = timer->timer;<br />
timer->timer = NULL;<br />
spin_unlock();<br />
hrtimer_cancel(&t->timer);<br />
kfree(t);<br />
<br />
/* UAF on t */<br />
hrtimer_cancel(&t->timer);<br />
<br />
In bpf_timer_cancel_and_free, this patch frees the timer->timer<br />
after a rcu grace period. This requires a rcu_head addition<br />
to the "struct bpf_hrtimer". Another kfree(t) happens in bpf_timer_init,<br />
this does not need a kfree_rcu because it is still under the<br />
spin_lock and timer->timer has not been visible by others yet.<br />
<br />
In bpf_timer_cancel, rcu_read_lock() is added because this helper<br />
can be used in a non rcu critical section context (e.g. from<br />
a sleepable bpf prog). Other timer->timer usages in helpers.c<br />
have been audited, bpf_timer_cancel() is the only place where<br />
timer->timer is used outside of the spin_lock.<br />
<br />
Another solution considered is to mark a t->flag in bpf_timer_cancel<br />
and clear it after hrtimer_cancel() is done. In bpf_timer_cancel_and_free,<br />
it busy waits for the flag to be cleared before kfree(t). This patch<br />
goes with a straight forward solution and frees timer->timer after<br />
a rcu grace period.
Impact
Base Score 3.x
5.50
Severity 3.x
MEDIUM
Vulnerable products and versions
CPE | From | Up to |
---|---|---|
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.15 (including) | 5.15.150 (excluding) |
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.16 (including) | 6.1.80 (excluding) |
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.2 (including) | 6.6.19 (excluding) |
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.7 (including) | 6.7.7 (excluding) |
cpe:2.3:o:linux:linux_kernel:6.8:rc1:*:*:*:*:*:* | ||
cpe:2.3:o:linux:linux_kernel:6.8:rc2:*:*:*:*:*:* | ||
cpe:2.3:o:linux:linux_kernel:6.8:rc3:*:*:*:*:*:* | ||
cpe:2.3:o:linux:linux_kernel:6.8:rc4:*:*:*:*:*:* | ||
cpe:2.3:o:linux:linux_kernel:6.8:rc5:*:*:*:*:*:* |
To consult the complete list of CPE names with products and versions, see this page
References to Advisories, Solutions, and Tools
- https://git.kernel.org/stable/c/0281b919e175bb9c3128bd3872ac2903e9436e3f
- https://git.kernel.org/stable/c/5268bb02107b9eedfdcd51db75b407d10043368c
- https://git.kernel.org/stable/c/7d80a9e745fa5b47da3bca001f186c02485c7c33
- https://git.kernel.org/stable/c/8327ed12e8ebc5436bfaa1786c49988894f9c8a6
- https://git.kernel.org/stable/c/addf5e297e6cbf5341f9c07720693ca9ba0057b5
- https://git.kernel.org/stable/c/0281b919e175bb9c3128bd3872ac2903e9436e3f
- https://git.kernel.org/stable/c/5268bb02107b9eedfdcd51db75b407d10043368c
- https://git.kernel.org/stable/c/7d80a9e745fa5b47da3bca001f186c02485c7c33
- https://git.kernel.org/stable/c/8327ed12e8ebc5436bfaa1786c49988894f9c8a6
- https://git.kernel.org/stable/c/addf5e297e6cbf5341f9c07720693ca9ba0057b5