CVE-2022-49607
Severity CVSS v4.0:
Pending analysis
Type:
CWE-362
Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
Publication date:
26/02/2025
Last modified:
01/10/2025
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
perf/core: Fix data race between perf_event_set_output() and perf_mmap_close()<br />
<br />
Yang Jihing reported a race between perf_event_set_output() and<br />
perf_mmap_close():<br />
<br />
CPU1 CPU2<br />
<br />
perf_mmap_close(e2)<br />
if (atomic_dec_and_test(&e2->rb->mmap_count)) // 1 - > 0<br />
detach_rest = true<br />
<br />
ioctl(e1, IOC_SET_OUTPUT, e2)<br />
perf_event_set_output(e1, e2)<br />
<br />
...<br />
list_for_each_entry_rcu(e, &e2->rb->event_list, rb_entry)<br />
ring_buffer_attach(e, NULL);<br />
// e1 isn&#39;t yet added and<br />
// therefore not detached<br />
<br />
ring_buffer_attach(e1, e2->rb)<br />
list_add_rcu(&e1->rb_entry,<br />
&e2->rb->event_list)<br />
<br />
After this; e1 is attached to an unmapped rb and a subsequent<br />
perf_mmap() will loop forever more:<br />
<br />
again:<br />
mutex_lock(&e->mmap_mutex);<br />
if (event->rb) {<br />
...<br />
if (!atomic_inc_not_zero(&e->rb->mmap_count)) {<br />
...<br />
mutex_unlock(&e->mmap_mutex);<br />
goto again;<br />
}<br />
}<br />
<br />
The loop in perf_mmap_close() holds e2->mmap_mutex, while the attach<br />
in perf_event_set_output() holds e1->mmap_mutex. As such there is no<br />
serialization to avoid this race.<br />
<br />
Change perf_event_set_output() to take both e1->mmap_mutex and<br />
e2->mmap_mutex to alleviate that problem. Additionally, have the loop<br />
in perf_mmap() detach the rb directly, this avoids having to wait for<br />
the concurrent perf_mmap_close() to get around to doing it to make<br />
progress.
Impact
Base Score 3.x
4.70
Severity 3.x
MEDIUM
Vulnerable products and versions
| CPE | From | Up to |
|---|---|---|
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 3.2.49 (including) | 3.3 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 3.4.52 (including) | 3.5 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 3.9.8 (including) | 4.9.325 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 4.10 (including) | 4.14.290 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 4.15 (including) | 4.19.254 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 4.20 (including) | 5.4.208 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.5 (including) | 5.10.134 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.11 (including) | 5.15.58 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.16 (including) | 5.18.15 (excluding) |
| cpe:2.3:o:linux:linux_kernel:5.19:rc1:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.19:rc2:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.19:rc3:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.19:rc4:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.19:rc5:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.19:rc6:*:*:*:*:*:* |
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/17f5417194136517ee9bbd6511249e5310e5617c
- https://git.kernel.org/stable/c/3bbd868099287ff9027db59029b502fcfa2202a0
- https://git.kernel.org/stable/c/43128b3eee337824158f34da6648163d2f2fb937
- https://git.kernel.org/stable/c/68e3c69803dada336893640110cb87221bb01dcf
- https://git.kernel.org/stable/c/98c3c8fd0d4c560e0f8335b79c407bbf7fc9462c
- https://git.kernel.org/stable/c/a9391ff7a7c5f113d6f2bf6621d49110950de49c
- https://git.kernel.org/stable/c/da3c256e2d0ebc87c7db0c605c9692b6f1722074
- https://git.kernel.org/stable/c/f836f9ac95df15f1e0af4beb0ec20021e8c91998



