Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (c) 2020 Facebook
0003 #include <linux/bpf.h>
0004 #include <bpf/bpf_helpers.h>
0005 #include <bpf/bpf_core_read.h>
0006 
0007 struct task_struct {
0008     int tgid;
0009 } __attribute__((preserve_access_index));
0010 
0011 struct {
0012     __uint(type, BPF_MAP_TYPE_ARRAY);
0013     __uint(max_entries, 1);
0014     __type(key, int);
0015     __type(value, int);
0016 } exp_tgid_map SEC(".maps");
0017 
0018 struct {
0019     __uint(type, BPF_MAP_TYPE_ARRAY);
0020     __uint(max_entries, 1);
0021     __type(key, int);
0022     __type(value, int);
0023 } results SEC(".maps");
0024 
0025 SEC("tp/raw_syscalls/sys_enter")
0026 int handle_sys_enter(void *ctx)
0027 {
0028     struct task_struct *task = (void *)bpf_get_current_task();
0029     int tgid = BPF_CORE_READ(task, tgid);
0030     int zero = 0;
0031     int real_tgid = bpf_get_current_pid_tgid() >> 32;
0032     int *exp_tgid = bpf_map_lookup_elem(&exp_tgid_map, &zero);
0033 
0034     /* only pass through sys_enters from test process */
0035     if (!exp_tgid || *exp_tgid != real_tgid)
0036         return 0;
0037 
0038     bpf_map_update_elem(&results, &zero, &tgid, 0);
0039 
0040     return 0;
0041 }
0042 
0043 char _license[] SEC("license") = "GPL";