]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
selftests/bpf: Test new __sk_buff field gso_size
authorWillem de Bruijn <willemb@google.com>
Tue, 3 Mar 2020 20:05:03 +0000 (15:05 -0500)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 4 Mar 2020 00:23:59 +0000 (16:23 -0800)
Analogous to the gso_segs selftests introduced in commit d9ff286a0f59
("bpf: allow BPF programs access skb_shared_info->gso_segs field").

Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200303200503.226217-4-willemdebruijn.kernel@gmail.com
tools/testing/selftests/bpf/prog_tests/skb_ctx.c
tools/testing/selftests/bpf/progs/test_skb_ctx.c
tools/testing/selftests/bpf/verifier/ctx_skb.c

index c6d6b685a9468f7cbd1d147be0aaafaa6c5829a2..4538bd08203f53205ee19c295b441d89047019eb 100644 (file)
@@ -14,6 +14,7 @@ void test_skb_ctx(void)
                .wire_len = 100,
                .gso_segs = 8,
                .mark = 9,
+               .gso_size = 10,
        };
        struct bpf_prog_test_run_attr tattr = {
                .data_in = &pkt_v4,
index 202de3938494e35466d8941086fa24e7e54fbedb..b02ea589ce7eaa308d36f81b75a7063de8713e3e 100644 (file)
@@ -23,6 +23,8 @@ int process(struct __sk_buff *skb)
                return 1;
        if (skb->gso_segs != 8)
                return 1;
+       if (skb->gso_size != 10)
+               return 1;
 
        return 0;
 }
index d438193804b212ffa80c94be47e8c1aca392181e..2e16b8e268f2f6ed7431df9b55abc2e75905e089 100644 (file)
        .result = ACCEPT,
        .prog_type = BPF_PROG_TYPE_SCHED_CLS,
 },
+{
+       "read gso_size from CGROUP_SKB",
+       .insns = {
+       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+                   offsetof(struct __sk_buff, gso_size)),
+       BPF_MOV64_IMM(BPF_REG_0, 0),
+       BPF_EXIT_INSN(),
+       },
+       .result = ACCEPT,
+       .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+},
+{
+       "read gso_size from CGROUP_SKB",
+       .insns = {
+       BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_1,
+                   offsetof(struct __sk_buff, gso_size)),
+       BPF_MOV64_IMM(BPF_REG_0, 0),
+       BPF_EXIT_INSN(),
+       },
+       .result = ACCEPT,
+       .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+},
+{
+       "write gso_size 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_size)),
+       BPF_MOV64_IMM(BPF_REG_0, 0),
+       BPF_EXIT_INSN(),
+       },
+       .result = REJECT,
+       .result_unpriv = REJECT,
+       .errstr = "invalid bpf_context access off=176 size=4",
+       .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+},
+{
+       "read gso_size from CLS",
+       .insns = {
+       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+                   offsetof(struct __sk_buff, gso_size)),
+       BPF_MOV64_IMM(BPF_REG_0, 0),
+       BPF_EXIT_INSN(),
+       },
+       .result = ACCEPT,
+       .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+},
 {
        "check wire_len is not readable by sockets",
        .insns = {