summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf
AgeCommit message (Collapse)Author
7 daysMerge tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpfLinus Torvalds
Pull bpf fixes from Alexei Starovoitov: "Mostly sockmap fixes as promised, plus uprobe ctx rewrite via bpf and cgroup-bpf fixes. - Reject writable map iterators on read-only maps (Adethya Srinivasan) - Various sockmap fixes (Alexei Starovoitov): - Clear the redirect target before the sk_msg prog runs - Check that the redirected message is the cork - Leave sk_stream_wait_memory() once the socket is dead - Keep the rest of the cork after a redirect - Don't let an SK_PASS verdict cover the next message - Subtract all dropped bytes from the return value of sendmsg() - Clear the end mark of elements added by bpf_msg_push_data() and bpf_msg_pop_data() - Fix ring capacity invariant break in bpf_msg_push_data() (Bo Cao) - Report RCU-tasks quiescent states in do_check() to fix rcu_tasks stalls during a long verification (Breno Leitao) - Various sockmap fixes (Chris Mason): - Give no progs to a TCP listener - Check the target of an egress redirect before each send - Check the TCP state in recvmsg() - Reset the copy position when corking - Don't copy 0 bytes into a full cork - Use a dedicated workqueue for freeing BPF programs to fix a deadlock between pack_mutex waiters and the vmalloc purge work (Emil Tsalapatis) - Fix verifier model mismatch on a narrow read of __sk_buff.remote_port (Henry Martin) - Fix bpf-gcc CO-RE relocation in verifier_sockmap_mutate selftest (Jiayuan Chen) - Restrict uprobe ctx writes to the registers that ptrace can set (Jiri Olsa) - Various sockmap fixes (Josef Bacik): - Write sg.start when recvmsg() faults - Don't let an SK_DROP verdict stick - Clear the resume state of a stopped psock - Various fixes (Michal Luczaj): - Fix "unresolved symbol tcp_request_sock" build error with CONFIG_INET=n - Restrict iter-context sockmap updates to iter/sockmap - Restrict bpf_sock_destroy() to iter/{tcp,udp} - Mark bpf_iter__sockmap::sk as PTR_TRUSTED - Mark backing_file_alloc/free LSM hooks as untrusted (Sergei Nizovtsev) - Various cgroup-bpf fixes (Shakeel Butt): - Don't read freed effective arrays in BPF_PROG_QUERY - Don't attach to a removed cgroup - Protect cgroup_bpf state with its own mutex, so that queries and the release work don't wait for cgroup_mutex - Don't lose errors in effective BPF_LSM_CGROUP queries - Check variable-offset accesses against special fields (Shihuang Liu)" * tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: (38 commits) selftests/bpf: Test which ctx registers a uprobe prog can write bpf: Restrict uprobe ctx writes to the registers ptrace can set selftests/bpf: Fix bpf-gcc CO-RE relocation in verifier_sockmap_mutate bpf, cgroup: Don't lose errors in effective BPF_LSM_CGROUP queries bpf, cgroup: Protect cgroup_bpf state with its own mutex bpf, cgroup: Don't attach to a removed cgroup bpf, cgroup: Don't read freed effective arrays in BPF_PROG_QUERY bpf: Fix verifier model mismatch on __sk_buff.remote_port narrow read bpf: Fix "unresolved symbol tcp_request_sock" build error selftests/bpf: Add iter/sockmap bpf_sock_destroy() negative test bpf: Mark bpf_iter__sockmap::sk as PTR_TRUSTED bpf: Restrict bpf_sock_destroy() to iter/{tcp,udp} bpf, docs: Document BPF_ITER_NOSLEEP selftests/bpf: Add negative test for sockmap update from non-sockmap iter bpf, sockmap: Restrict iter-context sockmap updates to iter/sockmap selftests/bpf: Remove sockmap update from bpf_iter_unix bpf, lsm: Mark backing_file_alloc/free LSM hooks as untrusted bpf: Report RCU-tasks quiescent states in do_check() bpf: Check variable-offset accesses against special fields bpf: Use dedicated workqueue for freeing BPF programs ...
8 daysselftests/bpf: Test which ctx registers a uprobe prog can writeJiri Olsa
A uprobe program can write only the pt_regs fields that ptrace can set to any value. Add verifier tests for x86-64, arm64 and riscv: - writes to the general registers, the stack pointer and the instruction pointer load - writes to cs, ss, flags and orig_ax on x86-64, to pstate and orig_x0 on arm64, and to status, badaddr and cause on riscv fail with "invalid bpf_context access" - a 4-byte write to the low half of a read-only field fails too - reading a read-only field still works - on x86-64, a kprobe program that writes ctx->flags fails to load Other arches get one test that just loads. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261118084451.12590-3-jolsa@kernel.org
8 daysselftests/bpf: Fix bpf-gcc CO-RE relocation in verifier_sockmap_mutateJiayuan Chen
bpf-gcc fails to load test_trace_iter_unix: Error: #766/6 verifier_sockmap_mutate/test_trace_iter_unix libbpf: elf: skipping section(3) .data (size 0) libbpf: elf: skipping unrecognized data section(18) .comment run_subtest:PASS:obj_open_mem 0 nsec libbpf: prog 'test_trace_iter_unix': relo #0: insn #0 (LDX/ST/STX) accesses field incorrectly. ... libbpf: prog 'test_trace_iter_unix': BPF program load failed: -EINVAL libbpf: prog 'test_trace_iter_unix': failed to load: -EINVAL libbpf: failed to load object 'verifier_sockmap_mutate' run_subtest:PASS:unexpected_load_success 0 nsec validate_msgs:FAIL:1014 expect_msg VERIFIER LOG: ============= 0: R1=ctx() R10=fp0 ; @ verifier_sockmap_mutate.c:124 0: <invalid CO-RE relocation> failed to resolve CO-RE relocation <byte_off> [4] struct bpf_iter__unix (0:0 @ offset 0) processed 1 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 ============= EXPECTED SUBSTR: 'cannot update sockmap in this context' GCC only applies preserve_access_index to types that carry the attribute themselves. The anonymous union holding the sock pointer doesn't, so the CO-RE access stops at the union ("0:0") instead of reaching the pointer ("0:0:0"), and libbpf rejects the relocation. Fixes: e16c83fa764f ("selftests/bpf: Add negative test for sockmap update from non-sockmap iter") Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://patch.msgid.link/20261117122417.340562-1-jiayuan.chen@linux.dev
13 daysselftests/bpf: Add iter/sockmap bpf_sock_destroy() negative testMichal Luczaj
bpf_sock_destroy() is restricted to socket-locked iters, TCP and UDP. Fail attempting it from iter/sockmap. Signed-off-by: Michal Luczaj <mhal@rbox.co> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261107-sockmap-update-limit-iter-v3-7-7c0bad1ad036@rbox.co
13 daysselftests/bpf: Add negative test for sockmap update from non-sockmap iterMichal Luczaj
Iterator-context sockmap updates are now restricted to iter/sockmap. Add a test that attempts an update from iter/unix and expects it to fail. Signed-off-by: Michal Luczaj <mhal@rbox.co> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261107-sockmap-update-limit-iter-v3-3-7c0bad1ad036@rbox.co
13 daysselftests/bpf: Remove sockmap update from bpf_iter_unixMichal Luczaj
BPF iterator programs that can update sockmaps will be limited to iter/sockmap. Remove the update from the unix selftest. This reverts commit 997b8483d44c ("selftests/bpf: Extend bpf_iter_unix to attempt deadlocking"). Signed-off-by: Michal Luczaj <mhal@rbox.co> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev> Link: https://patch.msgid.link/20261107-sockmap-update-limit-iter-v3-1-7c0bad1ad036@rbox.co
2026-11-12selftests/bpf: Check writable iterator attach to a read-only arrayAdethya Srinivasan
Reuse dump_bpf_array_map(), which writes to ctx->value, and attempt to attach it to an array with BPF_F_RDONLY_PROG set. Assert that the attach returns -EACCES and destroy the link if it unexpectedly succeeds. The test fails on an unfixed kernel and passes with the fix applied. Signed-off-by: Adethya Srinivasan <adethyasrinivasan@outlook.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/LO2P302MB019736CF58FAA4C98C6F78AABC702@LO2P302MB0197.GBRP302.PROD.OUTLOOK.COM
2026-11-10selftests/bpf: cover AF_XDP multi-buffer TX software checksumRongzheng Wang
Extend test_xdp_metadata to send the same UDP packet using every descriptor count from 1 through MAX_TX_DESCS (MAX_SKB_FRAGS + 1), and to run the existing metadata and checksum verification for each case. Build the packet once and write it into the TX descriptors in a loop instead of using a flat two-descriptor layout. Keep the first descriptor large enough to cover the checksum offset; the remaining payload is split across the continuation descriptors, with the last descriptor taking the remaining length. Reuse the existing AF_XDP setup, packet generation, completion, and receive helpers in xdp_metadata.c instead of adding a separate test harness. Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Signed-off-by: Rongzheng Wang <testwrzwrz@gmail.com> Link: https://patch.msgid.link/20261104034809.24545-3-testwrzwrz@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2026-11-02Merge tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpfLinus Torvalds
Pull bpf fixes from Alexei Starovoitov: "Fix various bugs in bpf core and bpf-lwt. Looks like the speed of us fixing bugs is higher than the number of new bugs found. Not out of the woods yet. sockmap fixes will come later. - Various fixes (Alexei Starovoitov): - Use one may_goto time slice per prog invocation instead of one per stack frame to fix a soft lockup in loops that nest across calls - Fix use-after-free in btf__add_type() in libbpf - Invalidate a dynptr slice when its stack buffer is written or when the frame of the buffer returns - Fix the tracking of pointers to the stack in SCEV - Keep the valid bytes of a packet pointer in SCEV - Fix bpf_throw() in a prog with a private stack in x86 JIT - Compare the arguments of an extension prog with those of its target - Don't accept memory of the prog for struct arguments of KF_ACQUIRE kfuncs and for arguments of an empty struct type - Fix mmap() of an arena: refuse address 0 and a length above max_entries pages, etc. - Don't let bpf_skb_adjust_room() raise gso_size to GSO_BY_FRAGS - Fix lwt progs: reset skb->cb and don't leave a stale MAC header after a prog pushes an IP header, require BPF_LWT_REROUTE when an lwt_in prog changes the protocol, don't call into IPv6 when it is disabled, don't look for the SRH again in the End.BPF helpers, and set a dst for test runs of lwt_in progs - Fix bpf_dynptr_copy() for overlapping ranges in one packet (Ayushman Rout) - Various fixes (Chris Mason): - Reject memory of the prog for kfunc projection type arguments - Require prog fd or capability for cgroup prog detach - Keep the skb network offset signed in cgroup skb progs - Reject non-IPv6 packets in BPF_LWT_ENCAP_SEG6 - Limit the SRH length and move the MAC header in bpf_lwt_seg6_adjust_srh() - Move the transport header together with the headers that bpf_skb_adjust_room() and bpf_lwt_seg6_adjust_srh() move, and use the inner transport header after a decap - Check the offset in bpf_skb_generic_{push,pop}() - Mark jmp mode of ftrace direct trampolines on x86 by clearing bit 63 of the address instead of setting bit 0, since an ftrace callback can start at an odd address (Daniel Borkmann) - Fix psock update-side data races on sk->sk_prot and progs in sockmap (Jakub Sitnicki) - Fix skb_pull() BUG in __bpf_redirect_neigh(): make sure that the MAC and IP headers are there and are linear (Jamal Hadi Salim) - Fix jited line info that is off by the CFI preamble on x86-64, arm64 and riscv64 (Jose Fernandez) - Clamp the trace length in __bpf_get_stack() to fix a write after the end of the buffer (Josef Bacik) - Drop percpu_counter from the htab element count, since its lock can deadlock with NMI and tracing progs that update the same map (Puranjay Mohan) - Propagate scalar precision through stack arguments (Xu Yunxiang) - Fix callback recursion selftest with llvm24 (Yonghong Song) - Free the skb when bpf_xmit() fails to expand the headroom (Yuqiang Sun)" * tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: (61 commits) libbpf: Fix use-after-free in btf__add_type selftests/bpf: Exercise stack argument precision on state reuse bpf: Propagate scalar precision through stack arguments selftests/bpf: Fix callback recursion test with noipa global func selftests/bpf: Test one may_goto time slice per prog invocation bpf: End bpf_loop() when the time of may_goto is up bpf: One may_goto time slice per prog invocation bpf: Pass a pointer to arch_bpf_timed_may_goto() s390/bpf: Support internal-only MOV instruction to resolve per-CPU addrs selftests/bpf: End the loop of parallel_test_bitmap after 50 ms selftests/bpf: Give the first loop of cond_break5 an end selftests/bpf: Don't cast a pointer to .bss in arena_htab_asm bpf: Emit timed may_goto for JITed progs only selftests/bpf: Test writes to the buffer of bpf_dynptr_slice_rdwr() bpf: Invalidate a dynptr slice when its stack buffer is written selftests/bpf: Test a callee that overwrites a spilled pointer of its caller bpf: Don't trust pointers spilled in slots that a callee can write selftests/bpf: Test the join of fp+0 with a value that is not a pointer to stack bpf: Fix the join of fp+0 with a value that is not a pointer to stack selftests/bpf: Run arena_mmap serially and test MAP_FIXED addresses ...
2026-11-02selftests/bpf: Exercise stack argument precision on state reuseXu Yunxiang
Add two asm regressions for the precision of the sixth argument, which is passed in a stack argument slot and used as a map value offset. The first test reuses a safe state after storing arg6 from a register. Precision must propagate from that slot to the register at an earlier checkpoint, so a later out-of-bounds path cannot reuse that checkpoint. The second test triggers conservative precision fallback by backtracking across a store through a register that later becomes a scalar through pointer subtraction. The caller's argument slot must become precise so an out-of-bounds argument cannot reuse the safe state. Both programs are load-only rejection tests and use the existing stack argument compiler and architecture guards. The two test programs were supplied by Alexei Starovoitov during review and are included unchanged. AI assistance was used in preparing this patch. Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com> Signed-off-by: Xu Yunxiang <xyx2021@mail.ustc.edu.cn> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/DMJI3GWXQOC9.UA3K9X139AR@gmail.com/ Link: https://patch.msgid.link/20261102190350.788433-3-xyx2021@mail.ustc.edu.cn
2026-11-02selftests/bpf: Fix callback recursion test with noipa global funcYonghong Song
With llvm24 after commit 28b4a2032f97 ("[BPF] Mark global functions noipa"), the test recursion_via_global_func_and_callback fails: 13: (85) call bpf_loop#181 4: frame1: R1=scalar() R10=fp0 cb ; return static_calls_global(i); @ verifier_global_subprogs.c:548 4: (85) call pc+1 ... ; return global_calls_loop(x); @ verifier_global_subprogs.c:543 6: (85) call pc+1 Func#3 ('global_calls_loop') is global and assumed valid. 7: frame2: R0=scalar() 7: (95) exit ... ; return static_calls_global(i); @ verifier_global_subprogs.c:548 5: (95) exit At callback return the register R0 has unknown scalar value should have been in [0, 1] ============= EXPECTED SUBSTR: 'recursive call from global_calls_loop() to loop_cb_calls_static()' #669/9 verifier_global_subprogs/recursion_via_global_func_and_callback:FAIL The callback loop_cb_calls_static() returns the result of static_calls_global(), which in turn returns the result of the global function global_calls_loop(). Before the above llvm24 commit, IPSCCP (interprocedural sparse conditional constant propagation) could fold the return value of global_calls_loop() into its callers. global_calls_loop() is not static, but it has a non-weak definition in the same compilation unit, so IPSCCP may assume that definition is the one called. It found that global_calls_loop() always returns 0 and replaced the uses of the call result with 0, which made static_calls_global() and then loop_cb_calls_static() return a constant 0 as well. The calls stay, only their return values are replaced. So the callback set R0 to 0 itself, passed the bpf_loop callback return range check, and verification went on to report the expected recursion. The llvm24 commit marks global functions noipa, since the verifier checks a global function only against its BTF prototype and freplace can replace it. With noipa, IPSCCP no longer propagates the return value of global_calls_loop() to callers. The verifier does not look into a global function either, so R0 after the call is an unknown scalar, and the callback return check fails before the recursion is detected. Make static_calls_global() return void and let loop_cb_calls_static() return 0 explicitly. The call chain the test is about stays the same, and the test passes with both llvm24 and earlier versions (e.g. llvm21 to llvm23). Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://github.com/llvm/llvm-project/pull/237690 Link: https://patch.msgid.link/20261102192727.762933-1-yonghong.song@linux.dev
2026-11-02selftests/bpf: Test one may_goto time slice per prog invocationAlexei Starovoitov
Most tests call a function that spins until may_goto stops it, four times. With one time slice for an invocation of the prog only the first call spins. With a time slice for each frame all four calls spin, and the test fails after 1 sec. group tests -------------- ------------------------------------------------------ the problem 9 insns, three levels of short loops, a subprog with 65534 iterations, bpf_loop() with a callback that spins or makes 60000 iterations ways to a loop call, call through a function without a loop, global function, callx, bpf_loop() inlined and not, bpf_for_each_map_elem(), bpf_user_ringbuf_drain(), bpf_find_vma(), bpf_rbtree_add() bpf_loop() ends when the time is up: inlined and not, in a callback of bpf_loop(). Goes on when BPF code calls the callback too count a loop that is on the stack ends when the time is up, 65535 calls that make one iteration read the clock new time slice timer, wq, task_work, call_rcu, call_rcu_tasks_trace, each after a prog on the cpu that used up its time. Tail call, extension prog same one a timer callback that interrupts the prog doesn't give it more time, the exception callback registers may_goto takes a register that is dead: R0-RN are live, for each N. A register that is live through the back edge only, at the target only, behind the may_goto only. All of that when it calls C and when the time is up. 16-byte return value other tracing prog with frames in a private stack, may_goto in dead code Two tests lock up a cpu on a kernel with a time slice for each frame: the 9 insns and the three levels of short loops. All other tests give up and fail there, or pass. The tests are for x86-64 and arm64 with the JIT only. may_goto_far gets four subtests with the may_goto in a subprog. The test is serial. Its progs spin for 250 ms in an RCU read-side critical section, one after the other. Next to them in 'test_progs -j' the test "mmap" gives up its wait for the end of a map. The test takes 10 sec. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261031215543.682284-10-alexei.starovoitov@gmail.com
2026-11-02bpf: One may_goto time slice per prog invocationAlexei Starovoitov
The count and the timestamp of may_goto are in the stack frame. So the limit of 250 ms is for one call of a subprog, not for one invocation of the prog, and loops that nest across calls multiply it. These 9 insns cause a soft lockup: main: sub: 1: call sub 1: may_goto 2f may_goto 2f goto 1b goto 1b 2: r0 = 0 2: r0 = 1 exit exit Use one count and one timestamp for all may_goto of a prog, in per-cpu memory of the prog. The main prog sets them in its first insns. When the time is up each loop ends at its next may_goto, in any function. rX = address of the count rX = &(void __percpu *)(rX) r12 = *(u64 *)(rX +0) if r12 == 0x0 goto target r12 -= 1 if r12 != 0x0 goto pc+2 r12 = rX call arch_bpf_timed_may_goto *(u64 *)(rX +0) = r12 rX is a register that is dead at the may_goto. When all ten are live R0 is saved in the stack. An async callback can interrupt the prog on the same cpu. So its caller sets count and timestamp, and puts the old values back at the end. A second invocation of the prog on the same cpu gives more time to the first one. x86-64 (Zen 5), nsec before after iteration, empty loop 0.36 0.44 iteration, the body takes 4 cycles 0.89 0.89 call of a subprog and 1 iteration 1.21 1.16 The 56 progs of scx with may_goto get 1.7% more JITed code and use 25% less stack. Fixes: e723608bf428 ("bpf: Add verifier support for timed may_goto") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261031215543.682284-8-alexei.starovoitov@gmail.com
2026-11-02bpf: Pass a pointer to arch_bpf_timed_may_goto()Alexei Starovoitov
arch_bpf_timed_may_goto() gets the offset of count and timestamp in the stack frame in BPF_REG_AX. Arch code adds the frame pointer to it, and calls bpf_check_timed_may_goto() with the result. On arm64, riscv, loongarch, powerpc and s390 the asm function does it. On x86-64 the JIT does it, because the frame pointer is in another register when the prog has a private stack. The next patch moves count and timestamp out of the stack frame. So pass the pointer in BPF_REG_AX, and let the verifier emit the addition: before after r12 = -16 r12 = r10 call arch_bpf_timed_may_goto r12 += -16 call arch_bpf_timed_may_goto The JITs know which register r10 is. The asm functions have a move in place of the addition, and the special case in the x86-64 JIT goes away. These insns run when the count is used up: in each 65535th iteration. The cost of an iteration does not change. Three tests have the insns of may_goto in them. Update them. Tested on x86-64, and on arm64 and s390 in QEMU. riscv, loongarch and powerpc are compile tested only. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261031215543.682284-7-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: End the loop of parallel_test_bitmap after 50 msAlexei Starovoitov
The two progs of parallel_test_bitmap change bits of the same words in a loop of 10000000 iterations with can_loop. The loop goes on until may_goto stops it. The functions that it calls retry a cmpxchg that fails: do { ... actual = cmpxchg(&bmp->bits[idx], old, new); if (actual == old) return true; } while (can_loop); return false; The retry is always possible only while each stack frame has a time slice of its own. With one time slice for all may_goto of a prog, a function that is called after the time is up makes no iteration. The bit does not change, and the test fails with -EINVAL, in 53 of 900 runs. Leave the loop after 50 ms. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261031215543.682284-5-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Give the first loop of cond_break5 an endAlexei Starovoitov
The main prog of cond_break5 spins until may_goto stops the loop. Then it calls a subprog and expects that the loop of the subprog makes iterations. This is true only while each stack frame has a time slice of its own. Stop the first loop after 100 iterations. The test still makes sure that may_goto works in the main prog and in a subprog of one prog. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261031215543.682284-4-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Don't cast a pointer to .bss in arena_htab_asmAlexei Starovoitov
arena_htab_asm is arena_htab.c with BPF_ARENA_FORCE_ASM. In this variant __arena has no address space, so arr1 is in .bss, and cast_kern() is a real insn. cast_kern(arr) turns the pointer to .bss into an offset in the arena. Each of the 100000 stores to arr[i] faults, and the fault handler of the arena skips it. Remove the cast. In the other variant it is a nop. The prog takes 67 ms in place of 950 ms on a kernel with lockdep. With one time slice for all may_goto of a prog, may_goto stops the loops of the old prog after 250 ms. The test does not see that, because it looks at the first keys only. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261031215543.682284-3-alexei.starovoitov@gmail.com
2026-11-02bpf: Emit timed may_goto for JITed progs onlyAlexei Starovoitov
The timed form of may_goto calls arch_bpf_timed_may_goto(). This function takes its argument and returns its result in BPF_REG_AX, in a register of the cpu. Only JITed code can call it. The verifier emits the timed form when the arch has a JIT that supports it. It does not look at the prog. With CONFIG_BPF_JIT_ALWAYS_ON=n the interpreter can run such a prog: the JIT is off, or it fails. The interpreter calls the function like a helper. The function takes what the C code left in that register for a pointer, and bpf_check_timed_may_goto() reads and writes through it. Emit the timed form only when the prog asks for a JIT, and make the JIT mandatory for such a prog. All other progs get the form that counts down from BPF_MAX_LOOPS. One test of verifier_may_goto_1 shows the insns of the timed form. Load it only when progs are JITed. Fixes: e723608bf428 ("bpf: Add verifier support for timed may_goto") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261031215543.682284-2-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Test writes to the buffer of bpf_dynptr_slice_rdwr()Alexei Starovoitov
bpf_dynptr_slice_rdwr() and bpf_dynptr_slice() can return the buffer. When the buffer is on the stack, a store to the buffer invalidates the slice. See "bpf: Invalidate a dynptr slice when its stack buffer is written". dynptr_fail.c gets short progs with skb, xdp and file dynptrs. They cover the events that invalidate a slice, the borders of the buffer, a copy of the slice on the stack and in a caller, pruning, read-only slices, and events that leave the slice valid. They end with a load through the slice and are only loaded. test_dynptr_skb_slice_rdwr_buffer in dynptr_success.c runs on a non-linear skb. It shows that the slice is the buffer, and that the pattern of the documentation continues to work. It passes without the fix too. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261102170958.3586893-3-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Test a callee that overwrites a spilled pointer of its callerAlexei Starovoitov
The caller spills &fp[-8] to fp-16 and passes a pointer to another slot of its frame to a callee, which stores a pointer to a map value to fp-16. The caller fills fp-16 and stores through it. That store is not a certain write to fp-8. Three valid progs read fp-8 after the store. The callee is a static subprog or a callback of bpf_loop(). In callee_overwrites_spilled_r10 the slot holds a copy of r10. That prog also needs "bpf: Fix the join of fp+0 with a value that is not a pointer to stack". Without the fix they fail with: reading from stack off -8+0 size 8, slot poisoned by dead code elimination In callee_overwrites_spilled_fp_hidden_store the store hides a write to the counter of a loop. Without the fix the prog loads, and it accesses a map value out of bounds. The test for callx checks the spilled pointer in the log. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261102055913.3598414-5-alexei.starovoitov@gmail.com
2026-11-02bpf: Don't trust pointers spilled in slots that a callee can writeAlexei Starovoitov
arg_track follows pointers to the stack through registers and spills. Scalar evolution and the removal of dead slots rely on it to know which slots an insn reads and writes. arg_track assumes that a call does not change the pointers that are spilled in the frame of the caller. But a static subprog or a callback can store a pointer to other memory there, and the caller can use it: *(u64 *)(r10 - 16) = fp-8 r1 = fp-16, r2 = map_value call sub ; *(u64 *)(r1 + 0) = r2 r7 = *(u64 *)(r10 - 16) ; verifier: map_value. arg_track: fp-8 *(u64 *)(r10 - 8) = fp-24 *(u64 *)(r7 + 0) = 0 ; arg_track: fp-8 is overwritten r8 = *(u64 *)(r10 - 8) ; verifier: fp-24. arg_track: none loop: r1 = *(u64 *)(r10 - 24) ; the counter of the loop ... *(u64 *)(r8 + 0) = 4096 ; arg_track: not a write to fp-24 Scalar evolution does not see the last store. It gives the counter the range of a loop that only increments it. The prog loads, and it accesses a map value out of bounds. Valid progs are rejected as well. The store through r7 makes fp-8 dead, and a later read of fp-8 fails with "slot poisoned by dead code elimination". When a static subprog or a callback can get a pointer to the frame of its caller, join every slot of that frame with "not a pointer to the stack". Reads and possible writes through a filled pointer are still seen, but no store through it is a certain write. It has to be every slot: the callee reaches the whole frame from one pointer, and callees are analyzed after the caller. The price is precision: an 8-byte load through a filled pointer gives a value that can point to any frame. For a spilled copy of r10 this needs "bpf: Fix the join of fp+0 with a value that is not a pointer to stack". In selftests, Cilium and sched_ext the stack marks change in 4 of 12522 progs. Verdicts, insns and states do not change in any prog. one_fp_clear_stack_threshold and two_fp_clear_stack_threshold expect the fake offset fp+0 in the log now. Fixes: bf0c571f7feb ("bpf: introduce forward arg-tracking dataflow analysis") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261102055913.3598414-4-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Test the join of fp+0 with a value that is not a pointer to stackAlexei Starovoitov
A register is r10 on one path and a pointer to a map value on the other path. A store through it is not a certain write to the stack. join_of_r10_and_map_value is a valid prog. It reads the slots after the stores. The join has one branch for "pointer to stack joins other value" and one branch for the reverse order. The prog has one register for each order, and it checks in the log that it takes both branches. Without the fix the slots are dead in front of the stores, and the verifier rejects the read: reading from stack off -8+0 size 8, slot poisoned by dead code elimination In join_of_r10_and_map_value_hidden_store the slot holds a pointer to the counter of a loop. Without the fix the pointer is lost, and scalar evolution does not see the store through it. The prog loads, and it accesses a map value out of bounds. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261102055913.3598414-3-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Run arena_mmap serially and test MAP_FIXED addressesAlexei Starovoitov
Each arena reserves 4 GiB of vmalloc space. The KASAN shadow of arenas from parallel tests can exhaust the memory of a CI VM. Thus commit a14f9ba080c1 ("selftests/bpf: Run arena tests serially") made arena_* and libarena* serial. Do the same for arena_mmap, which the commit below added later. Add four subtests for "bpf: Don't move a MAP_FIXED address in arena_get_unmapped_area()". Test that mmap() with MAP_FIXED or MAP_FIXED_NOREPLACE fails with EINVAL if the range crosses a 4 GiB boundary. Test that mmap() with MAP_FIXED also fails for a range that wraps and for a map_extra range that ends above TASK_SIZE. Today arena_map_alloc() accepts such a map_extra. map_extra_last_pages also passes if the kernel refuses the map, because no task can map this range. The arch code gets a range before the arena code tests it for a crossing. For the last two ranges LoongArch returns -EINVAL, and powerpc with the hash MMU returns -ENOMEM. There the two subtests do not reach that test. On the other architectures with arenas, the arena code returns -EINVAL or __get_unmapped_area() returns -ENOMEM. Thus the two subtests accept both errnos. All these errors occur before mmap() changes a mapping. Two other changes of that patch have no subtest. With MAP_FIXED the arch code gets len and not 2 * len. A 64-bit task on x86, arm64 or riscv does not see this. LoongArch, s390 and powerpc with the hash MMU compare the end of the range with different limits. In arena_mmap the unsigned ret changes only the errno of map_extra_last_pages, which accepts both. Fixes: 14d3e5bf9ffe ("selftests/bpf: Test the length and the address of an arena mmap()") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261102064231.2153879-3-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Test the arguments of an extension progAlexei Starovoitov
An extension must not expect more of its arguments than the callers of the replaced function provide. It must fail if it expects more memory, a non-NULL pointer or another kind of argument. The same argument, less memory or a pointer that can be NULL must pass. Test check_ext_args() at load and at attach to another function of the same target prog. The load must fail with the message of the check, and the attach with -EINVAL. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261101190535.1454146-13-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Test the length and the address of an arena mmap()Alexei Starovoitov
libbpf maps all max_entries pages of an arena and never maps it at address 0. No test maps an arena differently. Thus the checks from "bpf: Refuse an arena mmap() longer than max_entries pages" and "bpf: Refuse to map an arena at address 0" have no test. Test that a longer mmap() fails with E2BIG, and that an mmap() at address 0 fails with EINVAL. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261101190535.1454146-8-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Test bpf_throw() in a prog with a private stackAlexei Starovoitov
'Private stack, exception in main prog' and 'Private stack, exception in subprog' are fentry progs. The test loader does not attach them, and BPF_PROG_TEST_RUN of a fentry prog does not call the prog. They are loaded, but they never run. Add three raw_tp progs. BPF_PROG_TEST_RUN runs them, and the default exception callback returns the cookie of bpf_throw(): - the main prog has a private stack and throws - the main prog has a private stack, its subprog throws - the main prog has no private stack, its subprog has one and throws Without the fix of the x86-64 JIT the first two crash the kernel. The third one passes with and without it: it makes sure that only the frame of the main prog is taken into account. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261031050558.2410721-3-alexei.starovoitov@gmail.com
2026-11-02selftests/bpf: Test the valid bytes of a packet pointer in a counted loopAlexei Starovoitov
Each test adds r4 to a packet pointer. r4 is 0, 8 .. 48, but its umax is 50. test umax gets smaller result ---------------------------------------- ------------------- ------ widen_pkt_pointer_step_lowers_umax at the loop entry reject widen_pkt_pointer_step_lowers_umax_down the same, r6 += -8 reject widen_pkt_pointer_negative_offset no, only smax reject clamp_pkt_pointer_step_lowers_umax at the back edge reject union_pkt_pointer_var_off_lowers_umax r5 is r6 + 8 or r6 reject widen_pkt_pointer_keeps_valid_bytes at the loop entry loads The first five progs load without the fix. The last prog reads only bytes that the compare with pkt_end covers. widen_pkt_pointer_beyond_pkt_end makes sure that the mark "beyond pkt_end" is not in the state at the head of the loop. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261030210950.1904640-3-alexei.starovoitov@gmail.com
2026-11-01selftests/bpf: Test overlapping dynptr copies on xdp fragsAyushman Rout
Add dynptr tests for copies within one xdp packet with frags, where the source and the destination overlap and the destination is above the source: - test_dynptr_copy_xdp_overlap: both ranges cross from the linear part into frag0. bpf_dynptr_copy() of 1200 bytes with the destination 100 bytes above the source. - test_dynptr_copy_xdp_overlap_src_linear: the source is in the linear part and the destination crosses into frag0. - test_dynptr_copy_xdp_overlap_dst_frag: the source crosses into frag0 and the destination is in frag0. The new tests set err when the data is wrong. The existing test_dynptr_copy_xdp does not, so it can pass on corrupted data. Without the fix to bpf_dynptr_copy(), test_dynptr_copy_xdp_overlap fails. With it, all the new tests pass. Signed-off-by: Ayushman Rout <ayushmanrout27@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026162810.12862-3-ayushmanrout27@gmail.com
2026-10-30selftests/bpf: Test kprobe and fentry/fexit programs on one functionDaniel Borkmann
A kprobe next to a BPF trampoline makes the ftrace site of the function call ftrace_regs_caller and from there the list of ftrace callbacks, the path that crashed while ftrace_ops_list_func() started at an odd address. No test covers a function traced by both. Thus, attach an fentry program and a kprobe to bpf_fentry_test1(), then a second fentry program, which modifies the trampoline of the shared site, then an fexit program, after which ftrace_regs_caller enters the trampoline by a jmp, then detach the kprobe, after which the site jumps to it directly. After each step, check that every attached program ran once for the call and saw its argument, and the fexit program its return value. Without the previous fix the test crashes the kernel, but only where ftrace_ops_list_func() is at an odd address (in my test with gcc + CONFIG_CC_OPTIMIZE_FOR_SIZE=y). With the fix it passes: # LDLIBS=-static PKG_CONFIG='pkg-config --static' ./vmtest.sh -- ./test_progs -t fentry_kprobe_shared [...] #147 fentry_kprobe_shared:OK Summary: 1/0 PASSED, 0 SKIPPED, 0/0 FAILED Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: https://patch.msgid.link/20261028202345.1215859-2-daniel@iogearbox.net
2026-10-30Merge tag 'vfs-7.4-rc1.fixes' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs Pull vfs fixes from Christian Brauner: - writeback: - Update dirtied_when instead of dirtied_time_when when a wb switch puts an inode at the newest end of the target b_dirty list. The list was left out of order so move_expired_inodes() could stop before older inodes, and the lazytime expiration timestamp was reset - Clear the old wb's dirty-I/O state and bandwidth contribution when a batch of inode switches leaves its dirty lists empty. An empty wb stayed scheduled for periodic writeback and inflated bdi->tot_write_bandwidth - Take wb_switch_rwsem across the inode scan of cleanup_offline_cgwb(). The v7.3-rc5 fix that rotates scanned inodes let a scan racing a sync()'s queue_io() move lazytime inodes past the sync's cutoff, so sync() returned without persisting their timestamps - Don't kick writeback for an IOCB_DONTCACHE write on an inode that has no wb yet. With cgroup writeback an O_DIRECT RWF_DONTCACHE write to a block device dereferenced NULL - statmount/listmount/listns: - Refuse statmount() string requests with a buffer that isn't larger than struct statmount - Don't wrap around with a U64_MAX cursor in listmount() and listns() - Don't end listns() at an inactive namespace - Only add init_ipc_ns and init_net to the namespace trees if CONFIG_IPC_NS and CONFIG_NET_NS are enabled - iomap: - Only mark blocks uptodate in __iomap_write_begin() after reading them and let __iomap_write_end() mark the zeroed blocks uptodate once the copy from userspace succeeded - Check a chunk against max_integrity_io_size() on its own before the bio size check - Only enforce block alignment for direct I/O into holes and unwritten extents if IOMAP_DIO_FSBLOCK_ALIGNED is set - backing-file: - Check S_APPEND and S_IMMUTABLE on the backing inode. FUSE passthrough opens the backing file with vfs_open() which skips may_open(), so anyone who may open the FUSE file for writing could overwrite an append-only backing file anywhere or write to an immutable one. Open, mmap and writes now check the backing inode the way may_open() and do_mmap() do - Always call kiocb_end_write() for a queued write - Let backing files inherit FMODE_NONOTIFY from the user file. The event fds fanotify creates for permission events on a stacked filesystem raised FS_OPEN_PERM on the real path from inside the listener's read() and deadlocked listeners with marks on both layers - pidfs: - Look the task up before checking for exit information in PIDFD_GET_INFO and start over if the task no longer owns the pid once all fields have been read. A caller racing release_task() got neither PIDFD_INFO_PID nor PIDFD_INFO_EXIT or ESRCH although the exit information was available, and a caller racing a sub-thread's exec reported that thread's tid as the pid - Clear the mask bits of fields that lie beyond the struct size the caller passed. The uapi header promises that the mask names no such field but a caller passing PIDFD_INFO_SIZE_VER0 got the coredump and supported mask bits set for fields that were never written - aio: - Give the aio ring a ->read_folio that fails with EIO so a fault on a ring whose file was truncated gets SIGBUS instead of jumping to NULL - Check nr_events against the ring size before doubling it in ioctx_alloc() - splice: - Only write back an implicit file position in do_splice() when the splice helper succeeded. splice doesn't take f_pos_lock so a failed splice restored a stale snapshot over a position that a concurrent getdents() had moved. On ext2 the next readdir then trusted an offset inside a directory entry - Retry tee() when the input pipe was emptied or the output pipe filled between the prep steps and link_pipe() instead of returning 0 while the input pipe still has writers, as splice_pipe_to_pipe() does - ucount: - Take the reference that pins a ucounts level on the 0 -> 1 transition before checking the rlimit - Read the parent ucounts before dropping the rlimit count in do_dec_rlimit_put_ucounts() - inode: - Rotate inodes whose page cache couldn't be dropped to the tail of the LRU - Skip inodes that another LRU walker is isolating - setns: - Set nsset->flags before anything in prepare_nsset() can fail so the error path drops the cred prepared for CLONE_NEWUSER. A failing setns() with CLONE_NEWUSER and CLONE_NEWNS leaked it together with its user namespace - Refuse setns(CLONE_NEWNS) for a task that shares its fs_struct again when more namespaces are requested - minix: - Restore uptodate on the pinned bitmap buffers before redirtying them after a failed writeback instead of tripping the warning in mark_buffer_dirty(), as ext2 and ext4 do for their superblock buffers - Reject rmdir() of a directory with a corrupted link count with EFSCORRUPTED instead of hitting the drop_nlink() warning - userns: Keep the exec securebits and their locks when creating or joining a user namespace. set_cred_user_ns() reset all securebits to SECUREBITS_DEFAULT so anyone who may create a user namespace could shed SECBIT_EXEC_RESTRICT_FILE and SECBIT_EXEC_DENY_INTERACTIVE with a single unshare(CLONE_NEWUSER) - fs: Honor FOP_UNSIGNED_OFFSET in sys_llseek() and in the pread64(), pwrite64(), preadv() and pwritev() wrappers - proc/kcore: Advance the vmalloc retry in read_kcore_iter() by the last vread_iter() copy instead of the running total - eventpoll: Return the error when the wakeup source for EPOLLWAKEUP can't be created in EPOLL_CTL_MOD instead of reporting success without suspend protection - coredump: Mark do_coredump() noinline_for_stack - nsfs: Check the trailing bytes of a namespace file handle in bytes instead of words - netfs: Restore the per-level and per-point decoding of the debug mask - exportfs: Release the directory file get_name() opened with __fput_sync(). From nfsd's kernel threads the deferred fputs arrived faster than delayed_fput retired them and each pinned the directory's readdir state, growing unreclaimable slab by about 90 MB per second under a parallel tree walk - fs: Call ramfs_kill_sb() for a ramfs rootfs. Since rootfs can be unmounted as of v7.0 its struct ramfs_fs_info was leaked - signal: Check the blocked mask for every entry dequeue_synchronous_signal() looks at. The scan could select a blocked synchronous signal and deliver it while blocked - super: Convert the superblock device table from an rhltable to a plain hashtable under a spinlock. This fixes a bug from v7.3 where fs_bdev_freeze() froze a btrfs filesystem through a stale member that open_ctree() had already released while the freeze was waiting for SB_BORN - fork: Leave rcu_users at zero until copy_process() can't fail anymore. bpf_task_acquire() handed out trusted references to the new task from the task_alloc LSM hook and sched_ext's ops.init_task() and a failing fork freed the task behind them - xattr: Always run cap_convert_nscap() for a security.capability write. A zero-length setxattr() skipped it and let an unprivileged caller without CAP_SETFCAP or write permission on the file plant an empty security.capability xattr that made every execve() of the binary fail with EINVAL - namei: Skip the S_ISDIR assertion in - proc: Refuse to mount on entries below /proc/<pid>/net like fd/, fdinfo/ and map_files/. proc_net_d_revalidate() always fails so the first lookup by anyone with search permission ran d_invalidate() on the dentry and detached every mount on it, locked mounts included - libfs: Hold one mount reference for all pins instead of one per pin. The pin count is what keeps the mount alive, so the per-pin reference only cost a mntget() and a mntput() through mntput_no_expire_slowpath() for every debugfs, tracefs, securityfs or configfs file that comes and goes - iov_iter: Return 0 from iov_iter_alignment() for an empty iterator of any type - watch_queue: Give info_id its own storage instead of overlaying it with rcu_head - filelock: Take an active superblock reference while waiting for a delegation break. After a lazy umount closing the delegation holder could shut down the superblock under the waiter whose final iput() then ran shmem_evict_inode() on freed state - fs: Skip the copy_file_range() write limit checks when there is no data to copy - bpf: Allow bpf_d_path() from fentry on filp_close_sync(). Since close_range() became synchronous this cycle close(), close_range() and the closes on exec and exit no longer go through filp_close(). fexit stays rejected since the file may be gone by then - fs_pin: Dequeue the wait entry unconditionally in pin_kill(). A spuriously woken waiter kept its on-stack entry queued, took that as proof that the pin was alive and used the freed acct structure when umount() of the accounting file raced acct(2) - dcache: Don't fail __d_obtain_alias() for an inode without links and aliases. The ESTALE check added this cycle broke open_by_handle_at() and nfsd file handle decoding on NFS and FUSE where i_nlink is just what the server last reported and the handle may well still be valid - selftests/ovl: Fix the mountinfo expectations of the detached layer test which has failed since it was added * tag 'vfs-7.4-rc1.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (60 commits) fs: don't fail __d_obtain_alias() for unlinked inodes ns: don't add init_ipc_ns and init_net without namespace support aio: avoid request count overflow in ioctx_alloc() selftests/ovl: fix detached layer mountinfo expectations bpf: Allow bpf_d_path() from filp_close_sync() fs: skip copy_file_range write limits when there is no data minix: reject rmdir of a directory with a corrupted link count fs_pin: do not trust the pin after a spurious wakeup in pin_kill() ucount: read the parent ucounts before dropping the rlimit count splice: retry tee() instead of returning 0 when it races selftests/pidfd: test that fields beyond the struct size are not reported pidfs: do not report fields that do not fit into the caller's struct fs: let backing files inherit FMODE_NONOTIFY from the user file splice: avoid stale f_pos writeback on error backing-file: always end a queued write filelock: keep superblock active through delegation wait watch_queue: keep info_id separate from rcu_head iomap: only follow dio alignment requirement if specified iov_iter: fix NULL deref in iov_iter_alignment() backing-file: enforce append-only and immutable backing inodes ...
2026-10-30bpf: Allow bpf_d_path() from filp_close_sync()Ihor Solodrai
The d_path selftest closes its descriptors with close_range() so that its fentry program on filp_close() runs. Commit 056069eb2b66 ("fs: make close_range() synchronous") switched close_range() to filp_close_sync(), so the program still attaches but is never called: test_d_path_basic:FAIL:close trampoline for filp_close was not called With that series, close(), close_range() and the closes on exec and exit all go through filp_close_sync(). Few paths still reach filp_close(), dup2() being one of them, so a program on filp_close() no longer sees most file closes. Allow bpf_d_path() from filp_close_sync(), but only from fentry. filp_close_sync() drops the last file reference inline, so by the time an fexit program runs, file->f_path may already be freed, with no RCU delay for NORCU dentries such as pipes and sockets. Attach the selftest program to filp_close_sync() and keep triggering it with close_range(). Add a test rejecting bpf_d_path() from fexit/filp_close_sync. Fixes: 056069eb2b66 ("fs: make close_range() synchronous") Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://patch.msgid.link/20261021201400.5409-1-ihor.solodrai@linux.dev Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-10-29Merge tag 'net-7.4-rc1' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net Pull networking fixes from Jakub Kicinski: "Current release - new code bugs: - mctp: usblib: fix assertion breaking esoteric builds Previous releases - regressions: - Revert advertising the TCP MSS from the configured MTU - netlink: check sk_rcvbuf before charging the dump skb - eth: - ti: am65-cpts: fix support for PTP_EXTTS_REQUEST2 ioctl - mlx4: always create the eth and ib auxiliary devices - tg3: invert restart quirk logic to restrict SNP power-down bypass - bnxt: recycle agg buffers when Rx head buffer allocation fails Previous releases - always broken: - net: fix frag_list leak in skb_segment_list() error path - sctp: reject forged cookie peer_addr with unknown address family - vxlan: keep reserved_bits across changelink - net: limit priority VLAN untag depth - inet: frags: prevent acceptance of partially authenticated reassembly - gro: do not GRO GSO packets with inconsistent payload - tcp: avoid double destroy in tcp_abort() of an unaccepted child" * tag 'net-7.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net: (137 commits) tun: drop batched packets while the device is down selftests: net: netlink-dumps: start a dump with a notification queued netlink: check sk_rcvbuf before charging the dump skb net/sched: act_ife: do not consume the inner header on egress openvswitch: use eth_type_trans_careful() in internal_dev_recv() net: use eth_type_trans_careful() in __dev_forward_skb2() loopback: use eth_type_trans_careful() net: add eth_type_trans_careful() tcp: initialize mapped children before route lookup tcp: fix reordering addition overflow in MTU probing tcp: avoid double destroy in tcp_abort() of an unaccepted child net: bgmac: fix TX DMA unmapping and slot cleanup gro: do not GRO GSO packets with inconsistent payload net/packet: check TX_RING fragments before memory accounting eth: bnxt: hand XDP frags over to the copybreak skb eth: bnxt: free XDP frags when xdp_do_redirect() fails eth: bnxt: don't leak buffers when XDP agg buffer allocation fails eth: bnxt: resize Rx head buffers when rx-copybreak changes eth: bnxt: recycle agg buffers when Rx head buffer allocation fails netdev-genl: ignore NETDEV_UNREGISTER rebroadcasts ...
2026-10-29net: use eth_type_trans_careful() in __dev_forward_skb2()Eric Dumazet
A tc egress BPF program can push a tiny link-layer header with bpf_skb_change_head() on an skb whose head is almost empty, then redirect it to an Ethernet device ingress. __bpf_redirect_common() only checks mac_header < network_header, and __dev_forward_skb2() crashes in eth_type_trans(): tc filter add dev lo egress pref 1 matchall action vlan pop_eth continue tc filter add dev lo egress pref 2 bpf da obj prog.o # prog: bpf_skb_change_head(skb, 1, 0); # return bpf_redirect(veth1_ifindex, BPF_F_INGRESS); # AF_PACKET SOCK_RAW on lo: eth / eth / 8192 bytes of payload kernel BUG at include/linux/skbuff.h:2839! RIP: 0010:eth_type_trans (include/linux/etherdevice.h:635 net/ethernet/eth.c:163) Call Trace: __dev_forward_skb2 (net/core/dev.c:2507) dev_forward_skb_nomtu (net/core/dev.c:2546) __dev_queue_xmit (net/core/dev.c:4738 net/core/dev.c:4998) packet_sendmsg (net/packet/af_packet.c:3157 net/packet/af_packet.c:3189) Use eth_type_trans_careful(), and drop the packet if the Ethernet header can not be pulled. This also covers other dev_forward_skb() users (veth, macvlan, ipvlan, netdevsim, l2tp_eth). Update the empty_skb BPF selftest: at lwt_xmit, BPF_PROG_TEST_RUN strips the Ethernet header, so the "veth ETH_HLEN+1" packet is a 1-byte skb. Redirecting it to veth ingress used to read the Ethernet header past skb->tail and deliver a 1-byte frame; it is now dropped with NET_RX_DROP, as veth_xmit() already does at egress. Fixes: 3a0af8fd61f9 ("bpf: BPF for lightweight tunnel infrastructure") Signed-off-by: Eric Dumazet <edumazet@kernel.org> Reviewed-by: Jamal Hadi Salim <jhs@mojatatu.com> Tested-by: Jamal Hadi Salim <jhs@mojatatu.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20261028122703.2093730-4-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-10-28selftests/bpf: Test stack arguments across may_gotoAlexei Starovoitov
Each test passes arguments 6-8 on the stack. Thus it uses all the registers in which the JITs of x86-64, arm64 and riscv64 pass stack arguments. may_goto then ------------------------------------------- --------------------------- 70000 iterations in the callee the callee reads the args the time is up in the callee the callee reads the args 70000 iterations in the caller, after the the caller calls the callee writes of the args 70000 iterations have one look at the clock. Without the fix on x86-64 the second test fails, and the first test fails with the hpet clocksource. The third test passes there. The result depends on the registers that the C code uses. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-20-alexei.starovoitov@gmail.com
2026-10-28selftests/bpf: Test maybe_fork_scalars() at the head of a counted loopAlexei Starovoitov
The insn that forks is the head of a loop that scalar evolution counted. The state with 0 that maybe_fork_scalars() splits off is within the state that is kept at the head. The access is out of bounds only in the state with 0. Without the previous patch the verifier accepts the prog. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-18-alexei.starovoitov@gmail.com
2026-10-28selftests/bpf: Test the clamp of pointers in scalar evolutionAlexei Starovoitov
test the loop result -------------------------------------- ------------------------- ------ clamp_released_pointer releases ringbuf memory reject clamp_invalidated_pkt_pointer calls bpf_skb_pull_data() reject clamp_pkt_pointer_keeps_no_range compares with pkt_end reject clamp_pkt_pointer_keeps_range_of_entry has no compare loads In the first three tests a flag in a 32-bit spill separates the first iteration from the second one. Scalar evolution does not widen the flag. Thus the verifier does not prune the state that returns to the head of the loop, and it verifies the second iteration with the clamped register. Without the fixes the three progs load. In the last test the compare with pkt_end is in front of the loop. Its range must stay valid in the loop. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-16-alexei.starovoitov@gmail.com
2026-10-28selftests/bpf: Test a loop that moves a pointer to a bufferAlexei Starovoitov
ptr_buf moves one pointer to a buffer until it gets to a second pointer. It never reads through the pointer. It loads only if scalar evolution widens the pointer, and that is no longer the case. Change it to the loop that real progs have, for example bpf_iter_bpf_percpu_array_map.c. It counts in a register and reads through the pointer in each iteration. Without "bpf: Don't widen a pointer to a buffer in scalar evolution" the verifier rejects it with "invalid variable buffer offset". Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-13-alexei.starovoitov@gmail.com
2026-10-28selftests/bpf: Avoid a page fault in rcu_reentry while the handler is armedAlexei Starovoitov
The test arms a handler at rcu_segcblist_enqueue() for its thread. Then it deletes an element of a task storage map. The delete gets to rcu_segcblist_enqueue(), and the handler does a nested delete there. The handler fires at the first rcu_segcblist_enqueue() in the thread. A page fault can be the first: skel->bss->target_pid = tid the handler is armed the next insn is in a page that is not in memory asm_exc_page_fault filemap_fault v9fs_issue_read p9_req_put irq_work_run rcu_defer_drain rcu_segcblist_enqueue the handler deletes the element bpf_map_delete_elem() -ENOENT test_rcu_reentry:FAIL:boot_delete unexpected error: -2 (errno 2) The result depends on the layout of test_progs. In the binary that failed, test_rcu_reentry() crosses the end of a page immediately after the store. This binary fails each time when it is on 9p. A copy of the same file on ext4 passes. Move the store and the delete to a function. Call it one time without a pid and with a bad fd. This call brings the text and .bss into memory, and it does not arm the handler. Fixes: 0464f587c61a ("selftests/bpf: Add a call_srcu() re-entry reproducer") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-11-alexei.starovoitov@gmail.com
2026-10-28selftests/bpf: Wait for the last maps of map_kptr to be freedAlexei Starovoitov
map_kptr_race/htab_leak fails occasionally in a complete run of test_progs: test_htab_leak:FAIL:htab refcount unexpected htab refcount: actual 6 != expected 2 This is a race between two tests. It is not a leak in the kernel. - map_kptr runs immediately before htab_leak. The two tests examine the refcount of the same test object. - The kernel frees maps asynchronously. Thus the maps drop their references some time after close(). - map_kptr waits for that after each subtest, but not after the last one. Wait after the last subtest too. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-10-alexei.starovoitov@gmail.com
2026-10-28selftests/bpf: Test that a widened register is not linkedAlexei Starovoitov
Scalar evolution widens a register that has delta 4. Then the prog copies the register. With the stale delta the verifier finds that a read of uninitialized r9 is dead code, and it loads the prog. See "bpf: Clear delta of a register that scalar evolution widens". Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-9-alexei.starovoitov@gmail.com
2026-10-28selftests/bpf: Remove tests for arena access through numbersAlexei Starovoitov
With BPF_F_ARENA_SCALAR the verifier accepts a load or a store through a scalar as an access to arena. The next patch removes the flag. Remove its tests. Keep one test. Without the flag the verifier must reject such a load, also in a prog that has an arena. Move this test to verifier_arena.c. The removed tests were the only tests of a special path in the x86 JIT for the fetching AND/OR/XOR atomics. Only the flag used that path. arena_atomics tests the usual path. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-5-alexei.starovoitov@gmail.com
2026-10-28selftests/bpf: Remove tests for global data in arenaAlexei Starovoitov
The .arena.data section and the BPF_F_ARENA_SCALAR flag let a prog in Rust keep its global data in arena. The subsequent patches remove the two, because the compiler can do this work. First remove the tests for .arena.data. One of the tests is a prog in Rust. It has no replacement, because LLVM does not put the globals of Rust in arena at this time. No other selftest is in Rust. Thus also remove the makefile rules that build Rust. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261027190314.1440199-2-alexei.starovoitov@gmail.com
2026-10-27selftests/bpf: Restore stack pointer subrange pruning coverageEduard Zingerman
After the clamping changes, r7 returns to the header with [-72, -16] instead of the narrower [-64, -16], so the test no longer checks subrange pruning. Assign an invariant fp-16 pointer to r7 in the loop, giving r7 an ANY SCEV that is not clamped and restoring strict-subrange coverage. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-11-f373aec9825f@gmail.com
2026-10-27selftests/bpf: 32-bit copy of the counter compared at the latchEduard Zingerman
When building SCEV expressions for the loop: w7 = w1; r7 = (zext32 r1) w1 = w7; r1 = (zext32 (zext32 r1)) w1 += 2; r1 = (zext32 (+ (zext32 (zext32 r1)) 2)) Computed SCEV expression for r1: (zext32 (linear r1 2)) Substituting this into r7's expression at the latch: (zext32 (zext32 (linear r1 2))) Without (zext32 (zext32 X)) -> (zext32 X) simplification rule the latch would not be recognized as linear and header_count won't be computed. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-10-f373aec9825f@gmail.com
2026-10-27selftests/bpf: Cases for SCEV interaction with infinite loop detectionEduard Zingerman
Add three test cases exercising state pruning after loop counter clamping. All turn a 32-bit stack spill into STACK_MISC during the first iteration. This prevents a state match at the outer loop header on the next iteration, while allowing states to match further inside the loop. All are falsely reported as infinite loop w/o changes in patch [1]. - clamp_callee_state_pruning(), a callee overwrites the upper half of the caller's stack slot. States then match at the callee's exit, where the current frame has no active loop. Verify that current_loop() finds the caller's active loop. - clamp_nested_loop_state_pruning(), the overwrite happens inside an inner loop. Exercise matching states when the inner loop is entered again on a subsequent outer iteration. - clamp_nested_unrolled_loop_state_pruning(), same as above, but the inner loop is not recognized by SCEV and is unrolled with a precise counter, so its entries are never marked terminating. [1] bpf: avoid false infinite loop reports after changes in SCEV clamping Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-9-f373aec9825f@gmail.com
2026-10-27selftests/bpf: Cases with empty range error under old clamping logicEduard Zingerman
A 64-bit and 32-bit examples leading to an empty register range error when scev.c:bpf_clamp_scev_regs() intersected current register state with computed iteration range: r1 = 0; verification r3 = 0; path loop: r3 += 1; | <---------. if r3 != 5 goto +0; | r3 ∈ {5} | r1 += 1; | | if r1 != 5 goto loop; '-----------' r0 = 0; exit; - At header r3 ∈ {0,1,2,3,4}. - After `if r3 != 5 goto ...` continued with r3 ∈ {5}. - On a second iteration bpf_clamp_scev_regs() computed: r3 := {0,1,2,3,4} ∩ {5} = ∅ And reported an error: verifier bug: scev clamp produced empty range for r3 Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-8-f373aec9825f@gmail.com
2026-10-27selftests/bpf: Pointer operands for 32-bit recurrences/latchesEduard Zingerman
Add four tests for pointer operands in 32-bit SCEV analysis. Check that loop bounds are not inferred for the following program shapes: 32-bit latch | 32-bit recurrence -------------------------+-------------------------- r6 = ... pointer ... | r6 = ... pointer ... r7 = ... pointer ... | r7 = ... pointer ... l: r6 += 1 | l: w6 += 1 ... | ... if w6 < w7 goto l | if r6 < r7 goto l Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-7-f373aec9825f@gmail.com
2026-10-27bpf: Print 32-bit SCEV bounds as 32-bit numbersEduard Zingerman
- Print large 32-bit bounds without sign extension. - Omit 32-bit bounds when they coincide with 64-bit bounds. Before: loop header at ..., widening r0 to 0x80000000..0xffffffff (s32 0xffffffff80000000..-1) step 1 loop header at ..., widening r0 to 0..3 (s32 0..3) step 1 After: loop header at ..., widening r0 to 0x80000000..0xffffffff (s32 0x80000000..-1) step 1 loop header at ..., widening r0 to 0..3 step 1 Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-6-f373aec9825f@gmail.com
2026-10-27bpf: Avoid false infinite loop reports after changes in SCEV clampingEduard Zingerman
Clamping now reproduces the widened range at every back edge, so induction variable ranges no longer vary between iterations. This can produce identical checkpoint states in terminating programs, for example: int main(...) { for (int i = 0; i < 10; i++) { foo(...); for (int j = 0; j < 3; j++) ...; } } void foo(...) { ...; } Handle two cases in states.c:bpf_is_state_visited(): - For checkpoints inside foo(), look for active loops in upper frames as well. Otherwise current_loop() returns NULL and an identical callee state can trigger an infinite loop report. - For checkpoints inside the inner loop, skip the infinite loop check when the current state is inside a terminating loop in any frame. That loop bounds how many times its body is re-executed, so an identical state on a later iteration does not imply nontermination. This covers the inner loop above, re-entered with a fresh entry state on each outer iteration, and inner loops SCEV cannot analyze. The nested_terminating_prune test still rejects such an outer loop, but now reaches the jump complexity limit instead of reporting an infinite loop. Update its expected message accordingly. Fixes: 6ccf49f79327 ("bpf: Use SCEV to widen bounded loops") Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-3-f373aec9825f@gmail.com
2026-10-27bpf: Do not intersect with current register range on clampEduard Zingerman
scev.c:bpf_clamp_scev_regs() is called each time verifier returns to a loop header via a backedge. It's purpose is to re-establish computed variable ranges for registers with linear SCEVs. It can be defined as: - For each register R with linear SCEV compute: - loop_range(R) := entry_range(R) * iterations_count - range(R) := range(R) ∩ loop_range(R) Such formulation is necessary to avoid ranges over-approximation in examples like below: r1 = 0; SCEVs: r1 = (linear r1 1) r3 = 0; r3 = (linear r3 1) loop: r3 += 1; r1 += 1; if r1 < 5 goto loop; r0 = 0; exit; - At loop entry r3 is widened to be in a range r3 ∈ {0,1,2,3,4}. - After increment it becomes r3 ∈ {1,2,3,4,5}. - On a second iteration the bpf_clamp_scev_regs() forces r3 to become r3 ∈ {1,2,3,4}. W/o clamping logic r3 range wouldn't shrink preventing loop from converging in states.c:states_equal(). However, intersection logic might lead to assigning an empty range to a register, as in example below: r1 = 0; verification r3 = 0; path loop: r3 += 1; | <---------. if r3 != 5 goto +0; | r3 ∈ {5} | r1 += 1; | | if r1 != 5 goto loop; '-----------' r0 = 0; exit; - At header r3 ∈ {0,1,2,3,4}. - While exploring the branch `if r3 != 5 goto ...` with r3 ∈ {5}. - On a second iteration: r3 := {0,1,2,3,4} ∩ {5} = ∅ Which stops verification with the following error: verifier bug: scev clamp produced empty range for r3 Technically this means that the current verification path is impossible at runtime and should not be traced further. This commit mitigates the above by removing the intersection logic, the function is now defined as: - For each register R with linear SCEV compute: - range(R) := entry_range(R) * iterations_count This is still sound, provided that SCEV expressions loop execution counts are correct. Fixes: 6ccf49f79327 ("bpf: Use SCEV to widen bounded loops") Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-2-f373aec9825f@gmail.com