
CVE-2023-6931 kernel panic PoC
Kernel Panic PoC for CVE-2023-6931
CVE-2023-6931 is a vulnerability in perf_event that leads to a heap buffer overflow caused by an integer overflow in the read_size of a group.
perf_events is a performance monitoring and analysis framework provided by the Linux kernel. This framework enables the tracking of various performance-related data generated by both hardware and software components.
perf_event_open System call
An interface that allows user-space to configure and control performance events in the kernel.
It is used to create, group, control, or read data from events./proc/sys/kernel/perf_event_paranoid must be 1 or lowerulimit -n command.CONFIG_PERF_EVENTS must be set.The Vulnerability arises due to an integer overflow in the read_size of a group. The function perf_event_validate_size performs validation on the read_size. However, the wat read_size is validated only checks the read_size of the current event.
The key point is that during each validation, only the current event is validated, while previous events are not. If PERF_FORMAT_GROUP is set for the gorup leader, simply adding a current event can increase the read_size of the group leader.
This ultimately causes as issue in perf_read_group. The calculation of event->read_size is based on the read_format of the group leader, multiplied by nr_siblings. Since the read_size variable is a 2-byte u16, the maximum value it can hold is 0xffff.
To exploit this, the attacker first creates a group leader event with all possible read_format options set. Next, numerous sibling events are created. These siblings only set PERF_FORMAT_TOTAL_TIME_RUNNING in the read_Format to ensure no validation issues in perf_event_validate_size. As a result, the nr_siblings value becomes extremely large, but since each sibling event passes validation individually, there are no problems at this stage.
When perf_read_group is called in this state, the read_size of the group leader continues to increase because PERF_FORMAT_GROUP is set. Eventaully, this leads to an integer overflow, and kzalloc allocates a very small buffer. However, since the actual number of events is very large, a heap buffer overflow accurs, causing a kernel panic.