|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | + |
2 | 3 | #include <linux/bpf.h> |
3 | 4 | #include <bpf/bpf_helpers.h> |
4 | 5 | #include <bpf/bpf_tracing.h> |
5 | 6 |
|
| 7 | +struct trace_entry { |
| 8 | + short unsigned int type; |
| 9 | + unsigned char flags; |
| 10 | + unsigned char preempt_count; |
| 11 | + int pid; |
| 12 | +}; |
| 13 | + |
| 14 | +struct trace_event_raw_sys_enter { |
| 15 | + struct trace_entry ent; |
| 16 | + long int id; |
| 17 | + long unsigned int args[6]; |
| 18 | + char __data[0]; |
| 19 | +}; |
6 | 20 |
|
7 | 21 | struct event { |
8 | | - __u32 pid; |
9 | | - __u32 uid; |
10 | | - __u64 ts; |
| 22 | + __u32 pid; |
| 23 | + __u32 uid; |
| 24 | + __u64 ts; |
11 | 25 | }; |
12 | 26 |
|
13 | 27 | struct { |
14 | | - __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); |
15 | | - __uint(key_size, sizeof(int)); |
16 | | - __uint(value_size, sizeof(int)); |
| 28 | + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); |
| 29 | + __uint(key_size, sizeof(int)); |
| 30 | + __uint(value_size, sizeof(int)); |
17 | 31 | } events SEC(".maps"); |
18 | 32 |
|
19 | 33 | SEC("tp/syscalls/sys_enter_setuid") |
20 | | -int handle_setuid_entry(struct trace_event_raw_sys_enter *ctx) |
21 | | -{ |
22 | | - struct event data = {}; |
23 | | - |
24 | | - // Extract UID from the syscall arguments |
25 | | - data.uid = (unsigned int)ctx->args[0]; |
26 | | - data.ts = bpf_ktime_get_ns(); |
27 | | - data.pid = bpf_get_current_pid_tgid() >> 32; |
28 | | - |
29 | | - bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &data, sizeof(data)); |
30 | | - |
31 | | - return 0; |
| 34 | +int handle_setuid_entry(struct trace_event_raw_sys_enter *ctx) { |
| 35 | + struct event data = {}; |
| 36 | + |
| 37 | + // Extract UID from the syscall arguments |
| 38 | + data.uid = (unsigned int)ctx->args[0]; |
| 39 | + data.ts = bpf_ktime_get_ns(); |
| 40 | + data.pid = bpf_get_current_pid_tgid() >> 32; |
| 41 | + |
| 42 | + bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &data, sizeof(data)); |
| 43 | + |
| 44 | + return 0; |
32 | 45 | } |
33 | 46 |
|
34 | 47 | char LICENSE[] SEC("license") = "GPL"; |
0 commit comments