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 7char _license[] SEC("license") = "GPL"; 8 9/* rodata section */ 10const volatile pid_t pid; 11const volatile size_t bss_array_len; 12const volatile size_t data_array_len; 13 14/* bss section */ 15int sum = 0; 16int array[1]; 17 18/* custom data secton */ 19int my_array[1] SEC(".data.custom"); 20 21/* custom data section which should NOT be resizable, 22 * since it contains a single var which is not an array 23 */ 24int my_int SEC(".data.non_array"); 25 26/* custom data section which should NOT be resizable, 27 * since its last var is not an array 28 */ 29int my_array_first[1] SEC(".data.array_not_last"); 30int my_int_last SEC(".data.array_not_last"); 31 32int percpu_arr[1] SEC(".data.percpu_arr"); 33 34SEC("tp/syscalls/sys_enter_getpid") 35int bss_array_sum(void *ctx) 36{ 37 if (pid != (bpf_get_current_pid_tgid() >> 32)) 38 return 0; 39 40 /* this will be zero, we just rely on verifier not rejecting this */ 41 sum = percpu_arr[bpf_get_smp_processor_id()]; 42 43 for (size_t i = 0; i < bss_array_len; ++i) 44 sum += array[i]; 45 46 return 0; 47} 48 49SEC("tp/syscalls/sys_enter_getuid") 50int data_array_sum(void *ctx) 51{ 52 if (pid != (bpf_get_current_pid_tgid() >> 32)) 53 return 0; 54 55 /* this will be zero, we just rely on verifier not rejecting this */ 56 sum = percpu_arr[bpf_get_smp_processor_id()]; 57 58 for (size_t i = 0; i < data_array_len; ++i) 59 sum += my_array[i]; 60 61 return 0; 62} 63