Skip to content

Commit

Permalink
bpf:selftests: add bpf_mptcp_sock() verifier tests
Browse files Browse the repository at this point in the history
This patch adds verifier side tests for the new bpf_mptcp_sock() helper.

Currently, there is no easy way to test the token field since we cannot
get back the mptcp_sock, this could be a future amelioration.

Acked-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Nicolas Rybowski <nicolas.rybowski@tessares.net>
  • Loading branch information
nrybowski authored and jenkins-tessares committed Feb 7, 2021
1 parent 6512eb1 commit 02f0a51
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tools/testing/selftests/bpf/verifier/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,66 @@
.result_unpriv = REJECT,
.errstr_unpriv = "unknown func",
},
{
"bpf_mptcp_sock(skops->sk): no !skops->sk check",
.insns = {
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, offsetof(struct bpf_sock_ops, sk)),
BPF_EMIT_CALL(BPF_FUNC_mptcp_sock),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SOCK_OPS,
.result = REJECT,
.errstr = "type=sock_or_null expected=sock_common",
},
{
"bpf_mptcp_sock(skops->sk): no NULL check on ret",
.insns = {
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, offsetof(struct bpf_sock_ops, sk)),
BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 2),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
BPF_EMIT_CALL(BPF_FUNC_mptcp_sock),
BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, offsetof(struct bpf_mptcp_sock, token)),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SOCK_OPS,
.result = REJECT,
.errstr = "invalid mem access 'mptcp_sock_or_null'",
},
{
"bpf_mptcp_sock(skops->sk): msk->token",
.insns = {
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, offsetof(struct bpf_sock_ops, sk)),
BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 2),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
BPF_EMIT_CALL(BPF_FUNC_mptcp_sock),
BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
BPF_EXIT_INSN(),
BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, offsetof(struct bpf_mptcp_sock, token)),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SOCK_OPS,
.result = ACCEPT,
},
{
"bpf_mptcp_sock(skops->sk): msk->token cannot be modified",
.insns = {
BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, offsetof(struct bpf_sock_ops, sk)),
BPF_JMP_IMM(BPF_JNE, BPF_REG_1, 0, 2),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
BPF_EMIT_CALL(BPF_FUNC_mptcp_sock),
BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
BPF_EXIT_INSN(),
BPF_ST_MEM(BPF_W, BPF_REG_0, offsetof(struct bpf_mptcp_sock, token), 0x2a),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SOCK_OPS,
.result = REJECT,
.errstr = "cannot write into mptcp_sock",
},

0 comments on commit 02f0a51

Please sign in to comment.