summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2026-10-18alpha: link platform help text to the alphalinux.org wikiMatt Turner
The alphalinux.org wiki has a page for each system and motherboard covering its CPUs, firmware, Linux status and known issues. Link each platform's help text to the pages for the systems it supports. Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20261001165018.415526-3-mattst88@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: correct system descriptions in Kconfig help textMatt Turner
Fix the system lists in the "Alpha system type" choice and the platform help texts, cross-checked against the alphalinux.org wiki and the kernel sources: - There is no AlphaServer GS40 or DS10E. Wildfire also shipped with EV68 (21264C) CPUs. - "AS" means AlphaServer elsewhere in the list, but the Alcor "AS 600, AS 500" are AlphaStations, as is the Noritake "AlphaServer 600A". - Takara is 21164-based, not "11164". - Linux 6.10 dropped support for CPUs before EV56, which took the AlphaStation 600 and Alpha XL 300 with it. Say once that EV56 or later is required rather than qualifying every entry. - Add systems missing from their entries: the UP1500 (Nautilus), DS15 and TS202c (Titan), Digital Server 3300 (Noritake), Digital Server 5300 and 7300 (Rawhide), and the Ruffian boards in place of "Samsung APC164UX". - Add Eiger, Nautilus and RX164 to the summary list and help text to PC164, RX164, SX164 and Shark, which had none. Note that the Ruffian and RX164 boards have no SRM console. Also drop the Jensen and EV4/EV5 references removed in 6.10, and the claim that SRM cannot boot from IDE, which is not true of SRM in general. NR_CPUS can be set to 32 on any platform, so say what the hardware supports instead of implying a per-platform kernel limit. Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20261001165018.415526-2-mattst88@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: replace dead links in Kconfig help textMatt Turner
The Linux/Alpha FAQ, the unix-ag LX164 overview, the Rawhide install HOWTO and the Ruffian FAQ are all gone. Point the "Alpha system type" help at the system and motherboard lists on the alphalinux.org wiki instead, give LX164 a one-line description in place of its link, and drop the others. Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20261001165018.415526-1-mattst88@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: support the remaining kernel compression formatsMatt Turner
Nothing about the boot stub is specific to gzip, so wire up bzip2, lz4, lzma, lzo, xz and zstd as well: select the matching HAVE_KERNEL_* symbol, add a suffix-y entry and a compression rule for the piggy-backed image, and include the decompressor into the stub's misc.c. Only gzip's trailer already carries the uncompressed size, so the other formats use the _with_size variants; output_len, which vmlinux.scr takes from the last 4 bytes of the payload, then works for all of them. The stub passes it to __decompress(), which zstd requires. Signed-off-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20261017-alpha-kernel-compression-v2-3-c71e6b08dc63@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: add self-extracting compressed kernel boot stubMatt Turner
Alpha only ever supported gzip for the kernel image, and did so in a way out of step with every other architecture: aboot, the disk boot loader, decompresses vmlinux.gz itself with its own bundled inflate code, so adding a compression format meant writing a new decompressor inside aboot as well as in the kernel. Build a proper self-extracting arch/alpha/boot/compressed/vmlinux instead, modeled on parisc: a small ELF stub with the real, compressed vmlinux linked in, which decompresses the kernel, relocates it into place and jumps to its entry point. aboot needs no changes. The stub has no sanitizer or coverage runtime and must run on any Alpha, so it builds private copies of the arch/alpha/lib/ memory and division routines it needs instead of linking lib.a, whose objects carry the kernel's instrumentation and -mcpu=. The build now emits arch/alpha/boot/vmlinuz rather than vmlinux.gz, which was never a name aboot cared about and would be a lie for an ELF stub: the bootpz path in the same directory still produces real gzip data as vmlinux.nh.gz. Existing aboot.conf files name the image as it was installed in /boot, so only the command that copies it out of the build tree changes. Unlike parisc and mips, the stub is linked at START_ADDR rather than at a separate low address; see compressed/vmlinux.lds.S. It has no console output, since bringing up the HWRPB console callbacks needs more than the CRB dispatch the kernel proper does much later, so error() just halts. The legacy SRM netboot path (bootpz.c) is left alone: it has its own boot protocol (PALcode reinitialization, self-populated ZERO_PGE, build-time-computed image sizes) that does not fit this design without a separate rewrite, and keeps using plain gzip via vmlinux.nh.gz. Co-developed-by: Magnus Lindholm <linmag7@gmail.com> Signed-off-by: Magnus Lindholm <linmag7@gmail.com> Signed-off-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20261017-alpha-kernel-compression-v2-2-c71e6b08dc63@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18xz: add arch-specific tuning for alphaMatt Turner
Alpha has fixed-length, 4-byte-aligned instructions and no XZ BCJ filter, so it wants the same LZMA2 settings as the other 4-byte-aligned targets. Without an entry it hits the default case, which warns scripts/xz_wrap.sh: Arch-specific tuning is missing for 'alpha' and conservatively assumes 2-byte alignment. Alpha gains HAVE_KERNEL_XZ later in this series; the correct alignment also shrinks a UP1500 kernel's XZ image from 6469320 to 6448840 bytes. Signed-off-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Lasse Collin <lasse.collin@tukaani.org> Link: https://lore.kernel.org/r/20261017-alpha-kernel-compression-v2-1-c71e6b08dc63@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select SPARSE_IRQMatt Turner
NR_IRQS on Alpha is sized for the largest configuration each platform supports, and for Marvel that is 32 PIDs, or 32784 interrupts. Without SPARSE_IRQ that becomes a static irq_desc[] array of 12.6 MB in .data, carried by every Marvel and every generic kernel regardless of how many interrupts the machine actually has. A real ES47 uses 87 of them. That is not just wasted memory, it constrains where the kernel can be loaded. The image links at a fixed 0xfffffc0001010000, just above the console's low memory reservation, and with memory striping enabled the console leaves only about 16 MB of usable low memory before the rest is relocated to an interleaved aperture. A 12.6 MB array of mostly unused interrupt descriptors is the difference between fitting and not. Alpha already goes through irq_to_desc() rather than indexing irq_desc[] directly, so nothing stands in the way. The platforms do wire up their interrupts by number, though, which needs the descriptors to exist by then, so provide arch_probe_nr_irqs() returning the machine vector's count instead of taking the NR_IRQS_LEGACY default. Without it every interrupt above 15 would have no descriptor and the handler setup would be silently dropped. Tested on an ES47 (Marvel, 2 EV7z): boots with all device interrupts working, and .data drops by 12.6 MB, from 15.7 MB to 3.1 MB. Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-22-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select ARCH_WANT_IRQS_OFF_ACTIVATE_MMMatt Turner
activate_mm() on Alpha calls __load_new_mm_context() which assigns a new ASID and invokes PALcode swpctx. On SMP, an interrupt arriving between the ASID update and the page table switch could see inconsistent state. Ensure activate_mm() is called with interrupts disabled during exec. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-20-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select ARCH_WANT_LD_ORPHAN_WARNMatt Turner
With .eh_frame and the relocation sections now placed explicitly, an Alpha kernel links with no orphan sections left, so ask the linker to warn if new ones appear. Assisted-by: Claude:claude-opus-5 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-19-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: discard .eh_frame and the relocation sectionsMatt Turner
gcc emits .eh_frame for Alpha even though the kernel builds with -fno-asynchronous-unwind-tables, and nothing in the kernel consumes it: the stack trace code scans the stack for text addresses rather than unwinding DWARF. It was allocated in the loaded image, so dropping it shrinks vmlinux by about 1.1MB for a Marvel SMP configuration. The .rela* sections are equally useless, as the kernel image is not relocatable. The linker was already dropping their contents. Both were being placed as orphan sections, which is what drew attention to them. Assisted-by: Claude:claude-opus-5 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-18-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select SYSCTL_EXCEPTION_TRACEMatt Turner
Report unhandled user faults the way other architectures do, and hook up the debug.exception-trace sysctl that controls the reporting. The message gives the faulting address, the PC and the user stack pointer, and is rate limited. Assisted-by: Claude:claude-opus-5 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-17-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select ARCH_USE_MEMTESTMatt Turner
Wire up the generic early memtest from arch_mm_preinit(), which runs after parse_early_param() has picked up the memtest= command line option and before memblock_free_all() hands the memory to the buddy allocator. paging_init() would be the natural place, but Alpha calls it from setup_arch(), before the option is parsed, so the test would never run. The test range starts at the first DRAM address rather than physical zero because low memory on Alpha is owned by the console and PALcode. Tested under QEMU with memtest=4: all four patterns pass over the free memblock ranges, with no bad memory reserved. Also add ALPHA to the memtest= parameter's architecture list. Assisted-by: Claude:claude-opus-5 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-16-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select HAVE_GUP_FASTMatt Turner
The lockless GUP fast path needs the architecture to distinguish PTEs with no struct page behind them and to keep page table pages alive while a walker holds no lock. Alpha now has ARCH_HAS_PTE_SPECIAL, and it has selected MMU_GATHER_RCU_TABLE_FREE for a long time, so both requirements are met. PTEs are a single 64-bit word on Alpha, so the lockless reads that the generic walker performs cannot tear, and no arch-specific gup_fast_permitted() or ptep_get_lockless() is needed. Assisted-by: Claude:claude-opus-5 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-15-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select ARCH_HAS_DEBUG_VM_PGTABLEMatt Turner
CONFIG_DEBUG_VM_PGTABLE runs a boot-time self test over the page table helpers: the protection bit accessors, pte_modify(), the swap entry encoding including the exclusive marker, and, where the architecture supports them, the huge page helpers. Alpha implements everything the test needs for a three-level page table without huge page support. Also mark Alpha as "ok" in the debug-vm-pgtable feature matrix. Assisted-by: Claude:claude-opus-5 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-14-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: add ARCH_SUPPORTS_PAGE_TABLE_CHECK supportMatt Turner
Add the page table check helpers needed for CONFIG_PAGE_TABLE_CHECK and select ARCH_SUPPORTS_PAGE_TABLE_CHECK in Kconfig. Alpha does not support huge pages, so pmd_user_accessible_page() and pud_user_accessible_page() always return false. pte_user_accessible_page() checks for present PTEs with user read access (_PAGE_URE). Update the helpers to the three-argument pxx_user_accessible_page(mm, addr, pxx) signature introduced by commit cf8771ca4cdb ("mm/page_table_check: Pass mm_struct to pxx_user_accessible_page()"), matching the other architectures. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-13-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: add ARCH_HAS_PTE_SPECIAL supportMatt Turner
Add _PAGE_SPECIAL using bit 19 (0x80000), which is unused in the Alpha PTE layout. This enables pte_special()/pte_mkspecial() for marking PTEs that are not backed by struct page (VDSO mappings, zero page, io_remap_pfn_range, etc.). Include _PAGE_SPECIAL in _PAGE_CHG_MASK so it is preserved across pte_modify() calls. Also mark Alpha as "ok" in the pte_special feature matrix. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-12-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: add HAVE_ARCH_THREAD_STRUCT_WHITELIST supportMatt Turner
Alpha's thread_struct is empty (all per-thread state lives in thread_info), so the whitelist is trivially empty. This is more explicit than the generic fallback, which computes the full thread_struct size as copyable. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-11-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACEMatt Turner
Alpha has a clean split between user and kernel address spaces: user space occupies 0x0000000000000000-0x000003ffffffffff (TASK_SIZE), while kernel space uses KSEG and vmalloc regions near the top of the 64-bit address space. These are strictly non-overlapping. This enables optimizations in BPF and tracing that can skip address range checks when user and kernel pointers are distinguishable by address alone. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-10-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select HAVE_ARCH_COMPILER_HMatt Turner
Alpha already provides asm/compiler.h (wrapping uapi/asm/compiler.h) which defines architecture-specific compiler intrinsics like __kernel_cmpbge, __kernel_cttz, __kernel_ctlz, and __kernel_ctpop. Selecting HAVE_ARCH_COMPILER_H causes linux/compiler_types.h to include asm/compiler.h, making these definitions available consistently. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20260905-arch-kconfig-options-v2-v2-9-83e8245761a2@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18alpha: select ARCH_SUPPORTS_INT128Matt Turner
gcc supports __int128 on Alpha, and the 64x64 to 128-bit multiply that the users in the scheduler and in lib/ care about maps onto mulq/umulh rather than an out-of-line libgcc helper. Variable 128-bit shifts are another matter. gcc open-codes them when optimizing for speed, but with CONFIG_CC_OPTIMIZE_FOR_SIZE=y it calls the libgcc routines __ashlti3, __ashrti3 and __lshrti3 instead. The kernel does not link against libgcc, so provide the three helpers in C, as s390 does, and export them for modules. They are built into the kernel proper rather than lib.a so the exports are present even when nothing built in references them. Like the s390 versions they are marked noinstr, since the compiler may emit calls to them from noinstr code. Gate the select on CC_HAS_INT128 as the other 64-bit architectures do. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Matt Turner <mattst88@gmail.com> Tested-by: Magnus Lindholm <linmag7@gmail.com> Reviewed-by: Magnus Lindholm <linmag7@gmail.com> Link: https://lore.kernel.org/r/20261017174007.695344-1-mattst88@gmail.com Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
2026-10-18Merge power-supply fixes branchSebastian Reichel
Merge power-supply fixes branch to extend the epc_sem unregister fix contained in it from external_power_changed to also cover get/set property. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-17Merge branch 'kbuild-next-speedups' into kbuild-nextNathan Chancellor
This is the first round of commits and fix-ups from Lorenzo's Kbuild speed up series. Signed-off-by: Nathan Chancellor <nathan@kernel.org>
2026-10-17sched_ext: Merge branch 'for-7.3-fixes' into for-7.4Tejun Heo
Pull to receive 680edc7f23ad ("sched_ext: Don't queue balance callbacks from a core-sched pick") and resolve its conflict with the proxy execution work here so that for-next merges clean. Conflicts: - do_pick_task_scx(): 680edc7f23ad samples sched_core_enabled() into a new local next to the prev declaration, which 3d6577ea93c9 ("sched_ext: Split curr|donor references properly") changed to rq->donor. Kept rq->donor and added the local. Signed-off-by: Tejun Heo <tj@kernel.org>
2026-10-17sched_ext: Don't queue balance callbacks from a core-sched pickAndrea Righi
Commit ff0545e0c263 ("sched_ext: Don't leave balance callbacks queued across a pick retry") queues the deferred work as a balance callback only when do_pick_task_scx() returns a final pick. However, under core scheduling, a pick that returns a task isn't final either: pick_next_task() goes on to pick the SMT siblings, and their dispatch can release the shared rq lock with the callback still queued, triggering the rq_pin_lock() warning. Moreover, dispatch_core_pick() returns early when another dispatch is in flight on the rq, and do_pick_task_scx() then consumes %SCX_RQ_BAL_CB_PENDING set by that dispatch while it's still running. This can be reproduced running scx_qmap -I on SMT siblings with coresched-tagged workloads that frequently sleep, mixed with untagged CPU-bound tasks. Fix this by always deferring the pending work to the irq_work path from dispatch_core_pick() under core scheduling, for both the local and the sibling picks, and by leaving %SCX_RQ_BAL_CB_PENDING alone in do_pick_task_scx(), so that it's handled by the dispatch that set it. Sample the core scheduling state once at the start of the pick, since core scheduling can get enabled while a non-core dispatch has the rq lock released, and the follow-up work must match the dispatch path that ran. Fixes: 4c95380701f5 ("sched/ext: Fold balance_scx() into pick_task_scx()") Cc: stable@vger.kernel.org # v6.19+ Signed-off-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Tejun Heo <tj@kernel.org>
2026-10-17Merge branch 'bpf-memory-safety-lifetime-and-locking-fixes'Alexei Starovoitov
Alexei Starovoitov says: ==================== bpf: Memory safety, lifetime and locking fixes This series collects fixes for bugs in the BPF core, the verifier and the BPF side of the networking stack. Most of them are from Josef. Every bug was reproduced in a VM on top of bpf-next, on the kernel right before and right after the patch that fixes it. The splats are in the commit logs. That goes for what the reviews of v1 have found as well. Sleeping, or doing without RCU, where that is not allowed: 02 hash map for_each callbacks of sleepable programs 05 sleepable programs on the task_vma iterator 06 bpf_find_vma() callbacks of sleepable programs 24 maps that rely on RCU in bpf_wq and bpf_task_work callbacks Buffers that iterators and writable tracepoints hand to programs: 19 BPF_LINK_UPDATE skips the size check of the attach 25 tail calls from an iterator program 26 extensions of an iterator program 27 tail calls from a writable raw tracepoint program 28 extensions of a writable raw tracepoint program 29 writes over bpf_timer, bpf_spin_lock, kptr in a live map value The sk_storage map iterator: 14 a socket that sk_clone() is still building can be found and used 15 NULL dereference if the socket goes away 16 an element of a storage that was never published can be found 17 the socket is not held while the program runs Lifetime of local storage, programs and maps: 10 owner_refcnt saturates on the last unpin 30 map_free() frees elements under sleepable readers 22 a program is freed under its bpf_wq callback 23 an inner map is freed under a sleepable callback XDP and devices: 01 devmap egress programs free page_pool fragments as plain pages 20 stale offload->prog after bpf_prog_realloc() 21 a program is bound to a netdev that is being unregistered seg6local End.BPF and bpf_skb_adjust_room(): 11 the SRH of the inner packet is not validated after End.DT6 12 the inner header is not pulled for End.DT6 13 stale SRH pointer if End.B6 fails late 08 gso_size can drop to 0 or wrap around The rest: 03 inode leak if BPF_TOKEN_CREATE fails 04 preallocated hash map hands out an element that is still linked 07 BPF_JSET with a 64 bit mask, 32-bit kernels only 09 probe names of a perf event are read without event_mutex 18 unbounded recursion in the BTF show code Some of the fixes make the kernel refuse what it has accepted so far: - 02, 06: helpers, kfuncs and global functions that may sleep are rejected in these callbacks. - 05: sleepable programs cannot be attached to the task_vma iterator. - 24: in sleepable callbacks, and for inner maps in sleepable programs, maps that rely on RCU need bpf_rcu_read_lock(). - 25, 27: a program with a tail call cannot be attached to a map element iterator or to a writable tracepoint. - 29: an iterator program that writes over a special field cannot be attached to that map. - 04: a nested update of a preallocated hash map on the same CPU can fail with -EBUSY. - 08: bpf_skb_adjust_room() returns -ENOTSUPP if gso_size would drop below TCP_MIN_GSO_SIZE. - 28: writable raw tracepoint programs cannot be extended. With all 43 patches of the series applied, test_progs in its three flavors, test_maps and test_verifier show no new failures. cpumask/test_insert_leave is flaky when the tests run in parallel, with and without the series: its program does not check is_test_task(), so any other fork in the system makes it fail. veristat sees no difference for the 5689 programs of the selftests, nor for the 466 programs of the sched_ext schedulers that BPF CI builds: same verdicts, insns, states and stack depth. v1 -> v2, all of it after the reviews by sashiko and the BPF CI bot: - rebased - 04: cancel the special fields before the element goes into the slot - 08: leave at least TCP_MIN_GSO_SIZE - 16: new. The check in 17 did not hold for a storage that lost the race in bpf_local_storage_alloc(). - 20: update offload->prog under bpf_devs_lock, in bpf_jit_prog_release_other() as well - 24: a global function that is called with preemption or interrupts disabled got around the check - 28: new. Extensions got around 27. - 18: no change. bpf_snprintf_btf() and bpf_seq_printf_btf() only take vmlinux BTF, and the map read in bpffs is BTF_SHOW_UNSAFE. v1: https://lore.kernel.org/bpf/20261017012058.355787-1-alexei.starovoitov@gmail.com/ ==================== Patches 1-30 are applied. The other 13 need one more revision. Link: https://patch.msgid.link/20261017163745.3341787-1-alexei.starovoitov@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-10-17bpf: Free what map_free() unlinks for sleepable readersJosef Bacik
bpf_local_storage_map_free() takes the elements of the map off the lists of their owners, which are alive, and frees them, and the storage of an owner with its last element, behind a plain RCU grace period. Nobody uses the map any more, but the other maps of these owners are in use. A sleepable program calls the get and delete helpers under rcu_read_lock_trace() only. While it walks the list of an owner for its own map, or is about to lock the storage, the element it stands on, or the storage, can be freed under it. Whatever else takes an element off the list of a live owner frees it behind an RCU Tasks Trace grace period, which implies a plain one. Do so in bpf_local_storage_map_free() as well. It waits for these callbacks before it frees the map. This does not help a sleepable program that hands an owner to the helpers which nobody holds, and which may be gone by then. Fixes: dcf456c9a095 ("bpf: Fix usage of trace RCU in local storage.") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-31-alexei.starovoitov@gmail.com
2026-10-17bpf: Keep iterator programs off special map fieldsJosef Bacik
The bpf_map_elem iterator, for all but the per-cpu maps, and the bpf_sk_storage_map iterator hand the live value of an element to the program as a writable buffer. The verifier does not know the map when it checks the program, so nothing keeps the program from writing over a bpf_spin_lock, a bpf_timer, a kptr or another special field, which neither a map update nor a pointer to a map value can touch. With CAP_BPF and CAP_PERFMON, or a BPF token, a program can so make the kernel follow a pointer of its choice: after a write over a bpf_timer the kernel crashes on the written value when the element is removed. Offsets into a buffer are constants. Let the verifier record the range of bytes that a program may write through a read-write buffer, and refuse the program with -EACCES, at attach and at a link update, if a special field of the map lies in that range. A program that only reads, or that writes beside the special fields, works as before. One that writes on both sides of a special field is refused, since the range covers the field. Fixes: d6c4503cc296 ("bpf: Implement bpf iterator for hash maps") Fixes: 5ce6e77c7edf ("bpf: Implement bpf iterator for sock local storage map") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-30-alexei.starovoitov@gmail.com
2026-10-17bpf: Don't take an extension for a writable raw tracepoint programAlexei Starovoitov
bpf_probe_register() compares max_tp_access of the program that is attached with the size of the buffer that the tracepoint lets programs write to. An extension of that program, or of one of its global functions, gets the same context and the same pointer to the buffer. What it accesses is noted in its own max_tp_access, which nobody looks at. So it reads and writes behind the buffer, of a tracepoint that may have none: BUG: KASAN: stack-out-of-bounds in bpf_prog_5843f2b820eb4929_tr26_ext_far+0xf4/0x10c Write of size 4 at addr ffffc90000d8f894 by task wext/103 Refuse such extensions. Fixes: be8704ff07d2 ("bpf: Introduce dynamic program extensions") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-29-alexei.starovoitov@gmail.com
2026-10-17bpf: Assume no bounds for a writable tp with tail callsJosef Bacik
A writable raw tracepoint hands a buffer to the program. The verifier notes how far the program reaches into it, and bpf_probe_register() refuses a program that reaches further than the tracepoint allows. A program that does not touch the buffer passes, and can tail-call one of its type that reads and writes behind it. Take a BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE program with a tail call to reach as far as can be, as for the stack, the packet and the buffers of iterators. It cannot be attached any more. Plain raw tracepoint programs, for which the limit is zero, cannot get at the buffer, and a tail call stays within one type: they are left alone. Fixes: 9df1c28bb752 ("bpf: add writable context for raw tracepoints") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-28-alexei.starovoitov@gmail.com
2026-10-17bpf: Don't take an extension for an iterator programJosef Bacik
An extension inherits the expected_attach_type of the program it extends. If that is BPF_TRACE_ITER, check_attach_btf_id() hands the extension to bpf_iter_prog_supported(), which goes by the name of the attach function. For an extension that is the name of the subprogram it replaces, so the load fails with -EINVAL, unless that subprogram is called like the function of a target, bpf_iter_bpf_map_elem for example. Then the extension gets the context of that target. If the subprogram has as many arguments, it can use the key and the value as buffers, but how far it reaches is noted in the extension, where the test of the iterator link does not look: it reads and writes behind the elements of the map. And the id of the subprogram in the BTF of the program is cached as the id of the target, so that programs of that target which are loaded already cannot be attached. Refuse all extensions here. Fixes: 15d83c4d7cef ("bpf: Allow loading of a bpf_iter program") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-27-alexei.starovoitov@gmail.com
2026-10-17bpf: Assume no bounds for buffers behind a tail callJosef Bacik
The bpf_map_elem, bpf_sk_storage_map and sockmap iterators hand the key and the value of an element to the program as buffers. The verifier notes how far a program reaches into them, and the iterator compares that with the map when the program is attached. A program that does not touch the buffers passes. It can tail-call another program of the same target, which gets the same context, and whose reach nobody compares with the map: BUG: KASAN: slab-out-of-bounds in ___bpf_prog_run+0xa46a/0xae80 The program array can be filled at any time, so there is nothing to look at when the link is made. For the same reason a program with a tail call is taken to use the whole stack and the whole packet. Take it to reach as far as can be into the buffers as well, so that these iterators refuse it with -EACCES. Fixes: d6c4503cc296 ("bpf: Implement bpf iterator for hash maps") Fixes: 5ce6e77c7edf ("bpf: Implement bpf iterator for sock local storage map") Fixes: 0365351524d7 ("net: Allow iterating sockmap and sockhash") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-26-alexei.starovoitov@gmail.com
2026-10-17bpf: Check the maps that sleepable callbacks useJosef Bacik
Sleepable programs can only use the kinds of map that do without an RCU read side critical section. check_map_prog_compatibility() sees to that when a map is bound to the program, and asks whether the program is sleepable. That misses the bpf_wq or bpf_task_work callback of a program that is not, which runs sleepable all the same, and it misses an inner map, which is not bound. The bpf_wq callback of a tc program that looks a key up in a sockhash gets as far as WARNING: net/core/sock_map.c:903 at __sock_hash_lookup_elem+0x18f/0x1e0 Ask the same question for the map that is handed to a helper in sleepable context, unless the RCU read lock is held: by bpf_rcu_read_lock(), or by the helper that runs the callback, as bpf_for_each_map_elem() does for a hash map. Programs that take the lock go on working. Disabled preemption or interrupts are not enough, since the maps ask for rcu_read_lock_held(). The other parts of the program may use such a map as before. A global function that is called with preemption or interrupts disabled is verified for the non-sleepable context, in which nothing is known of all that. Verify it for a context of its own: not sleepable, and without the RCU read lock. It differs in what maps can be used, and in nothing else. What is refused from now on runs into the warning above, or uses what the map frees behind a plain RCU grace period: an entry of a devmap, of a perf event array or of a cgroup array. A bloom filter does without RCU. Add it to the list, so that callbacks which use one go on loading. As a side effect sleepable programs can use bloom filters as well. A pointer to the value of a devmap which a program keeps beyond bpf_rcu_read_unlock() is not dealt with here. Fixes: 638e4b825d52 ("bpf: Allows per-cpu maps and map-in-map in sleepable programs") Fixes: 8e83da9732d9 ("bpf: add bpf_wq_start") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-25-alexei.starovoitov@gmail.com
2026-10-17bpf: Count sleepable callbacks as sleepable map usersJosef Bacik
map->sleepable_refcnt tells bpf_map_fd_put_ptr() whether an inner map that is taken out of its outer map has to wait for an RCU Tasks Trace grace period as well. It counts the sleepable programs that use the outer map. The bpf_wq or bpf_task_work callback of a program that is not sleepable runs under rcu_read_lock_trace() only, and is not counted. Such a callback can look an inner map up and keep it while user space deletes it from the outer map. The inner map is freed behind a plain RCU grace period, under the callback: BUG: KASAN: slab-use-after-free in array_map_update_elem+0x6bc/0x7d0 Count a program with such a callback. The maps are bound before the verifier meets the callback, so raise the count of those that are bound when it does. Fixes: 8e83da9732d9 ("bpf: add bpf_wq_start") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-24-alexei.starovoitov@gmail.com
2026-10-17bpf: Keep a program until its bpf_wq callback has endedJosef Bacik
bpf_wq_work() runs the callback under rcu_read_lock_trace() only, since the callback may sleep. The program it belongs to need not be sleepable, and such a program is freed behind a plain RCU grace period. The reference that the bpf_wq holds is dropped when the map element goes, or when another callback is set, no matter whether the work is running. If that was the last reference the program is freed under the running callback, and the worker goes on in the freed JIT image: Oops: int3: 0000 [#1] SMP NOPTI RIP: 0010:0xffffffffc0600947 All it takes is to close the map and the program while the callback runs. Note in the program that it has a callback that runs sleepable, and wait for an RCU Tasks Trace grace period, which implies a plain one, before such a program is freed. Let bpf_wq_work() enter its read side critical section before it reads callback_fn. bpf_task_work holds a reference to the program until the callback is done. Fixes: 8e83da9732d9 ("bpf: add bpf_wq_start") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-23-alexei.starovoitov@gmail.com
2026-10-17bpf: Don't bind a program to a netdev that goes awayJosef Bacik
bpf_prog_dev_bound_init() looks the device up, takes bpf_devs_lock and registers the device for the program. The reference it holds does not keep the device registered. If bpf_dev_bound_netdev_unregister() has run by the time the lock is taken, nobody takes the program off the device any more: the bpf_offload_netdev and offload->netdev point to a net_device that is freed as soon as the reference is dropped. bpf_dev_bound_resolve_kfunc() dereferences it while the program is verified, and a new device at the same address finds the old entry. unregister_netdevice_many_notify() leaves NETREG_REGISTERED before it calls bpf_dev_bound_netdev_unregister(), which takes bpf_devs_lock. Look at reg_state under that lock, and treat a device that goes like one that is not there. Fixes: 2b3486bc2d23 ("bpf: Introduce device-bound XDP programs") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-22-alexei.starovoitov@gmail.com
2026-10-17bpf: Fix stale offload->prog pointer after reallocJosef Bacik
bpf_prog_realloc() moves a program that the rewrites of the verifier make outgrow its pages. It updates aux->prog, but not the offload->prog of a device-bound program. When the device is unregistered, __bpf_offload_dev_netdev_unregister() hands the stale pointer to __bpf_prog_offload_destroy(), which faults on the freed program: BUG: unable to handle page fault for address: ffffc90000071050 RIP: 0010:__bpf_prog_offload_destroy+0x3f/0x310 It takes the right to load a device-bound XDP program, CAP_BPF and CAP_NET_ADMIN or a BPF token, and a device that can be removed. Commit a1aa9ef47c29 ("bpf: Fix stale offload->prog pointer after constant blinding") repaired the other place that replaces a program. Do the same here. Nothing keeps the device while a program is loaded, so it can also be unregistered at that very moment. That frees the offload, and it may have read offload->prog already when the old copy of the program is freed. In both places update the pointer under bpf_devs_lock, before the old copy goes. Fixes: ab3f0063c48c ("bpf: offload: add infrastructure for loading programs for a specific netdev") Fixes: 2b3486bc2d23 ("bpf: Introduce device-bound XDP programs") Fixes: a1aa9ef47c29 ("bpf: Fix stale offload->prog pointer after constant blinding") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-21-alexei.starovoitov@gmail.com
2026-10-17bpf: Check the new program of an iterator link updateJosef Bacik
The bpf_map_elem, bpf_sk_storage_map and sockmap iterators hand the key and the value of an element to the program as buffers. The verifier only records how far a program reaches into them, and ->attach_target() compares that with the key and value size of the map. bpf_iter_link_replace() does not. BPF_LINK_UPDATE installs a program that an attach refuses with -EACCES, and the program then reads, and for a value writes, behind every element that the iterator visits. It takes CAP_BPF and CAP_PERFMON, or a BPF token. Split the test out of the three ->attach_target() and ask it, as ->check_prog(), for the new program of an update as well. Targets without such a test take every program of their kind, as before. Fixes: d6c4503cc296 ("bpf: Implement bpf iterator for hash maps") Fixes: 5ce6e77c7edf ("bpf: Implement bpf iterator for sock local storage map") Fixes: 0365351524d7 ("net: Allow iterating sockmap and sockhash") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-20-alexei.starovoitov@gmail.com
2026-10-17bpf: Bound the nesting that the BTF show code followsJosef Bacik
btf_struct_show() and btf_array_show() recurse for every nested struct and array. MAX_RESOLVE_DEPTH bounds one resolve walk when BTF is loaded, not the nesting: a member whose type is resolved already is not walked again, so BTF that defines its types from the inside out can nest them as deep as it has types. Whoever may load BTF, with CAP_BPF or a BPF token, can give such a type to the value of a map. Reading the file of that map in bpffs then overruns the kernel stack: with a few hundred levels the stack guard page is hit and the kernel panics. Stop at 32 levels. That is MAX_RESOLVE_DEPTH, and __btf_show_indent() has as many columns. Nothing is shown for a member that lies deeper, and the status becomes -E2BIG, which bpf_snprintf_btf() and bpf_seq_printf_btf() return. The types of an x86_64 defconfig kernel nest 14 deep. Fixes: b00b8daec828 ("bpf: btf: Add pretty print capability for data with BTF type info") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-19-alexei.starovoitov@gmail.com
2026-10-17bpf: Hold the socket in the sk_storage map iteratorJosef Bacik
The iterator over a sk_storage map passes the owner of an element to its program as ctx->sk, without a reference. All that it holds is the RCU read lock, which keeps the element and the storage, not the socket. An element is unlinked by bpf_sk_storage_free(), which __sk_destruct() calls right before it frees the socket. That is no better for a socket with SOCK_RCU_FREE: the grace period comes in front of __sk_destruct(), so a reader which starts behind call_rcu() still finds the element. The program and the helpers it hands ctx->sk to, such as bpf_sk_storage_get() or bpf_sk_storage_delete(), use a socket which is being freed on another CPU. It takes nothing but reading the iterator while sockets with an element in the map are closed, by whomever. Take a reference for the time of the program, and skip the element if there is none to be had. To look at the owner at all, do what bpf_selem_unlink_nofail() does for bpf_local_storage_map_free(): as long as the element is linked under the lock of the storage, bpf_local_storage_destroy() has not got past it, unless it has given up on the lock, and then it waits for owner_refcnt. The last reference may now be dropped by the iterator. The end of a socket may want process context: rfcomm_sock_destruct() takes a mutex. So only drop the reference under RCU, and free a socket whose last one it was when the RCU read lock has been released, which is at the end of a bucket and of every read() at the latest. Fixes: c69d2ddb2072 ("bpf: Using rcu_read_lock for bpf_sk_storage_map iterator") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-18-alexei.starovoitov@gmail.com
2026-10-17bpf: Link the first element after its storage is publishedAlexei Starovoitov
bpf_local_storage_alloc() links the first element of a new storage to the bucket of its map, and then publishes the storage in the owner with cmpxchg(). If another cpu has been faster, the element is taken out of the bucket again and is freed together with the storage. In between the iterator over a sk_storage map can find the element. It stays linked to a storage that points to the socket, but the socket knows nothing of that storage: bpf_sk_storage_free() neither unlinks the element nor waits for anybody who uses the storage. So nothing tells the iterator that the socket has gone away. Three cpus that create the first storage of a new AF_UNIX socket at the same time, and a fourth that reads the iterator, are enough: in 20 seconds its program was shown some 4000 elements of storages that had lost. If the socket is closed in time, the program is handed a freed socket. Link the element once the storage is published. Both happens under the lock of the bucket, which holds off whoever finds the element through the owner and wants to unlink it. Fixes: c69d2ddb2072 ("bpf: Using rcu_read_lock for bpf_sk_storage_map iterator") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-17-alexei.starovoitov@gmail.com
2026-10-17bpf: Fix NULL deref in the sk_storage map iteratorJosef Bacik
bpf_sk_storage_map_seq_find_next() hands out an element only if its local_storage pointer is set. __bpf_sk_storage_map_seq_show() then reads the pointer a second time and dereferences it without a test. Since bpf_local_storage_destroy() unlinks the elements with bpf_selem_unlink_nofail(), the pointer is reset to NULL when the socket which owns the element is destroyed, so it can change between the two reads. Reading the iterator while sockets with an element in the map are closed ends in a NULL pointer dereference. The sockets need not belong to the reader: where a program gives every new socket an element, an unprivileged user who opens and closes sockets is enough. Skip such an element, as the TCP and UDP iterators skip a socket which has been unhashed. Fixes: 0be08389c7f2 ("bpf: Switch to bpf_selem_unlink_nofail in bpf_local_storage_{map_free, destroy}") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-16-alexei.starovoitov@gmail.com
2026-10-17bpf: Clear sk_refcnt of a clone before its storage is linkedAlexei Starovoitov
sk_clone() sets sk_refcnt of the new socket some lines behind bpf_sk_storage_clone(). But the elements which that function copies are linked to their maps at once, and an element leads to its owner: the iterator over a sk_storage map hands the owner to its program. bpf_sk_storage_get() with BPF_SK_STORAGE_GET_F_CREATE and bpf_sk_storage_delete() rely on refcount_inc_not_zero() to tell whether they may touch the socket. sk_refcnt is in the part of struct sock which sock_copy() leaves out, and sk_prot_alloc() does not clear a clone unless init_on_alloc is on. It is zero in an object which has been a socket before, and anything in one which has not. If it is not zero, a helper gets a reference which refcount_set() wipes out, and the helper's sock_put() then drops one of the two references of the new socket, which is freed too early: IPv4: Attempt to release TCP socket in state 1 BUG: KASAN: slab-use-after-free in __raw_spin_lock_init+0x47/0x90 In the meantime the helper changes a storage which bpf_sk_storage_clone() fills without taking its lock. Nothing else can find the clone at this point. Say that it is not alive yet, before the first element is linked. Sockets whose parent has no storage are left alone. Fixes: a50a85e40c59 ("bpf: Expose bpf_sk_storage_* to iterator programs") Suggested-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-15-alexei.starovoitov@gmail.com
2026-10-17bpf: Update the SRH state if End.B6 fails lateJosef Bacik
For SEG6_LOCAL_ACTION_END_B6 and END_B6_ENCAP bpf_lwt_seg6_action() looks for the SRH again only if bpf_push_seg6_encap() has succeeded. That function pushes the new header, for which the head of the skb is reallocated if it has not got the room, and then looks up the route to the first segment. If there is none, it returns an error, and the pointer to the SRH in seg6_bpf_srh_states still points into the old head, which has been freed. The program goes on behind the error. bpf_lwt_seg6_store_bytes() and bpf_lwt_seg6_adjust_srh() read the SRH through that pointer. Look for the SRH whatever bpf_push_seg6_encap() says. Fixes: 486cdf21583e ("bpf: add End.DT6 action to bpf_lwt_seg6_action helper") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-14-alexei.starovoitov@gmail.com
2026-10-17bpf: Pull the inner header for End.DT6 in End.BPFJosef Bacik
bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6) pulls the outer headers off the packet and hands it to seg6_lookup_nexthop(), which reads the inner IPv6 header at skb->data. Nothing says that this header is in the head of the skb, or that there is one. If the head ends with the outer headers, the route is looked up for whatever lies behind the head, and the packet is dropped or leaves by the wrong route. If the program then pushes an SRH with SEG6_LOCAL_ACTION_END_B6, seg6_do_srh_inline() pulls an IPv6 header off a head which has none, and __skb_pull() hits its BUG(): the kernel panics on a packet from the network. GRO pulls the inner header of a plain IPv6 in IPv6 packet into the head. It takes a packet which GRO does not look into that far, one with a fragment header in front of the inner header for example, or a device without GRO, and a driver which leaves the inner header in a fragment. Make sure of the inner header together with the outer ones. The program goes on behind an error of the helper, so do it before the packet is changed. A pull which fails can still have moved the head, so look for the SRH again. Fixes: 486cdf21583e ("bpf: add End.DT6 action to bpf_lwt_seg6_action helper") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-13-alexei.starovoitov@gmail.com
2026-10-17bpf: Validate the SRH which End.DT6 uncovers in End.BPFJosef Bacik
input_action_end_bpf() validates the SRH of a packet and pulls it into the head before the program runs. If the program decapsulates the packet with bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6), bpf_update_srh_state() looks for a routing header in the inner packet and takes it for the new SRH as it is. Nobody has looked at that header, and whoever has sent the packet has written it. ipv6_find_hdr() finds it in a fragment of the skb as well, but hdrlen is then read at that offset from skb->data, past the end of the head. The header need not be an SRH, and its hdrlen need not fit into the packet, but it is marked as valid, and bpf_lwt_seg6_adjust_srh() and bpf_lwt_seg6_store_bytes() check their offsets against it. A program which then adds a TLV at the end of the SRH, where hdrlen has it, makes bpf_lwt_seg6_adjust_srh() move and write memory behind the head of the skb, as far as the sender likes within the 2 KB that hdrlen can say: BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x185/0x240 Read of size 2088 at addr ffff888107d6f09e by task srh/102 BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x1b5/0x240 Write of size 8 at addr ffff888107d6f8be by task srh/102 Use seg6_get_srh(), which pulls and validates the header. Without a valid SRH the state says that there is none, and the packet goes its way as before. The pull can move the head, so compute the data pointers behind it. Fixes: 486cdf21583e ("bpf: add End.DT6 action to bpf_lwt_seg6_action helper") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-12-alexei.starovoitov@gmail.com
2026-10-17bpf: Don't saturate owner_refcnt on the last unpinJosef Bacik
bpf_local_storage_map_free() pins the owner with refcount_inc_not_zero() while it uncharges an element. The pin counts when bpf_local_storage_destroy() could not get local_storage->lock: destroy() then goes on, drops the owner's reference and spins until the count is zero. So the pin is the last reference whenever it is needed, and refcount_dec() takes that for a bug: it warns "decrement hit 0; leaking memory" and saturates the count. Unless destroy() happens to read the count between the two stores it spins for ever, under rcu_read_lock(). Drop the pin with refcount_dec_and_test(). Fixes: 5d800f87d0a5 ("bpf: Support lockless unlink when freeing map or local storage") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-11-alexei.starovoitov@gmail.com
2026-10-17bpf: Read the probe of a perf event under event_mutexJosef Bacik
For a perf event on a kprobe or uprobe event which was made in tracefs, bpf_get_kprobe_info() and bpf_get_uprobe_info() look the probe up by name in the list of dynamic events, and hand a pointer to its symbol or file name back to the caller. None of the callers holds event_mutex. The perf event keeps its trace event alive, nothing else. Other dynamic events are removed from the list and freed during the walk. And a probe which shares its event with other probes can be deleted while the event is in use, so even the probe which is found can be freed, together with the string, before the caller has measured and copied it. The result is a use-after-free in the walk, in strlen() and in the copy to user space, or a NULL pointer dereference. The readers are BPF_OBJ_GET_INFO_BY_FD and fdinfo of a perf link, for whoever holds a descriptor of the link, and BPF_TASK_FD_QUERY. The other side is anybody who may write to dynamic_events, kprobe_events or uprobe_events. Take event_mutex in bpf_get_perf_event_info() and give the caller a copy of the name, which it has to free. Fixes: 41bdc4b40ed6 ("bpf: introduce bpf subcommand BPF_TASK_FD_QUERY") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-10-alexei.starovoitov@gmail.com
2026-10-17bpf: Don't let bpf_skb_adjust_room() use up the MSSJosef Bacik
When bpf_skb_adjust_room() grows a TCP GSO packet without BPF_F_ADJ_ROOM_FIXED_GSO, gso_size is lowered by the number of bytes added. Nothing looks at how large it is. gso_size is the size of the segments the peer has sent if the packet comes out of GRO, and what the sender has written into the virtio header if it comes from a tun device or a packet socket. If it equals len_diff the result is 0, and a packet of up to 64 KB is no GSO packet any more. If it is smaller, the 16 bit value wraps around. One less than len_diff gives GSO_BY_FRAGS. skb_segment() then takes the length of each segment from the frag_list. A packet with more than 64 KB of payload gets that far, and one from a tun device has no frag_list: BUG: KASAN: null-ptr-deref in skb_segment+0xcf1/0x1a90 BUG: kernel NULL pointer dereference, address: 0000000000000070 tcp_gso_segment+0x1be/0x9f0 inet_gso_segment+0x288/0x740 inet_gso_segment+0x288/0x740 skb_mac_gso_segment+0x179/0x2e0 What is left must not be less than TCP_MIN_GSO_SIZE either. The stack relies on that for the number of segments to fit into gso_segs, see commit c27c449d455a ("virtio-net: Ensure that TCP packets don't overflow gso_segs"). Refuse to grow a packet that would end up with less, with the error that other packets which cannot be adjusted get. Fixes: 2be7e212d541 ("bpf: add bpf_skb_adjust_room helper") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-9-alexei.starovoitov@gmail.com
2026-10-17bpf: Look at all 64 bits of a BPF_JSET mask on 32-bitJosef Bacik
In the branch of a BPF_JSET which is taken, the verifier can learn something about the register only if the mask has a single bit: then this bit is set. regs_refine_cond_op() tests this with is_power_of_2(val) and then ORs val into var_off. val is a u64, but is_power_of_2() takes an unsigned long. On a 32-bit kernel it only sees the lower half of the mask. For if r1 & 0xffffffff80000000 goto l which is a BPF_JSET | BPF_K with an immediate of 0x80000000, the lower half is a power of two. So the verifier takes all 33 bits for set at l, while the branch is taken if any of them is. A mask of 0x100000001 from a register does the same for bit 0. The log of an i386 kernel, for r6 = bpf_get_prandom_u32() << 31: 3: (45) if r6 & 0x80000000 goto pc+2 from 3 to 6: R6=0xffffffff80000000 R10=fp0 6: (77) r6 >>= 63 ; R6=1 When the program runs, r6 >> 63 is 0. >From then on the verifier works with known bits which the register does not have at run time. It accepts, for example, an offset into a map value which it derives from these bits and believes to be constant, and the program can access memory outside of the map value. Count the bits of the whole value. Only 32-bit kernels are affected. On a 64-bit kernel unsigned long holds the whole mask, and this patch changes nothing. Fixes: 960ea056561a ("bpf: verifier: teach the verifier to reason about the BPF_JSET instruction") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-8-alexei.starovoitov@gmail.com
2026-10-17bpf: Forbid sleeping in bpf_find_vma() callbacksJosef Bacik
A sleepable program can call bpf_find_vma() and use a sleepable helper such as bpf_copy_from_user() or bpf_copy_from_user_task() in the callback. The verifier accepts this, but bpf_find_vma() runs the callback with the mmap_lock of the mm held for read. If the user copy faults on that mm, the fault handler has to take mmap_lock again. Lockdep reports recursive locking, and if a writer queued up in between, the fault blocks behind the writer, which waits for the read lock the helper already holds: sleepable prog other thread of the same mm bpf_find_vma(current, ...) mmap_read_trylock(mm) mmap_write_lock(mm) <- waits callback: copy_from_user() page fault mmap_read_lock(mm) <- queued behind the writer This is the same problem as with sleepable task_vma iterator programs. The verifier checks synchronous callbacks in the caller's context, so in_sleepable_context() is true in the callback of a sleepable program. Verify the callback like a hash map for_each callback, as running in an RCU read-side critical section where sleeping is not allowed, and actually hold rcu_read_lock() around it, so that global functions the callback calls, which are then verified for a non-sleepable context, see the RCU protection they are verified with. Non-sleepable programs already run the callback under RCU, nothing changes for them. A sleepable program whose bpf_find_vma() callback calls any helper, kfunc or global function that may sleep is now rejected by the verifier, including ones that would be harmless under mmap_lock as they don't touch user memory. Fixes: 7c7e3d31e785 ("bpf: Introduce helper bpf_find_vma") Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261017163745.3341787-7-alexei.starovoitov@gmail.com