]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: include sub program tags in bpf_prog_info
authorSong Liu <songliubraving@fb.com>
Wed, 12 Dec 2018 17:37:46 +0000 (09:37 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 13 Dec 2018 11:22:28 +0000 (12:22 +0100)
Changes v2 -> v3:
1. remove check for bpf_dump_raw_ok().

Changes v1 -> v2:
1. Fix error path as Martin suggested.

This patch adds nr_prog_tags and prog_tags to bpf_prog_info. This is a
reliable way for user space to get tags of all sub programs. Before this
patch, user space need to find sub program tags via kallsyms.

This feature will be used in BPF introspection, where user space queries
information about BPF programs via sys_bpf.

Signed-off-by: Song Liu <songliubraving@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/uapi/linux/bpf.h
kernel/bpf/syscall.c

index aa582cd5bfcfab38abab4a5562288ae8cab01d67..e7d57e89f25fc7932c4af6a64f23203e93e30e65 100644 (file)
@@ -2717,6 +2717,8 @@ struct bpf_prog_info {
        __u32 nr_jited_line_info;
        __u32 line_info_rec_size;
        __u32 jited_line_info_rec_size;
+       __u32 nr_prog_tags;
+       __aligned_u64 prog_tags;
 } __attribute__((aligned(8)));
 
 struct bpf_map_info {
index b7c585838c723e25cbd1d2b352973a5b634590bd..7f1410d6fbe9ac9ce3877e37f0222ce45442a025 100644 (file)
@@ -2315,6 +2315,28 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
                }
        }
 
+       ulen = info.nr_prog_tags;
+       info.nr_prog_tags = prog->aux->func_cnt ? : 1;
+       if (ulen) {
+               __u8 __user (*user_prog_tags)[BPF_TAG_SIZE];
+               u32 i;
+
+               user_prog_tags = u64_to_user_ptr(info.prog_tags);
+               ulen = min_t(u32, info.nr_prog_tags, ulen);
+               if (prog->aux->func_cnt) {
+                       for (i = 0; i < ulen; i++) {
+                               if (copy_to_user(user_prog_tags[i],
+                                                prog->aux->func[i]->tag,
+                                                BPF_TAG_SIZE))
+                                       return -EFAULT;
+                       }
+               } else {
+                       if (copy_to_user(user_prog_tags[0],
+                                        prog->tag, BPF_TAG_SIZE))
+                               return -EFAULT;
+               }
+       }
+
 done:
        if (copy_to_user(uinfo, &info, info_len) ||
            put_user(info_len, &uattr->info.info_len))