| 1 | |
| 2 |
|
| 3 |
|
| 4 | #include <vmlinux.h>
|
| 5 | #include <bpf/bpf_helpers.h>
|
| 6 | #include "../test_kmods/bpf_testmod_kfunc.h"
|
| 7 | #include "bpf_misc.h"
|
| 8 |
|
| 9 | #if defined(__BPF_FEATURE_STACK_ARGUMENT)
|
| 10 |
|
| 11 | SEC("tc")
|
| 12 | __failure __msg("Unrecognized *(R11-8) type STRUCT")
|
| 13 | int test_stack_arg_big(struct __sk_buff *skb)
|
| 14 | {
|
| 15 | struct prog_test_big_arg s = { .a = 1, .b = 2 };
|
| 16 |
|
| 17 | return bpf_kfunc_call_stack_arg_big(1, 2, 3, 4, 5, s);
|
| 18 | }
|
| 19 |
|
| 20 | SEC("socket")
|
| 21 | __description("r11 in ALU instruction")
|
| 22 | __failure __msg("R11 is invalid")
|
| 23 | __naked void r11_alu_reject(void)
|
| 24 | {
|
| 25 | asm volatile (
|
| 26 | "r11 += 1;"
|
| 27 | "r0 = 0;"
|
| 28 | "exit;"
|
| 29 | ::: __clobber_all);
|
| 30 | }
|
| 31 |
|
| 32 | SEC("socket")
|
| 33 | __description("r11 store with non-DW size")
|
| 34 | __failure __msg("R11 is invalid")
|
| 35 | __naked void r11_store_non_dw(void)
|
| 36 | {
|
| 37 | asm volatile (
|
| 38 | "*(u32 *)(r11 - 8) = r1;"
|
| 39 | "r0 = 0;"
|
| 40 | "exit;"
|
| 41 | ::: __clobber_all);
|
| 42 | }
|
| 43 |
|
| 44 | SEC("socket")
|
| 45 | __description("r11 store with unaligned offset")
|
| 46 | __failure __msg("R11 is invalid")
|
| 47 | __naked void r11_store_unaligned(void)
|
| 48 | {
|
| 49 | asm volatile (
|
| 50 | "*(u64 *)(r11 - 4) = r1;"
|
| 51 | "r0 = 0;"
|
| 52 | "exit;"
|
| 53 | ::: __clobber_all);
|
| 54 | }
|
| 55 |
|
| 56 | SEC("socket")
|
| 57 | __description("r11 store with positive offset")
|
| 58 | __failure __msg("R11 is invalid")
|
| 59 | __naked void r11_store_positive_off(void)
|
| 60 | {
|
| 61 | asm volatile (
|
| 62 | "*(u64 *)(r11 + 8) = r1;"
|
| 63 | "r0 = 0;"
|
| 64 | "exit;"
|
| 65 | ::: __clobber_all);
|
| 66 | }
|
| 67 |
|
| 68 | SEC("socket")
|
| 69 | __description("r11 load with negative offset")
|
| 70 | __failure __msg("R11 is invalid")
|
| 71 | __naked void r11_load_negative_off(void)
|
| 72 | {
|
| 73 | asm volatile (
|
| 74 | "r0 = *(u64 *)(r11 - 8);"
|
| 75 | "exit;"
|
| 76 | ::: __clobber_all);
|
| 77 | }
|
| 78 |
|
| 79 | SEC("socket")
|
| 80 | __description("r11 load with non-DW size")
|
| 81 | __failure __msg("R11 is invalid")
|
| 82 | __naked void r11_load_non_dw(void)
|
| 83 | {
|
| 84 | asm volatile (
|
| 85 | "r0 = *(u32 *)(r11 + 8);"
|
| 86 | "exit;"
|
| 87 | ::: __clobber_all);
|
| 88 | }
|
| 89 |
|
| 90 | SEC("socket")
|
| 91 | __description("r11 store with zero offset")
|
| 92 | __failure __msg("R11 is invalid")
|
| 93 | __naked void r11_store_zero_off(void)
|
| 94 | {
|
| 95 | asm volatile (
|
| 96 | "*(u64 *)(r11 + 0) = r1;"
|
| 97 | "r0 = 0;"
|
| 98 | "exit;"
|
| 99 | ::: __clobber_all);
|
| 100 | }
|
| 101 |
|
| 102 | #else
|
| 103 |
|
| 104 | SEC("tc")
|
| 105 | __description("stack_arg_fail: not supported, dummy test")
|
| 106 | __success
|
| 107 | int test_stack_arg_big(struct __sk_buff *skb)
|
| 108 | {
|
| 109 | return 0;
|
| 110 | }
|
| 111 |
|
| 112 | #endif
|
| 113 |
|
| 114 | char _license[] SEC("license") = "GPL";
|