 perf: Avoid undefined behavior from stopping/starting inactive events · gregkh/linux@d689135 · GitHub Skip to content Navigation Menu Toggle navigation Sign in Appearance settings Platform AI CODE CREATION GitHub Copilot Write better code with AI GitHub Spark Build and deploy intelligent apps GitHub Models Manage and compare prompts MCP Registry New Integrate external tools DEVELOPER WORKFLOWS Actions Automate any workflow Codespaces Instant dev environments Issues Plan and track work Code Review Manage code changes APPLICATION SECURITY GitHub Advanced Security Find and fix vulnerabilities Code security Secure your code as you build Secret protection  EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial services Manufacturing Government View all industries View all solutions Resources EXPLORE BY TOPIC AI Software Development DevOps Security View all topics EXPLORE BY TYPE Customer stories Events &amp; webinars Ebooks &amp; reports Business insights GitHub Skills SUPPORT &amp; SERVICES Documentation Customer support Community forum Trust center Partners View all resources Open Source COMMUNITY GitHub Sponsors Fund open source developers PROGRAMS Security Lab Maintainer Community Accelerator GitHub Stars Archive Program REPOSITORIES Topics Trending Collections Enterprise ENTERPRISE SOLUTIONS Enterprise platform AI-powered developer platform AVAILABLE ADD-ONS GitHub Advanced Security Enterprise-grade security features Copilot for Business Enterprise-grade AI features Premium Support Enterprise-grade 24/7 support Pricing Search or jump to... Search code, repositories, users, issues, pull requests... --> Search Clear Search syntax tips Provide feedback --> We read every piece of feedback, and take your input very seriously.  Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly --> Name Query To see all available qualifiers, see our documentation . Cancel Create saved search Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} gregkh / linux Public Notifications You must be signed in to change notification settings Fork 686 Star 644 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit d689135 Browse files Browse files yskzalloc authored and gregkh committed perf: Avoid undefined behavior from stopping/starting inactive events [ Upstream commit b64fdd4 ] Calling pmu-&gt;start()/stop() on perf events in PERF_EVENT_STATE_OFF can leave event-&gt;hw.idx at -1. When PMU drivers later attempt to use this negative index as a shift exponent in bitwise operations, it leads to UBSAN shift-out-of-bounds reports. The issue is a logical flaw in how event groups handle throttling when some members are intentionally disabled. Based on the analysis and the reproducer provided by Mark Rutland (this issue on both arm64 and x86-64). The scenario unfolds as follows: 1. A group leader event is configured with a very aggressive sampling period (e.g., sample_period = 1). This causes frequent interrupts and triggers the throttling mechanism. 2. A child event in the same group is created in a disabled state (.disabled = 1). This event remains in PERF_EVENT_STATE_OFF. Since it hasn't been scheduled onto the PMU, its event-&gt;hw.idx remains initialized at -1. 3. When throttling occurs, perf_event_throttle_group() and later perf_event_unthrottle_group() iterate through all siblings, including the disabled child event. 4. perf_event_throttle()/unthrottle() are called on this inactive child event, which then call event-&gt;pmu-&gt;start()/stop(). 5. The PMU driver receives the event with hw.idx == -1 and attempts to use it as a shift exponent. e.g., in macros like PMCNTENSET(idx), leading to the UBSAN report. The throttling mechanism attempts to start/stop events that are not actively scheduled on the hardware. Move the state check into perf_event_throttle()/perf_event_unthrottle() so that inactive events are skipped entirely. This ensures only active events with a valid hw.idx are processed, preventing undefined behavior and silencing UBSAN warnings. The corrected check ensures true before proceeding with PMU operations. The problem can be reproduced with the syzkaller reproducer: Fixes: 9734e25 ("perf: Fix the throttle logic for a group") Signed-off-by: Yunseong Kim &lt;ysk@kzalloc.com&gt; Signed-off-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt; Reviewed-by: Kan Liang &lt;kan.liang@linux.intel.com&gt; Link: https://lore.kernel.org/r/20250812181046.292382-2-ysk@kzalloc.com Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt; 1 parent be15dab commit d689135 Copy full SHA for d689135 1 file changed + 6 Lines changed: 6 additions &amp; 0 deletions File tree Expand file tree Collapse file tree Open diff view settings Filter options kernel/events core.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ kernel/events/core.c ‎ Copy file name to clipboard Expand all lines: kernel/events/core.c + 6 Lines changed: 6 additions &amp; 0 deletions Original file line number Diff line number Diff line change @@ -2665,6 +2665,9 @@ static void perf_log_itrace_start(struct perf_event *event); 2665 2665 2666 2666 static void perf_event_unthrottle ( struct perf_event * event , bool start ) 2667 2667 { 2668 + if ( event -&gt; state != PERF_EVENT_STATE_ACTIVE ) 2669 + return ; 2670 + 2668 2671 event -&gt; hw . interrupts = 0 ; 2669 2672 if ( start ) 2670 2673 event -&gt; pmu -&gt; start ( event , 0 ); @@ -2674,6 +2677,9 @@ static void perf_event_unthrottle(struct perf_event *event, bool start) 2674 2677 2675 2678 static void perf_event_throttle ( struct perf_event * event ) 2676 2679 { 2680 + if ( event -&gt; state != PERF_EVENT_STATE_ACTIVE ) 2681 + return ; 2682 + 2677 2683 event -&gt; hw . interrupts = MAX_INTERRUPTS ; 2678 2684 event -&gt; pmu -&gt; stop ( event , 0 ); 2679 2685 if ( event == event -&gt; group_leader ) 0 commit comments Comments 0 ( 0 ) Footer &copy; 2026 GitHub,&nbsp;Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. 