Re: [PATCH v1 bpf-next] bpf: new helper bpf_get_current_pcomm
From: Carlos Antonio Neira Bustos <hidden>
Date: 2020-09-08 19:27:34
Also in:
bpf
On Wed, Aug 26, 2020 at 10:25:55PM -0700, Andrii Nakryiko wrote:
On Wed, Aug 26, 2020 at 9:06 AM Carlos Neira [off-list ref] wrote:quoted
In multi-threaded applications bpf_get_current_comm is returning per-thread names, this helper will return comm from real_parent. This makes a difference for some Java applications, where get_current_comm is returning per-thread names, but get_current_pcomm will return "java".Why not bpf_probe_read_kernel_str(dst, 16, task->real_parent->comm) for fentry/fexit/tp_btf/etc BTF-aware BPF programs or BPF_CORE_READ_STR_INTO(dst, task, real_parent, comm) for any BPF program that has bpf_probe_read_kernel[_str]() (which is pretty much every BPF program nowadays, I think)? Yes, CONFIG_DEBUG_INFO_BTF=y Kconfig is a requirement, but it's a good idea to have that if you are using BPF anyways.quoted
Signed-off-by: Carlos Neira <redacted> --- include/linux/bpf.h | 1 + include/uapi/linux/bpf.h | 15 ++++- kernel/bpf/core.c | 1 + kernel/bpf/helpers.c | 28 +++++++++ kernel/trace/bpf_trace.c | 2 + tools/include/uapi/linux/bpf.h | 15 ++++- .../selftests/bpf/prog_tests/current_pcomm.c | 57 +++++++++++++++++++ .../selftests/bpf/progs/test_current_pcomm.c | 17 ++++++ 8 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/current_pcomm.c create mode 100644 tools/testing/selftests/bpf/progs/test_current_pcomm.c[...]
Thanks Andrii, I'll use bpf_probe_read_kernel_str(dst, 16, task->real_parent->comm), I was not aware of that. Bests!.