]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Extend bpf_iter_unix to attempt deadlocking
authorMichal Luczaj <mhal@rbox.co>
Tue, 14 Apr 2026 14:13:17 +0000 (16:13 +0200)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 16 Apr 2026 00:22:55 +0000 (17:22 -0700)
Updating a sockmap from a unix iterator prog may lead to a deadlock.
Piggyback on the original selftest.

Signed-off-by: Michal Luczaj <mhal@rbox.co>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260414-unix-proto-update-null-ptr-deref-v4-3-2af6fe97918e@rbox.co
tools/testing/selftests/bpf/progs/bpf_iter_unix.c

index fea275df9e229362ee37f771a7f6e7f2e7a32460..a2652c8c3616f0b713e86ca83ceb4fd78eccd643 100644 (file)
@@ -7,6 +7,13 @@
 
 char _license[] SEC("license") = "GPL";
 
+SEC(".maps") struct {
+       __uint(type, BPF_MAP_TYPE_SOCKMAP);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, __u64);
+} sockmap;
+
 static long sock_i_ino(const struct sock *sk)
 {
        const struct socket *sk_socket = sk->sk_socket;
@@ -76,5 +83,8 @@ int dump_unix(struct bpf_iter__unix *ctx)
 
        BPF_SEQ_PRINTF(seq, "\n");
 
+       /* Test for deadlock. */
+       bpf_map_update_elem(&sockmap, &(int){0}, sk, 0);
+
        return 0;
 }