mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf/core: Prevent UBSAN negative‑idx shift by throttle/unthrottle group
@ 2025-07-23 21:04 Yunseong Kim
  0 siblings, 0 replies; only message in thread
From: Yunseong Kim @ 2025-07-23 21:04 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan
  Cc: Will Deacon, Yeoreum Yun, Austin Kim, Michelle Jin,
	linux-perf-users, linux-kernel, Yunseong Kim, syzkaller

Where perf_event_throttle_group() and perf_event_unthrottle_group() would
invoke pmu->start()/stop() on events still in the OFF state, leaving
event->hw.idx == -1 and triggering UBSAN shift-out-of-bounds errors
(negative shift exponent) in pmu enable/disable event. By checking
'event->state > PERF_EVENT_STATE_OFF' for both the group leader and each
sibling, this ensure only started events with valid hw.idx values are passed
to the PMU, preventing negative-index shifts undefined behavior.

The issue is reproducible using the syzlang and C reproducer available:
Link: https://lore.kernel.org/lkml/14fb716a-dedf-482a-8518-e5cc26165e97@kzalloc.com/

Fixes: 9734e25fbf5a ("perf: Fix the throttle logic for a group")
Signed-off-by: Yunseong Kim <ysk@kzalloc.com>
Tested-by: Yunseong Kim <ysk@kzalloc.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Yeoreum Yun <yeoreum.yun@arm.com>
Cc: syzkaller@googlegroups.com
---
 kernel/events/core.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 22fdf0c187cd..e5cec61be545 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2684,18 +2684,28 @@ static void perf_event_unthrottle_group(struct perf_event *event, bool skip_star
 {
 	struct perf_event *sibling, *leader = event->group_leader;
 
-	perf_event_unthrottle(leader, skip_start_event ? leader != event : true);
-	for_each_sibling_event(sibling, leader)
-		perf_event_unthrottle(sibling, skip_start_event ? sibling != event : true);
+	if (leader->state > PERF_EVENT_STATE_OFF)
+		perf_event_unthrottle(leader,
+			skip_start_event ? leader != event : true);
+
+	for_each_sibling_event(sibling, leader) {
+		if (sibling->state > PERF_EVENT_STATE_OFF)
+			perf_event_unthrottle(sibling,
+				skip_start_event ? sibling != event : true);
+	}
 }
 
 static void perf_event_throttle_group(struct perf_event *event)
 {
 	struct perf_event *sibling, *leader = event->group_leader;
 
-	perf_event_throttle(leader);
-	for_each_sibling_event(sibling, leader)
-		perf_event_throttle(sibling);
+	if (leader->state > PERF_EVENT_STATE_OFF)
+		perf_event_throttle(leader);
+
+	for_each_sibling_event(sibling, leader) {
+		if (sibling->state > PERF_EVENT_STATE_OFF)
+			perf_event_throttle(sibling);
+	}
 }
 
 static int
-- 
2.50.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-07-23 21:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-23 21:04 [PATCH] perf/core: Prevent UBSAN negative‑idx shift by throttle/unthrottle group Yunseong Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®