-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathmount.h
More file actions
653 lines (536 loc) · 20.9 KB
/
Copy pathmount.h
File metadata and controls
653 lines (536 loc) · 20.9 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
#ifndef _HOOKS_MOUNT_H_
#define _HOOKS_MOUNT_H_
#include "constants/syscall_macro.h"
#include "helpers/events_predicates.h"
#include "helpers/filesystem.h"
#include "helpers/syscalls.h"
HOOK_ENTRY("mnt_want_write")
int hook_mnt_want_write(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(mnt_want_write_predicate);
if (!syscall) {
return 0;
}
struct vfsmount *mnt = (struct vfsmount *)CTX_PARM1(ctx);
switch (syscall->type) {
case EVENT_UTIME:
if (syscall->setattr.file.path_key.mount_id > 0) {
return 0;
}
syscall->setattr.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
case EVENT_CHMOD:
if (syscall->setattr.file.path_key.mount_id > 0) {
return 0;
}
syscall->setattr.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
case EVENT_CHOWN:
if (syscall->setattr.file.path_key.mount_id > 0) {
return 0;
}
syscall->setattr.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
case EVENT_RENAME:
if (syscall->rename.src_file.path_key.mount_id > 0) {
return 0;
}
syscall->rename.src_file.path_key.mount_id = get_vfsmount_mount_id(mnt);
syscall->rename.target_file.path_key.mount_id = syscall->rename.src_file.path_key.mount_id;
break;
case EVENT_RMDIR:
if (syscall->rmdir.file.path_key.mount_id > 0) {
return 0;
}
syscall->rmdir.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
case EVENT_UNLINK:
if (syscall->unlink.file.path_key.mount_id > 0) {
return 0;
}
syscall->unlink.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
case EVENT_SETXATTR:
if (syscall->xattr.file.path_key.mount_id > 0) {
return 0;
}
syscall->xattr.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
case EVENT_REMOVEXATTR:
if (syscall->xattr.file.path_key.mount_id > 0) {
return 0;
}
syscall->xattr.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
}
return 0;
}
int __attribute__((always_inline)) trace__mnt_want_write_file(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(mnt_want_write_file_predicate);
if (!syscall) {
return 0;
}
struct file *file = (struct file *)CTX_PARM1(ctx);
struct vfsmount *mnt;
bpf_probe_read(&mnt, sizeof(mnt), &get_file_f_path_addr(file)->mnt);
switch (syscall->type) {
case EVENT_CHOWN:
if (syscall->setattr.file.path_key.mount_id > 0) {
return 0;
}
syscall->setattr.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
case EVENT_SETXATTR:
if (syscall->xattr.file.path_key.mount_id > 0) {
return 0;
}
syscall->xattr.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
case EVENT_REMOVEXATTR:
if (syscall->xattr.file.path_key.mount_id > 0) {
return 0;
}
syscall->xattr.file.path_key.mount_id = get_vfsmount_mount_id(mnt);
break;
}
return 0;
}
HOOK_ENTRY("mnt_want_write_file")
int hook_mnt_want_write_file(ctx_t *ctx) {
return trace__mnt_want_write_file(ctx);
}
// mnt_want_write_file_path was used on old kernels (RHEL 7)
HOOK_ENTRY("mnt_want_write_file_path")
int hook_mnt_want_write_file_path(ctx_t *ctx) {
return trace__mnt_want_write_file(ctx);
}
HOOK_SYSCALL_COMPAT_ENTRY3(mount, const char *, source, const char *, target, const char *, fstype) {
struct syscall_cache_t syscall = {
.type = EVENT_MOUNT,
};
collect_syscall_ctx(&syscall, SYSCALL_CTX_ARG_STR(0) | SYSCALL_CTX_ARG_STR(1) | SYSCALL_CTX_ARG_STR(2), (void *)source, (void *)target, (void *)fstype);
cache_syscall_update_cgroup(ctx, &syscall);
return 0;
}
HOOK_SYSCALL_ENTRY1(unshare, unsigned long, flags) {
// unshare is only used to propagate mounts created when a mount namespace is copied
if (!(flags & CLONE_NEWNS)) {
return 0;
}
struct syscall_cache_t syscall = {
.type = EVENT_UNSHARE_MNTNS,
};
cache_syscall_update_cgroup(ctx, &syscall);
return 0;
}
HOOK_SYSCALL_EXIT(unshare) {
pop_syscall(EVENT_UNSHARE_MNTNS);
return 0;
}
void __attribute__((always_inline)) fill_mount_fields(struct syscall_cache_t *syscall, struct mount_fields_t *mfields) {
mfields->root_key = syscall->mount.root_key;
mfields->mountpoint_key = syscall->mount.mountpoint_key;
mfields->device = syscall->mount.device;
mfields->bind_src_mount_id = syscall->mount.bind_src_mount_id;
mfields->ns_inum = syscall->mount.ns_inum;
mfields->mount_id_unique = syscall->mount.mount_id_unique;
mfields->parent_mount_id_unique = syscall->mount.parent_mount_id_unique;
mfields->bind_src_mount_id_unique = syscall->mount.bind_src_mount_id_unique;
bpf_probe_read_str(&mfields->fstype, sizeof(mfields->fstype), (void *)syscall->mount.fstype);
}
int __attribute__((always_inline)) send_detached_event(void *ctx, struct syscall_cache_t *syscall) {
struct mount_event_t event = {
.syscall.retval = 0,
.syscall_ctx.id = syscall->ctx_id,
.source = SOURCE_OPEN_TREE,
.mountfields.visible = false,
.mountfields.detached = true,
};
if (syscall->type == EVENT_FSMOUNT) {
event.source = SOURCE_FSMOUNT;
}
fill_mount_fields(syscall, &event.mountfields);
struct proc_cache_t *entry = fill_process_context(&event.process);
fill_cgroup_context(entry, &event.cgroup);
fill_span_context(&event.span);
send_event(ctx, EVENT_MOUNT, event);
return 0;
}
void __attribute__((always_inline)) handle_new_mount(void *ctx, struct syscall_cache_t *syscall, enum TAIL_CALL_PROG_TYPE prog_type, bool detached) {
// populate the root dentry key
struct dentry *root_dentry = get_vfsmount_dentry(get_mount_vfsmount(syscall->mount.newmnt));
syscall->mount.root_key.mount_id = get_mount_mount_id(syscall->mount.newmnt);
syscall->mount.mount_id_unique = get_mount_mount_id_unique(syscall->mount.newmnt);
syscall->mount.root_key.ino = get_dentry_ino(root_dentry);
update_path_id(&syscall->mount.root_key, 0, PATH_ID_INVALIDATE_TYPE_NONE);
if(!detached) {
// populate the mountpoint dentry key
syscall->mount.mountpoint_key.mount_id = get_mount_mount_id(syscall->mount.parent);
syscall->mount.parent_mount_id_unique = get_mount_mount_id_unique(syscall->mount.parent);
syscall->mount.mountpoint_key.ino = get_dentry_ino(syscall->mount.mountpoint_dentry);
update_path_id(&syscall->mount.mountpoint_key, 0, PATH_ID_INVALIDATE_TYPE_NONE);
}
// populate the device of the new mount
syscall->mount.device = get_mount_dev(syscall->mount.newmnt);
// populate the fs type of the new mount
struct super_block *sb = get_dentry_sb(root_dentry);
struct file_system_type *s_type = get_super_block_fs(sb);
bpf_probe_read(&syscall->mount.fstype, sizeof(syscall->mount.fstype), &s_type->name);
if (syscall->mount.root_key.mount_id == 0 || (!detached && syscall->mount.mountpoint_key.mount_id == 0) || syscall->mount.device == 0) {
pop_syscall(syscall->type);
return;
}
if(!detached) {
syscall->resolver.key = syscall->mount.root_key;
syscall->resolver.dentry = root_dentry;
syscall->resolver.event_type = 0;
syscall->resolver.flags = 0;
syscall->resolver.callback = select_dr_key(prog_type, DR_MOUNT_STAGE_ONE_CALLBACK_KPROBE_KEY, DR_MOUNT_STAGE_ONE_CALLBACK_TRACEPOINT_KEY);
syscall->resolver.iteration = 0;
syscall->resolver.ret = 0;
resolve_dentry(ctx, prog_type);
// if the tail call fails, we need to pop the syscall cache entry
pop_syscall(syscall->type);
} else {
send_detached_event(ctx, syscall);
}
}
int __attribute__((always_inline)) dr_mount_stage_one_callback(void *ctx, enum TAIL_CALL_PROG_TYPE prog_type) {
struct syscall_cache_t *syscall = peek_syscall_with(mountpoint_predicate);
if (!syscall) {
return 0;
}
syscall->resolver.key = syscall->mount.mountpoint_key;
syscall->resolver.dentry = syscall->mount.mountpoint_dentry;
syscall->resolver.event_type = 0;
syscall->resolver.flags = 0;
syscall->resolver.callback = select_dr_key(prog_type, DR_MOUNT_STAGE_TWO_CALLBACK_KPROBE_KEY, DR_MOUNT_STAGE_TWO_CALLBACK_TRACEPOINT_KEY);
syscall->resolver.iteration = 0;
syscall->resolver.ret = 0;
resolve_dentry(ctx, prog_type);
// if the tail call fails, we need to pop the syscall cache entry
pop_syscall(syscall->type);
return 0;
}
TAIL_CALL_FNC(dr_mount_stage_one_callback, ctx_t *ctx) {
return dr_mount_stage_one_callback(ctx, KPROBE_OR_FENTRY_TYPE);
}
TAIL_CALL_TRACEPOINT_FNC(dr_mount_stage_one_callback, struct tracepoint_syscalls_sys_exit_t *args) {
return dr_mount_stage_one_callback(args, TRACEPOINT_TYPE);
}
int __attribute__((always_inline)) dr_mount_stage_two_callback(void *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(mountpoint_predicate);
if (!syscall) {
return 0;
}
if (syscall->type == EVENT_MOUNT || syscall->type == EVENT_OPEN_TREE || syscall->type == EVENT_MOVE_MOUNT || syscall->type == EVENT_PIVOT_ROOT) {
struct mount_event_t event = {
.syscall.retval = 0,
.syscall_ctx.id = syscall->ctx_id,
.source = SOURCE_OPEN_TREE,
.mountfields.visible = false,
.mountfields.detached = false,
};
fill_mount_fields(syscall, &event.mountfields);
struct proc_cache_t *entry = fill_process_context(&event.process);
fill_cgroup_context(entry, &event.cgroup);
fill_span_context(&event.span);
if (syscall->type != EVENT_OPEN_TREE) {
// Only the first mount of a detached copy is detached from the VFS
// All the other mounts are ultimately attached to the detached mount
// That's why they aren't detached but are visible
event.mountfields.visible = true;
if(syscall->type == EVENT_MOUNT) {
event.source = SOURCE_MOUNT;
pop_syscall(EVENT_MOUNT);
} else {
event.source = SOURCE_MOVE_MOUNT;
}
}
if (syscall->type == EVENT_PIVOT_ROOT) {
event.source = SOURCE_PIVOT_ROOT;
send_event(ctx, EVENT_PIVOT_ROOT, event);
return 0;
}
if (syscall->type == EVENT_MOVE_MOUNT) {
send_event(ctx, EVENT_MOVE_MOUNT, event);
return 0;
}
send_event(ctx, EVENT_MOUNT, event);
} else if (syscall->type == EVENT_UNSHARE_MNTNS) {
struct unshare_mntns_event_t event = { 0 };
fill_mount_fields(syscall, &event.mountfields);
send_event(ctx, EVENT_UNSHARE_MNTNS, event);
}
return 0;
}
TAIL_CALL_FNC(dr_mount_stage_two_callback, ctx_t *ctx) {
return dr_mount_stage_two_callback(ctx);
}
TAIL_CALL_TRACEPOINT_FNC(dr_mount_stage_two_callback, struct tracepoint_syscalls_sys_exit_t *args) {
return dr_mount_stage_two_callback(args);
}
HOOK_ENTRY("mnt_change_mountpoint")
int hook_mnt_change_mountpoint(ctx_t *ctx)
{
struct syscall_cache_t *syscall = peek_syscall(EVENT_MOVE_MOUNT);
if(!syscall) {
return 0;
}
struct mount *newmnt = (struct mount *)CTX_PARM3(ctx);
if (syscall->mount.newmnt == newmnt) {
return 0;
}
syscall->mount.ns_inum = get_mount_mount_ns_inum(newmnt);
syscall->mount.newmnt = newmnt;
syscall->mount.parent = (struct mount *)CTX_PARM1(ctx);
struct mountpoint *mp = (struct mountpoint *)CTX_PARM2(ctx);
syscall->mount.mountpoint_dentry = get_mountpoint_dentry(mp);
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
return 0;
}
HOOK_ENTRY("make_visible")
int hook_make_visible(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(mountpoint_predicate);
if (!syscall) {
return 0;
}
struct mount *newmnt = (struct mount *)CTX_PARM1(ctx);
u32 ns_inum = get_mount_mount_ns_inum(newmnt);
if (syscall->type == EVENT_MOUNT) {
// copy_tree attaches the copies of a recursive bind mount before the mount itself is made visible, so
// we skip these copies here, commit_tree will call us again with the mount the syscall was issued for,
// once it joined the namespace. (ns_inum == 0 because the copies aren't part of any namespace at this point).
if (!ns_inum) {
return 0;
}
// attach_recursive_mnt is the only other hook covering regular mount syscalls and it cannot be trusted
// since 6.18: its arguments were replaced by a pinned_mountpoint and the compiler usually
// leaves an ISRA clone of it. It records the same mount as we do here, but only a older kernel versions (< 6.18).
if (syscall->mount.newmnt && syscall->mount.newmnt != newmnt) {
return 0;
}
} else if (syscall->mount.newmnt && syscall->mount.newmnt == newmnt) {
// check if this mount has already been processed by another hook
return 0;
}
syscall->mount.ns_inum = ns_inum;
syscall->mount.newmnt = newmnt;
syscall->mount.parent = get_mount_parent(newmnt);
struct mountpoint *mp = get_mount_mountpoint(newmnt);
syscall->mount.mountpoint_dentry = get_mountpoint_dentry(mp);
// plain mounts are sent from the mount syscall return hook, once the syscall is known to succeed
if (syscall->type != EVENT_MOUNT) {
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
}
return 0;
}
HOOK_ENTRY("attach_mnt")
int hook_attach_mnt(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(unshare_or_open_tree_or_move_mount);
if (!syscall) {
return 0;
}
struct mount *newmnt = (struct mount *)CTX_PARM1(ctx);
// check if this mount has already been processed by another hook
if (syscall->mount.newmnt == newmnt) {
return 0;
}
syscall->mount.ns_inum = get_mount_mount_ns_inum(newmnt);
syscall->mount.newmnt = newmnt;
syscall->mount.parent = (struct mount *)CTX_PARM2(ctx);
struct mountpoint *mp = (struct mountpoint *)CTX_PARM3(ctx);
syscall->mount.mountpoint_dentry = get_mountpoint_dentry(mp);
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
return 0;
}
HOOK_ENTRY("__attach_mnt")
int hook___attach_mnt(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(unshare_or_open_tree_or_move_mount);
if (!syscall) {
return 0;
}
struct mount *newmnt = (struct mount *)CTX_PARM1(ctx);
// check if this mount has already been processed by another hook
if (syscall->mount.newmnt == newmnt) {
return 0;
}
syscall->mount.ns_inum = get_mount_mount_ns_inum(newmnt);
syscall->mount.newmnt = newmnt;
syscall->mount.parent = (struct mount *)CTX_PARM2(ctx);
syscall->mount.mountpoint_dentry = get_mount_mountpoint_dentry(newmnt);
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
return 0;
}
HOOK_ENTRY("mnt_set_mountpoint")
int hook_mnt_set_mountpoint(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(unshare_or_move_mount);
if (!syscall) {
return 0;
}
struct mount *newmnt = (struct mount *)CTX_PARM3(ctx);
// check if this mount has already been processed by another hook
if (syscall->mount.newmnt == newmnt) {
return 0;
}
syscall->mount.ns_inum = get_mount_mount_ns_inum(newmnt);
syscall->mount.newmnt = newmnt;
syscall->mount.parent = (struct mount *)CTX_PARM1(ctx);
struct mountpoint *mp = (struct mountpoint *)CTX_PARM2(ctx);
syscall->mount.mountpoint_dentry = get_mountpoint_dentry(mp);
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
return 0;
}
HOOK_ENTRY("clone_mnt")
int hook_clone_mnt(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(mount_or_open_tree);
if (!syscall) {
return 0;
}
if (syscall->type != EVENT_OPEN_TREE && (syscall->mount.bind_src_mount_id != 0 || syscall->mount.newmnt)) {
return 0;
}
struct mount *bind_src_mnt = (struct mount *)CTX_PARM1(ctx);
syscall->mount.ns_inum = get_mount_mount_ns_inum(bind_src_mnt);
syscall->mount.bind_src_mount_id = get_mount_mount_id(bind_src_mnt);
syscall->mount.bind_src_mount_id_unique = get_mount_mount_id_unique(bind_src_mnt);
syscall->mount.clone_mnt_ctr++;
return 0;
}
HOOK_EXIT("clone_mnt")
int rethook_clone_mnt(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall(EVENT_OPEN_TREE);
if (!syscall) {
return 0;
}
if(syscall->mount.clone_mnt_ctr != 1) {
return 0;
}
struct mount *ret = (struct mount *)CTX_PARMRET(ctx);
syscall->mount.ns_inum = get_mount_mount_ns_inum(ret);
syscall->mount.newmnt = ret;
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, true);
return 0;
}
HOOK_ENTRY("attach_recursive_mnt")
int hook_attach_recursive_mnt(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(mount_or_move_mount);
if (!syscall) {
return 0;
}
struct mount *newmnt = (struct mount *)CTX_PARM1(ctx);
// check if this mount has already been processed by another hook
if (syscall->mount.newmnt == newmnt) {
return 0;
}
syscall->mount.newmnt = newmnt;
syscall->mount.parent = (struct mount *)CTX_PARM2(ctx);
struct mountpoint *mp = (struct mountpoint *)CTX_PARM3(ctx);
struct mount *topmnt = (struct mount *)CTX_PARM2(ctx);
syscall->mount.ns_inum = get_mount_mount_ns_inum(topmnt);
syscall->mount.mountpoint_dentry = get_mountpoint_dentry(mp);
if (syscall->type != EVENT_MOUNT) {
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
}
return 0;
}
HOOK_ENTRY("propagate_mnt")
int hook_propagate_mnt(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall_with(mount_or_move_mount);
if (!syscall) {
return 0;
}
struct mount *newmnt = (struct mount *)CTX_PARM3(ctx);
// check if this mount has already been processed by another hook
if (syscall->mount.newmnt == newmnt) {
return 0;
}
syscall->mount.ns_inum = get_mount_mount_ns_inum(newmnt);
syscall->mount.newmnt = newmnt;
syscall->mount.parent = (struct mount *)CTX_PARM1(ctx);
struct mountpoint *mp = (struct mountpoint *)CTX_PARM2(ctx);
syscall->mount.mountpoint_dentry = get_mountpoint_dentry(mp);
if (syscall->type != EVENT_MOUNT) {
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
}
return 0;
}
int __attribute__((always_inline)) sys_mount_ret(void *ctx, int retval, enum TAIL_CALL_PROG_TYPE prog_type) {
if (retval) {
pop_syscall(EVENT_MOUNT);
return 0;
}
struct syscall_cache_t *syscall = peek_syscall(EVENT_MOUNT);
if (!syscall) {
return 0;
}
handle_new_mount(ctx, syscall, prog_type, false);
return 0;
}
HOOK_SYSCALL_COMPAT_EXIT(mount) {
int retval = SYSCALL_PARMRET(ctx);
return sys_mount_ret(ctx, retval, KPROBE_OR_FENTRY_TYPE);
}
TAIL_CALL_TRACEPOINT_FNC(handle_sys_mount_exit, struct tracepoint_raw_syscalls_sys_exit_t *args) {
return sys_mount_ret(args, args->ret, TRACEPOINT_TYPE);
}
HOOK_EXIT("alloc_vfsmnt")
int rethook_alloc_vfsmnt(ctx_t *ctx) {
struct syscall_cache_t *syscall = peek_syscall(EVENT_FSMOUNT);
if (!syscall) {
return 0;
}
struct mount *newmnt = (struct mount *)CTX_PARMRET(ctx);
syscall->mount.newmnt = newmnt;
return 0;
}
HOOK_SYSCALL_ENTRY3(open_tree, int, dfd, const char *, filename, unsigned int, flags)
{
if (!(flags & OPEN_TREE_CLONE)) {
return 0;
}
struct syscall_cache_t syscall = {
.type = EVENT_OPEN_TREE,
};
cache_syscall_update_cgroup(ctx, &syscall);
return 0;
}
HOOK_SYSCALL_EXIT(open_tree) {
pop_syscall(EVENT_OPEN_TREE);
return 0;
}
HOOK_SYSCALL_ENTRY3(fsmount, int, fs_fd, unsigned int, flags, unsigned int, attr_flags)
{
struct syscall_cache_t syscall = {
.type = EVENT_FSMOUNT,
};
cache_syscall_update_cgroup(ctx, &syscall);
return 0;
}
HOOK_SYSCALL_EXIT(fsmount) {
struct syscall_cache_t *syscall = pop_syscall(EVENT_FSMOUNT);
if (!syscall) {
// should never happen
return 0;
}
if(syscall->retval >= 0) {
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, true);
}
return 0;
}
HOOK_SYSCALL_ENTRY4(move_mount, int, from_dfd, const char *, from_pathname, int, to_dfd, const char *, to_pathname)
{
struct syscall_cache_t syscall = {
.type = EVENT_MOVE_MOUNT,
};
cache_syscall_update_cgroup(ctx, &syscall);
return 0;
}
HOOK_SYSCALL_EXIT(move_mount) {
struct syscall_cache_t *syscall = pop_syscall(EVENT_MOVE_MOUNT);
if (!syscall) {
// should never happen
return 0;
}
return 0;
}
#endif