diff options
Diffstat (limited to 'tools/testing/selftests/bpf/test_sysctl.c')
-rw-r--r-- | tools/testing/selftests/bpf/test_sysctl.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/test_sysctl.c b/tools/testing/selftests/bpf/test_sysctl.c index fc33ae36b760..4f8ec1f10a80 100644 --- a/tools/testing/selftests/bpf/test_sysctl.c +++ b/tools/testing/selftests/bpf/test_sysctl.c | |||
@@ -32,6 +32,7 @@ struct sysctl_test { | |||
32 | enum bpf_attach_type attach_type; | 32 | enum bpf_attach_type attach_type; |
33 | const char *sysctl; | 33 | const char *sysctl; |
34 | int open_flags; | 34 | int open_flags; |
35 | int seek; | ||
35 | const char *newval; | 36 | const char *newval; |
36 | const char *oldval; | 37 | const char *oldval; |
37 | enum { | 38 | enum { |
@@ -140,7 +141,7 @@ static struct sysctl_test tests[] = { | |||
140 | /* If (file_pos == X) */ | 141 | /* If (file_pos == X) */ |
141 | BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_1, | 142 | BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_1, |
142 | offsetof(struct bpf_sysctl, file_pos)), | 143 | offsetof(struct bpf_sysctl, file_pos)), |
143 | BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 0, 2), | 144 | BPF_JMP_IMM(BPF_JNE, BPF_REG_7, 3, 2), |
144 | 145 | ||
145 | /* return ALLOW; */ | 146 | /* return ALLOW; */ |
146 | BPF_MOV64_IMM(BPF_REG_0, 1), | 147 | BPF_MOV64_IMM(BPF_REG_0, 1), |
@@ -153,6 +154,7 @@ static struct sysctl_test tests[] = { | |||
153 | .attach_type = BPF_CGROUP_SYSCTL, | 154 | .attach_type = BPF_CGROUP_SYSCTL, |
154 | .sysctl = "kernel/ostype", | 155 | .sysctl = "kernel/ostype", |
155 | .open_flags = O_RDONLY, | 156 | .open_flags = O_RDONLY, |
157 | .seek = 3, | ||
156 | .result = SUCCESS, | 158 | .result = SUCCESS, |
157 | }, | 159 | }, |
158 | { | 160 | { |
@@ -1481,6 +1483,11 @@ static int access_sysctl(const char *sysctl_path, | |||
1481 | if (fd < 0) | 1483 | if (fd < 0) |
1482 | return fd; | 1484 | return fd; |
1483 | 1485 | ||
1486 | if (test->seek && lseek(fd, test->seek, SEEK_SET) == -1) { | ||
1487 | log_err("lseek(%d) failed", test->seek); | ||
1488 | goto err; | ||
1489 | } | ||
1490 | |||
1484 | if (test->open_flags == O_RDONLY) { | 1491 | if (test->open_flags == O_RDONLY) { |
1485 | char buf[128]; | 1492 | char buf[128]; |
1486 | 1493 | ||