Skip to content

Commit d779195

Browse files
fomichevintel-lab-lkp
authored andcommitted
selftests/bpf: verify bpf_get_netns_cookie in BPF_PROG_TYPE_CGROUP_SOCKOPT
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 <[email protected]>
1 parent dda2569 commit d779195

File tree

1 file changed

+25
-0
lines changed
  • tools/testing/selftests/bpf/verifier

1 file changed

+25
-0
lines changed

tools/testing/selftests/bpf/verifier/ctx.c

+25
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,28 @@
195195
.result = REJECT,
196196
.errstr = "R1 type=inv expected=ctx",
197197
},
198+
{
199+
"pass ctx or null check, 9: ctx (cgroup/setsockopt)",
200+
.insns = {
201+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
202+
BPF_FUNC_get_netns_cookie),
203+
BPF_MOV64_IMM(BPF_REG_0, 0),
204+
BPF_EXIT_INSN(),
205+
},
206+
.prog_type = BPF_PROG_TYPE_CGROUP_SOCKOPT,
207+
.expected_attach_type = BPF_CGROUP_SETSOCKOPT,
208+
.result = ACCEPT,
209+
},
210+
{
211+
"pass ctx or null check, 10: null (cgroup/setsockopt)",
212+
.insns = {
213+
BPF_MOV64_IMM(BPF_REG_1, 0),
214+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
215+
BPF_FUNC_get_netns_cookie),
216+
BPF_MOV64_IMM(BPF_REG_0, 0),
217+
BPF_EXIT_INSN(),
218+
},
219+
.prog_type = BPF_PROG_TYPE_CGROUP_SOCKOPT,
220+
.expected_attach_type = BPF_CGROUP_SETSOCKOPT,
221+
.result = ACCEPT,
222+
},

0 commit comments

Comments
 (0)