Skip to content

Commit

Permalink
selftests/bpf: verify bpf_get_netns_cookie in BPF_PROG_TYPE_CGROUP_SO…
Browse files Browse the repository at this point in the history
…CKOPT

Add verifier ctx test to call bpf_get_netns_cookie from
cgroup/setsockopt.

  torvalds#269/p pass ctx or null check, 1: ctx Did not run the program (not supported) OK
  torvalds#270/p pass ctx or null check, 2: null Did not run the program (not supported) OK
  torvalds#271/p pass ctx or null check, 3: 1 OK
  torvalds#272/p pass ctx or null check, 4: ctx - const OK
  torvalds#273/p pass ctx or null check, 5: null (connect) Did not run the program (not supported) OK
  torvalds#274/p pass ctx or null check, 6: null (bind) Did not run the program (not supported) OK
  torvalds#275/p pass ctx or null check, 7: ctx (bind) Did not run the program (not supported) OK
  torvalds#276/p pass ctx or null check, 8: null (bind) OK
  torvalds#277/p pass ctx or null check, 9: ctx (cgroup/setsockopt) Did not run the program (not supported) OK
  torvalds#278/p pass ctx or null check, 10: null (cgroup/setsockopt) Did not run the program (not supported) OK

Signed-off-by: Stanislav Fomichev <sdf@google.com>
  • Loading branch information
fomichev authored and intel-lab-lkp committed Aug 12, 2021
1 parent dda2569 commit d779195
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tools/testing/selftests/bpf/verifier/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,28 @@
.result = REJECT,
.errstr = "R1 type=inv expected=ctx",
},
{
"pass ctx or null check, 9: ctx (cgroup/setsockopt)",
.insns = {
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
BPF_FUNC_get_netns_cookie),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_CGROUP_SOCKOPT,
.expected_attach_type = BPF_CGROUP_SETSOCKOPT,
.result = ACCEPT,
},
{
"pass ctx or null check, 10: null (cgroup/setsockopt)",
.insns = {
BPF_MOV64_IMM(BPF_REG_1, 0),
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
BPF_FUNC_get_netns_cookie),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_CGROUP_SOCKOPT,
.expected_attach_type = BPF_CGROUP_SETSOCKOPT,
.result = ACCEPT,
},

0 comments on commit d779195

Please sign in to comment.