From: Yunseong Kim <ysk@kzalloc.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
"Liang, Kan" <kan.liang@linux.intel.com>
Cc: Will Deacon <will@kernel.org>, Yeoreum Yun <yeoreum.yun@arm.com>,
Austin Kim <austindh.kim@gmail.com>,
Michelle Jin <shjy180909@gmail.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Yunseong Kim <ysk@kzalloc.com>,
syzkaller@googlegroups.com
Subject: [PATCH] perf/core: Prevent UBSAN negativeâidx shift by throttle/unthrottle group
Date: Wed, 23 Jul 2025 21:04:28 +0000 [thread overview]
Message-ID: <20250723210426.590974-3-ysk@kzalloc.com> (raw)
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
reply other threads:[~2025-07-23 21:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250723210426.590974-3-ysk@kzalloc.com \
--to=ysk@kzalloc.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=austindh.kim@gmail.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=shjy180909@gmail.com \
--cc=syzkaller@googlegroups.com \
--cc=will@kernel.org \
--cc=yeoreum.yun@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®