Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add pid limit for mptcpify prog

In order to prevent mptcpify prog from affecting the running results
of other BPF tests, a pid limit was added to restrict it from only
modifying its own program.

Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/8987e2938e15e8ec390b85b5dcbee704751359dc.1712054986.git.tanggeliang@kylinos.cn

authored by

Geliang Tang and committed by
Andrii Nakryiko
c07b4bcd 15ea39ad

+6
+2
tools/testing/selftests/bpf/prog_tests/mptcp.c
··· 273 273 if (!ASSERT_OK_PTR(mptcpify_skel, "skel_open_load")) 274 274 return libbpf_get_error(mptcpify_skel); 275 275 276 + mptcpify_skel->bss->pid = getpid(); 277 + 276 278 err = mptcpify__attach(mptcpify_skel); 277 279 if (!ASSERT_OK(err, "skel_attach")) 278 280 goto out;
+4
tools/testing/selftests/bpf/progs/mptcpify.c
··· 6 6 #include "bpf_tracing_net.h" 7 7 8 8 char _license[] SEC("license") = "GPL"; 9 + int pid; 9 10 10 11 SEC("fmod_ret/update_socket_protocol") 11 12 int BPF_PROG(mptcpify, int family, int type, int protocol) 12 13 { 14 + if (bpf_get_current_pid_tgid() >> 32 != pid) 15 + return protocol; 16 + 13 17 if ((family == AF_INET || family == AF_INET6) && 14 18 type == SOCK_STREAM && 15 19 (!protocol || protocol == IPPROTO_TCP)) {