]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
bpf: Append prog->aux->name in bpf_get_prog_name()
authorMartin KaFai Lau <kafai@fb.com>
Fri, 6 Oct 2017 04:52:13 +0000 (21:52 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 7 Oct 2017 22:29:39 +0000 (23:29 +0100)
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 <kafai@fb.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/core.c

index c6be15ae83ee7435d60004263128823caf334a6a..248961af2421d0ce554c0d5f1805df00569fbc4b 100644 (file)
@@ -309,12 +309,25 @@ bpf_get_prog_addr_region(const struct bpf_prog *prog,
 
 static void bpf_get_prog_name(const struct bpf_prog *prog, char *sym)
 {
+       const char *end = sym + KSYM_NAME_LEN;
+
        BUILD_BUG_ON(sizeof("bpf_prog_") +
-                    sizeof(prog->tag) * 2 + 1 > KSYM_NAME_LEN);
+                    sizeof(prog->tag) * 2 +
+                    /* name has been null terminated.
+                     * We should need +1 for the '_' preceding
+                     * the name.  However, the null character
+                     * is double counted between the name and the
+                     * sizeof("bpf_prog_") above, so we omit
+                     * the +1 here.
+                     */
+                    sizeof(prog->aux->name) > KSYM_NAME_LEN);
 
        sym += snprintf(sym, KSYM_NAME_LEN, "bpf_prog_");
        sym  = bin2hex(sym, prog->tag, sizeof(prog->tag));
-       *sym = 0;
+       if (prog->aux->name[0])
+               snprintf(sym, (size_t)(end - sym), "_%s", prog->aux->name);
+       else
+               *sym = 0;
 }
 
 static __always_inline unsigned long