1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2021 Facebook */ 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 struct { 11 __uint(type, BPF_MAP_TYPE_TASK_STORAGE); 12 __uint(map_flags, BPF_F_NO_PREALLOC); 13 __type(key, int); 14 __type(value, __u64); 15 } task_storage SEC(".maps"); 16 17 int run_count = 0; 18 int valid_ptr_count = 0; 19 int null_ptr_count = 0; 20 21 SEC("fentry/exit_creds") 22 int BPF_PROG(trace_exit_creds, struct task_struct *task) 23 { 24 __u64 *ptr; 25 26 ptr = bpf_task_storage_get(&task_storage, task, 0, 27 BPF_LOCAL_STORAGE_GET_F_CREATE); 28 if (ptr) 29 __sync_fetch_and_add(&valid_ptr_count, 1); 30 else 31 __sync_fetch_and_add(&null_ptr_count, 1); 32 33 __sync_fetch_and_add(&run_count, 1); 34 return 0; 35 } 36