1*8bcb9c62SJiri Olsa // SPDX-License-Identifier: GPL-2.0 2*8bcb9c62SJiri Olsa #include <linux/bpf.h> 3*8bcb9c62SJiri Olsa #include <bpf/bpf_helpers.h> 4*8bcb9c62SJiri Olsa #include <bpf/bpf_tracing.h> 5*8bcb9c62SJiri Olsa #include <stdbool.h> 6*8bcb9c62SJiri Olsa #include "bpf_kfuncs.h" 7*8bcb9c62SJiri Olsa #include "bpf_misc.h" 8*8bcb9c62SJiri Olsa 9*8bcb9c62SJiri Olsa char _license[] SEC("license") = "GPL"; 10*8bcb9c62SJiri Olsa 11*8bcb9c62SJiri Olsa int pid = 0; 12*8bcb9c62SJiri Olsa 13*8bcb9c62SJiri Olsa int idx_entry = 0; 14*8bcb9c62SJiri Olsa int idx_return = 0; 15*8bcb9c62SJiri Olsa 16*8bcb9c62SJiri Olsa __u64 test_uprobe_cookie_entry[6]; 17*8bcb9c62SJiri Olsa __u64 test_uprobe_cookie_return[3]; 18*8bcb9c62SJiri Olsa 19*8bcb9c62SJiri Olsa static int check_cookie(void) 20*8bcb9c62SJiri Olsa { 21*8bcb9c62SJiri Olsa __u64 *cookie = bpf_session_cookie(); 22*8bcb9c62SJiri Olsa 23*8bcb9c62SJiri Olsa if (bpf_session_is_return()) { 24*8bcb9c62SJiri Olsa if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return)) 25*8bcb9c62SJiri Olsa return 1; 26*8bcb9c62SJiri Olsa test_uprobe_cookie_return[idx_return++] = *cookie; 27*8bcb9c62SJiri Olsa return 0; 28*8bcb9c62SJiri Olsa } 29*8bcb9c62SJiri Olsa 30*8bcb9c62SJiri Olsa if (idx_entry >= ARRAY_SIZE(test_uprobe_cookie_entry)) 31*8bcb9c62SJiri Olsa return 1; 32*8bcb9c62SJiri Olsa *cookie = test_uprobe_cookie_entry[idx_entry]; 33*8bcb9c62SJiri Olsa return idx_entry++ % 2; 34*8bcb9c62SJiri Olsa } 35*8bcb9c62SJiri Olsa 36*8bcb9c62SJiri Olsa 37*8bcb9c62SJiri Olsa SEC("uprobe.session//proc/self/exe:uprobe_session_recursive") 38*8bcb9c62SJiri Olsa int uprobe_recursive(struct pt_regs *ctx) 39*8bcb9c62SJiri Olsa { 40*8bcb9c62SJiri Olsa if (bpf_get_current_pid_tgid() >> 32 != pid) 41*8bcb9c62SJiri Olsa return 1; 42*8bcb9c62SJiri Olsa 43*8bcb9c62SJiri Olsa return check_cookie(); 44*8bcb9c62SJiri Olsa } 45