Lines Matching +full:i +full:- +full:leak +full:- +full:current
1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright (C) 2009-2010 Frederic Weisbecker <fweisbec@gmail.com>
32 if (tp_event->perf_perm) { in perf_trace_event_perm()
33 ret = tp_event->perf_perm(tp_event, p_event); in perf_trace_event_perm()
42 if (p_event->parent) in perf_trace_event_perm()
46 * It's ok to check current process (owner) permissions in here, in perf_trace_event_perm()
52 ret = perf_allow_tracepoint(&p_event->attr); in perf_trace_event_perm()
64 if (!p_event->attr.exclude_callchain_user) in perf_trace_event_perm()
65 return -EINVAL; in perf_trace_event_perm()
71 if (p_event->attr.sample_type & PERF_SAMPLE_STACK_USER) in perf_trace_event_perm()
72 return -EINVAL; in perf_trace_event_perm()
75 /* No tracing, just counting, so no obvious leak */ in perf_trace_event_perm()
76 if (!(p_event->attr.sample_type & PERF_SAMPLE_RAW)) in perf_trace_event_perm()
79 /* Some events are ok to be traced by non-root users... */ in perf_trace_event_perm()
80 if (p_event->attach_state == PERF_ATTACH_TASK) { in perf_trace_event_perm()
81 if (tp_event->flags & TRACE_EVENT_FL_CAP_ANY) in perf_trace_event_perm()
86 * ...otherwise raw tracepoint data can be a severe data leak, in perf_trace_event_perm()
89 ret = perf_allow_tracepoint(&p_event->attr); in perf_trace_event_perm()
100 int ret = -ENOMEM; in perf_trace_event_reg()
103 p_event->tp_event = tp_event; in perf_trace_event_reg()
104 if (tp_event->perf_refcount++ > 0) in perf_trace_event_reg()
114 tp_event->perf_events = list; in perf_trace_event_reg()
118 int i; in perf_trace_event_reg() local
120 for (i = 0; i < PERF_NR_CONTEXTS; i++) { in perf_trace_event_reg()
125 perf_trace_buf[i] = buf; in perf_trace_event_reg()
129 ret = tp_event->class->reg(tp_event, TRACE_REG_PERF_REGISTER, NULL); in perf_trace_event_reg()
138 int i; in perf_trace_event_reg() local
140 for (i = 0; i < PERF_NR_CONTEXTS; i++) { in perf_trace_event_reg()
141 free_percpu(perf_trace_buf[i]); in perf_trace_event_reg()
142 perf_trace_buf[i] = NULL; in perf_trace_event_reg()
146 if (!--tp_event->perf_refcount) { in perf_trace_event_reg()
147 free_percpu(tp_event->perf_events); in perf_trace_event_reg()
148 tp_event->perf_events = NULL; in perf_trace_event_reg()
156 struct trace_event_call *tp_event = p_event->tp_event; in perf_trace_event_unreg()
157 int i; in perf_trace_event_unreg() local
159 if (--tp_event->perf_refcount > 0) in perf_trace_event_unreg()
162 tp_event->class->reg(tp_event, TRACE_REG_PERF_UNREGISTER, NULL); in perf_trace_event_unreg()
170 free_percpu(tp_event->perf_events); in perf_trace_event_unreg()
171 tp_event->perf_events = NULL; in perf_trace_event_unreg()
173 if (!--total_ref_count) { in perf_trace_event_unreg()
174 for (i = 0; i < PERF_NR_CONTEXTS; i++) { in perf_trace_event_unreg()
175 free_percpu(perf_trace_buf[i]); in perf_trace_event_unreg()
176 perf_trace_buf[i] = NULL; in perf_trace_event_unreg()
183 struct trace_event_call *tp_event = p_event->tp_event; in perf_trace_event_open()
184 return tp_event->class->reg(tp_event, TRACE_REG_PERF_OPEN, p_event); in perf_trace_event_open()
189 struct trace_event_call *tp_event = p_event->tp_event; in perf_trace_event_close()
190 tp_event->class->reg(tp_event, TRACE_REG_PERF_CLOSE, p_event); in perf_trace_event_close()
218 u64 event_id = p_event->attr.config; in perf_trace_init()
219 int ret = -EINVAL; in perf_trace_init()
223 if (tp_event->event.type == event_id && in perf_trace_init()
224 tp_event->class && tp_event->class->reg && in perf_trace_init()
242 trace_event_put_ref(p_event->tp_event); in perf_trace_destroy()
253 if (p_event->attr.kprobe_func) { in perf_kprobe_init()
254 func = strndup_user(u64_to_user_ptr(p_event->attr.kprobe_func), in perf_kprobe_init()
258 return (ret == -EINVAL) ? -E2BIG : ret; in perf_kprobe_init()
268 func, (void *)(unsigned long)(p_event->attr.kprobe_addr), in perf_kprobe_init()
269 p_event->attr.probe_offset, is_retprobe); in perf_kprobe_init()
290 trace_event_put_ref(p_event->tp_event); in perf_kprobe_destroy()
293 destroy_local_trace_kprobe(p_event->tp_event); in perf_kprobe_destroy()
305 if (!p_event->attr.uprobe_path) in perf_uprobe_init()
306 return -EINVAL; in perf_uprobe_init()
308 path = strndup_user(u64_to_user_ptr(p_event->attr.uprobe_path), in perf_uprobe_init()
312 return (ret == -EINVAL) ? -E2BIG : ret; in perf_uprobe_init()
315 ret = -EINVAL; in perf_uprobe_init()
319 tp_event = create_local_trace_uprobe(path, p_event->attr.probe_offset, in perf_uprobe_init()
346 trace_event_put_ref(p_event->tp_event); in perf_uprobe_destroy()
348 destroy_local_trace_uprobe(p_event->tp_event); in perf_uprobe_destroy()
354 struct trace_event_call *tp_event = p_event->tp_event; in perf_trace_add()
357 p_event->hw.state = PERF_HES_STOPPED; in perf_trace_add()
362 * the right per-cpu hlist. in perf_trace_add()
364 if (!tp_event->class->reg(tp_event, TRACE_REG_PERF_ADD, p_event)) { in perf_trace_add()
368 pcpu_list = tp_event->perf_events; in perf_trace_add()
370 return -EINVAL; in perf_trace_add()
373 hlist_add_head_rcu(&p_event->hlist_entry, list); in perf_trace_add()
381 struct trace_event_call *tp_event = p_event->tp_event; in perf_trace_del()
386 * the right per-cpu hlist. in perf_trace_del()
388 if (!tp_event->class->reg(tp_event, TRACE_REG_PERF_DEL, p_event)) in perf_trace_del()
389 hlist_del_rcu(&p_event->hlist_entry); in perf_trace_del()
412 /* zero the dead bytes from align to not leak stack to user */ in perf_trace_buf_alloc()
413 memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64)); in perf_trace_buf_alloc()
446 if ((unsigned long)ops->private != smp_processor_id()) in perf_ftrace_function_call()
452 * @event->hlist entry is NULL (per INIT_HLIST_NODE), and all in perf_ftrace_function_call()
457 head.first = &event->hlist_entry; in perf_ftrace_function_call()
460 sizeof(u64)) - sizeof(u32)) in perf_ftrace_function_call()
471 entry->ip = ip; in perf_ftrace_function_call()
472 entry->parent_ip = parent_ip; in perf_ftrace_function_call()
483 struct ftrace_ops *ops = &event->ftrace_ops; in perf_ftrace_function_register()
485 ops->func = perf_ftrace_function_call; in perf_ftrace_function_register()
486 ops->private = (void *)(unsigned long)nr_cpu_ids; in perf_ftrace_function_register()
493 struct ftrace_ops *ops = &event->ftrace_ops; in perf_ftrace_function_unregister()
516 event->ftrace_ops.private = (void *)(unsigned long)smp_processor_id(); in perf_ftrace_event_register()
519 event->ftrace_ops.private = (void *)(unsigned long)nr_cpu_ids; in perf_ftrace_event_register()
523 return -EINVAL; in perf_ftrace_event_register()