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

Configure Feed

Select the types of activity you want to include in your feed.

selftest/bpf: Ensure no module loading in bpf_setsockopt(TCP_CONGESTION)

This patch adds a test to ensure bpf_setsockopt(TCP_CONGESTION, "not_exist")
will not trigger the kernel module autoload.

Before the fix:

[ 40.535829] BUG: sleeping function called from invalid context at include/linux/sched/mm.h:274
[...]
[ 40.552134] tcp_ca_find_autoload.constprop.0+0xcb/0x200
[ 40.552689] tcp_set_congestion_control+0x99/0x7b0
[ 40.553203] do_tcp_setsockopt+0x3ed/0x2240
[...]
[ 40.556041] __bpf_setsockopt+0x124/0x640

Signed-off-by: Martin KaFai Lau <martin.lau@linux.dev>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220830231953.792412-1-martin.lau@linux.dev

authored by

Martin KaFai Lau and committed by
Daniel Borkmann
19707294 84e5a0f2

+4
+4
tools/testing/selftests/bpf/progs/setget_sockopt.c
··· 32 32 unsigned int flip:1; 33 33 }; 34 34 35 + static const char not_exist_cc[] = "not_exist"; 35 36 static const char cubic_cc[] = "cubic"; 36 37 static const char reno_cc[] = "reno"; 37 38 ··· 308 307 const char *new_cc; 309 308 int new_cc_len; 310 309 310 + if (!bpf_setsockopt(ctx, IPPROTO_TCP, TCP_CONGESTION, 311 + (void *)not_exist_cc, sizeof(not_exist_cc))) 312 + return 1; 311 313 if (bpf_getsockopt(ctx, IPPROTO_TCP, TCP_CONGESTION, old_cc, sizeof(old_cc))) 312 314 return 1; 313 315 if (!bpf_strncmp(old_cc, sizeof(old_cc), cubic_cc)) {