-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhs_trace.bpf.c
More file actions
793 lines (725 loc) · 17 KB
/
hs_trace.bpf.c
File metadata and controls
793 lines (725 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
#include "hs_trace.h"
#include "vmlinux.h"
#include <asm/unistd.h>
#include <bpf/bpf_core_read.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <linux/limits.h>
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1024 * 1024);
} output SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__type(key, u32);
__type(value, u32);
__uint(max_entries, 1);
} missed_events SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, u32);
__type(value, u64);
__uint(max_entries, 1024 * 1024);
} pipe_tracker SEC(".maps");
// struct {
// __uint(type, BPF_MAP_TYPE_HASH);
// __type(key, struct unique_file_t);
// __type(value, char[4096]);
// __uint(max_entries, 256);
// } read_path_set SEC(".maps");
//
// struct {
// __uint(type, BPF_MAP_TYPE_HASH);
// __type(key, struct unique_file_t);
// __type(value, char[4096]);
// __uint(max_entries, 256);
// } write_path_set SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, u32);
__type(value, u32);
__uint(max_entries, 1024);
} pid_set SEC(".maps");
enum syscall_event_type {
SYS_ENTER0,
SYS_ENTER1,
SYS_ENTER2,
SYS_EXIT
};
struct sys_enter_pipe2_args {
unsigned short common_type;
unsigned char common_flags;
unsigned char common_preempt_count;
int common_pid;
int id; // syscall number
int *fildes; // pipe fds
long flags; // flags
};
SEC("tracepoint/syscalls/sys_enter_pipe2")
int
BPF_PROG(hs_trace_create_pipe)
{
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid & 0xFFFFFFFF;
if (bpf_map_lookup_elem(&pid_set, &pid) == NULL) {
return 0;
}
u64 ptr = (u64)((struct sys_enter_pipe2_args *)ctx)->fildes;
if (bpf_map_update_elem(&pipe_tracker, &pid, &ptr, BPF_ANY) < 0) {
bpf_printk("failed to update pipe_tracker with pid %d\n", pid);
return 0;
}
return 0;
}
struct sys_exit_pipe2_args {
unsigned short common_type;
unsigned char common_flags;
unsigned char common_preempt_count;
int common_pid;
int id; // syscall number
long ret; // return value
};
SEC("tracepoint/syscalls/sys_exit_pipe2")
int
BPF_PROG(hs_trace_create_pipe_exit)
{
struct sys_enter_info2_t *enter2;
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid & 0xFFFFFFFF;
if (bpf_map_lookup_elem(&pid_set, &pid) == NULL) {
// bpf_printk("pid %d is not in set\n", pid);
return 0;
}
if (((struct sys_exit_pipe2_args *)ctx)->ret < 0) {
return 0;
}
u64 *fds_pointers;
if ((fds_pointers = bpf_map_lookup_elem(&pipe_tracker, &pid)) == NULL) {
return 0;
}
if ((enter2 = bpf_ringbuf_reserve(
&output, sizeof(struct sys_enter_info2_t), 0)) == NULL) {
// bpf_printk("FAILED to reserve space in ring buffer
// for "
// "event_type == "
// "SYS_ENTER2\n");
u32 key = 0;
u32 *missed = bpf_map_lookup_elem(&missed_events, &key);
if (missed) {
__sync_fetch_and_add(missed, 1);
}
return 0;
}
enter2->pid_tgid = pid_tgid;
enter2->syscall_nr = ((struct sys_exit_pipe2_args *)ctx)->id;
enter2->flags = -1;
bpf_map_delete_elem(&pipe_tracker, &pid);
int fds[2];
bpf_probe_read_user(&fds, sizeof(fds), (void *)(*fds_pointers));
enter2->fd = fds[0];
enter2->fd2 = fds[1];
// bpf_rcu_read_lock();
struct task_struct *t = (void *)bpf_get_current_task_btf();
struct files_struct *files = BPF_CORE_READ(t, files);
struct fdtable *fdtp = NULL;
bpf_probe_read_kernel(&fdtp, sizeof(fdtp), &files->fdt);
struct file **fd_array = NULL;
bpf_probe_read_kernel(&fd_array, sizeof(fd_array), &fdtp->fd);
int fd0 = fds[0];
struct file *file0 = NULL;
bpf_probe_read_kernel(&file0, sizeof(file0), &fd_array[fd0]);
u64 ino = 0;
ino = BPF_CORE_READ(file0, f_inode, i_ino);
// bpf_rcu_read_unlock();
char *path2 = NULL;
char pipe_str[32];
BPF_SNPRINTF(enter2->path, sizeof(pipe_str), "/pipe:[%d]", ino);
bpf_probe_read_user_str(&enter2->path2, sizeof(enter2->path2), path2);
bpf_ringbuf_submit(enter2, 0);
struct sys_exit_info_t *exit;
if ((exit = bpf_ringbuf_reserve(&output, sizeof(struct sys_exit_info_t),
0)) == NULL) {
// bpf_printk(
// "FAILED to reserve space in ring buffer for event_type ==
// " "SYS_EXIT\n");
u32 key = 0;
u32 *missed = bpf_map_lookup_elem(&missed_events, &key);
if (missed) {
__sync_fetch_and_add(missed, 1);
}
return 0;
}
exit->pid_tgid = pid_tgid;
exit->ret = ((struct sys_exit_pipe2_args *)ctx)->ret;
bpf_ringbuf_submit(exit, 0);
return 0;
}
SEC("tp_btf/sched_process_fork")
int
BPF_PROG(hs_trace_process_fork, struct task_struct *parent,
struct task_struct *child)
{
u32 dummy_val = 1;
u64 p_pid = parent->pid;
u64 c_pid = child->pid;
u64 p_pid_tgid = (p_pid << 32) | p_pid;
u64 c_pid_tgid = (c_pid << 32) | c_pid;
// bpf_printk("sched_process_fork called with parent %d and child %d\n",
// p_pid, c_pid);
if (bpf_map_lookup_elem(&pid_set, &p_pid) == NULL) {
// bpf_printk("parent pid %d not in set\n", p_pid);
return 0;
}
if (bpf_map_update_elem(&pid_set, &c_pid, &dummy_val, BPF_ANY) < 0) {
bpf_printk("failed to update pid set with %d\n", c_pid);
return 0;
}
bpf_printk("update pid set with %d\n", c_pid);
struct sys_enter_info0_t *enter0;
if ((enter0 = bpf_ringbuf_reserve(
&output, sizeof(struct sys_enter_info0_t), 0)) == NULL) {
// bpf_printk(
// "FAILED to reserve space in ring buffer for event_type ==
// " "SYS_ENTER0\n");
u32 key = 0;
u32 *missed = bpf_map_lookup_elem(&missed_events, &key);
if (missed) {
__sync_fetch_and_add(missed, 1);
}
return 0;
}
enter0->pid_tgid = p_pid_tgid;
enter0->syscall_nr = __NR_clone;
enter0->flags = 0;
bpf_ringbuf_submit(enter0, 0);
struct sys_exit_info_t *exit;
if ((exit = bpf_ringbuf_reserve(&output, sizeof(struct sys_exit_info_t),
0)) == NULL) {
// bpf_printk(
// "FAILED to reserve space in ring buffer for event_type ==
// " "SYS_EXIT\n");
u32 key = 0;
u32 *missed = bpf_map_lookup_elem(&missed_events, &key);
if (missed) {
__sync_fetch_and_add(missed, 1);
}
return 0;
}
exit->pid_tgid = p_pid_tgid;
exit->ret = c_pid_tgid;
bpf_ringbuf_submit(exit, 0);
return 0;
}
SEC("tp_btf/sched_process_exit")
int
BPF_PROG(hs_trace_process_exit, struct task_struct *p)
{
u32 pid = p->pid;
if (bpf_map_delete_elem(&pid_set, &pid) < 0) {
bpf_printk("failed to delete %d from pid set\n", pid);
return 0;
}
bpf_printk("removed %d from pid set\n", pid);
return 0;
}
SEC("tp_btf/sys_enter")
int
BPF_PROG(hs_trace_sys_enter, struct pt_regs *regs, long syscall_id)
{
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid & 0xFFFFFFFF;
if (bpf_map_lookup_elem(&pid_set, &pid) == NULL) {
// bpf_printk("pid %d is not in set\n", pid);
return 0;
}
int fd = -1;
int fd2 = -1;
char *path = NULL;
char *path2 = NULL;
int flags = 0;
enum syscall_event_type event_type;
switch (syscall_id) {
#ifdef __NR_openat
case __NR_openat: /* individually */
fd = (int)PT_REGS_PARM1_CORE(regs);
path = (char *)PT_REGS_PARM2_CORE(regs);
flags = (int)PT_REGS_PARM3_CORE(regs);
event_type = SYS_ENTER1;
break;
#endif
#ifdef __NR_openat2
case __NR_openat2: /* individually */
fd = (int)PT_REGS_PARM1_CORE(regs);
path = (char *)PT_REGS_PARM2_CORE(regs);
flags = (int)PT_REGS_PARM3_CORE(regs);
event_type = SYS_ENTER1;
break;
#endif
#ifdef __NR_open
case __NR_open:
path = (char *)PT_REGS_PARM1_CORE(regs);
flags = (int)PT_REGS_PARM2_CORE(regs);
event_type = SYS_ENTER1;
break;
#endif
#ifdef __NR_chdir
case __NR_chdir:
path = (char *)PT_REGS_PARM1_CORE(regs);
event_type = SYS_ENTER1;
break;
#endif
#ifdef __NR_symlinkat
case __NR_symlinkat:
fd = (int)PT_REGS_PARM2_CORE(regs);
path = (char *)PT_REGS_PARM3_CORE(regs);
event_type = SYS_ENTER1;
break;
#endif
#ifdef __NR_symlink
case __NR_symlink:
#endif
// NOTE: symlink only incurs a dependency for the symlink file
// itself
path = (char *)PT_REGS_PARM2_CORE(regs);
event_type = SYS_ENTER1;
break;
#ifdef __NR_link
case __NR_link:
#endif
// NOTE: link incurs a dependency on both the original path and
// the new path for the inode
path = (char *)PT_REGS_PARM1_CORE(regs);
path2 = (char *)PT_REGS_PARM2_CORE(regs);
event_type = SYS_ENTER2;
break;
#ifdef __NR_renameat2
case __NR_renameat2:
#endif
// TODO (dan 2025-05-27): flags for renameat2 might need special
// handling
flags = (int)PT_REGS_PARM5_CORE(regs);
#ifdef __NR_renameat
case __NR_renameat:
#endif
fd = (int)PT_REGS_PARM1_CORE(regs);
fd2 = (int)PT_REGS_PARM3_CORE(regs);
path = (char *)PT_REGS_PARM2_CORE(regs);
path2 = (char *)PT_REGS_PARM4_CORE(regs);
event_type = SYS_ENTER2;
break;
#ifdef __NR_rename
case __NR_rename:
path = (char *)PT_REGS_PARM1_CORE(regs);
path2 = (char *)PT_REGS_PARM2_CORE(regs);
event_type = SYS_ENTER2;
break;
#endif
#ifdef __NR_inotify_add_watch
case __NR_inotify_add_watch:
path = (char *)PT_REGS_PARM2_CORE(regs);
event_type = SYS_ENTER1;
break;
#endif
#ifdef __NR_dup2
case __NR_dup2:
#endif
#ifdef __NR_dup3
case __NR_dup3:
fd = (int)PT_REGS_PARM1_CORE(regs);
fd2 = (int)PT_REGS_PARM2_CORE(regs);
event_type = SYS_ENTER2;
break;
#endif
#ifdef __NR_dup
case __NR_dup:
fd = (int)PT_REGS_PARM1_CORE(regs);
event_type = SYS_ENTER1;
break;
#endif
#ifdef __NR_execve
case __NR_execve: /* r_first_path_set */
#endif
#ifdef __NR_statfs
case __NR_statfs:
#endif
#ifdef __NR_getxattr
case __NR_getxattr:
#endif
#ifdef __NR_lgetxattr
case __NR_lgetxattr:
#endif
#ifdef __NR_stat
case __NR_stat:
#endif
#ifdef __NR_lstat
case __NR_lstat:
#endif
#ifdef __NR_access
case __NR_access:
#endif
#ifdef __NR_readlink
case __NR_readlink:
#endif
path = (char *)PT_REGS_PARM1_CORE(regs);
event_type = SYS_ENTER1;
break;
#ifdef __NR_truncate
case __NR_truncate: /* w_first_path_set */
#endif
#ifdef __NR_acct
case __NR_acct:
#endif
#ifdef __NR_mkdir
case __NR_mkdir:
#endif
#ifdef __NR_rmdir
case __NR_rmdir:
#endif
#ifdef __NR_creat
case __NR_creat:
#endif
#ifdef __NR_chmod
case __NR_chmod:
#endif
#ifdef __NR_chown
case __NR_chown:
#endif
#ifdef __NR_lchown
case __NR_lchown:
#endif
#ifdef __NR_utime
case __NR_utime:
#endif
#ifdef __NR_utimes
case __NR_utimes:
#endif
#ifdef __NR_mknod
case __NR_mknod:
#endif
#ifdef __NR_unlink
case __NR_unlink:
#endif
path = (char *)PT_REGS_PARM1_CORE(regs);
event_type = SYS_ENTER1;
break;
#ifdef __NR_newfstatat
case __NR_newfstatat: /* r_fd_path_set */
#endif
#ifdef __NR_statx
case __NR_statx:
#endif
#ifdef __NR_name_to_handle_at
case __NR_name_to_handle_at:
#endif
#ifdef __NR_readlinkat
case __NR_readlinkat:
#endif
#ifdef __NR_faccessat
case __NR_faccessat:
#endif
#ifdef __NR_faccessat2
case __NR_faccessat2:
#endif
#ifdef __NR_execveat
case __NR_execveat:
#endif
fd = (int)PT_REGS_PARM1_CORE(regs);
path = (char *)PT_REGS_PARM2_CORE(regs);
event_type = SYS_ENTER1;
break;
#ifdef __NR_linkat
case __NR_linkat: /* w_fd_path_set */
#endif
#ifdef __NR_unlinkat
case __NR_unlinkat:
#endif
#ifdef __NR_utimensat
case __NR_utimensat:
#endif
#ifdef __NR_mkdirat
case __NR_mkdirat:
#endif
#ifdef __NR_mknodat
case __NR_mknodat:
#endif
#ifdef __NR_fchownat
case __NR_fchownat:
#endif
#ifdef __NR_fchmodat
case __NR_fchmodat:
#endif
#ifdef __NR_futimeat
case __NR_futimeat:
#endif
fd = (int)PT_REGS_PARM1_CORE(regs);
path = (char *)PT_REGS_PARM2_CORE(regs);
event_type = SYS_ENTER1;
break;
default:
// bpf_printk("ignoring sys_enter event for syscall %ld\n",
// syscall_id);
return 0;
}
bpf_printk("sys_enter called on %ld\n", syscall_id);
struct sys_enter_info0_t *enter0;
struct sys_enter_info1_t *enter1;
struct sys_enter_info2_t *enter2;
if (event_type == SYS_ENTER0) {
if ((enter0 = bpf_ringbuf_reserve(
&output, sizeof(struct sys_enter_info0_t), 0)) ==
NULL) {
// bpf_printk("FAILED to reserve space in ring buffer
// for "
// "event_type == "
// "SYS_ENTER0\n");
u32 key = 0;
u32 *missed = bpf_map_lookup_elem(&missed_events, &key);
if (missed) {
__sync_fetch_and_add(missed, 1);
}
return 0;
}
enter0->pid_tgid = pid_tgid;
enter0->syscall_nr = syscall_id;
enter0->flags = flags;
bpf_ringbuf_submit(enter0, 0);
} else if (event_type == SYS_ENTER1) {
if ((enter1 = bpf_ringbuf_reserve(
&output, sizeof(struct sys_enter_info1_t), 0)) ==
NULL) {
// bpf_printk("FAILED to reserve space in ring buffer
// for "
// "event_type == "
// "SYS_ENTER1\n");
u32 key = 0;
u32 *missed = bpf_map_lookup_elem(&missed_events, &key);
if (missed) {
__sync_fetch_and_add(missed, 1);
}
return 0;
}
enter1->pid_tgid = pid_tgid;
enter1->syscall_nr = syscall_id;
enter1->flags = flags;
enter1->fd = fd;
bpf_probe_read_user_str(&enter1->path, sizeof(enter1->path),
path);
bpf_ringbuf_submit(enter1, 0);
} else if (event_type == SYS_ENTER2) {
if ((enter2 = bpf_ringbuf_reserve(
&output, sizeof(struct sys_enter_info2_t), 0)) ==
NULL) {
// bpf_printk("FAILED to reserve space in ring buffer
// for "
// "event_type == "
// "SYS_ENTER2\n");
u32 key = 0;
u32 *missed = bpf_map_lookup_elem(&missed_events, &key);
if (missed) {
__sync_fetch_and_add(missed, 1);
}
return 0;
}
enter2->pid_tgid = pid_tgid;
enter2->syscall_nr = syscall_id;
enter2->flags = flags;
enter2->fd = fd;
enter2->fd2 = fd2;
bpf_probe_read_user_str(&enter2->path, sizeof(enter2->path),
path);
bpf_probe_read_user_str(&enter2->path2, sizeof(enter2->path2),
path2);
bpf_ringbuf_submit(enter2, 0);
}
return 0;
}
struct sys_exit_args {
unsigned short common_type;
unsigned char common_flags;
unsigned char common_preempt_count;
int common_pid;
long id; // syscall number
long ret; // return value
};
SEC("tracepoint/raw_syscalls/sys_exit")
int
BPF_PROG(hs_trace_sys_exit)
{
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid & 0xFFFFFFFF;
if (bpf_map_lookup_elem(&pid_set, &pid) == NULL) {
return 0;
}
long syscall_id = ((struct sys_exit_args *)ctx)->id;
// bpf_printk("sys_exit event for syscall %ld\n", syscall_id);
switch (syscall_id) {
#ifdef __NR_openat
case __NR_openat: /* individually */
#endif
#ifdef __NR_openat2
case __NR_openat2: /* individually */
#endif
#ifdef __NR_open
case __NR_open:
#endif
#ifdef __NR_chdir
case __NR_chdir:
#endif
#ifdef __NR_symlinkat
case __NR_symlinkat:
#endif
#ifdef __NR_symlink
case __NR_symlink:
#endif
#ifdef __NR_link
case __NR_link:
#endif
#ifdef __NR_rename
case __NR_rename:
#endif
#ifdef __NR_renameat
case __NR_renameat:
#endif
#ifdef __NR_renameat2
case __NR_renameat2:
#endif
#ifdef __NR_inotify_add_watch
case __NR_inotify_add_watch:
#endif
#ifdef __NR_execve
case __NR_execve: /* r_first_path_set */
#endif
#ifdef __NR_dup2
case __NR_dup2:
#endif
#ifdef __NR_dup3
case __NR_dup3:
#endif
#ifdef __NR_dup
#endif
#ifdef __NR_statfs
case __NR_statfs:
#endif
#ifdef __NR_getxattr
case __NR_getxattr:
#endif
#ifdef __NR_lgetxattr
case __NR_lgetxattr:
#endif
#ifdef __NR_stat
case __NR_stat:
#endif
#ifdef __NR_lstat
case __NR_lstat:
#endif
#ifdef __NR_access
case __NR_access:
#endif
#ifdef __NR_readlink
case __NR_readlink:
#endif
#ifdef __NR_truncate
case __NR_truncate: /* w_first_path_set */
#endif
#ifdef __NR_acct
case __NR_acct:
#endif
#ifdef __NR_mkdir
case __NR_mkdir:
#endif
#ifdef __NR_rmdir
case __NR_rmdir:
#endif
#ifdef __NR_creat
case __NR_creat:
#endif
#ifdef __NR_chmod
case __NR_chmod:
#endif
#ifdef __NR_chown
case __NR_chown:
#endif
#ifdef __NR_lchown
case __NR_lchown:
#endif
#ifdef __NR_utime
case __NR_utime:
#endif
#ifdef __NR_utimes
case __NR_utimes:
#endif
#ifdef __NR_mknod
case __NR_mknod:
#endif
#ifdef __NR_unlink
case __NR_unlink:
#endif
#ifdef __NR_newfstatat
case __NR_newfstatat: /* r_fd_path_set */
#endif
#ifdef __NR_statx
case __NR_statx:
#endif
#ifdef __NR_name_to_handle_at
case __NR_name_to_handle_at:
#endif
#ifdef __NR_readlinkat
case __NR_readlinkat:
#endif
#ifdef __NR_faccessat
case __NR_faccessat:
#endif
#ifdef __NR_faccessat2
case __NR_faccessat2:
#endif
#ifdef __NR_execveat
case __NR_execveat:
#endif
#ifdef __NR_linkat
case __NR_linkat: /* w_fd_path_set */
#endif
#ifdef __NR_unlinkat
case __NR_unlinkat:
#endif
#ifdef __NR_utimensat
case __NR_utimensat:
#endif
#ifdef __NR_mkdirat
case __NR_mkdirat:
#endif
#ifdef __NR_mknodat
case __NR_mknodat:
#endif
#ifdef __NR_fchownat
case __NR_fchownat:
#endif
#ifdef __NR_fchmodat
case __NR_fchmodat:
#endif
#ifdef __NR_futimeat
case __NR_futimeat:
#endif
break;
default:
return 0;
}
bpf_printk("sys_exit called on %ld\n", syscall_id);
struct sys_exit_info_t *exit;
if ((exit = bpf_ringbuf_reserve(&output, sizeof(struct sys_exit_info_t),
0)) == NULL) {
// bpf_printk(
// "FAILED to reserve space in ring buffer for event_type ==
// " "SYS_EXIT\n");
u32 key = 0;
u32 *missed = bpf_map_lookup_elem(&missed_events, &key);
if (missed) {
__sync_fetch_and_add(missed, 1);
}
return 0;
}
exit->pid_tgid = pid_tgid;
exit->ret = ((struct sys_exit_args *)ctx)->ret;
bpf_ringbuf_submit(exit, 0);
return 0;
}
char LICENSE[] SEC("license") = "Dual BSD/GPL";