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

bpf: Fix test_bpf_obj_id() when the bpf_jit_enable sysctl is diabled

test_bpf_obj_id() should not expect a non zero jited_prog_len
to be returned by bpf_obj_get_info_by_fd() when
net.core.bpf_jit_enable is 0.

The patch checks for net.core.bpf_jit_enable and
has different expectation on jited_prog_len.

This patch also removes the pwd.h header which I forgot
to remove after making changes.

Fixes: 95b9afd3987f ("bpf: Test for bpf ID")
Reported-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Martin KaFai Lau and committed by
David S. Miller
fad07430 97a7a37a

+15 -4
+15 -4
tools/testing/selftests/bpf/test_progs.c
··· 23 23 #include <sys/wait.h> 24 24 #include <sys/resource.h> 25 25 #include <sys/types.h> 26 - #include <pwd.h> 26 + #include <fcntl.h> 27 27 28 28 #include <linux/bpf.h> 29 29 #include <linux/err.h> ··· 297 297 const __u32 array_key = 0; 298 298 const int nr_iters = 2; 299 299 const char *file = "./test_obj_id.o"; 300 + const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable"; 300 301 301 302 struct bpf_object *objs[nr_iters]; 302 303 int prog_fds[nr_iters], map_fds[nr_iters]; ··· 306 305 struct bpf_map_info map_infos[nr_iters + 1]; 307 306 char jited_insns[128], xlated_insns[128]; 308 307 __u32 i, next_id, info_len, nr_id_found, duration = 0; 309 - int err = 0; 308 + int sysctl_fd, jit_enabled = 0, err = 0; 310 309 __u64 array_value; 310 + 311 + sysctl_fd = open(jit_sysctl, 0, O_RDONLY); 312 + if (sysctl_fd != -1) { 313 + char tmpc; 314 + 315 + if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1) 316 + jit_enabled = (tmpc != '0'); 317 + close(sysctl_fd); 318 + } 311 319 312 320 err = bpf_prog_get_fd_by_id(0); 313 321 CHECK(err >= 0 || errno != ENOENT, ··· 349 339 if (CHECK(err || 350 340 prog_infos[i].type != BPF_PROG_TYPE_SOCKET_FILTER || 351 341 info_len != sizeof(struct bpf_prog_info) || 352 - !prog_infos[i].jited_prog_len || 342 + (jit_enabled && !prog_infos[i].jited_prog_len) || 353 343 !prog_infos[i].xlated_prog_len, 354 344 "get-prog-info(fd)", 355 - "err %d errno %d i %d type %d(%d) info_len %u(%lu) jited_prog_len %u xlated_prog_len %u\n", 345 + "err %d errno %d i %d type %d(%d) info_len %u(%lu) jit_enabled %d jited_prog_len %u xlated_prog_len %u\n", 356 346 err, errno, i, 357 347 prog_infos[i].type, BPF_PROG_TYPE_SOCKET_FILTER, 358 348 info_len, sizeof(struct bpf_prog_info), 349 + jit_enabled, 359 350 prog_infos[i].jited_prog_len, 360 351 prog_infos[i].xlated_prog_len)) 361 352 goto done;