 bpf: Fix invalid prog-&gt;stats access when update_effective_progs fails · gregkh/linux@539137e · 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 676 Star 636 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit 539137e Browse files Browse files Pu Lehui authored and gregkh committed bpf: Fix invalid prog-&gt;stats access when update_effective_progs fails [ Upstream commit 7dc211c ] Syzkaller triggers an invalid memory access issue following fault injection in update_effective_progs. The issue can be described as follows: __cgroup_bpf_detach update_effective_progs compute_effective_progs bpf_prog_array_alloc &lt;-- fault inject purge_effective_progs /* change to dummy_bpf_prog */ array-&gt;items[index] = &amp;dummy_bpf_prog.prog ---softirq start--- __do_softirq ... __cgroup_bpf_run_filter_skb __bpf_prog_run_save_cb bpf_prog_run stats = this_cpu_ptr(prog-&gt;stats) /* invalid memory access */ flags = u64_stats_update_begin_irqsave(&amp;stats-&gt;syncp) ---softirq end--- static_branch_dec(&amp;cgroup_bpf_enabled_key[atype]) The reason is that fault injection caused update_effective_progs to fail and then changed the original prog into dummy_bpf_prog.prog in purge_effective_progs. Then a softirq came, and accessing the members of dummy_bpf_prog.prog in the softirq triggers invalid mem access. To fix it, skip updating stats when stats is NULL. Fixes: 492ecee ("bpf: enable program stats") Signed-off-by: Pu Lehui &lt;pulehui@huawei.com&gt; Link: https://lore.kernel.org/r/20251115102343.2200727-1-pulehui@huaweicloud.com Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt; Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt; 1 parent ee7db11 commit 539137e Copy full SHA for 539137e 2 file s changed + 10 - 5 Lines changed: 10 additions &amp; 5 deletions File tree Expand file tree Collapse file tree Open diff view settings Filter options include/linux filter.h kernel/bpf syscall.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ include/linux/filter.h ‎ Copy file name to clipboard Expand all lines: include/linux/filter.h + 7 - 5 Lines changed: 7 additions &amp; 5 deletions Original file line number Diff line number Diff line change @@ -692,11 +692,13 @@ static __always_inline u32 __bpf_prog_run(const struct bpf_prog *prog, 692 692 ret = dfunc ( ctx , prog -&gt; insnsi , prog -&gt; bpf_func ); 693 693 694 694 duration = sched_clock () - start ; 695 - stats = this_cpu_ptr ( prog -&gt; stats ); 696 - flags = u64_stats_update_begin_irqsave ( &amp; stats -&gt; syncp ); 697 - u64_stats_inc ( &amp; stats -&gt; cnt ); 698 - u64_stats_add ( &amp; stats -&gt; nsecs , duration ); 699 - u64_stats_update_end_irqrestore ( &amp; stats -&gt; syncp , flags ); 695 + if ( likely ( prog -&gt; stats )) { 696 + stats = this_cpu_ptr ( prog -&gt; stats ); 697 + flags = u64_stats_update_begin_irqsave ( &amp; stats -&gt; syncp ); 698 + u64_stats_inc ( &amp; stats -&gt; cnt ); 699 + u64_stats_add ( &amp; stats -&gt; nsecs , duration ); 700 + u64_stats_update_end_irqrestore ( &amp; stats -&gt; syncp , flags ); 701 + } 700 702 } else { 701 703 ret = dfunc ( ctx , prog -&gt; insnsi , prog -&gt; bpf_func ); 702 704 } Collapse file ‎ kernel/bpf/syscall.c ‎ Copy file name to clipboard Expand all lines: kernel/bpf/syscall.c + 3 Lines changed: 3 additions &amp; 0 deletions Original file line number Diff line number Diff line change @@ -2281,6 +2281,9 @@ void notrace bpf_prog_inc_misses_counter(struct bpf_prog *prog) 2281 2281 struct bpf_prog_stats * stats ; 2282 2282 unsigned int flags ; 2283 2283 2284 + if ( unlikely (! prog -&gt; stats )) 2285 + return ; 2286 + 2284 2287 stats = this_cpu_ptr ( prog -&gt; stats ); 2285 2288 flags = u64_stats_update_begin_irqsave ( &amp; stats -&gt; syncp ); 2286 2289 u64_stats_inc ( &amp; stats -&gt; misses ); 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. 