Skip to content

Commit 1901139

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-specify-access-type-of-bpf_sysctl_get_name-args'
Jerome Marchand says: ==================== bpf: Specify access type of bpf_sysctl_get_name args The second argument of bpf_sysctl_get_name() helper is a pointer to a buffer that is being written to. However that isn't specify in the prototype. Until commit 37cce22 ("bpf: verifier: Refactor helper access type tracking") that mistake was hidden by the way the verifier treated helper accesses. Since then, the verifier, working on wrong infromation from the prototype, can make faulty optimization that would had been caught by the test_sysctl selftests if it was run by the CI. The first patch fixes bpf_sysctl_get_name prototype. The second patch converts the test_sysctl to prog_tests so that it will be run by the CI and catch similar issues in the future. Changes in v3: - Use ASSERT* macro instead of CHECK_FAIL. - Remove useless code. Changes in v2: - Replace ARG_PTR_TO_UNINIT_MEM by ARG_PTR_TO_MEM | MEM_WRITE. - Converts test_sysctl to prog_tests. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents aa485e8 + b8a2054 commit 1901139

File tree

4 files changed

+11
-34
lines changed

4 files changed

+11
-34
lines changed

kernel/bpf/cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ static const struct bpf_func_proto bpf_sysctl_get_name_proto = {
21342134
.gpl_only = false,
21352135
.ret_type = RET_INTEGER,
21362136
.arg1_type = ARG_PTR_TO_CTX,
2137-
.arg2_type = ARG_PTR_TO_MEM,
2137+
.arg2_type = ARG_PTR_TO_MEM | MEM_WRITE,
21382138
.arg3_type = ARG_CONST_SIZE,
21392139
.arg4_type = ARG_ANYTHING,
21402140
};

tools/testing/selftests/bpf/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ test_lirc_mode2_user
2121
flow_dissector_load
2222
test_tcpnotify_user
2323
test_libbpf
24-
test_sysctl
2524
xdping
2625
test_cpp
2726
*.d

tools/testing/selftests/bpf/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ endif
7373
# Order correspond to 'make run_tests' order
7474
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_progs \
7575
test_sockmap \
76-
test_tcpnotify_user test_sysctl \
76+
test_tcpnotify_user \
7777
test_progs-no_alu32
7878
TEST_INST_SUBDIRS := no_alu32
7979

@@ -220,7 +220,7 @@ ifeq ($(VMLINUX_BTF),)
220220
$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
221221
endif
222222

223-
# Define simple and short `make test_progs`, `make test_sysctl`, etc targets
223+
# Define simple and short `make test_progs`, `make test_maps`, etc targets
224224
# to build individual tests.
225225
# NOTE: Semicolon at the end is critical to override lib.mk's default static
226226
# rule for binaries.
@@ -329,7 +329,6 @@ NETWORK_HELPERS := $(OUTPUT)/network_helpers.o
329329
$(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS)
330330
$(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRACE_HELPERS)
331331
$(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) $(TESTING_HELPERS)
332-
$(OUTPUT)/test_sysctl: $(CGROUP_HELPERS) $(TESTING_HELPERS)
333332
$(OUTPUT)/test_tag: $(TESTING_HELPERS)
334333
$(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS)
335334
$(OUTPUT)/xdping: $(TESTING_HELPERS)

tools/testing/selftests/bpf/test_sysctl.c renamed to tools/testing/selftests/bpf/prog_tests/test_sysctl.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2019 Facebook
33

4-
#include <fcntl.h>
5-
#include <stdint.h>
6-
#include <stdio.h>
7-
#include <stdlib.h>
8-
#include <string.h>
9-
#include <unistd.h>
10-
11-
#include <linux/filter.h>
12-
13-
#include <bpf/bpf.h>
14-
#include <bpf/libbpf.h>
15-
16-
#include <bpf/bpf_endian.h>
17-
#include "bpf_util.h"
4+
#include "test_progs.h"
185
#include "cgroup_helpers.h"
19-
#include "testing_helpers.h"
206

217
#define CG_PATH "/foo"
228
#define MAX_INSNS 512
@@ -1608,26 +1594,19 @@ static int run_tests(int cgfd)
16081594
return fails ? -1 : 0;
16091595
}
16101596

1611-
int main(int argc, char **argv)
1597+
void test_sysctl(void)
16121598
{
1613-
int cgfd = -1;
1614-
int err = 0;
1599+
int cgfd;
16151600

16161601
cgfd = cgroup_setup_and_join(CG_PATH);
1617-
if (cgfd < 0)
1618-
goto err;
1602+
if (!ASSERT_OK_FD(cgfd < 0, "create_cgroup"))
1603+
goto out;
16191604

1620-
/* Use libbpf 1.0 API mode */
1621-
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
1605+
if (!ASSERT_OK(run_tests(cgfd), "run_tests"))
1606+
goto out;
16221607

1623-
if (run_tests(cgfd))
1624-
goto err;
1625-
1626-
goto out;
1627-
err:
1628-
err = -1;
16291608
out:
16301609
close(cgfd);
16311610
cleanup_cgroup_environment();
1632-
return err;
1611+
return;
16331612
}

0 commit comments

Comments
 (0)