]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - tools/testing/selftests/bpf/test_verifier.c
bpf: allow BPF programs access skb_shared_info->gso_segs field
[linux.git] / tools / testing / selftests / bpf / test_verifier.c
index 4f67afeec8d90b6df496f805633d28fc34b3cfe6..e4fef6ca8071b9febc3acbec193e0988c925643c 100644 (file)
@@ -5663,6 +5663,42 @@ static struct bpf_test tests[] = {
                .result = ACCEPT,
                .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
        },
+       {
+               "read gso_segs from CGROUP_SKB",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, gso_segs)),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+       },
+       {
+               "write gso_segs from CGROUP_SKB",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
+                                   offsetof(struct __sk_buff, gso_segs)),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .result = REJECT,
+               .result_unpriv = REJECT,
+               .errstr = "invalid bpf_context access off=164 size=4",
+               .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+       },
+       {
+               "read gso_segs from CLS",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, gso_segs)),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+       },
        {
                "multiple registers share map_lookup_elem result",
                .insns = {