Skip to content

Commit e92d51a

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Thomas Gleixner: - Prevent a potential inconistency in the perf user space access which might lead to evading sanity checks. - Prevent perf recording function trace entries twice * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/ftrace: Fix double traces of perf on ftrace:function perf/core: Fix potential double-fetch bug
2 parents d0d6ab5 + 75e8387 commit e92d51a

7 files changed

Lines changed: 22 additions & 13 deletions

File tree

include/linux/perf_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ extern void perf_event_init(void);
12011201
extern void perf_tp_event(u16 event_type, u64 count, void *record,
12021202
int entry_size, struct pt_regs *regs,
12031203
struct hlist_head *head, int rctx,
1204-
struct task_struct *task);
1204+
struct task_struct *task, struct perf_event *event);
12051205
extern void perf_bp_event(struct perf_event *event, void *data);
12061206

12071207
#ifndef perf_misc_flags

include/linux/trace_events.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ void perf_trace_run_bpf_submit(void *raw_data, int size, int rctx,
508508
static inline void
509509
perf_trace_buf_submit(void *raw_data, int size, int rctx, u16 type,
510510
u64 count, struct pt_regs *regs, void *head,
511-
struct task_struct *task)
511+
struct task_struct *task, struct perf_event *event)
512512
{
513-
perf_tp_event(type, count, raw_data, size, regs, head, rctx, task);
513+
perf_tp_event(type, count, raw_data, size, regs, head, rctx, task, event);
514514
}
515515
#endif
516516

kernel/events/core.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7906,16 +7906,15 @@ void perf_trace_run_bpf_submit(void *raw_data, int size, int rctx,
79067906
}
79077907
}
79087908
perf_tp_event(call->event.type, count, raw_data, size, regs, head,
7909-
rctx, task);
7909+
rctx, task, NULL);
79107910
}
79117911
EXPORT_SYMBOL_GPL(perf_trace_run_bpf_submit);
79127912

79137913
void perf_tp_event(u16 event_type, u64 count, void *record, int entry_size,
79147914
struct pt_regs *regs, struct hlist_head *head, int rctx,
7915-
struct task_struct *task)
7915+
struct task_struct *task, struct perf_event *event)
79167916
{
79177917
struct perf_sample_data data;
7918-
struct perf_event *event;
79197918

79207919
struct perf_raw_record raw = {
79217920
.frag = {
@@ -7929,9 +7928,15 @@ void perf_tp_event(u16 event_type, u64 count, void *record, int entry_size,
79297928

79307929
perf_trace_buf_update(record, event_type);
79317930

7932-
hlist_for_each_entry_rcu(event, head, hlist_entry) {
7931+
/* Use the given event instead of the hlist */
7932+
if (event) {
79337933
if (perf_tp_event_match(event, &data, regs))
79347934
perf_swevent_event(event, count, &data, regs);
7935+
} else {
7936+
hlist_for_each_entry_rcu(event, head, hlist_entry) {
7937+
if (perf_tp_event_match(event, &data, regs))
7938+
perf_swevent_event(event, count, &data, regs);
7939+
}
79357940
}
79367941

79377942
/*
@@ -9611,6 +9616,8 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
96119616
if (ret)
96129617
return -EFAULT;
96139618

9619+
attr->size = size;
9620+
96149621
if (attr->__reserved_1)
96159622
return -EINVAL;
96169623

kernel/trace/trace_event_perf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ static void
306306
perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip,
307307
struct ftrace_ops *ops, struct pt_regs *pt_regs)
308308
{
309+
struct perf_event *event;
309310
struct ftrace_entry *entry;
310311
struct hlist_head *head;
311312
struct pt_regs regs;
@@ -329,8 +330,9 @@ perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip,
329330

330331
entry->ip = ip;
331332
entry->parent_ip = parent_ip;
333+
event = container_of(ops, struct perf_event, ftrace_ops);
332334
perf_trace_buf_submit(entry, ENTRY_SIZE, rctx, TRACE_FN,
333-
1, &regs, head, NULL);
335+
1, &regs, head, NULL, event);
334336

335337
#undef ENTRY_SIZE
336338
}

kernel/trace/trace_kprobe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
12001200
memset(&entry[1], 0, dsize);
12011201
store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize);
12021202
perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs,
1203-
head, NULL);
1203+
head, NULL, NULL);
12041204
}
12051205
NOKPROBE_SYMBOL(kprobe_perf_func);
12061206

@@ -1236,7 +1236,7 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
12361236
entry->ret_ip = (unsigned long)ri->ret_addr;
12371237
store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize);
12381238
perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs,
1239-
head, NULL);
1239+
head, NULL, NULL);
12401240
}
12411241
NOKPROBE_SYMBOL(kretprobe_perf_func);
12421242
#endif /* CONFIG_PERF_EVENTS */

kernel/trace/trace_syscalls.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id)
596596
(unsigned long *)&rec->args);
597597
perf_trace_buf_submit(rec, size, rctx,
598598
sys_data->enter_event->event.type, 1, regs,
599-
head, NULL);
599+
head, NULL, NULL);
600600
}
601601

602602
static int perf_sysenter_enable(struct trace_event_call *call)
@@ -667,7 +667,7 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
667667
rec->nr = syscall_nr;
668668
rec->ret = syscall_get_return_value(current, regs);
669669
perf_trace_buf_submit(rec, size, rctx, sys_data->exit_event->event.type,
670-
1, regs, head, NULL);
670+
1, regs, head, NULL, NULL);
671671
}
672672

673673
static int perf_sysexit_enable(struct trace_event_call *call)

kernel/trace/trace_uprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ static void __uprobe_perf_func(struct trace_uprobe *tu,
11561156
}
11571157

11581158
perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs,
1159-
head, NULL);
1159+
head, NULL, NULL);
11601160
out:
11611161
preempt_enable();
11621162
}

0 commit comments

Comments
 (0)