summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2026-06-05bpf: Restore sysctl new-value from 1 to 0Dawei Feng
Commit 4e63acdff864 ("bpf: Introduce bpf_sysctl_{get,set}_new_value helpers") changed the success return value to 0, but failed to update the corresponding check in __cgroup_bpf_run_filter_sysctl(). Since bpf_prog_run_array_cg() now returns 0 on success, the legacy ret == 1 condition is never satisfied. As a result, the modified value is ignored, and bpf_sysctl_set_new_value() fails to replace the write buffer. Fix this by checking for a return value of 0 instead, so cgroup/sysctl programs can correctly replace the pending sysctl buffer. This bug was discovered during a manual code review. Tested via a cgroup/sysctl BPF reproducer overriding writes to a target sysctl. Pre-fix, bpf_sysctl_set_new_value("foo") was silently ignored: the write returned 8192 and the value remained "600". Post-fix, the BPF replacement buffer properly propagates: the write returns 3 and the value updates to "foo". Fixes: f10d05966196 ("bpf: Make BPF_PROG_RUN_ARRAY return -err instead of allow boolean") Cc: stable@vger.kernel.org Acked-by: Yonghong Song <yonghong.song@linux.dev> Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Signed-off-by: Dawei Feng <dawei.feng@seu.edu.cn> Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev> Acked-by: Xu Kuohai <xukuohai@huawei.com> Link: https://lore.kernel.org/r/20260603105317.944304-4-dawei.feng@seu.edu.cn Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: use kvfree() for replaced sysctl write bufferDawei Feng
proc_sys_call_handler() allocates its temporary sysctl buffer with kvzalloc() and passes it to __cgroup_bpf_run_filter_sysctl(). Since kvzalloc() may fall back to vmalloc() for large allocations, freeing that buffer with kfree() is wrong and can corrupt memory. Use kvfree() to safely handle both kmalloc and kvzalloc()/vmalloc allocations. The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1-rc5. Reproduced the bug based on v7.1-rc4 in a QEMU x86_64 guest booted with KASAN and CONFIG_FAILSLAB enabled. To exercise the replacement path, the test tree also included the accompanying fix for the stale ret == 1 check in __cgroup_bpf_run_filter_sysctl(). The reproducer confines failslab injections to the proc_sys_call_handler() range, uses stacktrace-depth=32, and injects fail-nth=1 while writing 8191 bytes to /proc/sys/kernel/domainname from a task in the target cgroup. Under that setup, fail-nth=1 triggered the fault: BUG: unable to handle page fault for address: ffffeb0200024d48 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: Oops: 0000 SMP KASAN NOPTI CPU: 2 UID: 0 PID: 209 Comm: repro_proc_sys_ Not tainted 7.1.0-rc4-00686-g97625979a5d4 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 RIP: 0010:kfree+0x6e/0x510 ... Call Trace: <TASK> ? __cgroup_bpf_run_filter_sysctl+0x626/0xc30 __cgroup_bpf_run_filter_sysctl+0x74d/0xc30 ? __pfx___cgroup_bpf_run_filter_sysctl+0x10/0x10 ? srso_return_thunk+0x5/0x5f ? __kvmalloc_node_noprof+0x345/0x870 ? proc_sys_call_handler+0x250/0x480 ? srso_return_thunk+0x5/0x5f proc_sys_call_handler+0x3a2/0x480 ? __pfx_proc_sys_call_handler+0x10/0x10 ? srso_return_thunk+0x5/0x5f ? selinux_file_permission+0x39f/0x500 ? srso_return_thunk+0x5/0x5f ? lock_is_held_type+0x9e/0x120 vfs_write+0x98e/0x1000 ... </TASK> With this fix applied on top of the same test setup, rerunning the reproducer with fail-nth=1 yields no corresponding Oops reports. Fixes: 4508943794ef ("proc: use kvzalloc for our kernel buffer") Cc: stable@vger.kernel.org Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev> Acked-by: Yonghong Song <yonghong.song@linux.dev> Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Signed-off-by: Dawei Feng <dawei.feng@seu.edu.cn> Link: https://lore.kernel.org/r/20260603105317.944304-3-dawei.feng@seu.edu.cn Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: NUL-terminate replaced sysctl valueDawei Feng
When writing to sysctls, proc_sys_call_handler() guarantees that the buffer passed to proc handlers is NUL-terminated. If bpf_sysctl_set_new_value() replaces the pending sysctl value, it can hand a replacement buffer directly to proc handlers. However, the helper currently copies only buf_len bytes into that buffer without appending a NUL terminator, leaving downstream parsers vulnerable to out-of-bounds access. Fix this by appending a '\0' after the replaced value to restore the expected sysctl semantics. Since the helper already rejects buf_len greater than PAGE_SIZE - 1, there is always room for the extra byte. Reproduced in a QEMU x86_64 guest booted with KASAN while exercising the sysctl replacement path with a cgroup/sysctl BPF program. The reproducer targets `/proc/sys/net/core/flow_limit_cpu_bitmap`, fills the original user write buffer with non-zero bytes, and overrides the sysctl value so the replacement buffer lacks a terminating NUL. Under that setup, the pre-fix kernel reported: BUG: KASAN: slab-out-of-bounds in strnchrnul+0x72/0x90 Read of size 1 at addr ffff88800de57000 by task repro_patch3/66 CPU: 0 UID: 0 PID: 66 Comm: repro_patch3 Not tainted 7.1.0-rc3-00269-g8370ca1f87cc #6 PREEMPT(lazy) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x68/0xa0 print_report+0xcb/0x5e0 ? __virt_addr_valid+0x21d/0x3f0 ? strnchrnul+0x72/0x90 ? strnchrnul+0x72/0x90 kasan_report+0xca/0x100 ? strnchrnul+0x72/0x90 strnchrnul+0x72/0x90 bitmap_parse+0x37/0x2e0 flow_limit_cpu_sysctl+0xc6/0x840 ? __pfx_flow_limit_cpu_sysctl+0x10/0x10 ? __kvmalloc_node_noprof+0x5ba/0x870 proc_sys_call_handler+0x31d/0x480 ? __pfx_proc_sys_call_handler+0x10/0x10 ? selinux_file_permission+0x39f/0x500 ? lock_is_held_type+0x9e/0x120 vfs_write+0x98e/0x1000 ... </TASK> The buggy address is located 0 bytes to the right of allocated 4096-byte region [ffff88800de56000, ffff88800de57000) With this fix applied, rerunning the same sysctl-targeted path yields no corresponding KASAN reports. Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Signed-off-by: Dawei Feng <dawei.feng@seu.edu.cn> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20260603105317.944304-2-dawei.feng@seu.edu.cn Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-06Merge tag 'drm-intel-fixes-2026-06-05' of ↵Dave Airlie
https://gitlab.freedesktop.org/drm/i915/kernel into drm-fixes - Fix color blob reference handling in intel_plane_state (Chaitanya Kumar Borah) - Revert "drm/i915/backlight: Remove try_vesa_interface" [backlight] (Suraj Kandpal) Signed-off-by: Dave Airlie <airlied@redhat.com> From: Tvrtko Ursulin <tursulin@igalia.com> Link: https://patch.msgid.link/aiKgmwz7VGOaFXIv@linux
2026-06-06Merge tag 'drm-misc-fixes-2026-06-05' of ↵Dave Airlie
https://gitlab.freedesktop.org/drm/misc/kernel into drm-fixes Short summary of fixes pull: dumb-buffer: - remove strict limits on buffer geometry ethosu: - reject unsupported NPU_OP_RESIZE - fix index of IFM region - fix weight index - fix overflows in DMA-size calculations - reject DMA commands with uninitialized length - fix OOB write in ethosu_gem_cmdstream_copy_and_validate imx: - fix kernel-doc warnings ivpu: - add overflow checks in firmware handling and get_info_ioctl v3d: - wait for pending L2T flush before cleaning caches - fix leak of vaddr - skip CSD when it has zeroed workgroups - fix ref counting in performance monitoring Signed-off-by: Dave Airlie <airlied@redhat.com> From: Thomas Zimmermann <tzimmermann@suse.de> Link: https://patch.msgid.link/20260605072602.GA268798@linux.fritz.box
2026-06-05Merge branch 'bpf-update-transport_header-when-encapsulating-udp-tunnel-in-lwt'Alexei Starovoitov
Leon Hwang says: ==================== bpf: Update transport_header when encapsulating UDP tunnel in lwt Currently, bpf_lwt_push_ip_encap() does not update skb->transport_header. When a driver, e.g. ice, reuses the stale skb->transport_header to offload checksum computation to NIC hardware, VxLAN packets encapsulated by bpf_lwt_push_encap() helper may be dropped due to incorrect checksum. Update skb->transport_header in bpf_lwt_push_ip_encap() whenever the encapsulated packet uses UDP, so checksum offload works correctly. Changes: v3 -> v4: * Address comments from Emil: * Make the logic of skb_set_transport_header() clearer in patch #1. * Fold the code of fexit_lwt_push_ip_encap() into test_lwt_ip_encap.c in patch #2. * Resolve assorted issues of test in patch #2. * v3: https://lore.kernel.org/bpf/20260601150203.20352-1-leon.hwang@linux.dev/ v2 -> v3: * Drop patch #1 and #2 of v2 that aim to resolve potential issues reported by sashiko (per Alexei). * Check target IP version and UDP tunnel in test (per sashiko). * v2: https://lore.kernel.org/bpf/20260529151351.69911-1-leon.hwang@linux.dev/ v1 -> v2: * Address sashiko's reviews: * Fix TOCTOU issue in lwt to avoid changing hdr after checks. * Add check iph->ihl < 5 in lwt to avoid infinite-loop in MIPS driver. * Update comment style in selftests with BPF comment style. * v1: https://lore.kernel.org/bpf/20260525142650.2569-1-leon.hwang@linux.dev/ ==================== Link: https://patch.msgid.link/20260602150931.49629-1-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Add tests to verify the fix of encapsulating VxLAN in lwtLeon Hwang
Add two tests to verify the transport header of skb has been set when encapsulate VxLAN using bpf_lwt_push_encap() helper. 1. VxLAN over IPv4. 2. VxLAN over IPv6. Without the fix, the tests would fail: lwt_ip_encap_vxlan:FAIL:transport_hdr offset unexpected transport_hdr offset: actual 70 != expected 20 #208 lwt_ip_encap_vxlan_ipv4:FAIL lwt_ip_encap_vxlan:FAIL:transport_hdr offset unexpected transport_hdr offset: actual 110 != expected 40 #209 lwt_ip_encap_vxlan_ipv6:FAIL The unexpected offsets are: outer encap headers (IPv4: iphdr+udp+vxlan+eth = 50 bytes, IPv6: ipv6hdr+udp+vxlan+eth = 70 bytes) plus the inner IP header (20 or 40 bytes), because without the fix transport_header still points at the inner transport layer instead of the outer UDP header. Assisted-by: Claude:claude-sonnet-4-6 Cc: Leon Hwang <leon.huangfu@shopee.com> Signed-off-by: Leon Hwang <leon.hwang@linux.dev> Link: https://lore.kernel.org/r/20260602150931.49629-3-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: Update transport_header when encapsulating UDP tunnel in lwtLeon Hwang
Currently, bpf_lwt_push_ip_encap() does not update skb->transport_header. When a driver, e.g. ice, reuses the stale skb->transport_header to offload checksum computation to NIC hardware, VxLAN packets encapsulated by bpf_lwt_push_encap() helper may be dropped due to incorrect checksum. Update skb->transport_header in bpf_lwt_push_ip_encap() whenever the encapsulated packet uses UDP, so checksum offload works correctly. Fixes: 52f278774e79 ("bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap") Cc: Leon Hwang <leon.huangfu@shopee.com> Signed-off-by: Leon Hwang <leon.hwang@linux.dev> Link: https://lore.kernel.org/r/20260602150931.49629-2-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05Merge branch 'risc-v-jit-support-for-bpf_get_current_task-_btf'Alexei Starovoitov
Varun R Mallya says: ==================== RISC-V JIT support for bpf_get_current_task/_btf These two patches add support for the bpf_get_current_task and bpf_get_current_task_btf kfuncs in RISC-V JIT and add a selftest. The first patch adds support for cpu and feature detection on the JIT disassembly helper function as RISC-V JITed code was not being disassembled using `LLVMCreateDisasm` as it was missing the "+c" CPU feature and JITed code contained RISC-V Compressed (C) Extension. This patch generalizes that to detect CPU features and enables testing on more RISC-V JIT work ahead. The second patch, which actually adds this support has been benchmarked on QEMU RISC-V and shows significant improvements. It was benchmarked using a simple loop inside a bpf program that ran bpf_get_current_task() and execution time was measured. It used bpf_prog_test_run_opts() to repeatedly trigger the BPF program. The loop ran in 1 second intervals and it kept firing bpf_prog_test_run_opts() as fast as possible until a second had elapsed and then reported statistics. ==================== Link: https://patch.msgid.link/20260602205847.102825-1-varunrmallya@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf, riscv: inline bpf_get_current_task() and bpf_get_current_task_btf()Varun R Mallya
On RISC-V, the current task pointer is stored in the thread pointer register (tp). Emit a single `mv a5, tp` instead of a full helper call for BPF_FUNC_get_current_task and BPF_FUNC_get_current_task_btf. Register bpf_jit_inlines_helper_call() entries for both helpers so the verifier treats them as inlined, and add the expected `mv a5, tp` annotation to the riscv64 selftests. The following show changes before and after this patch. Before patch: auipc t1,0x817a # load upper PC-relative address jalr -2004(t1) # call bpf_get_current_task helper mv a5,a0 # move return value to BPF_REG_0 After patch: mv a5,tp # directly: a5 = current (tp = thread pointer) Benchmark (bpf_prog_test_run wrapping bpf_get_current_task in loop, batch=100, 10s, QEMU RISC-V): | runs/sec | helper-calls/sec | ns/call -------------+-----------+------------------+--------- Before patch | 173,490 | 17,349,090 | 57 After patch | 320,497 | 32,049,780 | 31 -------------+-----------+------------------+--------- Improvement | +84.7% | +84.7% | -45.6% Signed-off-by: Varun R Mallya <varunrmallya@gmail.com> Acked-by: Björn Töpel <bjorn@kernel.org> Link: https://lore.kernel.org/r/20260602205847.102825-3-varunrmallya@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: use host CPU features in JIT disassemblerVarun R Mallya
Pass the host CPU name and feature string to LLVMCreateDisasmCPUFeatures() instead of using LLVMCreateDisasm(), so the disassembler correctly decodes CPU-specific instructions and extensions such as RISC-V compressed and vector instructions. Signed-off-by: Varun R Mallya <varunrmallya@gmail.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://lore.kernel.org/r/20260602205847.102825-2-varunrmallya@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05Merge branch 'bpf-check-tail-zero-of-bpf_map_info-and-bpf_prog_info'Alexei Starovoitov
Leon Hwang says: ==================== bpf: Check tail zero of bpf_map_info and bpf_prog_info Check the tail bytes of bpf_map_info and bpf_prog_info due to padding when getting map info and prog info via BPF_OBJ_GET_INFO_BY_FD, which was discussed in the thread "bpf: Check tail zero of bpf_common_attr using offsetofend" [1]. Links: [1] https://lore.kernel.org/bpf/20260518145446.6794-2-leon.hwang@linux.dev/ Changes: v2 -> v3: * Add "__u32 :32" to bpf_map_info and bpf_prog_info (per Alexei). * v2: https://lore.kernel.org/bpf/20260604150505.99129-1-leon.hwang@linux.dev/ v1 -> v2: * Collect Acked-by tags from Mykyta, thanks. * Update Fixes tag in patch #2 (per bot+bpf-ci) * v1: https://lore.kernel.org/bpf/20260603144518.67065-1-leon.hwang@linux.dev/ ==================== Link: https://patch.msgid.link/20260605155249.20772-1-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Add tests to verify checking padding bytes for ↵Leon Hwang
bpf_[map,prog]_info Add two tests to verify that the tail padding 4 bytes of struct bpf_map_info and bpf_prog_info are checked in syscall.c using bpf_check_uarg_tail_zero(). Signed-off-by: Leon Hwang <leon.hwang@linux.dev> Link: https://lore.kernel.org/r/20260605155249.20772-4-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: Check tail zero of bpf_prog_infoLeon Hwang
Since there're 4 bytes padding at the end of struct bpf_prog_info, they won't be checked by bpf_check_uarg_tail_zero(). pahole -C bpf_prog_info ./vmlinux struct bpf_prog_info { ... __u32 attach_btf_obj_id; /* 220 4 */ __u32 attach_btf_id; /* 224 4 */ /* size: 232, cachelines: 4, members: 38 */ /* sum members: 224 */ /* sum bitfield members: 1 bits, bit holes: 1, sum bit holes: 31 bits */ /* padding: 4 */ /* forced alignments: 9 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); If a future kernel extension adds a new 4-byte field, older userspace programs allocating this structure on the stack might inadvertently pass uninitialized stack garbage into the new field, permanently breaking backward compatibility. -- sashiko [1] Fix it by changing sizeof(info) to offsetofend(struct bpf_prog_info, attach_btf_id). And, add "__u32 :32" to the tail of struct bpf_prog_info. [1] https://lore.kernel.org/bpf/20260513224823.6494FC19425@smtp.kernel.org/ Fixes: aba64c7da983 ("bpf: Add verified_insns to bpf_prog_info and fdinfo") Acked-by: Mykyta Yatsenko <yatsenko@meta.com> Signed-off-by: Leon Hwang <leon.hwang@linux.dev> Link: https://lore.kernel.org/r/20260605155249.20772-3-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: Check tail zero of bpf_map_infoLeon Hwang
Since there're 4 bytes padding at the end of struct bpf_map_info, they won't be checked by bpf_check_uarg_tail_zero(). pahole -C bpf_map_info ./vmlinux struct bpf_map_info { ... __u64 hash __attribute__((__aligned__(8))); /* 88 8 */ __u32 hash_size; /* 96 4 */ /* size: 104, cachelines: 2, members: 18 */ /* padding: 4 */ /* forced alignments: 1 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); If a future kernel extension adds a new 4-byte field, older userspace programs allocating this structure on the stack might inadvertently pass uninitialized stack garbage into the new field, permanently breaking backward compatibility. -- sashiko [1] Fix it by changing sizeof(info) to offsetofend(struct bpf_map_info, hash_size). And, add "__u32 :32" to the tail of struct bpf_map_info. [1] https://lore.kernel.org/bpf/20260513224823.6494FC19425@smtp.kernel.org/ Fixes: ea2e6467ac36 ("bpf: Return hashes of maps in BPF_OBJ_GET_INFO_BY_FD") Acked-by: Mykyta Yatsenko <yatsenko@meta.com> Signed-off-by: Leon Hwang <leon.hwang@linux.dev> Link: https://lore.kernel.org/r/20260605155249.20772-2-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05perf sched: Replace BUG_ON and add NULL checks in replay event helpersArnaldo Carvalho de Melo
get_new_event() has three issues: 1. The zalloc() result is dereferenced without a NULL check, crashing on allocation failure. 2. BUG_ON(!task->atoms) kills the process when realloc() fails. Since perf.data is untrusted input, this should be a graceful error. 3. The realloc pattern assigns directly to task->atoms, losing the old pointer on failure. task->nr_events is also incremented before the realloc, leaving corrupted state on failure. Fix get_new_event() to: - Check the zalloc() result before dereferencing - Use a temporary for realloc() to avoid losing the old pointer - Increment nr_events only after successful realloc - Return NULL instead of calling BUG_ON on failure Also fix add_sched_event_wakeup() where zalloc() for wait_sem is passed to sem_init() without a NULL check. Update all callers (add_sched_event_run, add_sched_event_wakeup, add_sched_event_sleep) to handle NULL returns by returning early. The replay may produce incomplete output on OOM but will not crash. Fixes: ec156764d424 ("perf sched: Import schedbench.c") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05perf sched: Use thread__put() in free_idle_threads()Arnaldo Carvalho de Melo
free_idle_threads() calls thread__delete() directly instead of thread__put(), bypassing the reference counting lifecycle. Under REFCNT_CHECKING builds, this leaks the pointer handle since thread__delete() frees the object without going through the refcount wrapper. The idle threads are created via thread__new() (refcount=1) in get_idle_thread(). Callers get additional references via thread__get() which they release with thread__put(). free_idle_threads() drops the base reference — thread__put() is the correct call, matching the thread__new() acquisition. Fixes: 49394a2a24c7 ("perf sched timehist: Introduce timehist command") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05perf sched: Fix thread reference leak in idle hist processingArnaldo Carvalho de Melo
timehist_sched_change_event() sets itr->last_thread to NULL at the end of idle hist processing without calling thread__put() first. The thread reference was acquired via thread__get() in timehist_get_thread() (line 2581), so every idle context switch leaks a thread reference when --idle-hist is active. Use thread__zput() to properly release the reference before clearing the pointer. Fixes: 5d8f17fb5822 ("perf sched timehist: Add -I/--idle-hist option") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05perf sched: Use is_idle_sample() for idle thread runtime cast guardArnaldo Carvalho de Melo
timehist_sched_change_event() uses thread__tid(thread) == 0 to decide whether to cast thread_runtime to idle_thread_runtime. However, a crafted perf.data can set common_pid=0 and common_tid=0 (the perf_sample fields) while prev_pid != 0 (the tracepoint field). is_idle_sample() returns false (it checks prev_pid for sched_switch), so timehist_get_thread() goes through machine__findnew_thread() and returns the machine's TID 0 thread — whose priv data is a regular thread_runtime, not the larger idle_thread_runtime allocated by init_idle_thread(). The subsequent cast to idle_thread_runtime reads past the thread_runtime allocation, accessing itr->last_thread, itr->cursor, and itr->callchain from adjacent heap memory. Writing to itr->last_thread corrupts the heap; calling thread__put() on the OOB value frees an arbitrary pointer. Replace the thread__tid() == 0 check with is_idle_sample(), which uses the tracepoint-specific prev_pid field and correctly identifies whether the sample originated from an idle thread with idle_thread_runtime priv. Fixes: 5d8f17fb5822 ("perf sched timehist: Add -I/--idle-hist option") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05perf sched: Clean up idle_threads entry on init failureArnaldo Carvalho de Melo
get_idle_thread() allocates a thread via thread__new() and stores it in idle_threads[cpu], then calls init_idle_thread() to set up the private data. If init_idle_thread() fails (e.g. OOM for the idle_thread_runtime struct), the function returns NULL but leaves the partially initialized thread in idle_threads[cpu]. On subsequent calls for the same CPU, get_idle_thread() finds a non-NULL idle_threads[cpu], skips allocation, and returns thread__get() on a thread that has no priv data. Callers then get a thread whose thread__priv() returns NULL, leading to unexpected behavior. Release the thread and reset the slot to NULL on init failure so the entry doesn't persist in a corrupted state. Fixes: 49394a2a24c7 ("perf sched timehist: Introduce timehist command") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05perf c2c: Bounds-check CPU IDs in setup_nodes() topology loopArnaldo Carvalho de Melo
setup_nodes() iterates CPU maps from the perf.data topology header and uses cpu.cpu directly as an array index into cpu2node[] (allocated with c2c.cpus_cnt = env->nr_cpus_avail entries) and __set_bit(cpu.cpu, set) (bitmap also sized to c2c.cpus_cnt). A crafted perf.data with topology CPU IDs exceeding nr_cpus_avail causes out-of-bounds heap writes into both the cpu2node array and the per-node bitmap. Add a bounds check to skip CPU IDs that fall outside the valid range. Fixes: 1e181b92a2da ("perf c2c report: Add 'node' sort key") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05perf c2c: Bounds-check CPU and node IDs before bitmap and array accessArnaldo Carvalho de Melo
c2c_he__set_cpu() passes sample->cpu directly to __set_bit(cpu, cpuset) after only checking for the (u32)-1 sentinel. The cpuset bitmap is allocated with c2c.cpus_cnt bits (from env->nr_cpus_avail), so a crafted perf.data with CPU IDs exceeding that count causes out-of-bounds heap writes. c2c_he__set_node() similarly passes the node ID from mem2node__node() to __set_bit(node, nodeset) after only checking for negative values. The nodeset bitmap is sized to c2c.nodes_cnt (from env->nr_numa_nodes), so a node ID exceeding that causes OOB writes. process_sample_event() indexes c2c.cpu2node[cpu] and c2c_he->node_stats[node] without bounds checking. Both arrays are sized to c2c.cpus_cnt and c2c.nodes_cnt respectively. Add bounds checks in all three paths: - c2c_he__set_cpu(): return if sample->cpu >= c2c.cpus_cnt - c2c_he__set_node(): return if node >= c2c.nodes_cnt - process_sample_event(): clamp cpu to 0 if >= cpus_cnt, guard node_stats access with bounds check Fixes: 1e181b92a2da ("perf c2c report: Add 'node' sort key") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05dt-bindings: display: panel: Describe Samsung SOFEF01-M DDICMarijn Suijten
Document the Samsung SOFEF01-M Display-Driver-IC and 1080x2520@60Hz command-mode DSI panels found in many Sony phones: - Sony Xperia 5 (kumano bahamut): amb609tc01 - Sony Xperia 10 II (seine pdx201): ams597ut01 - Sony Xperia 10 III (lena pdx213): ams597ut04 - Sony Xperia 10 IV (murray pdx225): ams597ut05 - Sony Xperia 10 V (zambezi pdx235): ams605dk01 - Sony Xperia 10 VI (columbia pdx246): ams605dk01 Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> Link: https://patch.msgid.link/20251222-drm-panels-sony-v2-4-82a87465d163@somainline.org [robh: move vci-supply property to top-level] Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2026-06-05Merge branch 'selftests-bpf-tolerate-partial-builds-across-kernel-configs'Alexei Starovoitov
Ricardo B. Marliere says: ==================== selftests/bpf: Tolerate partial builds across kernel configs Currently the BPF selftests can only be built by using the minimum kernel configuration defined in tools/testing/selftests/bpf/config*. This poses a problem in distribution kernels that may have some of the flags disabled or set as module. For example, we have been running the tests regularly in openSUSE Tumbleweed [1] [2] but to work around this fact we created a special package [3] that build the tests against an auxiliary vmlinux with the BPF Kconfig. We keep a list of known issues that may happen due to, amongst other things, configuration mismatches [4] [5]. The maintenance of this package is far from ideal, especially for enterprise kernels. The goal of this series is to enable the common usecase of running the following in any system: ```sh make -C tools/testing/selftests install \ SKIP_TARGETS= \ TARGETS=bpf \ BPF_STRICT_BUILD=0 \ O=/lib/modules/$(uname -r)/build ``` As an example, the following script targeting a minimal config can be used for testing: ```sh make defconfig scripts/config --file .config \ --enable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT \ --enable DEBUG_INFO_BTF \ --enable BPF_SYSCALL \ --enable BPF_JIT make olddefconfig make -j$(nproc) make -j$(nproc) -C tools/testing/selftests install \ SKIP_TARGETS= \ TARGETS=bpf \ BPF_STRICT_BUILD=0 ``` This produces a test_progs binary with 592 subtests, against the total of 727. Many of them will still fail or be skipped at runtime due to lack of symbols, but at least there will be a clear way of building the tests. [1]: https://openqa.opensuse.org/tests/5811715 [2]: https://openqa.opensuse.org/tests/5811730 [3]: https://src.opensuse.org/rmarliere/kselftests [4]: https://github.com/openSUSE/kernel-qe/blob/main/kselftests_known_issues.yaml [5]: https://openqa.opensuse.org/tests/5811730/logfile?filename=run_kselftests-config_mismatches.txt --- Changes in v12: - Rebase from 11 to 8 commits: split the test_kmods KDIR patch into a pure KDIR fix (no PERMISSIVE) and a separate tolerance patch; squash the BPF_STRICT_BUILD toggle with its first PERMISSIVE user; squash the four test_progs partial-build patches into one; move the install fix to immediately follow the first PERMISSIVE user - Link to v11: https://patch.msgid.link/20260430-selftests-bpf_misconfig-v11-0-e11f7a8c4fdc@suse.com Changes in v11: - Gate the BTFIDS pretty-print on $(filter 1,$(V)) so V=0 and V=2 still print the marker; only V=1 suppresses it (patch 6) - Use asm volatile ("") in the uprobe_multi_func_{1,2,3} weak stubs to match the strong definitions in prog_tests/uprobe_multi_test.c (patch 10) - Link to v10: https://patch.msgid.link/20260430-selftests-bpf_misconfig-v10-0-cd302a31af16@suse.com Changes in v10: - Drop $(wildcard $^) from the bench link recipe so cc fails cleanly on the first missing input and the || fallback emits one SKIP-LINK line instead of a wall of undefined-reference errors; also makes make -n accurate (patch 9) - Include <alloca.h> in testing_helpers.c for alloca() (patch 10) - Link to v9: https://patch.msgid.link/20260429-selftests-bpf_misconfig-v9-0-c311f06b4791@suse.com Changes in v9: - Also pass KBUILD_OUTPUT=$(KMOD_O_VALID) when invoking kbuild so an inherited command-line KBUILD_OUTPUT cannot disagree with O= (patch 2) - Note BPFOBJ remains a normal prereq intentionally (patch 5) - Sub-shell isolate cd/CC and use $@ for $(RM); gate the BTFIDS pretty-print on $(V) so verbose mode does not double-print (patch 6) - Restrict permissive compile-failure tolerance and partial-link to test_progs%; runners with strong cross-object references (test_maps) keep strict semantics (patches 6 and 8) - Link to v8: https://patch.msgid.link/20260428-selftests-bpf_misconfig-v8-0-bf02cf97dbcb@suse.com Changes in v8: - In permissive mode, keep source changes to already-built tests triggering relinks, while using recipe-time $(wildcard ...) to pick up fresh .test.o files without duplicate linker inputs (patch 8) - Resolve relative O=/KBUILD_OUTPUT before recursing into test_kmods, and only treat it as a kernel build dir when it contains Module.symvers (patch 2) - Note in the commit message that PERMISSIVE-mode bisecting here needs the next two patches (patch 6) - Clarify in the commit message that order-only skeleton prereqs do not break the new-skel-via-local-header case (patch 5) - Exclude not-built tests from the success count so summary and JSON report them only as skipped (patch 7) - Tighten commit messages for accuracy and clarity - Link to v7: https://patch.msgid.link/20260416-selftests-bpf_misconfig-v7-0-a078e18012e4@suse.com Changes in v7: - Use $(abspath) for KMOD_O so relative O= paths resolve correctly when make -C changes directory (patch 2) - Guard make clean against missing KDIR unconditionally; there is nothing to clean when kernel headers are absent (patch 2) - Drop explicit $(TRUNNER_TEST_OBJS) from linker filter in strict mode; $^ already contains them as normal prerequisites (patch 8) - Link to v6: https://patch.msgid.link/20260416-selftests-bpf_misconfig-v6-0-7efeab504af1@suse.com Changes in v6: - Add --ignore-missing-args to -extras rsync so out-of-tree permissive builds do not abort when .ko files are absent (patch 2) - Use $(abspath) for KMOD_O so relative O= paths resolve correctly when make -C changes directory (patch 2) - Guard make clean against missing KDIR unconditionally so cleaning does not abort when kernel headers are absent (patch 2) - Remove stale skeleton headers in early-exit paths when .bpf.o is missing on incremental builds (patch 3) - Fix strict-mode skeleton rules: use && before temp file cleanup so bpftool failures are not masked by rm -f exit code (patch 3) - Track test filter selection separately from not_built so -t/-n flags are respected for unbuilt tests (patch 7) - Make TRUNNER_TEST_OBJS order-only only in permissive mode, preserving incremental relinking in strict builds (patch 8) - Drop explicit $(TRUNNER_TEST_OBJS) from linker filter in strict mode; they are already in $^ as normal prerequisites (patch 8) - Reorder: move skip-unbuilt-tests patch before partial-linking patch for bisectability - Link to v5: https://patch.msgid.link/20260415-selftests-bpf_misconfig-v5-0-03d0a52a898a@suse.com Changes in v5: - Add BPF_STRICT_BUILD toggle as patch 1 so every subsequent patch gates tolerance behind PERMISSIVE from the start, making the series bisectable with strict-by-default at every point - Fix O= commit message; make parent cp conditional (patch 2) - Tolerate linked skeleton failures (patch 3) - Skip feature detection for emit_tests (patch 4) - Clarify bench is all-or-nothing in commit message (patch 8) - Move stack_mprotect() to testing_helpers.c, drop weak stubs (patch 9) - Report not-built tests as "SKIP (not built)" in output (patch 10) - Drop overly broad 2>/dev/null || true from install rsync; rely solely on --ignore-missing-args which already handles absent files (patch 11) - Link to v4: https://patch.msgid.link/20260406-selftests-bpf_misconfig-v4-0-9914f50efdf7@suse.com Changes in v4: - Drop the test_kmods kselftest module flow patch: lib.mk gen_mods_dir invokes $(MAKE) -C $(TEST_GEN_MODS_DIR) without forwarding RESOLVE_BTFIDS, breaking ASAN and GCC BPF CI builds (Makefile.modfinal cannot find resolve_btfids in the kbuild output tree) - Link to v3: https://patch.msgid.link/20260406-selftests-bpf_misconfig-v3-0-587a1114263c@suse.com Changes in v3: - Split test_kmods patch into two: fix KDIR handling (O= passthrough, EXTRA_CFLAGS/EXTRA_LDFLAGS clearing) and wire into lib.mk via TEST_GEN_MODS_DIR - Pass O= through to the kernel module build so artifacts land in the output tree, not the source tree - Clear EXTRA_CFLAGS and EXTRA_LDFLAGS when invoking the kernel build to prevent host flags (e.g. -static) leaking into module compilation - Replace the bespoke test_kmods pattern rule with lib.mk module infrastructure (TEST_GEN_MODS_DIR); lib.mk now drives build and clean lifecycle - Make the .ko copy step resilient: emit SKIP instead of failing when a module is absent - Expand the uprobe weak stub comment in bpf_cookie.c to explain why noinline is required - Link to v2: https://patch.msgid.link/20260403-selftests-bpf_misconfig-v2-0-f06700380a9d@suse.com Changes in v2: - Skip test_kmods build/clean when KDIR directory does not exist - Use `Module.symvers` instead of `.config` for in-tree detection - Fix skeleton order-only prereqs commit message - Guard BTFIDS step when .test.o is absent - Add `__weak stack_mprotect()` stubs in `bpf_cookie.c` and `iters.c` - Link to v1: https://patch.msgid.link/20260401-selftests-bpf_misconfig-v1-0-3ae42c0af76f@suse.com Assisted-by: {codex,claude} Tested-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Ricardo B. Marliere <rbm@suse.com> --- Ricardo B. Marlière (11): selftests/bpf: Add BPF_STRICT_BUILD toggle selftests/bpf: Fix test_kmods KDIR to honor O= and distro kernels selftests/bpf: Tolerate BPF and skeleton generation failures selftests/bpf: Avoid rebuilds when running emit_tests selftests/bpf: Make skeleton headers order-only prerequisites of .test.d selftests/bpf: Tolerate test file compilation failures selftests/bpf: Skip tests whose objects were not built selftests/bpf: Allow test_progs to link with a partial object set selftests/bpf: Tolerate benchmark build failures selftests/bpf: Provide weak definitions for cross-test functions selftests/bpf: Tolerate missing files during install tools/testing/selftests/bpf/Makefile | 177 ++++++++++++++------- .../testing/selftests/bpf/prog_tests/bpf_cookie.c | 17 +- tools/testing/selftests/bpf/prog_tests/iters.c | 2 - tools/testing/selftests/bpf/prog_tests/test_lsm.c | 22 --- tools/testing/selftests/bpf/test_kmods/Makefile | 30 +++- tools/testing/selftests/bpf/test_progs.c | 53 +++++- tools/testing/selftests/bpf/test_progs.h | 1 + tools/testing/selftests/bpf/testing_helpers.c | 18 +++ tools/testing/selftests/bpf/testing_helpers.h | 1 + 9 files changed, 226 insertions(+), 95 deletions(-) --- base-commit: b93c55b4932dd7e32dca8cf34a3443cc87a02906 change-id: 20260401-selftests-bpf_misconfig-4c33ef5c56da Best regards, -- Ricardo B. Marlière <rbm@suse.com> ==================== Link: https://patch.msgid.link/20260602-selftests-bpf_misconfig-v12-0-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Tolerate missing files during installRicardo B. Marlière
With partial builds, some TEST_GEN_FILES entries can be absent at install time. rsync treats missing source arguments as fatal and aborts kselftest installation. Override INSTALL_SINGLE_RULE in selftests/bpf to use --ignore-missing-args, while keeping the existing bpf-specific INSTALL_RULE extension logic. Also add --ignore-missing-args to the TEST_INST_SUBDIRS rsync loop so that subdirectories with no .bpf.o files (e.g. when a test runner flavor was skipped) do not abort installation. Note that the INSTALL_SINGLE_RULE override applies globally to all file categories including static source files (TEST_PROGS, TEST_FILES). These are version-controlled and should always be present, so the practical risk is negligible. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-11-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Provide weak definitions for cross-test functionsRicardo B. Marlière
Some test files reference functions defined in other translation units that may not be compiled when skeletons are missing. Replace forward declarations of uprobe_multi_func_{1,2,3}() with weak no-op stubs so the linker resolves them regardless of which objects are present. The stub bodies are `asm volatile ("")` rather than empty, matching the shape of the strong definitions in prog_tests/uprobe_multi_test.c. This keeps the weak and strong sides on the same footing for the optimiser (noinline + asm-barrier), which is the form upstream already relies on for these functions. Move stack_mprotect() from test_lsm.c into testing_helpers.c so it is always available. The previous weak-stub approach returned 0, which would cause callers expecting -1/EPERM to fail their assertions deterministically. Having the real implementation in a shared utility avoids this problem entirely. Include <alloca.h> for alloca() so the build does not rely on glibc's implicit declaration via <stdlib.h>. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-10-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Tolerate benchmark build failuresRicardo B. Marlière
Benchmark objects depend on skeletons that may be missing when some BPF programs fail to build. In that case, benchmark object compilation or final bench linking should not abort the full selftests/bpf build. Keep both steps non-fatal, emit SKIP-BENCH or SKIP-LINK, and remove failed outputs so stale objects or binaries are not reused by later incremental builds. Note that because bench.c statically references every benchmark via extern symbols, partial linking is not possible: if any single benchmark object fails, the entire bench binary is skipped. This is by design -- the error handler catches all compilation failures including genuine ones, but those are caught by full-config CI runs. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-9-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Allow test_progs to link with a partial object setRicardo B. Marlière
When individual test files are skipped due to compilation failures, their .test.o files are absent. The linker step currently lists all expected .test.o files as explicit prerequisites, so make considers any missing one an error. In permissive mode, declare the test objects that already exist on disk (via parse-time $(wildcard ...)) as normal prerequisites of the binary so that modifications to a test source still trigger a relink, and keep the full TRUNNER_TEST_OBJS list as order-only prerequisites so that initial fresh builds still produce them and missing objects do not abort the link. The recipe filter is split per mode: in permissive mode it combines a recipe-time $(wildcard ...) (which catches objects freshly produced via the order-only path on a fresh build) with $(filter-out $(TRUNNER_TEST_OBJS),$^) (which keeps the non-test inputs from $^ but drops the parse-time wildcard duplicates). This avoids passing the same .test.o twice to the linker while still presenting test objects before libbpf.a so that GNU ld, which scans static archives left-to-right, pulls in archive members referenced exclusively by test objects (e.g. ring_buffer__new from ringbuf.c). In default (strict) mode the recipe remains the simple $(filter %.a %.o,$^) since TRUNNER_TEST_OBJS is part of $^ exactly once. Gate the partial-link behavior on $(if $(filter test_progs%,$1),...) so it only applies to test_progs and its flavors. test_maps and similar runners using strong cross-object references would link-fail with a partial set and intentionally retain strict link semantics. Note: adding a brand-new test_*.c file in permissive mode requires removing the binary (or a clean rebuild) before the new test is linked in, because the parse-time $(wildcard ...) is evaluated when the Makefile is read and will not yet see the new .test.o. This is acceptable since permissive mode targets tolerant CI builds rather than incremental development. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-8-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Skip tests whose objects were not builtRicardo B. Marlière
When both run_test and run_serial_test are NULL (because the corresponding .test.o was not compiled), mark the test as not built instead of fatally aborting. Report these tests as "SKIP (not built)" in per-test output and include them in the skip count so they remain visible in CI results and JSON output. The summary line shows the not-built count when nonzero: Summary: 50/55 PASSED, 5 SKIPPED (3 not built), 0 FAILED Tests filtered out by -t/-n remain invisible as before; only genuinely unbuilt tests are surfaced. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-7-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Tolerate test file compilation failuresRicardo B. Marlière
Individual test files may fail to compile when headers or kernel features required by that test are absent. Currently this aborts the entire build. Make the per-test compilation non-fatal: remove the output object on failure and print a SKIP-TEST marker to stderr. Guard the BTFIDS post-processing step so it is skipped when the object file is absent. The linker step will later ignore absent objects, allowing the remaining tests to build and run. Group cd and CC in a sub-shell so a cd failure cannot leak into the error-handling branch and operate in the original working directory; use $@ (absolute path) for $(RM) so it cannot match an unrelated file there. Replace the $(call msg,...) in the BTFIDS block with a plain printf (the msg macro expands to @printf, which is a make-recipe construct and is invalid inside a shell if-then-fi body) and gate the printf on $(filter 1,$(V)) so verbose mode (V=1) does not double-print the line that the recipe shell already echoes; non-verbose modes (V unset, V=0, V=2, ...) still print the BTFIDS marker, matching the convention of the shared msg macro. Restrict tolerance to test_progs and its flavors via an inlined $(if $(filter test_progs%,$1),$(if $(PERMISSIVE),...)) check: runners with strong cross-object references (e.g. test_maps) would link-fail with a partial object set, so they keep strict semantics even when BPF_STRICT_BUILD=0. The check is inlined rather than stored in a helper variable so $1 is substituted at $(call) time and the per-runner result is baked into each recipe. Note on bisectability: this change is gated entirely behind PERMISSIVE for test_progs%, so default builds (BPF_STRICT_BUILD!=0) compile and run identically at every commit in the series. Bisecting in PERMISSIVE mode at this commit still requires the next two patches ("selftests/bpf: Skip tests whose objects were not built" and "selftests/bpf: Allow test_progs to link with a partial object set") to avoid the linker rejecting missing objects and the runtime aborting on NULL function pointers. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-6-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Make skeleton headers order-only prerequisites of .test.dRicardo B. Marlière
The .test.d dependency files are generated by the C preprocessor and list the headers each test file actually #includes. Skeleton headers appear in those generated lists, so the .test.o -> .skel.h dependency is already tracked by the .d file content. Making skeletons order-only prerequisites of .test.d means that a missing or skipped skeleton does not prevent .test.d generation, and regenerating a skeleton does not force .test.d to be recreated. This avoids unnecessary recompilation and, more importantly, avoids build errors when a skeleton was intentionally skipped due to a BPF compilation failure. $$(BPFOBJ) is intentionally kept as a normal prerequisite: a libbpf rebuild legitimately invalidates .test.d, since libbpf header changes can affect the headers .test.o sees. Only the skeleton headers are moved to order-only. Note that adding a new BPF skeleton via a modified existing local header still works correctly: GNU make builds order-only prerequisites that do not exist (the order-only qualifier only suppresses timestamp-driven rebuilds, not existence-driven builds), so a brand-new .skel.h listed in TRUNNER_BPF_SKELS is generated even when .test.d is otherwise up to date. The modified local header invalidates .test.o through the previously included .d content, forcing a recompile that regenerates .test.d with the new .skel.h dependency captured by gcc -MMD. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-5-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Avoid rebuilds when running emit_testsRicardo B. Marlière
emit_tests is used while installing selftests to generate the kselftest list. Pulling in .d files for this goal can trigger BPF rebuild rules and mix build output into list generation. Skip dependency file inclusion for emit_tests, like clean goals, so list generation stays side-effect free. Also add emit_tests to NON_CHECK_FEAT_TARGETS so that feature detection is skipped; without this, Makefile.feature's $(info) output leaks into stdout and corrupts the test list captured by the top-level selftests Makefile. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-4-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Tolerate BPF and skeleton generation failuresRicardo B. Marlière
Some BPF programs cannot be built on distro kernels because required BTF types or features are missing. A single failure currently aborts the selftests/bpf build. Make BPF object and skeleton generation best effort in permissive mode: emit SKIP-BPF or SKIP-SKEL to stderr, remove failed outputs so downstream rules can detect absence, and continue with remaining tests. Apply the same tolerance to linked skeletons (TRUNNER_BPF_SKELS_LINKED), which depend on multiple .bpf.o files and abort the build when any dependency is missing. Note that progress messages (GEN-SKEL, LINK-BPF) are also redirected to stderr as a side effect of rewriting the recipes into single-shell pipelines; the $(call msg,...) macro is a make-recipe construct that cannot be used inside an &&-chained shell command sequence. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-3-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Fix test_kmods KDIR to honor O= and distro kernelsRicardo B. Marlière
test_kmods/Makefile always pointed KDIR at the kernel source tree root, ignoring O= and KBUILD_OUTPUT. On distro kernels where the source tree has not been built, the Makefile had no fallback and would fail unconditionally. When O= or KBUILD_OUTPUT is set and points at a prepared kernel build directory (one containing Module.symvers), pass it through so kbuild can locate the correct build infrastructure (scripts, Kconfig, etc.). Note that the module artifacts themselves still land in the M= directory, which is test_kmods/; O= only controls where kbuild finds its build infrastructure. Fall back to /lib/modules/$(uname -r)/build when neither an explicit valid build directory nor an in-tree Module.symvers is present. A selftests-only O= value (one that does not contain Module.symvers, e.g. a private output directory) is intentionally not treated as a kernel build directory. Without this guard, a user invoking "make -C tools/testing/selftests/bpf O=/tmp/out" would have test_kmods try to use /tmp/out as the kernel build dir and fail. The parent bpf/Makefile resolves O= and KBUILD_OUTPUT to absolute paths before invoking the test_kmods sub-make. Without this, $(abspath ...) inside test_kmods/Makefile would resolve relative paths against the sub-make's CWD (test_kmods/) rather than the user's invocation directory. When O= is passed to kbuild, also pass KBUILD_OUTPUT=$(KMOD_O_VALID) explicitly. The parent invocation lifts KBUILD_OUTPUT into MAKEFLAGS as a command-line variable, which would otherwise suppress kbuild's own "KBUILD_OUTPUT := $(O)" assignment and cause it to use the inherited KBUILD_OUTPUT instead of the validated O=. Guard both all and clean against a missing KDIR so the step is silently skipped rather than fatal. Make the parent Makefile's cp conditional so it does not abort when modules were not built. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-2-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Add BPF_STRICT_BUILD toggleRicardo B. Marlière
Distro kernels often lack BTF types or kernel features required by some BPF selftests, causing the build to abort on the first failure and preventing the remaining tests from running. Add BPF_STRICT_BUILD (default 1) to control build failure tolerance. When set to 0, the PERMISSIVE make variable is assigned a non-empty value that subsequent Makefile rules use to make individual build steps non-fatal. When set to 1 (the default), the build fails on any error, preserving the existing behavior for CI and direct builds. Users can opt in to permissive mode on the command line: make -C tools/testing/selftests \ TARGETS=bpf SKIP_TARGETS= BPF_STRICT_BUILD=0 Suggested-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-1-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: Clear rb node linkage when freeing bpf_rb_rootKaitao Cheng
bpf_rb_root_free() detaches the root by copying the current rb_root_cached and then replacing the live root with RB_ROOT_CACHED. It then walks the copied root and drops each object contained in the tree. This leaves the rb node state intact while dropping the object. If the object is refcounted and survives the drop, its bpf_rb_node_kern still contains an owner pointer to the freed root and stale rb tree linkage. If a later bpf_rb_root allocation reuses the same address, bpf_rbtree_remove() can incorrectly pass the owner check and call rb_erase_cached() on a node whose rb pointers belong to the old tree. Mirror the list draining behavior by marking nodes as busy while the root is being detached, then clear the rb node and release the owner before dropping the containing object. This makes surviving nodes unowned and safe to reject from remove or accept for a later add. Fixes: 9c395c1b99bd ("bpf: Add basic bpf_rb_{root,node} support") Signed-off-by: Kaitao Cheng <chengkaitao@kylinos.cn> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20260605094143.5509-1-kaitao.cheng@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05x86/virt/tdx: Document TDX module updateChao Gao
Recent changes introduced TDX module update support. This is a thorny feature to use correctly. It is intended for informed admins only who are expected to either be doing things very carefully, or using it via userspace programs that handle the pitfalls for them. Document the basics of how to use the feature and what is expected of the user in order for it to go correctly. Both to help the intended users of the feature and as a "here be dragons" note for the more casual TDX users. [ dhansen: tweak docs a bit, clarify update constraints ] Signed-off-by: Chao Gao <chao.gao@intel.com> [dropped "Implementation details" section, update log] Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
2026-06-05Merge branch 'object-relationship-tracking-refactor-followup'Alexei Starovoitov
Amery Hung says: ==================== Object relationship tracking refactor followup Hi, The main patchset refactoring object relationship tracking in the verifier has landed and this is a followup that addresses the remaining feedback in v6 [0]. [0] https://lore.kernel.org/bpf/20260529014936.2811085-1-ameryhung@gmail.com/ v2 -> v3 - Fix cleanup in patch 2 (AI bots) v1 -> v2 - Add patch 2 fixing silent failure when acquiring reference for struct_ops argument - Add patch 4 removing WARN_ON_ONCE in check_ids() - Add fix tags ==================== Link: https://patch.msgid.link/20260605202056.1780352-1-ameryhung@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak testAmery Hung
use_file_dynptr_slice_after_put_file() reads the dynptr via bpf_dynptr_data(), which always returns NULL for a read-only file dynptr, making the example confusing. Switch to bpf_dynptr_slice(), the correct read API for file dynptrs, and read (rather than write) the slice since it is read-only. The test still fails as expected. Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/r/20260605202056.1780352-6-ameryhung@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: Remove WARN_ON_ONCE in check_ids()Amery Hung
check_ids() warned when it ran out of idmap slots, assuming this was impossible because the slots are bounded by the number of registers and stack slots. That assumption no longer holds: referenced dynptrs acquire an intermediate reference that lives in refs[] but is not backed by any register or stack slot [0], so a program can accumulate more reference ids than the idmap can hold and exhaust it. Exhaustion is fine for verification correctness. check_ids() already returns false, which makes the states compare as not equivalent and prevents unsound pruning. The only effect of the WARN_ON_ONCE() is log noise, or a panic under panic_on_warn. Drop the warning and keep returning false. [0] 308c7a0ae885 ("bpf: Refactor object relationship tracking and fix dynptr UAF bug") Signed-off-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/r/20260605202056.1780352-5-ameryhung@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: Compare parent_id in refsafe() for REF_TYPE_PTRAmery Hung
refsafe() compared each reference's id and type but not its parent_id, so two states whose PTR references differ only in the parent object they were derived from could be wrongly treated as equivalent and pruned. Fix it by checking parent_id too. Fixes: 308c7a0ae885 ("bpf: Refactor object relationship tracking and fix dynptr UAF bug") Signed-off-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/r/20260605202056.1780352-4-ameryhung@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: Check acquire_reference() error for "__ref" struct_ops argumentsAmery Hung
When acquiring references for struct_ops program arguments tagged with "__ref", the return value of acquire_reference() was stored directly into u32 ctx_arg_info[i].ref_id without checking for failure. acquire_reference() returns -ENOMEM when acquire_reference_state() fails to allocate, so the error was silently stored as a ref_id instead of aborting verification. Fix it by checking the return. Fixes: a687df2008f6 ("bpf: Support getting referenced kptr from struct_ops argument") Signed-off-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/r/20260605202056.1780352-3-ameryhung@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpf: Fix dead error check on acquire_reference() in check_kfunc_callAmery Hung
acquire_reference() returns a signed int that may be a negative errno but was converted to unsigned, which makes the subsequent error check deadcode. Fix it by declaring 'id' as int so the error path is taken correctly. Fixes: 308c7a0ae885 ("bpf: Refactor object relationship tracking and fix dynptr UAF bug") Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/r/20260605202056.1780352-2-ameryhung@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05bpftool: Restrict feature tests during bootstrap compilationIan Rogers
When the perf build executes 'make -C ../bpf/bpftool bootstrap', bpftool's Makefile unconditionally evaluated feature checks for llvm, libcap, libbfd, and disassembler libraries because the bootstrap target was not exempted. Since the bootstrap bpftool strictly compiles minimal AST parsing and C code generation logic without linking LLVM or disassembler libraries, these feature check sub-makes are completely redundant. Exempt the bootstrap target from non-essential feature tests to eliminate unneeded sub-make fork overhead during Kbuild startup. Tested-by: James Clark <james.clark@linaro.org> Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Quentin Monnet <qmo@kernel.org> Link: https://lore.kernel.org/r/20260531010750.525160-1-irogers@google.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05dt-bindings: soc: ti,omap-dmm: Convert to DT schemaBhargav Joshi
Convert the TI OMAP Dynamic Memory Manager (DMM) dt binding from text format to DT schema. During conversion following changes were made: - Move file from /bindings/arm/omap to /bindings/soc/ti/ - Make the 'ti,hwmods' property optional and mark it deprecated as it is no longer used, it is kept to support legacy dtbs. - Add the missing required property 'interrupts' to example node. Signed-off-by: Bhargav Joshi <j.bhargav.u@gmail.com> Link: https://patch.msgid.link/20260605-ti-omap-dmm-v2-1-1b460742ec83@gmail.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2026-06-05selftests/bpf: Fix flaky file_reader testMykyta Yatsenko
file_reader/on_open_expect_fault test expects page fault when reading pages from the test harness executable. It is not guaranteed that those are paged out, even after madvise(MADV_PAGEOUT). Relax the condition in the test to succeed with both 0 and -EFAULT returned. Fixes: 784cdf931543 ("selftests/bpf: add file dynptr tests") Reported-by: Shung-Hsi Yu <shung-hsi.yu@suse.com> Closes: https://lore.kernel.org/all/ah6g7JSYOWGp2oAG@u94a/ Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com> Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20260603-file_reader_flake-v1-1-7f3f52d1e388@meta.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-06-05Merge tag 'io_uring-7.1-20260605' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux Pull io_uring fix from Jens Axboe: "A single fix for a missing flag mask when multishot is used with an incrementally consumed buffer ring, potentially leading to application confusion because of lack of IORING_CQE_F_BUF_MORE consistency" * tag 'io_uring-7.1-20260605' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: io_uring/net: inherit IORING_CQE_F_BUF_MORE across bundle recv retries
2026-06-05perf stat: Bounds-check CPU index in topology aggregation callbacksArnaldo Carvalho de Melo
Six perf_env__get_*_aggr_by_cpu() functions access env->cpu[cpu.cpu] after only checking cpu.cpu != -1. env->cpu[] is allocated with env->nr_cpus_avail entries, so a CPU index from an untrusted perf.data file that exceeds that count causes an out-of-bounds heap read. Replace the != -1 guard with >= 0 && < env->nr_cpus_avail in all six functions. The >= 0 check also catches -1 and any other negative values that could bypass the old check. Affected functions: - perf_env__get_socket_aggr_by_cpu() - perf_env__get_die_aggr_by_cpu() - perf_env__get_cache_aggr_by_cpu() - perf_env__get_cluster_aggr_by_cpu() - perf_env__get_core_aggr_by_cpu() - perf_env__get_cpu_aggr_by_cpu() Fixes: 68d702f7a120 ("perf stat report: Add support to initialize aggr_map from file") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05perf mmap: Guard cpu__get_node() return in aio_bind()Arnaldo Carvalho de Melo
perf_mmap__aio_bind() passes the cpu__get_node() return value directly to an unsigned long variable (node_index). When cpu__get_node() returns -1 for an unknown CPU, the implicit int-to-unsigned-long conversion sign-extends it to ULONG_MAX. This causes bitmap_zalloc(ULONG_MAX + 1) which wraps to bitmap_zalloc(0), returning a zero-sized allocation. The subsequent __set_bit(ULONG_MAX, node_mask) then writes massively out of bounds. Check the return value in a signed temporary before assigning to node_index, and skip the NUMA binding when the node is unknown. Fixes: c44a8b44ca9f ("perf record: Bind the AIO user space buffers to nodes") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-06-05perf sched: Fix register_pid() overflow, strcpy, and BUG_ONArnaldo Carvalho de Melo
register_pid() has several issues when processing untrusted perf.data: 1. Integer overflow: (pid + 1) * sizeof(struct task_desc *) can wrap to a small value on 32-bit systems when pid is large (e.g. 0x40000000), causing realloc to return a tiny buffer followed by out-of-bounds writes in the initialization loop. 2. Heap buffer overflow: strcpy(task->comm, comm) copies the untrusted comm string into a fixed 20-byte COMM_LEN buffer with no length check. 3. BUG_ON on allocation failure: perf.data is untrusted input, so allocation failures should be handled gracefully rather than killing the process. 4. Realloc of sched->tasks assigned directly back, leaking the old pointer on failure; nr_tasks incremented before the realloc, leaving corrupted state on failure. Cap pid at PID_MAX_LIMIT (4194304, matching the kernel's maximum on 64-bit), replace strcpy with strlcpy, guard against NULL comm, replace BUG_ON with NULL returns using safe realloc patterns, and add NULL checks in callers that dereference the result. Fixes: ec156764d424 ("perf sched: Import schedbench.c") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: Ingo Molnar <mingo@elte.hu> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>