From ed02a14435608a0cac5187d5e64671f921accbe9 Mon Sep 17 00:00:00 2001 From: mickey_zhu Date: Fri, 19 May 2023 14:17:59 +0800 Subject: [PATCH] libbpf-tools: Avoid virtual memory area [uprobes] warning Refer to kernel commit 704bde3cc26a ("uprobes: Use vm_special_mapping to name the XOL vma"), processes setup the [uprobes] special virtual memory area with uprobe events to excute original instruction out of line. open_elf() would throw a warning of 'Could not open [uprobes]' when attaching uprobes. For example, use memleak to trace userspace apps allocations with command 'memleak -c ' or 'memleak -p ': ~ # ps | grep dropbear 76 root 2100 S dropbear 79 root 2340 S grep dropbear ~ # memleak -p 76 using default object: libc.so.6 using page size: 4096 tracing kernel: false Tracing outstanding memory allocs... Hit Ctrl-C to end [0:18:54] Top 3 stacks with outstanding allocations: 147 bytes in 1 allocations from stack Could not open [uprobes] 0 [<000000000001b3bc>] free+0x7b2c [/bin/dropbear] 64 bytes in 1 allocations from stack 0 [<00000000000288c8>] free+0x15038 [/bin/dropbear] So remove '[uprobes]' from get_elf_type() to avoid this warning. Signed-off-by: mickey_zhu --- libbpf-tools/trace_helpers.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libbpf-tools/trace_helpers.c b/libbpf-tools/trace_helpers.c index 89c48351c4e2..408aeb26a122 100644 --- a/libbpf-tools/trace_helpers.c +++ b/libbpf-tools/trace_helpers.c @@ -243,6 +243,7 @@ static bool is_file_backed(const char *mapname) STARTS_WITH(mapname, "[stack") || STARTS_WITH(mapname, "/SYSV") || STARTS_WITH(mapname, "[heap]") || + STARTS_WITH(mapname, "[uprobes]") || STARTS_WITH(mapname, "[vsyscall]")); } @@ -256,6 +257,11 @@ static bool is_vdso(const char *path) return !strcmp(path, "[vdso]"); } +static bool is_uprobes(const char *path) +{ + return !strcmp(path, "[uprobes]"); +} + static int get_elf_type(const char *path) { GElf_Ehdr hdr; @@ -265,6 +271,8 @@ static int get_elf_type(const char *path) if (is_vdso(path)) return -1; + if (is_uprobes(path)) + return -1; e = open_elf(path, &fd); if (!e) return -1;