108b08956SJP Kobryn // SPDX-License-Identifier: GPL-2.0 208b08956SJP Kobryn /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ 308b08956SJP Kobryn 408b08956SJP Kobryn #include "vmlinux.h" 508b08956SJP Kobryn #include <bpf/bpf_helpers.h> 608b08956SJP Kobryn 708b08956SJP Kobryn char _license[] SEC("license") = "GPL"; 808b08956SJP Kobryn 908b08956SJP Kobryn /* rodata section */ 1008b08956SJP Kobryn const volatile pid_t pid; 1108b08956SJP Kobryn const volatile size_t bss_array_len; 1208b08956SJP Kobryn const volatile size_t data_array_len; 1308b08956SJP Kobryn 1408b08956SJP Kobryn /* bss section */ 1508b08956SJP Kobryn int sum = 0; 1608b08956SJP Kobryn int array[1]; 1708b08956SJP Kobryn 1808b08956SJP Kobryn /* custom data secton */ 1908b08956SJP Kobryn int my_array[1] SEC(".data.custom"); 2008b08956SJP Kobryn 2108b08956SJP Kobryn /* custom data section which should NOT be resizable, 2208b08956SJP Kobryn * since it contains a single var which is not an array 2308b08956SJP Kobryn */ 2408b08956SJP Kobryn int my_int SEC(".data.non_array"); 2508b08956SJP Kobryn 2608b08956SJP Kobryn /* custom data section which should NOT be resizable, 2708b08956SJP Kobryn * since its last var is not an array 2808b08956SJP Kobryn */ 2908b08956SJP Kobryn int my_array_first[1] SEC(".data.array_not_last"); 3008b08956SJP Kobryn int my_int_last SEC(".data.array_not_last"); 3108b08956SJP Kobryn 32*c21de5fcSAndrii Nakryiko int percpu_arr[1] SEC(".data.percpu_arr"); 33*c21de5fcSAndrii Nakryiko 3408b08956SJP Kobryn SEC("tp/syscalls/sys_enter_getpid") bss_array_sum(void * ctx)3508b08956SJP Kobrynint bss_array_sum(void *ctx) 3608b08956SJP Kobryn { 3708b08956SJP Kobryn if (pid != (bpf_get_current_pid_tgid() >> 32)) 3808b08956SJP Kobryn return 0; 3908b08956SJP Kobryn 40*c21de5fcSAndrii Nakryiko /* this will be zero, we just rely on verifier not rejecting this */ 41*c21de5fcSAndrii Nakryiko sum = percpu_arr[bpf_get_smp_processor_id()]; 4208b08956SJP Kobryn 4308b08956SJP Kobryn for (size_t i = 0; i < bss_array_len; ++i) 4408b08956SJP Kobryn sum += array[i]; 4508b08956SJP Kobryn 4608b08956SJP Kobryn return 0; 4708b08956SJP Kobryn } 4808b08956SJP Kobryn 4908b08956SJP Kobryn SEC("tp/syscalls/sys_enter_getuid") data_array_sum(void * ctx)5008b08956SJP Kobrynint data_array_sum(void *ctx) 5108b08956SJP Kobryn { 5208b08956SJP Kobryn if (pid != (bpf_get_current_pid_tgid() >> 32)) 5308b08956SJP Kobryn return 0; 5408b08956SJP Kobryn 55*c21de5fcSAndrii Nakryiko /* this will be zero, we just rely on verifier not rejecting this */ 56*c21de5fcSAndrii Nakryiko sum = percpu_arr[bpf_get_smp_processor_id()]; 5708b08956SJP Kobryn 5808b08956SJP Kobryn for (size_t i = 0; i < data_array_len; ++i) 5908b08956SJP Kobryn sum += my_array[i]; 6008b08956SJP Kobryn 6108b08956SJP Kobryn return 0; 6208b08956SJP Kobryn } 63