aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Maguire <alan.maguire@oracle.com>2023-10-04 10:44:57 +0100
committerHengqi Chen <chenhengqi@outlook.com>2023-10-05 22:28:03 +0800
commite6775c49ff1eb13a541a9c68c9edb586e909ce34 (patch)
tree550f67eddc524d08ed7038b856df92badc1b98ae
parent32be0a338e9fc89f21168ac7fa3eb6557baa9ba1 (diff)
downloadbcc-e6775c49ff1eb13a541a9c68c9edb586e909ce34.tar.gz
ksnoop: use bpf_get_func_ip() where helper is available
bpf_get_func_ip(ctx) will get the function address; use it where available using the BPF core enum value check for the function. This avoids needing to get the caller IP via KSNOOP_IP_FIX() for more up-to-date kernels. This fixes issue #4746 for kernels newer than 5.13; an additional followup will be needed to address this for older kernels. Kindly tested by https://github.com/matthew-olson-intel on a recent kernel. Reported-by: dubeyabhishek (https://github.com/dubeyabhishek) Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
-rw-r--r--libbpf-tools/ksnoop.bpf.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libbpf-tools/ksnoop.bpf.c b/libbpf-tools/ksnoop.bpf.c
index d76dc12c..f07ff561 100644
--- a/libbpf-tools/ksnoop.bpf.c
+++ b/libbpf-tools/ksnoop.bpf.c
@@ -89,7 +89,11 @@ static struct trace *get_trace(struct pt_regs *ctx, bool entry)
return NULL;
if (entry) {
- ip = KSNOOP_IP_FIX(PT_REGS_IP_CORE(ctx));
+ if (bpf_core_enum_value_exists(enum bpf_func_id,
+ BPF_FUNC_get_func_ip))
+ ip = bpf_get_func_ip(ctx);
+ else
+ ip = KSNOOP_IP_FIX(PT_REGS_IP_CORE(ctx));
if (stack_depth >= FUNC_MAX_STACK_DEPTH - 1)
return NULL;
/* verifier doesn't like using "stack_depth - 1" as array index