Skip to content

Commit 368211f

Browse files
iamkafaidavem330
authored andcommitted
bpf: Append prog->aux->name in bpf_get_prog_name()
This patch makes the bpf_prog's name available in kallsyms. The new format is bpf_prog_tag[_name]. Sample kallsyms from running selftests/bpf/test_progs: [root@arch-fb-vm1 ~]# egrep ' bpf_prog_[0-9a-fA-F]{16}' /proc/kallsyms ffffffffa0048000 t bpf_prog_dabf0207d1992486_test_obj_id ffffffffa0038000 t bpf_prog_a04f5eef06a7f555__123456789ABCDE ffffffffa0050000 t bpf_prog_a04f5eef06a7f555 Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 067cae4 commit 368211f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

kernel/bpf/core.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,25 @@ bpf_get_prog_addr_region(const struct bpf_prog *prog,
309309

310310
static void bpf_get_prog_name(const struct bpf_prog *prog, char *sym)
311311
{
312+
const char *end = sym + KSYM_NAME_LEN;
313+
312314
BUILD_BUG_ON(sizeof("bpf_prog_") +
313-
sizeof(prog->tag) * 2 + 1 > KSYM_NAME_LEN);
315+
sizeof(prog->tag) * 2 +
316+
/* name has been null terminated.
317+
* We should need +1 for the '_' preceding
318+
* the name. However, the null character
319+
* is double counted between the name and the
320+
* sizeof("bpf_prog_") above, so we omit
321+
* the +1 here.
322+
*/
323+
sizeof(prog->aux->name) > KSYM_NAME_LEN);
314324

315325
sym += snprintf(sym, KSYM_NAME_LEN, "bpf_prog_");
316326
sym = bin2hex(sym, prog->tag, sizeof(prog->tag));
317-
*sym = 0;
327+
if (prog->aux->name[0])
328+
snprintf(sym, (size_t)(end - sym), "_%s", prog->aux->name);
329+
else
330+
*sym = 0;
318331
}
319332

320333
static __always_inline unsigned long

0 commit comments

Comments
 (0)