summaryrefslogtreecommitdiff
path: root/tools/testing
AgeCommit message (Collapse)Author
9 daysMerge tag 'sched_ext-for-7.3-rc6-fixes' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext Pull sched_ext fixes from Tejun Heo: - Taking a CPU offline could hang, or stall until the watchdog ejected the BPF scheduler, when tasks on the dying CPU were still held by the scheduler or sitting on a user dispatch queue. Re-enqueue them onto the local queue when the runqueue goes offline so that the CPU pushes them off like the other sched classes. - The sequence number guarding against stale dispatches was per runqueue, so a task re-enqueued on another CPU could get the same number and a dispatch meant for its earlier instance was applied to the new one. Use a per-task counter. - A task dispatched to another CPU's local queue got its ops.dequeue() only when picked to run and flagged as a core-sched pick. Call it at insertion like for same-CPU dispatches. * tag 'sched_ext-for-7.3-rc6-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext: sched_ext: Generate qseq from a per-task counter selftests/sched_ext: Add a test for ops.dequeue() on remote local DSQ moves sched_ext: Call ops.dequeue() when a task arrives on a remote local DSQ sched_ext: Fix CPU hotplug hang when a dying CPU's tasks sit in the BPF scheduler
9 daysselftests/mm: cleanup -Wformat issues in hugetlb-mmapCarlos Llamas
Commit ae571cd6015c ("selftests/mm: hugetlb-mmap: add setup of HugeTLB pages") and commit 9c5a65f374f8 ("selftests/mm: merge map_hugetlb into hugepage-mmap") added logs of 'hugepage_size' which has a size_t type. However, the incorrect format specifier '%lu' was used which triggers -Wformat warnings when building for 32-bit: hugetlb-mmap.c:125:55: warning: format specifies type 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') [-Wformat] 125 | ksft_print_msg("Default size hugepages (%lu kB)\n", hugepage_size >> 10); | ~~~ ^~~~~~~~~~~~~~~~~~~ | %zu hugetlb-mmap.c:134:47: warning: format specifies type 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') [-Wformat] 134 | ksft_exit_skip("Not enough %lu Kb pages\n", hugepage_size >> 10); | ~~~ ^~~~~~~~~~~~~~~~~~~ | %zu Fix this by switching to the expected '%zu' format specifier. Link: https://lore.kernel.org/20260927162419.820609-1-cmllamas@google.com Fixes: ae571cd6015c ("selftests/mm: hugetlb-mmap: add setup of HugeTLB pages") Fixes: 9c5a65f374f8 ("selftests/mm: merge map_hugetlb into hugepage-mmap") Signed-off-by: Carlos Llamas <cmllamas@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com> Reviewed-by: SJ Park <sj@kernel.org> Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Cc: Mike Rapoport <rppt@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Liam R. Howlett <liam@infradead.org> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Shuah Khan <shuah@kernel.org> Cc: <stable@vger.kernel.org>
9 daysmm/mremap: fix locked_vm leak from MREMAP_DONTUNMAP self-mergeLorenzo Stoakes (ARM)
Patch series "mm/mremap: fix two issues with MREMAP_DONTUNMAP", v2. The MREMAP_DONTUNMAP feature is highly unusual in that it permits mremap() operations that keep the original VMA in place. Historically this has led to a lot of bugs where non-obvious interactions occur between existing mremap() operations and the original VMA. Commit 397432cab17b ("mm/mremap: account mm->locked_vm correctly for MREMAP_DONTUNMAP") fixed an accidentally introduced bug around mm->locked_vm accounting, but this wasn't the only issue. And thus history repeats itself, as it turns out that mm->locked_vm accounting is broken by MREMAP_DONTUNMAP yet again by two further cases, and has been broken ever since the feature was introduced. Both relate to the fact that VMA_LOCKED_BIT is cleared on the source VMA (it has to be as all page tables are moved): 1. If an unfaulted VMA_LOCKONFAULT_BIT anonymous VMA self-merges it clears the VMA_LOCKED_BIT flag and permanently leaks mm->locked_vm pages. 2. If a partial mremap() is performed on a locked VMA there is a leak equal to the number of pages not copied. (Both for MREMAP_DONTUNMAP operations only) Both issues can be fixed by treating the source range as distinct from the destination range, which is the definition of what MREMAP_DONTUNMAP does so is appropriate. In case 1, simply disallow the self-merge, keeping adjacent source and destination VMAs distinct. In case 2, split the source range ahead of time if the VMA is mlock()'d, so accounting is always correct. Both changes were tested locally and confirmed to fix the issues. For the purposes of a backport, the fixes are kept distinct, a follow-up series can add self-tests. This patch (of 2): The MREMAP_DONTUNMAP feature is highly unusual in that it permits mremap() operations that keep the original VMA in place. Historically this has led to a lot of bugs where non-obvious interactions occur between existing mremap() operations and the original VMA. Fix another of these - self-merge. Self-merge occurs when a VMA is moved in front of or behind itself and the attributes of the VMA permit such a merge. Practically this can only happen for unfaulted anonymous VMAs due to the page offset equality requirement for merge: |------------| | | | v |...........||-----------||...........| | || unfaulted || | |...........||-----------||...........| ^ | | | |------------| This becomes problematic if the VMA is configured by the user to mlock-on-fault, i.e. the VMA_LOCKED_BIT, VMA_LOCKONFAULT_BIT VMA flags are set. MREMAP_DONTUNMAP clears mlock flags for the source VMA and maintains them for the destination VMA. Self-merge makes this impossible (there is only one VMA) and incorrectly clears the destination VMA's mlock flags. This causes a leak in mm->locked_vm as clearing this flag does not decrement the counter and the VMA no longer has VMA_LOCKED_BIT set so it is not decremented on unmap. Resolve this by simply disallowing a self-merge in this case - the source and destination VMAs are kept distinct and then are able to have distinct mlock() flags. Update dontunmap_complete() to make the now-redundant self-merge check a VM_WARN_ON_ONCE() instead to guard against future regressions. Also update the VMA userland tests to reflect the change. Link: https://lore.kernel.org/20260930-fix-dontunmap-partial-self-merge-v2-0-f388985a0f0a@kernel.org Link: https://lore.kernel.org/20260930-fix-dontunmap-partial-self-merge-v2-1-f388985a0f0a@kernel.org Fixes: e346b3813067 ("mm/mremap: add MREMAP_DONTUNMAP to mremap()") Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Pedro Falcato <pfalcato@suse.de> Acked-by: Kiryl Shutsemau (Meta) <kas@kernel.org> Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com> Tested-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com> Cc: Liam R. Howlett <liam@infradead.org> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Jann Horn <jannh@google.com> Cc: Brian Geffon <bgeffon@google.com> Cc: Minchan Kim <minchan@kernel.org> Cc: <stable@vger.kernel.org>
9 daysselftests/filesystems: test covered mountsChristian Brauner
Test that mount cycles are resolved and test that mount covers behave as expected. Link: https://patch.msgid.link/20261002-work-mount-cover-v1-3-232a8f52b43c@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
9 daysselftests: net: tun: add test for VLAN-tagged GSO without NEEDS_CSUMEric Dumazet
Add selftests in tun.c verifying that a VLAN-tagged (802.1Q) TCPv4 GSO packet without VIRTIO_NET_HDR_F_NEEDS_CSUM (both flags = 0 and flags = VIRTIO_NET_HDR_F_DATA_VALID) is accepted when written to a TAP device (/dev/net/tun with IFF_TAP | IFF_NO_PI | IFF_VNET_HDR). Also verify that the following are rejected with -EINVAL: - a mismatched GSO type (VIRTIO_NET_HDR_GSO_TCPV6 on a VLAN-tagged IPv4 packet). - a frame whose TCP header is truncated after 10 bytes. Pulling only sizeof(struct iphdr) + sizeof(struct tcphdr) bytes would accept it, so this requires the transport offset found by flow dissection. Finally, verify that a 65540-byte frame is accepted. Its skb->len is above U16_MAX while it is flow-dissected, before eth_type_trans() pulls the Ethernet header. Based on a reproducer by Michael S. Tsirkin <mst@redhat.com>. Signed-off-by: Eric Dumazet <edumazet@kernel.org> Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20261001191140.2818991-4-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 dayskselftest/arm64/mte: Use MTE safe memory accessorsVladimir Murzin
Use MTE safe memory accessors instead of library functions with arbitrary implementations. Also, for consistency, use accessors even for byte size accesses. Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com> Tested-by: Muhammad Usama Anjum <usama.anjum@arm.com> Reviewed-by: Muhammad Usama Anjum <usama.anjum@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
10 dayskselftest/arm64/mte: Introduce MTE safe memory accessorsVladimir Murzin
The MTE selftests assume that they can skip (expected) MTE faults by advancing the PC by 4 in mte_default_handler(), but this is not generally safe, as the faults are triggered from arbitrary library functions (e.g. memset() and memcpy()). For instance, memset() could be implemented as simple as: mov x3, x0 // copy pointer add x4, x0, x2 // calculate end loop: strb w1, [x3], #1 // faulting access cmp x3, x4 b.ne loop ret which leads to an infinite loop since X3 could not be updated. Or, it could be having advanced implementation (FEAT_MOPS): mov x3, x0 // copy pointer setp [x3]!, x2!, x1 // prologue setm [x3]!, x2!, x1 // main sete [x3]!, x2!, x1 // epilogue ret with faulting access at prologue advancing PC to main could lead to infinite loop due to main could be triggering unaligned access fault which kernel fixing up by advancing PC back to prologue. Instead of relying on arbitrary implementations of library functions introduce helpers to perform the faulting accesses, where those faults can safely be handled. Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com> Tested-by: Muhammad Usama Anjum <usama.anjum@arm.com> Reviewed-by: Muhammad Usama Anjum <usama.anjum@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
10 dayskselftest/arm64: Extend gcs-locking to cover cases where enable is unlockedMark Brown
The gcs-locking test case currently only covers locking combinations of the various flags that can be set for GCS (enable, write and push) where enable is included in the locked bits. Since it is valid to only lock a combination of write and push while leaving enable user controllable we should also cover those cases, add coverage for them. The new cases pass as expected. Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
10 daysselftests/seccomp: Split fork_and_close into clone and close testsKees Cook
fork_and_close checked three things against one listener: that a restarted clone3() creates exactly one child, that a restarted close() releases its descriptor, and that a supervisor error reaches the caller after a restart. A three-pass loop chose what each pass did for each variant, and a failure in the first check kept the others from running. Split it into notification_restart.clone and notification_restart.close, each with one mediated syscall, one signal, and one expected result per variant. They share helpers that fork the filtered child, receive its listener, and interrupt its notification. notification_restart_child() now uses the same fork and report helpers, and the filter flags are computed in one place. Drop the supervisor error check, which failed_receive already covers. Tests run on ARCH=x86_64 defconfig with CONFIG_PROVE_LOCKING=y, CONFIG_DEBUG_ATOMIC_SLEEP=y, and CONFIG_DEBUG_LIST=y under QEMU, built with GCC 16.2.0: seccomp_bpf passes 137/137 with 5 skips, and the 28 notification_restart tests pass in 25 of 25 runs at -smp 2 and -smp 4. On v7.3-rc2 the restart and both variants fail and the others pass. Assisted-by: LLM Signed-off-by: Kees Cook <kees@kernel.org>
10 daysselftests/seccomp: test addfd with an O_PATH descriptorCong Wang
SECCOMP_IOCTL_NOTIF_ADDFD used to reject O_PATH source descriptors with EBADF. Add a regression test that injects one into a notified task. Verify that the injected descriptor retains O_PATH semantics and the requested close-on-exec flag. The test fails on the original fget() path and passes with fget_raw(). Assisted-by: Codex:gpt-6 Signed-off-by: Cong Wang <cwang@multikernel.io> Link: https://patch.msgid.link/20260924223018.564548-3-xiyou.wangcong@gmail.com Signed-off-by: Kees Cook <kees@kernel.org>
10 daysselftests/seccomp: cover restart of unreceived notificationsCong Wang
Exercise restart and killable-wait flag combinations before receipt, after a failed receive, and after receipt. Cover repeated interruptions, listener closure, fatal signals, flag validation and supervisor errors. Verify that restarted fork creates exactly one child, close releases its descriptor, and denied fork returns EAGAIN. Preserve compatibility checks with restart disabled. Synchronize pre-receipt signals through a socket and check post-receipt response preservation without task-state polling. All 136 seccomp selftests passed before the polling cleanup. After that change, all four revised post-receipt variants and the existing wait-killable test passed. Assisted-by: Codex:gpt-6 Signed-off-by: Cong Wang <cwang@multikernel.io> Link: https://patch.msgid.link/20260924204209.477694-3-xiyou.wangcong@gmail.com Signed-off-by: Kees Cook <kees@kernel.org>
10 daysselftests: net: Fix minor issues in cork_fragsize.pyAlice Mikityanska
return None is unreachable in check_kernel_config, because the try block always returns a True or False value, and the except block continues the loop. The return None was supposed to be outside the for loop, to make pylint happy by making all the flows of the function return a value explicitly. While at it, make the docstring of check_dmesg_clean clearer by explaining the return values. Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260901195714.673548-1-alice.kernel%40fastmail.im Signed-off-by: Alice Mikityanska <alice@isovalent.com> Link: https://patch.msgid.link/20261001124201.584805-1-alice.kernel@fastmail.im Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysselftests/net: add SO_RESERVE_MEM testEric Dumazet
Add a kselftest suite covering SO_RESERVE_MEM behavior: - Reject unsupported socket types (UDP/SOCK_DGRAM, UNIX/SOCK_STREAM, SOCK_RAW, MPTCP) with EOPNOTSUPP, for both zero and non-zero values. - Validate bounds (negative values and values > SZ_1G return EINVAL). - Verify reserve adjustments (increase, decrease, page rounding, and reset to 0) and corresponding sk_meminfo[SK_MEMINFO_FWD_ALLOC] changes via getsockopt(SO_MEMINFO). - Exercise cgroup v2 memory.max enforcement returning ENOMEM when the requested reservation exceeds the cgroup limit. - Verify that a child socket returned by accept() starts with a 0 reserve even when its parent listener configured a non-zero SO_RESERVE_MEM. - Verify reserve retention across TCP send/receive/ACK cycles. Each test runs in private mount and network namespaces. cgroup2 is mounted on a private tmpfs, so nothing is left behind in the host filesystem. The test process is moved to a dedicated leaf cgroup, and back to its original cgroup on teardown. The memory controller is enabled in the root of the hierarchy if needed, and left enabled like selftests/cgroup do, as disabling it could break other users. Also enable CONFIG_CGROUPS=y and CONFIG_MEMCG=y in tools/testing/selftests/net/config. Signed-off-by: Eric Dumazet <edumazet@kernel.org> Link: https://patch.msgid.link/20261001192137.309983-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysselftests/bpf: Test dynptr teardown on subprog returnXu Yunxiang
Add failure tests for slices that escape a subprogram from a dynptr in the callee stack. Cover immediate use of a ring buffer clone slice, release-time invalidation of a caller dynptr slice after it crosses a subprogram return, and immediate use of an skb dynptr slice in a qdisc program. Cover the error path where a subprogram would otherwise lose the last dynptr capable of releasing a referenced resource. Also add a success control which derives a slice from a caller-owned dynptr and creates a separate clone in the callee. Destroying that callee-local clone on return must not invalidate the caller dynptr's slice. Signed-off-by: Xu Yunxiang <xyx2021@mail.ustc.edu.cn> Reviewed-by: Amery Hung <ameryhung@gmail.com> Link: https://lore.kernel.org/bpf/20260927120422.1042107-3-xyx2021@mail.ustc.edu.cn Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
10 daysbpf: Destroy callee-local dynptrs on subprog returnXu Yunxiang
A data slice is valid only while the specific dynptr that produced it remains valid. prepare_func_exit() copies a subprogram return value into the caller and then frees the callee state without applying the normal destruction semantics to dynptrs in the callee stack. A callee can therefore derive a slice from a local dynptr, return or spill the slice into its caller, and then let the dynptr disappear with the callee frame. The slice retains the id of a dynptr that is no longer in the verifier state, so the verifier continues to accept accesses through it. Before the object relationship refactor, bpf_dynptr_data() slices from referenced dynptrs also carried the shared reference id, allowing a later release to catch some of these escaped slices. The refactor made those slices precise children of their source dynptr and exposed the missing teardown as an accepted stale access even after the shared resource is released. Add destroy_dynptrs_in_stack_slots() to apply the existing dynptr teardown to an inclusive range of stack slots. Reuse it for dynptr initialization, variable-offset stack writes, and the entire callee stack before freeing the frame. The teardown rejects losing the last dynptr for a referenced resource and invalidates the dynptr and all its descendants, including slices held in the caller. Propagate errors through prepare_func_exit(). Reuse the existing teardown API and diagnostic. Update the affected callback test expectation in this change so the commit remains test-clean. Fixes: 308c7a0ae885 ("bpf: Refactor object relationship tracking and fix dynptr UAF bug") Reported-by: Sashiko <sashiko-bot@kernel.org> Suggested-by: Amery Hung <ameryhung@gmail.com> Signed-off-by: Xu Yunxiang <xyx2021@mail.ustc.edu.cn> Reviewed-by: Amery Hung <ameryhung@gmail.com> Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/CAMB2axOmdHwSrHihSRskDywkCmEGQOX+6dZPN_A9u-HhxY3UDA@mail.gmail.com Link: https://lore.kernel.org/r/CAMB2axMmrTb+UZ84UD48MwMtXbk1s9bWtreU3AOfjzU0fPT0BA@mail.gmail.com Link: https://lore.kernel.org/bpf/20260927120422.1042107-2-xyx2021@mail.ustc.edu.cn Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
10 daysselftests: drv-net: psp: test that rx-assoc fails on closed and listen socksDaniel Zahka
Cover two of the basic psp assoc states that have been defeatured. Do not include tests with shutdown(), connect(..., AF_UNSPEC), etc. I don't think the coverage is worth the complexity. That should be done with packetdrill. Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com> Fixes: 6b46ca260e22 ("net: psp: add socket security association code") Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20260930-psp-defeat-v2-4-f266e7447129@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysselftests: drv-net: psp: swap closed for connected sockets in assoc testsDaniel Zahka
Future work will only allow rx-assoc and tx-assoc to be performed when the sock is in TCP_ESTABLISHED state. Several assoc_ tests, as well as dev_rotate_spi, test using the rx-assoc and tx-assoc uapi calls against sockets in TCP_CLOSE state. These tests don't involve sending or receiving data, nor involve looking up psp device by dst entry, so using a disposable disconnected socket was just a convenience. These can be replaced by a disposable loopback socket. The loopback sockets are IPv4, where the sockets they replace were AF_INET6. This doesn't reduce coverage, since the assoc handlers accept any TCP socket and don't look at the address family. Some users of rx-assoc and tx-assoc on closed sockets are left if they validate errors that are returned before the kernel will check the socket for TCP_ESTABLISHED. Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com> Fixes: 6b46ca260e22 ("net: psp: add socket security association code") Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20260930-psp-defeat-v2-1-f266e7447129@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
11 daysselftests/core: test CLOSE_RANGE_CLOEXEC_ONLYChristian Brauner
Cover closing what is marked: - close-on-exec descriptors in the range go, the ones outside stay, and a range above the table closes nothing - with CLOSE_RANGE_EXCEPT it is the other way around, and the kept ones keep their flag, for a window in the middle, at the top and at the bottom - descriptors without close-on-exec are never touched, in or out of the range - a range that cannot hold an open descriptor keeps nothing, one that covers everything keeps everything, in place and in a clone - the unshare form leaves the table it was cloned from alone, with and without CLOSE_RANGE_EXCEPT - the unshare form keeps the descriptors without the flag that sit in the range it drops from, and hands the dropped slots out again - a kept range above the last descriptor without close-on-exec still comes back, so the clone is sized off the range too Also check that asking for CLOSE_RANGE_CLOEXEC at the same time is refused, whatever else is asked for, and that the bounds are still checked. The extra cases came out of the same walk with the close-on-exec mask on top: a marked and an unmarked descriptor on each side of every window position, and the size of the clone when only unmarked ones are left in the range it drops from. Link: https://patch.msgid.link/20260921-work-file-close_range_except-v1-10-c20d0b49270d@kernel.org Reviewed-by: Jann Horn <jannh@google.com> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
11 daysselftests/core: test CLOSE_RANGE_EXCEPTChristian Brauner
Cover the inverted range: - with plain close the window stays and everything outside of it goes, stdio included - a window at the top, one that cannot hold a descriptor and one of a single descriptor keep just what they name, and so does the unshare form on a table that is not shared - with CLOSE_RANGE_CLOEXEC everything outside of the window is marked and the window is not, in place and in a clone, for a window in the middle, at the bottom, at the top and above the table - with CLOSE_RANGE_UNSHARE the table the child cloned from is untouched, a window near the top of the table comes back whole, one at the bottom keeps stdio, one that cannot hold a descriptor keeps nothing, and the slots left behind are handed out again from the bottom - the bounds are checked before the range is turned around The extra cases came out of walking the window positions that __range_close(), __range_cloexec() and dup_fd() tell apart: at the bottom, in the middle, at the top, above the table, a single descriptor and none, on a shared and on a private table. Link: https://patch.msgid.link/20260921-work-file-close_range_except-v1-7-c20d0b49270d@kernel.org Reviewed-by: Jann Horn <jannh@google.com> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
11 daysselftests/core: test the hole CLOSE_RANGE_UNSHARE leaves behindChristian Brauner
Cover a range in the middle of a full word: - the descriptors in it are gone from the clone and the ones around it are still there - the slots are handed out again, the word is not left marked full - the table the child cloned from is untouched Link: https://patch.msgid.link/20260921-work-file-close_range_except-v1-2-c20d0b49270d@kernel.org Reviewed-by: Jann Horn <jannh@google.com> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
11 daysMerge 7.3-rc6 into char-misc-nextGreg Kroah-Hartman
This resolves a number of merge conflicts between the branches, and we pick up the fixes in 7.3-rc6 that we need for testing. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
11 daysselftests/nfsd: check that listener removal asks rpcbind onceJeff Layton
Cover the teardown side of the same rule. Remove one listener, then three, with the stub silent, and compare what it saw. Three removals must not cost three timeouts. Both measurements also pay the svc_unregister() sweep that nfsd_destroy_serv() runs once the last listener is gone, so that cancels out of the comparison. The listeners are registered with the stub answering, so each one has an entry to remove. Assisted-by: LLM Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://patch.msgid.link/20260901-nfsd-nl-hang-v5-15-a540d86668b0@kernel.org Signed-off-by: Chuck Lever <cel@kernel.org>
11 daysselftests/nfsd: check that listener_set asks rpcbind onceJeff Layton
Cover the change that stops a listener_set request from registering after rpcbind stops answering. RPCB_STUB_SILENT is new. It reads a call and writes nothing back, so the kernel waits out its own timeout. RPCB_STUB_REFUSE cannot serve here: a refusal is an answer, and the count ignores it on purpose. Every procedure but the NULL one is silenced, so an unregistration goes unanswered as well. The NULL one has to be answered: rpcb_create_af_local() builds its client without RPC_CLNT_CREATE_NOPING, so rpc_create() pings at creation. Silencing that ping too would fail the AF_LOCAL client, send rpcb_create_local() on to the loopback client of rpcb_create_local_net(), and leave the stub seeing one call per request no matter how many listeners it carried. - rpcb_stop_after_failure. Ask for one listener, then for three, and compare what the stub saw. Three entries must not cost three times as much. - rpcb_silent_set_complete. The entry that finds rpcbind silent is the one that pays the timeout, and with v3 enabled it is the only entry whose listener would be lost. Require that a three-entry request brings up all three, succeeds, and warns. - rpcb_v4_only_bounded. The case that needs the count rather than a failed listener. version_set_only() makes the server v4-only, so vs_rpcb_optnl discards every error and every listener comes up. Require that the listeners are present, that the ack warns about them, and that three entries do not cost three round trips. - rpcb_retry_next_request. The stop lasts for one request. After the stub starts to answer, the next request must reach rpcbind again. The counts these tests compare include the unregistrations that the teardown between the two measurements issues. The preceding patches bound that direction too, so the sweeps stay at one timeout rather than one per program and version. version_set_only() is new. NFSD_CMD_VERSION_SET clears every version before it reads the request, so one nest leaves the server v4-only. It returns -EBUSY once a serv exists, so the test calls it first. Assisted-by: LLM Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://patch.msgid.link/20260901-nfsd-nl-hang-v5-14-a540d86668b0@kernel.org Signed-off-by: Chuck Lever <cel@kernel.org>
11 daysselftests/nfsd: add a per-netns rpcbind stub and the listener round-tripsJeff Layton
The creation of a listener registers with rpcbind. svc_xprt_create_from_sa() passes flags of 0, so pmap_register is true in svc_setup_socket(). A fresh netns has no rpcbind. Every registration therefore waits out the local rpcbind timeout, once for each program and version, and the registration failure then takes the listener down. The host's rpcbind is not an option either. svc_rpcb_setup() opens with a call to svc_unregister(), which would clear the host's nfsd entries. Serve rpcbind from inside the namespace instead. The abstract AF_LOCAL name that the kernel tries first is per-netns, because unix_find_abstract() takes a struct net. Bind "\0/run/rpcbind.sock" and fork a minimal responder: - the responder never decodes arguments. The NULL procedure gets an empty success, and SET and UNSET get TRUE. - the responder answers RPCBVERS_4 as well as RPCBVERS_2. A v4 refusal makes __svc_rpcb_register6() return -EAFNOSUPPORT, which would leave every IPv6 listener unregistered. - the responder counts accepted connections and received calls in a page that it shares with the test, and reads its mode from that page on every call. The mode lives there rather than in the child so that a test can change it with a serv already up: killing and restarting the stub would close the connection the kernel holds, and rpcb_register_call() issues UNSET over AF_LOCAL with RPC_TASK_NOCONNECT, so the next call would fail at once with -ENOTCONN instead of waiting out a timeout. - PR_SET_PDEATHSIG plus an explicit kill in FIXTURE_TEARDOWN make sure that no stub outlives its test. With the stub in place, add the tests that need a serv. These cover the create, add and remove paths and the LISTENER_GET round trips: tcp, udp, several listeners at once, an idempotent re-set, the removal of a subset, the destruction of a serv from an empty list, and IPv6. Two more tests cover the empty-list request and the -EBUSY refusal after THREADS_SET has started threads. The netlink socket asks for NETLINK_EXT_ACK, so that the tests can read the extack message. It also asks for NETLINK_CAP_ACK, so that the kernel does not echo the request back and the TLVs sit at a fixed offset. FIXTURE_TEARDOWN drops whatever a test left running. A listener holds a reference to the netns, and that netns outlives the test process. Threads pin the listeners. Anything left up therefore leaks the namespace. Several of these tests exist to catch a revert, not to describe the interface. The errno alone shows none of them: - val_reject_keeps_listeners. An unknown transport name ends in -EPROTONOSUPPORT either way, because svc_xprt_create_from_sa() returns that error too. The difference is the state that it leaves. Without the up-front check, nfsd_nl_listener_set_doit() has already destroyed the listeners that did not match by the time the name fails. - val_bad_transport. This test now also requires that the stub saw no traffic. A request that reaches svc_xprt_create_from_sa() has run nfsd_create_serv(). svc_bind() then pings rpcbind at client creation and sweeps stale entries with svc_unregister(). Silence at the stub is therefore what shows that the kernel refused the request up front. - val_second_entry_bad. This test now also sends a LISTENER_GET. svc_xprt_create_from_sa() also returns -EAFNOSUPPORT for the bad entry, and the doit keeps the listeners that it did create. The well-formed tcp entry ahead of it would otherwise still be up. - sem_register_refused. This test puts the stub in a mode that answers RPCBPROC_SET with FALSE. rpcb_register_call() turns that answer into -EACCES, svc_register() then fails, and svc_setup_socket() creates no listener. The bare errno does not show that, because a bind can return -EACCES too, so the test reads the listener set back and requires that it is empty. - sem_create_failure_extack. This test squats on the port first, so the listener cannot bind. The extack must then name the transport that failed. - func_empty_destroys. This test uses the connection count. LISTENER_GET replies empty both for a destroyed serv and for a live serv with no permsocks. But only nfsd_destroy_serv() reaches svc_xprt_destroy_all(..., unregister=true) -> svc_rpcb_cleanup() -> rpcb_put_local(), which drops the last user and shuts the local client down. The next serv has to connect again. - sem_busy_on_change and sem_busy_on_remove read the listeners back, because -EBUSY says nothing about what the doit did before it returned. find_listener() matches the address as well as the transport, the family and the port. Every listener here is created on loopback, so a reply that names 0.0.0.0 has to fail. Assisted-by: LLM Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://patch.msgid.link/20260901-nfsd-nl-hang-v5-13-a540d86668b0@kernel.org Signed-off-by: Chuck Lever <cel@kernel.org>
11 daysselftests/nfsd: exercise listener_set request validationJeff Layton
Add regression tests for the NFSD_CMD_LISTENER_SET checks that nfsd_nl_validate_listeners() runs before the code takes nfsd_mutex. The tests cover a bad transport name, an absent transport name, a missing address, a truncated or unsupported sockaddr, a bad address family, a malformed entry behind a well-formed one, and more than NFSD_NL_LISTENER_MAX entries. One more test sends a LISTENER_GET to an empty netns. None of these requests reach nfsd_create_serv(), so nothing here creates a serv or registers with rpcbind. The tests that do need a serv come next, with a stub. The tests use kselftest_harness.h, so each test runs in its own net and mount namespace. /run is masked there. unix_find_bsd() resolves by inode and takes no struct net, so a connect to "/var/run/rpcbind.sock" from this netns would otherwise reach the rpcbind on the host. svc_rpcb_setup() opens with a call to svc_unregister(), which would then clear the host's nfsd registrations. The config fragment must therefore cover the fixture as well as nfsd: NAMESPACES and NET_NS for the unshare(), SHMEM and TMPFS for the mask, and UNIX for the AF_LOCAL rpcbind client. Without them, every test skips. Add the new directory to the NFSD MAINTAINERS entry, which does not cover tools/testing/selftests/ today. Assisted-by: LLM Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://patch.msgid.link/20260901-nfsd-nl-hang-v5-12-a540d86668b0@kernel.org Signed-off-by: Chuck Lever <cel@kernel.org>
11 daysselftests/alsa: Add a test for snd-aloop notify modeHenrik Enquist
Add a test for the hw constraints between the playback and capture devices of an snd-aloop cable, and for the "PCM Slave" controls that report the playback side's parameters to the capture application. With notify disabled, a playback opened while a capture is set up must be pinned to the capture's parameters. With notify enabled, it may pick others. Starting it stops the running capture, and the "PCM Slave Format", "Rate", "Channels" and "Access Mode" controls report the new parameters, each with a value event. A capture opened second is pinned to the playback either way. The tests only check hw_refine results, stream states and control values, so they don't depend on timing. They skip if snd-aloop isn't loaded or the devices are in use. Without "ALSA: aloop: Don't constrain playback params in notify mode", the two notify mode tests fail. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Henrik Enquist <henrik.enquist@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20261003-aloop-notify-fix-v1-2-ba5dfb831bf5@gmail.com
11 daysselftests/alsa: Check that a write does not silently change other controlsHyeongJun An
A control whose register mask is wider than its field clobbers the field next to it. No event is sent for the neighbour, so nothing notices. The es8316 bug fixed in commit 6c1bb4031729 ("ASoC: codec: es8316: "DAC Soft Ramp Rate" is just a 2 bit control") was one. Add a test that writes each control's minimum and then its maximum. After each write it compares the other controls on the card with a snapshot. The minimum clears the field and the maximum sets its top bit, which is where a mask one bit too wide lands. Some drivers link controls on purpose, so a change announced with a value event is only logged. A silent one fails. On an HDA HDMI codec and snd-dummy, 39 controls in all, it reports nothing. A snd-dummy copy with an injected silent overlap fails, and the same overlap announced with a value event passes. Suggested-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/all/0fefbfe1-021b-46b2-8945-15956e75e37f@sirena.org.uk/ Signed-off-by: HyeongJun An <sammiee5311@gmail.com> Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20260930111534.3782264-3-sammiee5311@gmail.com
11 daysselftests/alsa: Do not take another control's event as our ownHyeongJun An
The wait_for_event() skips an event for a different control with a continue inside its do-while loop. But continue goes straight to the loop condition, and that tests the mask of the event just skipped. So a value event for another control ends the wait as if it were ours. A driver that notifies a second control from its put() queues that event first. The core only sends ours once put() returns. So the wait returns early and leaves ours in the queue. The next test then reports it as spurious. And event_missing passes for a control whose put() said nothing changed, as long as it notified a neighbour. To fix this, clear the mask before skipping the event. Fixes: b1446bda5645 ("kselftest: alsa: Check for event generation when we write to controls") Signed-off-by: HyeongJun An <sammiee5311@gmail.com> Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20260930111534.3782264-2-sammiee5311@gmail.com
12 daysselftests/filesystems: check that reading the root of an empty mount ↵Christian Brauner
namespace stalls nobody A readdir of the root of an empty mount namespace stuck in the page fault of its buffer must stall neither a create nor a lookup in that directory. The test needs userfaultfd and skips without it. Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-21-dd44b89d44ce@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
12 daysselftests/filesystems: add a helper that holds a readdir in a page faultChristian Brauner
A getdents64() whose buffer is a page registered with userfaultfd sits in handle_userfault() with whatever iterate_dir() took before it copied the entries. Add readdir_hold.h for tests that want to know what that blocks: it opens the userfaultfd before the test enters a user namespace, the fault happens in the kernel and needs CAP_SYS_PTRACE in the initial one, starts the readdir in a thread, waits until that thread is stuck, queues a create behind it and waits for it to settle, then probes a lookup with a watchdog and says whether it came back. The page is released afterwards so that everything drains on a kernel that still holds the lock across the copy. The two users follow. Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-20-dd44b89d44ce@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
12 daysselftests/filesystems: check that an automount below an overlay layer is refusedChristian Brauner
Make sure that we don't automount on top of internal things. Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-12-dd44b89d44ce@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
12 daysselftests/filesystems: check the atime of the empty mount namespace rootChristian Brauner
No access time updates for immutable nullfs. Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-11-dd44b89d44ce@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
12 daysselftests/filesystems: check that a lock lands on the right mount and staysChristian Brauner
Check MNT_LOCKED: - A child in a user namespace of its own triggers the tracefs automount through a directory descriptor on the host's debugfs mount. The copy in the child's namespace has to be locked and the host's mount unlocked. - A child moves a bind of that automount beneath a locked covering mount, unmounts the covering mount and asks for the umount of an unlocked ancestor. This must not expire the mount which holds the lock now. - The host mounts and unmounts on a directory that a locked mount covers in a user namespace further down the propagation chain. That cover has to be locked afterwards as it was before. Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-10-dd44b89d44ce@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
12 daysselftests/filesystems: check that an immutable inode takes no write hintChristian Brauner
Check that an immutable inode takes no write hint. Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-4-dd44b89d44ce@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
12 daysKVM: arm64: selftests: Test VGICv3 redistributor region retryKarl Mehltretter
A failed REDIST_REGION write can remove redistributor iodevs without clearing their cached vCPU assignments. A retry then skips those assignments and leaves the redistributors absent from the MMIO bus. Create two partial regions, reject a third region that overlaps the distributor, and retry at a valid address. After initializing the VGIC, have the guest read GICR_TYPER from all four redistributors and check their processor numbers. This verifies the final configuration without assuming that assignments survive the failed write. Keep the redistributor IPAs outside the guest RAM memslot and install only the stage-1 mappings needed for the MMIO accesses. If an iodev is missing, KVM_RUN therefore exits with KVM_EXIT_MMIO. Without the fix, the first redistributor access exits at 0x8030008. Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com> Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev> Tested-by: Fuad Tabba <fuad.tabba@linux.dev> Link: https://patch.msgid.link/20260831081005.41346-5-kmehltretter@gmail.com Signed-off-by: Marc Zyngier <maz@kernel.org>
12 daysKVM: arm64: selftests: Pass guest code to vm_gic_create_with_vcpus()Karl Mehltretter
Pass the guest-code address to vm_gic_create_with_vcpus(), and use guest_code at the existing call sites. This lets tests with different guest code reuse the common VM and VGIC setup while retaining the void * interface of vm_create_with_vcpus(). Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com> Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev> Tested-by: Fuad Tabba <fuad.tabba@linux.dev> Link: https://patch.msgid.link/20260831081005.41346-4-kmehltretter@gmail.com Signed-off-by: Marc Zyngier <maz@kernel.org>
12 daysselftests/bpf: Format data_in_arena_rust.rs with rustfmtAlexei Starovoitov
'make rustfmtcheck' checks every .rs file in the tree and fails since the test in Rust was added: Diff in tools/testing/selftests/bpf/progs/data_in_arena_rust.rs:42: #[no_mangle] static IN_RODATA: Node = Node { val: 3, next: None }; #[no_mangle] -static mut IN_DATA: Node = Node { val: 20, next: Some(&IN_RODATA) }; +static mut IN_DATA: Node = Node { + val: 20, + next: Some(&IN_RODATA), +}; Format the file with rustfmt. The code and the data of the program don't change. Fixes: e86cb7315451 ("selftests/bpf: Add test for global data of a program in Rust") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261003203326.1086454-1-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysselftests/bpf: Fix data_in_arena test with GCCAlexei Starovoitov
GCC doesn't support indirect calls in BPF: progs/data_in_arena.c: In function 'use_ops': progs/data_in_arena.c:65:1: error: indirect call in function, which are not supported by eBPF Call add1() directly when the test is built with GCC. use_ops() still loads the pointers to data that are next to the pointer to the function in .data.rel.ro and dereferences them. Once the build is fixed data_in_arena/arena_var_no_map fails with GCC: test_arena_var_no_map:FAIL:open unexpected pointer: 0x559fb35d3ca0 GCC doesn't support address spaces. __arena is a type tag only there, so avar is in .data instead of .addr_space.1 and there is nothing wrong with the object. Use __arena_global. It puts the variable into .addr_space.1 with both compilers. Fixes: 27e24617a83b ("selftests/bpf: Add test for global data in arena") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261003150456.168903-1-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 dayslib: Move SipHash into lib/crypto/Eric Biggers
The addition of SipHash to lib/ predated the existence of the lib/crypto/ directory. Since SipHash is a cryptographic algorithm, move it from the top-level lib/ directory to lib/crypto/. (This does mean HalfSipHash comes with it too, as it's in the same files. But lib/crypto/ still seems like the proper place for both.) Specifically: - Move both siphash.c and siphash_kunit.c. Keep the header <linux/siphash.h> as-is for now. - Drop the dedicated MAINTAINERS entry for SipHash, as per the suggestion from Jason (https://lore.kernel.org/r/asB7QVFMlgKgbje2@zx2c4.com/). The C files now just fold up to the "CRYPTO LIBRARY" entry. Add the header explicitly, as it otherwise would be left unmaintained. - Move the kconfig option that controls the KUnit test. Put "CRYPTO_LIB" in its name and update the prompt and help text to make it consistent with the other crypto library test options. - Enable the KUnit test in lib/crypto/.kunitconfig. - Link to siphash.rst from the appropriate place in libcrypto-hash.rst. - Use obj-y instead of lib-y, for consistency with the fact that currently lib/crypto/ doesn't use kbuild's support for library file goals. We could keep it as lib-y, but virtually every kernel needs SipHash support anyway (with vsprintf, printk, IPv4, IPv6, etc. depending on it) so there is no practical difference in this case. Acked-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Jason A. Donenfeld <Jason@zx2c4.com> Link: https://patch.msgid.link/20261003162827.155527-1-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
13 daysselftests/bpf: Add test for global data of a program in RustAlexei Starovoitov
data_in_arena_rust.rs shows why libbpf keeps .data, .bss and .rodata of a program in Rust in arena. A reference in Rust is an address that can be stored in data. The list in the test has a node in each of the three sections. IN_BSS.next is stored by the program, IN_DATA.next is a relocation in .data against .rodata. sum() follows them and reads all nodes with the same insns: 5: w0 = *(u32 *)(r1 + 0x8) 8: r1 = *(u64 *)(r1 + 0x0) The same program without .arena.data section, when the sections are array maps: libbpf: elf: skipping relo section(9) .rel.data for section(8) .data ... 16: (79) r1 = *(u64 *)(r1 +0) ; frame1: R1=scalar() ... 13: (61) r0 = *(u32 *)(r1 +8) R1 invalid mem access 'scalar' The program is built by upstream rustc for its bpfel-unknown-none target. Nothing is done to the output: rustc emits LLVM bitcode and clang makes the object of it for the cpu version of the test_progs flavor. rustc has no prebuilt core for the target, so core is built from the source that comes with rustc, like the kernel does it. That takes 5 seconds. The subtest is skipped when: - there is no rustc or it is older than 1.87. core is built as edition 2024, which it is since then. - rustc comes without the source of core (rustup component add rust-src). - clang is older than 23 or older than LLVM of rustc. It can't read the bitcode then. There are no kfuncs in the program. rustc doesn't emit debug info for extern functions, so there would be no BTF for them. panic=abort is a stop gap. Nothing in the program panics, so the panic handler is not loaded. The series from Yonghong are about to add support for panic=unwind. Tested with rustc 1.95.0-nightly (LLVM 22.1) and clang 24. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-16-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysselftests/bpf: Add test for global data in arenaAlexei Starovoitov
Load the program that reads and writes .data, .bss and .rodata from the object with .arena.data section. Check that initial values set through the skeleton reach the program and that the values written by the program are seen through the skeleton. Also check: - alignment of a section. - pointers to data and to a const string that are stored in data and in read-only data, next to a pointer to a function that callx uses. - bpf_strncmp() with a string literal, bpf_printk() and BPF_SNPRINTF(). - an object that has an arena map and __arena variables. - the load fails when a pointer in data points to a section that is not in arena or to a variable of the kernel. - the load fails when there are pointers in data and the arena is pinned or reused. - the open fails when there are __arena variables and no arena map. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-15-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysselftests/bpf: Add tests for a variable that is smaller than its typeAlexei Starovoitov
Check that a variable in DATASEC that is smaller than its type is not printed when the map is read from bpffs and when bpftool dumps it. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-12-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysbpf: Allow a variable in DATASEC that is smaller than its typeAlexei Starovoitov
LLVM splits a static of a Rust program into pieces. Every piece is a VAR with the type of the whole static: [223] STRUCT 'BpfCell<core::option::Option<...>>' size=32 vlen=1 [236] VAR '..scx_cosmos9TASK_CTXS.0' type_id=223, linkage=static [248] DATASEC '.bss' size=0 vlen=9 type_id=236 offset=24648 size=1 (VAR '..TASK_CTXS.0') and the kernel rejects such BTF with "Invalid size". Allow it. The size of a variable in DATASEC is used in two places: - btf_find_datasec_var() looks for timers, spin locks, kptrs and other special fields. btf_find_field_one() skips a variable when its size is not the size of its type, so there are no special fields in a piece. - btf_datasec_show() prints variables by their types. It would read past the piece and past the end of the map value when the piece is the last one. Don't print the pieces. "global data test #8" and "#10" in prog_tests/btf.c expect "Invalid size". BTF of both is loaded now. The map of #10 is not created, since its value is larger than the section. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-10-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysselftests/bpf: Add test for arguments without names in static functionsAlexei Starovoitov
Check that BTF with a static function that has an argument without a name is loaded. Vararg has no name too. Check that a global function with it is loaded as before. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Alan Maguire <alan.maguire@oracle.com> Link: https://lore.kernel.org/bpf/20261002124714.180012-9-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysbpf: Allow arguments without names in static functions in BTFAlexei Starovoitov
Some static functions in BTF of a Rust program have arguments without names: [71] FUNC_PROTO '(anon)' ret_type_id=0 vlen=1 '(anon)' type_id=72 [81] FUNC 'unwrap_failed' type_id=71 linkage=static and the kernel rejects such BTF with "Invalid arg#1". It's 5 of 25 static functions in scx_cosmos and 6 of 24 in scx_simple. The verifier looks at types of the arguments. The names are printed only, as "(anon)" when there is none. Allow such static FUNC. Global functions are checked as before. The test "func (Some arg has no name)" in prog_tests/btf.c has a static function. Make it global to keep the check. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Alan Maguire <alan.maguire@oracle.com> Link: https://lore.kernel.org/bpf/20261002124714.180012-8-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysselftests/bpf: Add tests for names of Rust types and functions in BTFAlexei Starovoitov
Check that BTF with names of STRUCT, FWD, TYPEDEF and FUNC that Rust makes is loaded and that the name of FUNC is an identifier in kallsyms. The test is serial. Programs are not in kallsyms while bpf_jit_harden is set and there are tests that set it for a while. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-7-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysbpf: Allow names of Rust types and functions in BTFAlexei Starovoitov
Names of types and functions in BTF that LLVM makes for a Rust program are not C identifiers: [69] STRUCT 'NonNull<str>' size=16 vlen=1 [147] FUNC 'write_fmt<scx_cosmos::BpfStream>' type_id=146 and the kernel rejects such BTF with "Invalid name". scx_simple and scx_cosmos schedulers written in Rust have them in STRUCT, FWD and FUNC, made of letters, digits and " #&()*,:;<>[]{}", 430 characters at most. Allow any printable character in btf_name_valid_identifier(), like it's done for DATASEC. It checks names of types, functions, members, enumerators, variables and arguments, so all of them can have such characters now. The limit of KSYM_NAME_LEN stays. The name of FUNC is a part of the name of the program in kallsyms, where a space would break the parsers. Replace what is not a character of an identifier with '_' there. Tests in prog_tests/btf.c expect "Invalid name" for names with '!' and '*', which are valid now. Put a character that is not printable there. The type name '?foo' is expected to load. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-6-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysselftests/bpf: Add tests for arena access through numbersAlexei Starovoitov
Add tests for load and store through the address that bpf_arena_alloc_pages() returned, without cast_kern: - all sizes, sign extending load, atomics, load-acquire, store-release. - no register is changed by the access, whatever the upper half of the address is, and 64-bit math on the address stays 64-bit. - a number that is not an address of arena, address of the stack included, reads zeroes and writes nowhere at both ends of the range of insn offset. - insn that sees a number on one path and PTR_TO_ARENA on another, followed by access through PTR_TO_ARENA. - store in a callback of bpf_loop(). - NULL that a helper returned and a number that is less than a page are addresses of arena too. - xchg that loads into the register that holds the address. - rejected: prog without arena, prog without BPF_F_ARENA_SCALAR, pointer to stack at the same insn, xchg that loads into the register that holds a pointer to stack, numbers passed to helpers. The tests are for x86 and arm64, other JITs don't take the flag. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-5-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysselftests/bpf: Add tests for ALU on pointers with CAP_PERFMONAlexei Starovoitov
Check that &=, |=, ^=, >>=, *= and 32-bit &= on a pointer to map value produce a number for a program with CAP_PERFMON and that the number can't be dereferenced. They are rejected without CAP_PERFMON, with CAP_BPF or without it. Pointer that may be NULL and pointer to map are rejected as before. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-3-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
13 daysbpf: Allow bitwise ops, shifts and mul/div on pointers with CAP_PERFMONAlexei Starovoitov
Rust's core::fmt keeps a flag in the low bit of a pointer: r2 = *(u64 *)(r1 + 0) r3 = r2 r3 &= 1 r2 >>= 1 The verifier rejects it: r0 &= 8 R0 bitwise operator &= on pointer prohibited Negation and byte swap of a pointer already produce a number when allow_ptr_leaks is set. Do the same for bitwise ops, shifts, *=, /= and %=, 64-bit and 32-bit. The result is an unknown number. With CAP_PERFMON the program can store the pointer and load it back as a number already. += and -= are not changed: they keep the pointer, 32-bit += is rejected. Pointers that allow no arithmetic and pointers that may be NULL are still rejected. Two tests in verifier_value_illegal_alu store through the result of &= and /=. They are rejected at the store now. Update expected messages. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20261002124714.180012-2-alexei.starovoitov@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>