0001
0002
0003 #include <linux/types.h>
0004 #include <linux/bpf.h>
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/bpf_tracing.h>
0007
0008 #define STRNCMP_STR_SZ 4096
0009
0010
0011 const volatile unsigned int cmp_str_len = 1;
0012 const char target[STRNCMP_STR_SZ];
0013
0014 long hits = 0;
0015 char str[STRNCMP_STR_SZ];
0016
0017 char _license[] SEC("license") = "GPL";
0018
0019 static __always_inline int local_strncmp(const char *s1, unsigned int sz,
0020 const char *s2)
0021 {
0022 int ret = 0;
0023 unsigned int i;
0024
0025 for (i = 0; i < sz; i++) {
0026
0027 ret = (unsigned char)s1[i] - (unsigned char)s2[i];
0028 if (ret || !s1[i])
0029 break;
0030 }
0031
0032 return ret;
0033 }
0034
0035 SEC("tp/syscalls/sys_enter_getpgid")
0036 int strncmp_no_helper(void *ctx)
0037 {
0038 if (local_strncmp(str, cmp_str_len + 1, target) < 0)
0039 __sync_add_and_fetch(&hits, 1);
0040 return 0;
0041 }
0042
0043 SEC("tp/syscalls/sys_enter_getpgid")
0044 int strncmp_helper(void *ctx)
0045 {
0046 if (bpf_strncmp(str, cmp_str_len + 1, target) < 0)
0047 __sync_add_and_fetch(&hits, 1);
0048 return 0;
0049 }
0050