]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
selftests/bpf: Add tests for sock_ops ctx access with same src/dst register
authorJiayuan Chen <jiayuan.chen@linux.dev>
Tue, 7 Apr 2026 02:26:28 +0000 (10:26 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sun, 12 Apr 2026 19:28:05 +0000 (12:28 -0700)
commit04013c3ca022734ec2897b28a96d4cbd8a930407
tree90015fcae0717b9697b7782fdf148427056729be
parent10f86a2a5c91fc4c4d001960f1c21abe52545ef6
selftests/bpf: Add tests for sock_ops ctx access with same src/dst register

Add selftests to verify SOCK_OPS_GET_SK() and SOCK_OPS_GET_FIELD() correctly
return NULL/zero when dst_reg == src_reg and is_fullsock == 0.

Three subtests are included:
 - get_sk: ctx->sk with same src/dst register (SOCK_OPS_GET_SK)
 - get_field: ctx->snd_cwnd with same src/dst register (SOCK_OPS_GET_FIELD)
 - get_sk_diff_reg: ctx->sk with different src/dst register (baseline)

Each BPF program uses inline asm (__naked) to force specific register
allocation, reads is_fullsock first, then loads the field using the same
(or different) register. The test triggers TCP_NEW_SYN_RECV via a TCP
handshake and checks that the result is NULL/zero when is_fullsock == 0.

Reviewed-by: Sun Jian <sun.jian.kdev@gmail.com>
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20260407022720.162151-3-jiayuan.chen@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/bpf/prog_tests/sock_ops_get_sk.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/sock_ops_get_sk.c [new file with mode: 0644]