selftests/bpf: Add pid limit for mptcpify prog
authorGeliang Tang <tanggeliang@kylinos.cn>
Tue, 2 Apr 2024 10:50:21 +0000 (18:50 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 2 Apr 2024 17:05:49 +0000 (10:05 -0700)
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
tools/testing/selftests/bpf/prog_tests/mptcp.c
tools/testing/selftests/bpf/progs/mptcpify.c

index 8f8d792307c1c979be648f657e69585e10af4842..4e0f692958723040af931f65c65fc537104142b1 100644 (file)
@@ -273,6 +273,8 @@ static int run_mptcpify(int cgroup_fd)
        if (!ASSERT_OK_PTR(mptcpify_skel, "skel_open_load"))
                return libbpf_get_error(mptcpify_skel);
 
+       mptcpify_skel->bss->pid = getpid();
+
        err = mptcpify__attach(mptcpify_skel);
        if (!ASSERT_OK(err, "skel_attach"))
                goto out;
index 53301ae8a8f7c82a2dfc092f117de3b9b85bbf1c..cbdc730c3a47162ca69342eae2a41db193da6338 100644 (file)
@@ -6,10 +6,14 @@
 #include "bpf_tracing_net.h"
 
 char _license[] SEC("license") = "GPL";
+int pid;
 
 SEC("fmod_ret/update_socket_protocol")
 int BPF_PROG(mptcpify, int family, int type, int protocol)
 {
+       if (bpf_get_current_pid_tgid() >> 32 != pid)
+               return protocol;
+
        if ((family == AF_INET || family == AF_INET6) &&
            type == SOCK_STREAM &&
            (!protocol || protocol == IPPROTO_TCP)) {