1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ 3 4 #include "vmlinux.h" 5 #include <bpf/bpf_helpers.h> 6 #include <bpf/bpf_tracing.h> 7 8 char _license[] SEC("license") = "GPL"; 9 10 /* rodata section */ 11 const volatile pid_t pid; 12 const volatile size_t bss_array_len; 13 const volatile size_t data_array_len; 14 15 /* bss section */ 16 int sum = 0; 17 int array[1]; 18 19 /* custom data section */ 20 int my_array[1] SEC(".data.custom"); 21 22 /* custom data section which should NOT be resizable, 23 * since it contains a single var which is not an array 24 */ 25 int my_int SEC(".data.non_array"); 26 27 /* custom data section which should NOT be resizable, 28 * since its last var is not an array 29 */ 30 int my_array_first[1] SEC(".data.array_not_last"); 31 int my_int_last SEC(".data.array_not_last"); 32 33 int percpu_arr[1] SEC(".data.percpu_arr"); 34 35 SEC("tp/syscalls/sys_enter_getpid") bss_array_sum(void * ctx)36int bss_array_sum(void *ctx) 37 { 38 if (pid != (bpf_get_current_pid_tgid() >> 32)) 39 return 0; 40 41 /* this will be zero, we just rely on verifier not rejecting this */ 42 sum = percpu_arr[bpf_get_smp_processor_id()]; 43 44 for (size_t i = 0; i < bss_array_len; ++i) 45 sum += array[i]; 46 47 return 0; 48 } 49 50 SEC("tp/syscalls/sys_enter_getuid") data_array_sum(void * ctx)51int data_array_sum(void *ctx) 52 { 53 if (pid != (bpf_get_current_pid_tgid() >> 32)) 54 return 0; 55 56 /* this will be zero, we just rely on verifier not rejecting this */ 57 sum = percpu_arr[bpf_get_smp_processor_id()]; 58 59 for (size_t i = 0; i < data_array_len; ++i) 60 sum += my_array[i]; 61 62 return 0; 63 } 64 65 SEC("struct_ops/test_1") BPF_PROG(test_1)66int BPF_PROG(test_1) 67 { 68 return 0; 69 } 70 71 struct bpf_testmod_ops { 72 int (*test_1)(void); 73 }; 74 75 SEC(".struct_ops.link") 76 struct bpf_testmod_ops st_ops_resize = { 77 .test_1 = (void *)test_1 78 }; 79