]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - tools/testing/selftests/bpf/test_verifier.c
bpf: fix up test cases with mixed signed/unsigned bounds
[karo-tx-linux.git] / tools / testing / selftests / bpf / test_verifier.c
index 0ff8c55c0464a62bddd2bf6bd99ffc5041798ac3..64b39d37d91d8ec0fa40ba548e54f9cdabf5c716 100644 (file)
@@ -1073,44 +1073,75 @@ static struct bpf_test tests[] = {
                .result = ACCEPT,
        },
        {
-               "check cb access: byte, oob 1",
+               "__sk_buff->hash, offset 0, byte store not permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
                        BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0,
-                                   offsetof(struct __sk_buff, cb[4]) + 4),
+                                   offsetof(struct __sk_buff, hash)),
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
                .result = REJECT,
        },
        {
-               "check cb access: byte, oob 2",
+               "__sk_buff->tc_index, offset 3, byte store not permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
                        BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0,
-                                   offsetof(struct __sk_buff, cb[0]) - 1),
+                                   offsetof(struct __sk_buff, tc_index) + 3),
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
                .result = REJECT,
        },
        {
-               "check cb access: byte, oob 3",
+               "check skb->hash byte load permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
                        BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
-                                   offsetof(struct __sk_buff, cb[4]) + 4),
+                                   offsetof(struct __sk_buff, hash)),
+#else
+                       BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, hash) + 3),
+#endif
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+       },
+       {
+               "check skb->hash byte load not permitted 1",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, hash) + 1),
+                       BPF_EXIT_INSN(),
+               },
+               .errstr = "invalid bpf_context access",
+               .result = REJECT,
+       },
+       {
+               "check skb->hash byte load not permitted 2",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, hash) + 2),
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
                .result = REJECT,
        },
        {
-               "check cb access: byte, oob 4",
+               "check skb->hash byte load not permitted 3",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
                        BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
-                                   offsetof(struct __sk_buff, cb[0]) - 1),
+                                   offsetof(struct __sk_buff, hash) + 3),
+#else
+                       BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, hash)),
+#endif
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
@@ -1188,44 +1219,53 @@ static struct bpf_test tests[] = {
                .result = REJECT,
        },
        {
-               "check cb access: half, oob 1",
+               "check __sk_buff->hash, offset 0, half store not permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
                        BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0,
-                                   offsetof(struct __sk_buff, cb[4]) + 4),
+                                   offsetof(struct __sk_buff, hash)),
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
                .result = REJECT,
        },
        {
-               "check cb access: half, oob 2",
+               "check __sk_buff->tc_index, offset 2, half store not permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
                        BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0,
-                                   offsetof(struct __sk_buff, cb[0]) - 2),
+                                   offsetof(struct __sk_buff, tc_index) + 2),
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
                .result = REJECT,
        },
        {
-               "check cb access: half, oob 3",
+               "check skb->hash half load permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
+                       BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, hash)),
+#else
                        BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
-                                   offsetof(struct __sk_buff, cb[4]) + 4),
+                                   offsetof(struct __sk_buff, hash) + 2),
+#endif
                        BPF_EXIT_INSN(),
                },
-               .errstr = "invalid bpf_context access",
-               .result = REJECT,
+               .result = ACCEPT,
        },
        {
-               "check cb access: half, oob 4",
+               "check skb->hash half load not permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
+                       BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, hash) + 2),
+#else
                        BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
-                                   offsetof(struct __sk_buff, cb[0]) - 2),
+                                   offsetof(struct __sk_buff, hash)),
+#endif
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
@@ -1366,28 +1406,6 @@ static struct bpf_test tests[] = {
        },
        {
                "check cb access: double, oob 2",
-               .insns = {
-                       BPF_MOV64_IMM(BPF_REG_0, 0),
-                       BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0,
-                                   offsetof(struct __sk_buff, cb[4]) + 8),
-                       BPF_EXIT_INSN(),
-               },
-               .errstr = "invalid bpf_context access",
-               .result = REJECT,
-       },
-       {
-               "check cb access: double, oob 3",
-               .insns = {
-                       BPF_MOV64_IMM(BPF_REG_0, 0),
-                       BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0,
-                                   offsetof(struct __sk_buff, cb[0]) - 8),
-                       BPF_EXIT_INSN(),
-               },
-               .errstr = "invalid bpf_context access",
-               .result = REJECT,
-       },
-       {
-               "check cb access: double, oob 4",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
                        BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
@@ -1398,22 +1416,22 @@ static struct bpf_test tests[] = {
                .result = REJECT,
        },
        {
-               "check cb access: double, oob 5",
+               "check __sk_buff->ifindex dw store not permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
-                       BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
-                                   offsetof(struct __sk_buff, cb[4]) + 8),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0,
+                                   offsetof(struct __sk_buff, ifindex)),
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
                .result = REJECT,
        },
        {
-               "check cb access: double, oob 6",
+               "check __sk_buff->ifindex dw load not permitted",
                .insns = {
                        BPF_MOV64_IMM(BPF_REG_0, 0),
                        BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
-                                   offsetof(struct __sk_buff, cb[0]) - 8),
+                                   offsetof(struct __sk_buff, ifindex)),
                        BPF_EXIT_INSN(),
                },
                .errstr = "invalid bpf_context access",
@@ -2639,6 +2657,171 @@ static struct bpf_test tests[] = {
                .prog_type = BPF_PROG_TYPE_SCHED_CLS,
                .flags = F_LOAD_WITH_STRICT_ALIGNMENT,
        },
+       {
+               "direct packet access: test18 (imm += pkt_ptr, 1)",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data)),
+                       BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data_end)),
+                       BPF_MOV64_IMM(BPF_REG_0, 8),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_2),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
+                       BPF_STX_MEM(BPF_B, BPF_REG_2, BPF_REG_2, 0),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+       },
+       {
+               "direct packet access: test19 (imm += pkt_ptr, 2)",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data)),
+                       BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data_end)),
+                       BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
+                       BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 3),
+                       BPF_MOV64_IMM(BPF_REG_4, 4),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_4, BPF_REG_2),
+                       BPF_STX_MEM(BPF_B, BPF_REG_4, BPF_REG_4, 0),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+       },
+       {
+               "direct packet access: test20 (x += pkt_ptr, 1)",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data)),
+                       BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data_end)),
+                       BPF_MOV64_IMM(BPF_REG_0, 0xffffffff),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
+                       BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8),
+                       BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffff),
+                       BPF_MOV64_REG(BPF_REG_4, BPF_REG_0),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_4, BPF_REG_2),
+                       BPF_MOV64_REG(BPF_REG_5, BPF_REG_4),
+                       BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 0xffff - 1),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_5, BPF_REG_4, 0),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+               .result = ACCEPT,
+       },
+       {
+               "direct packet access: test21 (x += pkt_ptr, 2)",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data)),
+                       BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data_end)),
+                       BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
+                       BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 9),
+                       BPF_MOV64_IMM(BPF_REG_4, 0xffffffff),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_4, -8),
+                       BPF_LDX_MEM(BPF_DW, BPF_REG_4, BPF_REG_10, -8),
+                       BPF_ALU64_IMM(BPF_AND, BPF_REG_4, 0xffff),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_4, BPF_REG_2),
+                       BPF_MOV64_REG(BPF_REG_5, BPF_REG_4),
+                       BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 0xffff - 1),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_5, BPF_REG_4, 0),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+               .result = ACCEPT,
+       },
+       {
+               "direct packet access: test22 (x += pkt_ptr, 3)",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data)),
+                       BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data_end)),
+                       BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
+                       BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -8),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_3, -16),
+                       BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_10, -16),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 11),
+                       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -8),
+                       BPF_MOV64_IMM(BPF_REG_4, 0xffffffff),
+                       BPF_STX_XADD(BPF_DW, BPF_REG_10, BPF_REG_4, -8),
+                       BPF_LDX_MEM(BPF_DW, BPF_REG_4, BPF_REG_10, -8),
+                       BPF_ALU64_IMM(BPF_RSH, BPF_REG_4, 48),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_4, BPF_REG_2),
+                       BPF_MOV64_REG(BPF_REG_0, BPF_REG_4),
+                       BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 2),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 2),
+                       BPF_MOV64_IMM(BPF_REG_2, 1),
+                       BPF_STX_MEM(BPF_H, BPF_REG_4, BPF_REG_2, 0),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+               .result = ACCEPT,
+       },
+       {
+               "direct packet access: test23 (x += pkt_ptr, 4)",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data)),
+                       BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data_end)),
+                       BPF_MOV64_IMM(BPF_REG_0, 0xffffffff),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
+                       BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8),
+                       BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffff),
+                       BPF_MOV64_REG(BPF_REG_4, BPF_REG_0),
+                       BPF_MOV64_IMM(BPF_REG_0, 31),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_4),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_2),
+                       BPF_MOV64_REG(BPF_REG_5, BPF_REG_0),
+                       BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 0xffff - 1),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_5, BPF_REG_0, 0),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+               .result = REJECT,
+               .errstr = "cannot add integer value with 47 upper zero bits to ptr_to_packet",
+       },
+       {
+               "direct packet access: test24 (x += pkt_ptr, 5)",
+               .insns = {
+                       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data)),
+                       BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data_end)),
+                       BPF_MOV64_IMM(BPF_REG_0, 0xffffffff),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
+                       BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8),
+                       BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xff),
+                       BPF_MOV64_REG(BPF_REG_4, BPF_REG_0),
+                       BPF_MOV64_IMM(BPF_REG_0, 64),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_4),
+                       BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_2),
+                       BPF_MOV64_REG(BPF_REG_5, BPF_REG_0),
+                       BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 0xffff - 1),
+                       BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
+                       BPF_STX_MEM(BPF_DW, BPF_REG_5, BPF_REG_0, 0),
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_EXIT_INSN(),
+               },
+               .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+               .result = ACCEPT,
+       },
        {
                "helper access to packet: test1, valid packet_ptr range",
                .insns = {
@@ -4786,7 +4969,7 @@ static struct bpf_test tests[] = {
                        BPF_JMP_IMM(BPF_JSGT, BPF_REG_2,
                                sizeof(struct test_val), 4),
                        BPF_MOV64_IMM(BPF_REG_4, 0),
-                       BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
+                       BPF_JMP_REG(BPF_JSGE, BPF_REG_4, BPF_REG_2, 2),
                        BPF_MOV64_IMM(BPF_REG_3, 0),
                        BPF_EMIT_CALL(BPF_FUNC_probe_read),
                        BPF_MOV64_IMM(BPF_REG_0, 0),
@@ -4812,7 +4995,7 @@ static struct bpf_test tests[] = {
                        BPF_JMP_IMM(BPF_JSGT, BPF_REG_2,
                                sizeof(struct test_val) + 1, 4),
                        BPF_MOV64_IMM(BPF_REG_4, 0),
-                       BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
+                       BPF_JMP_REG(BPF_JSGE, BPF_REG_4, BPF_REG_2, 2),
                        BPF_MOV64_IMM(BPF_REG_3, 0),
                        BPF_EMIT_CALL(BPF_FUNC_probe_read),
                        BPF_MOV64_IMM(BPF_REG_0, 0),
@@ -4840,7 +5023,7 @@ static struct bpf_test tests[] = {
                        BPF_JMP_IMM(BPF_JSGT, BPF_REG_2,
                                sizeof(struct test_val) - 20, 4),
                        BPF_MOV64_IMM(BPF_REG_4, 0),
-                       BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
+                       BPF_JMP_REG(BPF_JSGE, BPF_REG_4, BPF_REG_2, 2),
                        BPF_MOV64_IMM(BPF_REG_3, 0),
                        BPF_EMIT_CALL(BPF_FUNC_probe_read),
                        BPF_MOV64_IMM(BPF_REG_0, 0),
@@ -4867,7 +5050,7 @@ static struct bpf_test tests[] = {
                        BPF_JMP_IMM(BPF_JSGT, BPF_REG_2,
                                sizeof(struct test_val) - 19, 4),
                        BPF_MOV64_IMM(BPF_REG_4, 0),
-                       BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
+                       BPF_JMP_REG(BPF_JSGE, BPF_REG_4, BPF_REG_2, 2),
                        BPF_MOV64_IMM(BPF_REG_3, 0),
                        BPF_EMIT_CALL(BPF_FUNC_probe_read),
                        BPF_MOV64_IMM(BPF_REG_0, 0),
@@ -5235,6 +5418,98 @@ static struct bpf_test tests[] = {
                },
                .result = ACCEPT,
        },
+       {
+               "check bpf_perf_event_data->sample_period byte load permitted",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
+                       BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct bpf_perf_event_data, sample_period)),
+#else
+                       BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct bpf_perf_event_data, sample_period) + 7),
+#endif
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .prog_type = BPF_PROG_TYPE_PERF_EVENT,
+       },
+       {
+               "check bpf_perf_event_data->sample_period half load permitted",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
+                       BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct bpf_perf_event_data, sample_period)),
+#else
+                       BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct bpf_perf_event_data, sample_period) + 6),
+#endif
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .prog_type = BPF_PROG_TYPE_PERF_EVENT,
+       },
+       {
+               "check bpf_perf_event_data->sample_period word load permitted",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
+                       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct bpf_perf_event_data, sample_period)),
+#else
+                       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct bpf_perf_event_data, sample_period) + 4),
+#endif
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .prog_type = BPF_PROG_TYPE_PERF_EVENT,
+       },
+       {
+               "check bpf_perf_event_data->sample_period dword load permitted",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+                       BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct bpf_perf_event_data, sample_period)),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .prog_type = BPF_PROG_TYPE_PERF_EVENT,
+       },
+       {
+               "check skb->data half load not permitted",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
+                       BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data)),
+#else
+                       BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, data) + 2),
+#endif
+                       BPF_EXIT_INSN(),
+               },
+               .result = REJECT,
+               .errstr = "invalid bpf_context access",
+       },
+       {
+               "check skb->tc_classid half load not permitted for lwt prog",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
+                       BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, tc_classid)),
+#else
+                       BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
+                                   offsetof(struct __sk_buff, tc_classid) + 2),
+#endif
+                       BPF_EXIT_INSN(),
+               },
+               .result = REJECT,
+               .errstr = "invalid bpf_context access",
+               .prog_type = BPF_PROG_TYPE_LWT_IN,
+       },
 };
 
 static int probe_filter_length(const struct bpf_insn *fp)
@@ -5358,7 +5633,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
 
        fd_prog = bpf_verify_program(prog_type ? : BPF_PROG_TYPE_SOCKET_FILTER,
                                     prog, prog_len, test->flags & F_LOAD_WITH_STRICT_ALIGNMENT,
-                                    "GPL", 0, bpf_vlog, sizeof(bpf_vlog));
+                                    "GPL", 0, bpf_vlog, sizeof(bpf_vlog), 1);
 
        expected_ret = unpriv && test->result_unpriv != UNDEF ?
                       test->result_unpriv : test->result;
@@ -5484,7 +5759,7 @@ static int do_test(bool unpriv, unsigned int from, unsigned int to)
        }
 
        printf("Summary: %d PASSED, %d FAILED\n", passes, errors);
-       return errors ? -errors : 0;
+       return errors ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 int main(int argc, char **argv)