Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next
[linux-2.6-microblaze.git] / kernel / events / core.c
index 7c436d7..d1f0a7e 100644 (file)
@@ -9644,6 +9644,24 @@ static int perf_event_set_bpf_handler(struct perf_event *event, u32 prog_fd)
        if (IS_ERR(prog))
                return PTR_ERR(prog);
 
+       if (event->attr.precise_ip &&
+           prog->call_get_stack &&
+           (!(event->attr.sample_type & __PERF_SAMPLE_CALLCHAIN_EARLY) ||
+            event->attr.exclude_callchain_kernel ||
+            event->attr.exclude_callchain_user)) {
+               /*
+                * On perf_event with precise_ip, calling bpf_get_stack()
+                * may trigger unwinder warnings and occasional crashes.
+                * bpf_get_[stack|stackid] works around this issue by using
+                * callchain attached to perf_sample_data. If the
+                * perf_event does not full (kernel and user) callchain
+                * attached to perf_sample_data, do not allow attaching BPF
+                * program that calls bpf_get_[stack|stackid].
+                */
+               bpf_prog_put(prog);
+               return -EPROTO;
+       }
+
        event->prog = prog;
        event->orig_overflow_handler = READ_ONCE(event->overflow_handler);
        WRITE_ONCE(event->overflow_handler, bpf_overflow_handler);
@@ -11585,7 +11603,7 @@ SYSCALL_DEFINE5(perf_event_open,
        struct perf_event *group_leader = NULL, *output_event = NULL;
        struct perf_event *event, *sibling;
        struct perf_event_attr attr;
-       struct perf_event_context *ctx, *uninitialized_var(gctx);
+       struct perf_event_context *ctx, *gctx;
        struct file *event_file = NULL;
        struct fd group = {NULL, 0};
        struct task_struct *task = NULL;