Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2021 Facebook */
0003 
0004 #include "vmlinux.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/bpf_tracing.h>
0007 
0008 char _license[] SEC("license") = "GPL";
0009 
0010 struct {
0011     __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
0012     __uint(map_flags, BPF_F_NO_PREALLOC);
0013     __type(key, int);
0014     __type(value, __u64);
0015 } task_storage SEC(".maps");
0016 
0017 int valid_ptr_count = 0;
0018 int null_ptr_count = 0;
0019 
0020 SEC("fentry/exit_creds")
0021 int BPF_PROG(trace_exit_creds, struct task_struct *task)
0022 {
0023     __u64 *ptr;
0024 
0025     ptr = bpf_task_storage_get(&task_storage, task, 0,
0026                    BPF_LOCAL_STORAGE_GET_F_CREATE);
0027     if (ptr)
0028         __sync_fetch_and_add(&valid_ptr_count, 1);
0029     else
0030         __sync_fetch_and_add(&null_ptr_count, 1);
0031     return 0;
0032 }