| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "../btf/testdata/bpf_core_read.h" |
| 5 |
#include "common.h" |
| 6 |
|
| 7 |
char __license[] __section("license") = "Dual MIT/GPL"; |
| 8 |
|
| 9 |
struct bpf_map_def __section("maps") kprobe_map = { |
| 10 |
.type = BPF_MAP_TYPE_HASH, |
| 11 |
.key_size = sizeof(uint32_t), |
| 12 |
.value_size = sizeof(uint64_t), |
| 13 |
.max_entries = 128, |
| 14 |
}; |
| 15 |
|
| 16 |
#pragma clang attribute push(__attribute__((preserve_access_index)), apply_to = record) |
| 17 |
struct ns_common { |
| 18 |
unsigned int inum; |
| 19 |
}; |
| 20 |
struct mnt_namespace { |
| 21 |
struct ns_common ns; |
| 22 |
}; |
| 23 |
struct nsproxy { |
| 24 |
struct mnt_namespace *mnt_ns; |
| 25 |
}; |
| 26 |
struct task_struct { |
| 27 |
struct nsproxy *nsproxy; |
| 28 |
}; |
| 29 |
#pragma clang attribute pop |
| 30 |
|
| 31 |
static inline int impl() { |
| 32 |
uint64_t initval = 1, *valp; |
| 33 |
|
| 34 |
struct task_struct *task = (struct task_struct *)bpf_get_current_task(); |
| 35 |
uint32_t mntns = BPF_CORE_READ(task, nsproxy, mnt_ns, ns.inum); |
| 36 |
|
| 37 |
valp = bpf_map_lookup_elem(&kprobe_map, &mntns); |
| 38 |
if (!valp) { |
| 39 |
bpf_map_update_elem(&kprobe_map, &mntns, &initval, 0); |
| 40 |
return 0; |
| 41 |
} |
| 42 |
__sync_fetch_and_add(valp, 1); |
| 43 |
|
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
#define DEFINE_PROBE(i) \ |
| 48 |
__section("kprobe/sys_execvea" #i) int kprobe_execve##i() { \ |
| 49 |
return impl(); \ |
| 50 |
} |
| 51 |
|
| 52 |
DEFINE_PROBE(0); |
| 53 |
DEFINE_PROBE(1); |
| 54 |
DEFINE_PROBE(2); |
| 55 |
DEFINE_PROBE(3); |
| 56 |
DEFINE_PROBE(4); |
| 57 |
DEFINE_PROBE(5); |
| 58 |
DEFINE_PROBE(6); |
| 59 |
DEFINE_PROBE(7); |
| 60 |
DEFINE_PROBE(8); |
| 61 |
DEFINE_PROBE(9); |
| 62 |
|
| 63 |
DEFINE_PROBE(10); |
| 64 |
DEFINE_PROBE(11); |
| 65 |
DEFINE_PROBE(12); |
| 66 |
DEFINE_PROBE(13); |
| 67 |
DEFINE_PROBE(14); |
| 68 |
DEFINE_PROBE(15); |
| 69 |
DEFINE_PROBE(16); |
| 70 |
DEFINE_PROBE(17); |
| 71 |
DEFINE_PROBE(18); |
| 72 |
DEFINE_PROBE(19); |
| 73 |
|
| 74 |
DEFINE_PROBE(20); |
| 75 |
DEFINE_PROBE(21); |
| 76 |
DEFINE_PROBE(22); |
| 77 |
DEFINE_PROBE(23); |
| 78 |
DEFINE_PROBE(24); |
| 79 |
DEFINE_PROBE(25); |
| 80 |
DEFINE_PROBE(26); |
| 81 |
DEFINE_PROBE(27); |
| 82 |
DEFINE_PROBE(28); |
| 83 |
DEFINE_PROBE(29); |