Skip to content

Commit 33f70e4

Browse files
nrybowskikernel-patches-bot
authored andcommitted
This patch adds verifier side tests for the new bpf_mptcp_sock() helper.
Here are the new tests : - NULL bpf_sock is correctly handled - We cannot access a field from bpf_mptcp_sock if the latter is NULL - We can access a field from bpf_mptcp_sock if the latter is not NULL - We cannot modify a field from bpf_mptcp_sock. Note that "token" is currently the only field in bpf_mptcp_sock. Currently, there is no easy way to test the token field since we cannot get back the mptcp_sock in userspace, this could be a future amelioration. Acked-by: Matthieu Baerts <[email protected]> Signed-off-by: Nicolas Rybowski <[email protected]> --- Notes: v1 -> v2: - new patch: mandatory selftests (Alexei) tools/testing/selftests/bpf/verifier/sock.c | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+)
1 parent a1fdd37 commit 33f70e4

File tree

1 file changed

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

1 file changed

+63
-0
lines changed

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,66 @@
631631
.prog_type = BPF_PROG_TYPE_SK_REUSEPORT,
632632
.result = ACCEPT,
633633
},
634+
{
635+
"bpf_mptcp_sock(skops->sk): no !skops->sk check",
636+
.insns = {
637+
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, offsetof(struct bpf_sock_ops, sk)),
638+
BPF_EMIT_CALL(BPF_FUNC_mptcp_sock),
639+
BPF_MOV64_IMM(BPF_REG_0, 0),
640+
BPF_EXIT_INSN(),
641+
},
642+
.prog_type = BPF_PROG_TYPE_SOCK_OPS,
643+
.result = REJECT,
644+
.errstr = "type=sock_or_null expected=sock_common",
645+
},
646+
{
647+
"bpf_mptcp_sock(skops->sk): no NULL check on ret",
648+
.insns = {
649+
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, offsetof(struct bpf_sock_ops, sk)),
650+
BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 2),
651+
BPF_MOV64_IMM(BPF_REG_0, 0),
652+
BPF_EXIT_INSN(),
653+
BPF_EMIT_CALL(BPF_FUNC_mptcp_sock),
654+
BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, offsetof(struct bpf_mptcp_sock, token)),
655+
BPF_MOV64_IMM(BPF_REG_0, 0),
656+
BPF_EXIT_INSN(),
657+
},
658+
.prog_type = BPF_PROG_TYPE_SOCK_OPS,
659+
.result = REJECT,
660+
.errstr = "invalid mem access 'mptcp_sock_or_null'",
661+
},
662+
{
663+
"bpf_mptcp_sock(skops->sk): msk->token",
664+
.insns = {
665+
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, offsetof(struct bpf_sock_ops, sk)),
666+
BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 2),
667+
BPF_MOV64_IMM(BPF_REG_0, 0),
668+
BPF_EXIT_INSN(),
669+
BPF_EMIT_CALL(BPF_FUNC_mptcp_sock),
670+
BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
671+
BPF_EXIT_INSN(),
672+
BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, offsetof(struct bpf_mptcp_sock, token)),
673+
BPF_MOV64_IMM(BPF_REG_0, 0),
674+
BPF_EXIT_INSN(),
675+
},
676+
.prog_type = BPF_PROG_TYPE_SOCK_OPS,
677+
.result = ACCEPT,
678+
},
679+
{
680+
"bpf_mptcp_sock(skops->sk): msk->token cannot be modified",
681+
.insns = {
682+
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, offsetof(struct bpf_sock_ops, sk)),
683+
BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 2),
684+
BPF_MOV64_IMM(BPF_REG_0, 0),
685+
BPF_EXIT_INSN(),
686+
BPF_EMIT_CALL(BPF_FUNC_mptcp_sock),
687+
BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
688+
BPF_EXIT_INSN(),
689+
BPF_ST_MEM(BPF_W, BPF_REG_0, offsetof(struct bpf_mptcp_sock, token), 0x2a),
690+
BPF_MOV64_IMM(BPF_REG_0, 0),
691+
BPF_EXIT_INSN(),
692+
},
693+
.prog_type = BPF_PROG_TYPE_SOCK_OPS,
694+
.result = REJECT,
695+
.errstr = "cannot write into mptcp_sock",
696+
},

0 commit comments

Comments
 (0)