hc
2023-12-06 d38611ca164021d018c1b23eee65bbebc09c63e0
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
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2019 Carlos Neira cneirabustos@gmail.com */
 
#include <linux/bpf.h>
#include <stdint.h>
#include <bpf/bpf_helpers.h>
 
static volatile struct {
   __u64 dev;
   __u64 ino;
   __u64 pid_tgid;
   __u64 user_pid_tgid;
} res;
 
SEC("raw_tracepoint/sys_enter")
int trace(void *ctx)
{
   __u64  ns_pid_tgid, expected_pid;
   struct bpf_pidns_info nsdata;
   __u32 key = 0;
 
   if (bpf_get_ns_current_pid_tgid(res.dev, res.ino, &nsdata,
          sizeof(struct bpf_pidns_info)))
       return 0;
 
   ns_pid_tgid = (__u64)nsdata.tgid << 32 | nsdata.pid;
   expected_pid = res.user_pid_tgid;
 
   if (expected_pid != ns_pid_tgid)
       return 0;
 
   res.pid_tgid = ns_pid_tgid;
 
   return 0;
}
 
char _license[] SEC("license") = "GPL";