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(&amp;e2-&gt;rb-&gt;mmap_count)) // 1 - &gt; 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, &amp;e2-&gt;rb-&gt;event_list, rb_entry)<br /> ring_buffer_attach(e, NULL);<br /> // e1 isn&amp;#39;t yet added and<br /> // therefore not detached<br /> <br /> ring_buffer_attach(e1, e2-&gt;rb)<br /> list_add_rcu(&amp;e1-&gt;rb_entry,<br /> &amp;e2-&gt;rb-&gt;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(&amp;e-&gt;mmap_mutex);<br /> if (event-&gt;rb) {<br /> ...<br /> if (!atomic_inc_not_zero(&amp;e-&gt;rb-&gt;mmap_count)) {<br /> ...<br /> mutex_unlock(&amp;e-&gt;mmap_mutex);<br /> goto again;<br /> }<br /> }<br /> <br /> The loop in perf_mmap_close() holds e2-&gt;mmap_mutex, while the attach<br /> in perf_event_set_output() holds e1-&gt;mmap_mutex. As such there is no<br /> serialization to avoid this race.<br /> <br /> Change perf_event_set_output() to take both e1-&gt;mmap_mutex and<br /> e2-&gt;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.

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:*:*:*:*:*:*