Skip to content

Commit 317eb56

Browse files
fomichevNobody
authored and
Nobody
committed
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. #269/p pass ctx or null check, 1: ctx Did not run the program (not supported) OK #270/p pass ctx or null check, 2: null Did not run the program (not supported) OK #271/p pass ctx or null check, 3: 1 OK #272/p pass ctx or null check, 4: ctx - const OK #273/p pass ctx or null check, 5: null (connect) Did not run the program (not supported) OK #274/p pass ctx or null check, 6: null (bind) Did not run the program (not supported) OK #275/p pass ctx or null check, 7: ctx (bind) Did not run the program (not supported) OK #276/p pass ctx or null check, 8: null (bind) OK #277/p pass ctx or null check, 9: ctx (cgroup/setsockopt) Did not run the program (not supported) OK #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 7314b6b commit 317eb56

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

Lines changed: 25 additions & 0 deletions
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)