Skip to content

Commit baa1d7a

Browse files
committed
retrieve mount fields with make_visible for >=6.18 kernel support
1 parent c71b5a6 commit baa1d7a

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

  • pkg/security/ebpf/c/include/hooks

pkg/security/ebpf/c/include/hooks/mount.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,23 @@ int hook_mnt_change_mountpoint(ctx_t *ctx)
340340

341341
HOOK_ENTRY("make_visible")
342342
int hook_make_visible(ctx_t *ctx) {
343-
struct syscall_cache_t *syscall = peek_syscall_with(unshare_or_open_tree_or_move_mount);
343+
struct syscall_cache_t *syscall = peek_syscall_with(mountpoint_predicate);
344344
if (!syscall) {
345345
return 0;
346346
}
347347

348348
struct mount *newmnt = (struct mount *)CTX_PARM1(ctx);
349-
// check if this mount has already been processed by another hook
350-
if (syscall->mount.newmnt == newmnt) {
349+
350+
if (syscall->type == EVENT_MOUNT) {
351+
// attach_recursive_mnt is the only other hook covering plain mounts and it cannot be trusted
352+
// since 6.18: its arguments were replaced by a pinned_mountpoint and the compiler usually
353+
// leaves only an ISRA clone of it. commit_tree calls us once per propagated copy, the first
354+
// one being the mount the syscall was issued for, so take it and re-read its fields here.
355+
if (syscall->mount.newmnt && syscall->mount.newmnt != newmnt) {
356+
return 0;
357+
}
358+
} else if (syscall->mount.newmnt && syscall->mount.newmnt == newmnt) {
359+
// check if this mount has already been processed by another hook
351360
return 0;
352361
}
353362

@@ -357,7 +366,10 @@ int hook_make_visible(ctx_t *ctx) {
357366
struct mountpoint *mp = get_mount_mountpoint(newmnt);
358367
syscall->mount.mountpoint_dentry = get_mountpoint_dentry(mp);
359368

360-
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
369+
// plain mounts are sent from the mount syscall return hook, once the syscall is known to succeed
370+
if (syscall->type != EVENT_MOUNT) {
371+
handle_new_mount(ctx, syscall, KPROBE_OR_FENTRY_TYPE, false);
372+
}
361373

362374
return 0;
363375
}

0 commit comments

Comments
 (0)