Merge tag 'mlx5-updates-2021-04-21' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / kernel / bpf / syscall.c
index c3bb03c..fd49519 100644 (file)
@@ -854,6 +854,11 @@ static int map_create(union bpf_attr *attr)
                        err = PTR_ERR(btf);
                        goto free_map;
                }
+               if (btf_is_kernel(btf)) {
+                       btf_put(btf);
+                       err = -EACCES;
+                       goto free_map;
+               }
                map->btf = btf;
 
                if (attr->btf_value_type_id) {
@@ -1689,7 +1694,9 @@ static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred)
 {
        bpf_prog_kallsyms_del_all(prog);
        btf_put(prog->aux->btf);
-       bpf_prog_free_linfo(prog);
+       kvfree(prog->aux->jited_linfo);
+       kvfree(prog->aux->linfo);
+       kfree(prog->aux->kfunc_tab);
        if (prog->aux->attach_btf)
                btf_put(prog->aux->attach_btf);
 
@@ -1731,25 +1738,28 @@ static int bpf_prog_release(struct inode *inode, struct file *filp)
 static void bpf_prog_get_stats(const struct bpf_prog *prog,
                               struct bpf_prog_stats *stats)
 {
-       u64 nsecs = 0, cnt = 0;
+       u64 nsecs = 0, cnt = 0, misses = 0;
        int cpu;
 
        for_each_possible_cpu(cpu) {
                const struct bpf_prog_stats *st;
                unsigned int start;
-               u64 tnsecs, tcnt;
+               u64 tnsecs, tcnt, tmisses;
 
-               st = per_cpu_ptr(prog->aux->stats, cpu);
+               st = per_cpu_ptr(prog->stats, cpu);
                do {
                        start = u64_stats_fetch_begin_irq(&st->syncp);
                        tnsecs = st->nsecs;
                        tcnt = st->cnt;
+                       tmisses = st->misses;
                } while (u64_stats_fetch_retry_irq(&st->syncp, start));
                nsecs += tnsecs;
                cnt += tcnt;
+               misses += tmisses;
        }
        stats->nsecs = nsecs;
        stats->cnt = cnt;
+       stats->misses = misses;
 }
 
 #ifdef CONFIG_PROC_FS
@@ -1768,14 +1778,16 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)
                   "memlock:\t%llu\n"
                   "prog_id:\t%u\n"
                   "run_time_ns:\t%llu\n"
-                  "run_cnt:\t%llu\n",
+                  "run_cnt:\t%llu\n"
+                  "recursion_misses:\t%llu\n",
                   prog->type,
                   prog->jited,
                   prog_tag,
                   prog->pages * 1ULL << PAGE_SHIFT,
                   prog->aux->id,
                   stats.nsecs,
-                  stats.cnt);
+                  stats.cnt,
+                  stats.misses);
 }
 #endif
 
@@ -2539,6 +2551,9 @@ static int bpf_tracing_link_fill_link_info(const struct bpf_link *link,
                container_of(link, struct bpf_tracing_link, link);
 
        info->tracing.attach_type = tr_link->attach_type;
+       bpf_trampoline_unpack_key(tr_link->trampoline->key,
+                                 &info->tracing.target_obj_id,
+                                 &info->tracing.target_btf_id);
 
        return 0;
 }
@@ -2712,7 +2727,6 @@ out_unlock:
 out_put_prog:
        if (tgt_prog_fd && tgt_prog)
                bpf_prog_put(tgt_prog);
-       bpf_prog_put(prog);
        return err;
 }
 
@@ -2825,7 +2839,10 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr)
                        tp_name = prog->aux->attach_func_name;
                        break;
                }
-               return bpf_tracing_prog_attach(prog, 0, 0);
+               err = bpf_tracing_prog_attach(prog, 0, 0);
+               if (err >= 0)
+                       return err;
+               goto out_put_prog;
        case BPF_PROG_TYPE_RAW_TRACEPOINT:
        case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
                if (strncpy_from_user(buf,
@@ -2934,6 +2951,7 @@ attach_type_to_prog_type(enum bpf_attach_type attach_type)
                return BPF_PROG_TYPE_SK_MSG;
        case BPF_SK_SKB_STREAM_PARSER:
        case BPF_SK_SKB_STREAM_VERDICT:
+       case BPF_SK_SKB_VERDICT:
                return BPF_PROG_TYPE_SK_SKB;
        case BPF_LIRC_MODE2:
                return BPF_PROG_TYPE_LIRC_MODE2;
@@ -3436,6 +3454,7 @@ static int bpf_prog_get_info_by_fd(struct file *file,
        bpf_prog_get_stats(prog, &stats);
        info.run_time_ns = stats.nsecs;
        info.run_cnt = stats.cnt;
+       info.recursion_misses = stats.misses;
 
        if (!bpf_capable()) {
                info.jited_prog_len = 0;