Skip to content

Commit ba6a901

Browse files
TropicaoMartin KaFai Lau
authored andcommitted
selftests/bpf: do not disable /dev/null device access in cgroup dev test
test_dev_cgroup currently loads a small bpf program allowing any access on urandom and zero devices, disabling access to any other device. It makes migrating this test to test_progs impossible, since this one manipulates extensively /dev/null. Allow /dev/null manipulation in dev_cgroup program to make its usage in test_progs framework possible. Update test_dev_cgroup.c as well to match this change while it has not been removed. Reviewed-by: Alan Maguire <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 92cc245 commit ba6a901

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

tools/testing/selftests/bpf/progs/dev_cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ int bpf_prog1(struct bpf_cgroup_dev_ctx *ctx)
4141
bpf_trace_printk(fmt, sizeof(fmt), ctx->major, ctx->minor);
4242
#endif
4343

44-
/* Allow access to /dev/zero and /dev/random.
44+
/* Allow access to /dev/null and /dev/urandom.
4545
* Forbid everything else.
4646
*/
4747
if (ctx->major != 1 || type != BPF_DEVCG_DEV_CHAR)
4848
return 0;
4949

5050
switch (ctx->minor) {
51-
case 5: /* 1:5 /dev/zero */
51+
case 3: /* 1:3 /dev/null */
5252
case 9: /* 1:9 /dev/urandom */
5353
return 1;
5454
}

tools/testing/selftests/bpf/test_dev_cgroup.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,25 @@ int main(int argc, char **argv)
5454
goto err;
5555
}
5656

57-
/* All operations with /dev/zero and and /dev/urandom are allowed,
57+
/* All operations with /dev/null and /dev/urandom are allowed,
5858
* everything else is forbidden.
5959
*/
60-
assert(system("rm -f /tmp/test_dev_cgroup_null") == 0);
61-
assert(system("mknod /tmp/test_dev_cgroup_null c 1 3"));
62-
assert(system("rm -f /tmp/test_dev_cgroup_null") == 0);
63-
64-
/* /dev/zero is whitelisted */
6560
assert(system("rm -f /tmp/test_dev_cgroup_zero") == 0);
66-
assert(system("mknod /tmp/test_dev_cgroup_zero c 1 5") == 0);
61+
assert(system("mknod /tmp/test_dev_cgroup_zero c 1 5"));
6762
assert(system("rm -f /tmp/test_dev_cgroup_zero") == 0);
6863

69-
assert(system("dd if=/dev/urandom of=/dev/zero count=64") == 0);
64+
/* /dev/null is whitelisted */
65+
assert(system("rm -f /tmp/test_dev_cgroup_null") == 0);
66+
assert(system("mknod /tmp/test_dev_cgroup_null c 1 3") == 0);
67+
assert(system("rm -f /tmp/test_dev_cgroup_null") == 0);
68+
69+
assert(system("dd if=/dev/urandom of=/dev/null count=64") == 0);
7070

7171
/* src is allowed, target is forbidden */
7272
assert(system("dd if=/dev/urandom of=/dev/full count=64"));
7373

7474
/* src is forbidden, target is allowed */
75-
assert(system("dd if=/dev/random of=/dev/zero count=64"));
75+
assert(system("dd if=/dev/random of=/dev/null count=64"));
7676

7777
error = 0;
7878
printf("test_dev_cgroup:PASS\n");

0 commit comments

Comments
 (0)