1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (C) 2024. Huawei Technologies Co., Ltd */ 3 #include <linux/types.h> 4 #include <bpf/bpf_helpers.h> 5 6 #include "bpf_misc.h" 7 8 int target_pid = 0; 9 void *user_ptr = 0; 10 int read_ret[8]; 11 12 char _license[] SEC("license") = "GPL"; 13 14 SEC("fentry/" SYS_PREFIX "sys_nanosleep") 15 int do_probe_read(void *ctx) 16 { 17 char buf[8]; 18 19 if ((bpf_get_current_pid_tgid() >> 32) != target_pid) 20 return 0; 21 22 read_ret[0] = bpf_probe_read_kernel(buf, sizeof(buf), user_ptr); 23 read_ret[1] = bpf_probe_read_kernel_str(buf, sizeof(buf), user_ptr); 24 read_ret[2] = bpf_probe_read(buf, sizeof(buf), user_ptr); 25 read_ret[3] = bpf_probe_read_str(buf, sizeof(buf), user_ptr); 26 read_ret[4] = bpf_probe_read_user(buf, sizeof(buf), user_ptr); 27 read_ret[5] = bpf_probe_read_user_str(buf, sizeof(buf), user_ptr); 28 29 return 0; 30 } 31 32 SEC("fentry.s/" SYS_PREFIX "sys_nanosleep") 33 int do_copy_from_user(void *ctx) 34 { 35 char buf[8]; 36 37 if ((bpf_get_current_pid_tgid() >> 32) != target_pid) 38 return 0; 39 40 read_ret[6] = bpf_copy_from_user(buf, sizeof(buf), user_ptr); 41 read_ret[7] = bpf_copy_from_user_task(buf, sizeof(buf), user_ptr, 42 bpf_get_current_task_btf(), 0); 43 44 return 0; 45 } 46