]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - lib/test_bpf.c
Merge tag 'rtc-4.13-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni...
[mirror_ubuntu-artful-kernel.git] / lib / test_bpf.c
index be88cbaadde3aeed809b2997e2ef683fba62dba4..d9d5a410955c948b4e923d729417bc9dbb91e514 100644 (file)
@@ -84,6 +84,7 @@ struct bpf_test {
        } test[MAX_SUBTESTS];
        int (*fill_helper)(struct bpf_test *self);
        __u8 frag_data[MAX_DATA];
+       int stack_depth; /* for eBPF only, since tests don't call verifier */
 };
 
 /* Large test cases need separate allocation and fill handler. */
@@ -434,6 +435,30 @@ loop:
        return 0;
 }
 
+static int bpf_fill_jump_around_ld_abs(struct bpf_test *self)
+{
+       unsigned int len = BPF_MAXINSNS;
+       struct bpf_insn *insn;
+       int i = 0;
+
+       insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
+       if (!insn)
+               return -ENOMEM;
+
+       insn[i++] = BPF_MOV64_REG(R6, R1);
+       insn[i++] = BPF_LD_ABS(BPF_B, 0);
+       insn[i] = BPF_JMP_IMM(BPF_JEQ, R0, 10, len - i - 2);
+       i++;
+       while (i < len - 1)
+               insn[i++] = BPF_LD_ABS(BPF_B, 1);
+       insn[i] = BPF_EXIT_INSN();
+
+       self->u.ptr.insns = insn;
+       self->u.ptr.len = len;
+
+       return 0;
+}
+
 static int __bpf_fill_stxdw(struct bpf_test *self, int size)
 {
        unsigned int len = BPF_MAXINSNS;
@@ -455,6 +480,7 @@ static int __bpf_fill_stxdw(struct bpf_test *self, int size)
 
        self->u.ptr.insns = insn;
        self->u.ptr.len = len;
+       self->stack_depth = 40;
 
        return 0;
 }
@@ -2317,7 +2343,8 @@ static struct bpf_test tests[] = {
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
-               { { 38, 256 } }
+               { { 38, 256 } },
+               .stack_depth = 64,
        },
        /* BPF_ALU | BPF_MOV | BPF_X */
        {
@@ -4169,6 +4196,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0xff } },
+               .stack_depth = 40,
        },
        {
                "ST_MEM_B: Store/Load byte: max positive",
@@ -4181,6 +4209,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x7f } },
+               .stack_depth = 40,
        },
        {
                "STX_MEM_B: Store/Load byte: max negative",
@@ -4194,6 +4223,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0xff } },
+               .stack_depth = 40,
        },
        {
                "ST_MEM_H: Store/Load half word: max negative",
@@ -4206,6 +4236,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0xffff } },
+               .stack_depth = 40,
        },
        {
                "ST_MEM_H: Store/Load half word: max positive",
@@ -4218,6 +4249,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x7fff } },
+               .stack_depth = 40,
        },
        {
                "STX_MEM_H: Store/Load half word: max negative",
@@ -4231,6 +4263,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0xffff } },
+               .stack_depth = 40,
        },
        {
                "ST_MEM_W: Store/Load word: max negative",
@@ -4243,6 +4276,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0xffffffff } },
+               .stack_depth = 40,
        },
        {
                "ST_MEM_W: Store/Load word: max positive",
@@ -4255,6 +4289,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x7fffffff } },
+               .stack_depth = 40,
        },
        {
                "STX_MEM_W: Store/Load word: max negative",
@@ -4268,6 +4303,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0xffffffff } },
+               .stack_depth = 40,
        },
        {
                "ST_MEM_DW: Store/Load double word: max negative",
@@ -4280,6 +4316,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0xffffffff } },
+               .stack_depth = 40,
        },
        {
                "ST_MEM_DW: Store/Load double word: max negative 2",
@@ -4297,6 +4334,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x1 } },
+               .stack_depth = 40,
        },
        {
                "ST_MEM_DW: Store/Load double word: max positive",
@@ -4309,6 +4347,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x7fffffff } },
+               .stack_depth = 40,
        },
        {
                "STX_MEM_DW: Store/Load double word: max negative",
@@ -4322,6 +4361,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0xffffffff } },
+               .stack_depth = 40,
        },
        /* BPF_STX | BPF_XADD | BPF_W/DW */
        {
@@ -4336,6 +4376,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x22 } },
+               .stack_depth = 40,
        },
        {
                "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
@@ -4351,6 +4392,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0 } },
+               .stack_depth = 40,
        },
        {
                "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
@@ -4363,6 +4405,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x12 } },
+               .stack_depth = 40,
        },
        {
                "STX_XADD_W: X + 1 + 1 + 1 + ...",
@@ -4384,6 +4427,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x22 } },
+               .stack_depth = 40,
        },
        {
                "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
@@ -4399,6 +4443,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0 } },
+               .stack_depth = 40,
        },
        {
                "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
@@ -4411,6 +4456,7 @@ static struct bpf_test tests[] = {
                INTERNAL,
                { },
                { { 0, 0x12 } },
+               .stack_depth = 40,
        },
        {
                "STX_XADD_DW: X + 1 + 1 + 1 + ...",
@@ -5022,6 +5068,14 @@ static struct bpf_test tests[] = {
                { { ETH_HLEN, 0xbef } },
                .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
        },
+       {
+               "BPF_MAXINSNS: jump around ld_abs",
+               { },
+               INTERNAL,
+               { 10, 11 },
+               { { 2, 10 } },
+               .fill_helper = bpf_fill_jump_around_ld_abs,
+       },
        /*
         * LD_IND / LD_ABS on fragmented SKBs
         */
@@ -5663,7 +5717,7 @@ static struct sk_buff *populate_skb(char *buf, int size)
        if (!skb)
                return NULL;
 
-       memcpy(__skb_put(skb, size), buf, size);
+       __skb_put_data(skb, buf, size);
 
        /* Initialize a fake skb with test pattern. */
        skb_reset_mac_header(skb);
@@ -5809,6 +5863,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
                /* Type doesn't really matter here as long as it's not unspec. */
                fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
                memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
+               fp->aux->stack_depth = tests[which].stack_depth;
 
                /* We cannot error here as we don't need type compatibility
                 * checks.