Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'perf_urgent_for_v6.1_rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf fixes from Borislav Petkov:
"Two more fixes to the perf sigtrap handling:

- output the address in the sample only when it has been requested

- handle the case where user-only events can hit in kernel and thus
upset the sigtrap sanity checking"

* tag 'perf_urgent_for_v6.1_rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf: Consider OS filter fail
perf: Fixup SIGTRAP and sample_flags interaction

+25 -2
+25 -2
kernel/events/core.c
··· 9273 9273 return __perf_event_account_interrupt(event, 1); 9274 9274 } 9275 9275 9276 + static inline bool sample_is_allowed(struct perf_event *event, struct pt_regs *regs) 9277 + { 9278 + /* 9279 + * Due to interrupt latency (AKA "skid"), we may enter the 9280 + * kernel before taking an overflow, even if the PMU is only 9281 + * counting user events. 9282 + */ 9283 + if (event->attr.exclude_kernel && !user_mode(regs)) 9284 + return false; 9285 + 9286 + return true; 9287 + } 9288 + 9276 9289 /* 9277 9290 * Generic event overflow handling, sampling. 9278 9291 */ ··· 9319 9306 } 9320 9307 9321 9308 if (event->attr.sigtrap) { 9309 + /* 9310 + * The desired behaviour of sigtrap vs invalid samples is a bit 9311 + * tricky; on the one hand, one should not loose the SIGTRAP if 9312 + * it is the first event, on the other hand, we should also not 9313 + * trigger the WARN or override the data address. 9314 + */ 9315 + bool valid_sample = sample_is_allowed(event, regs); 9322 9316 unsigned int pending_id = 1; 9323 9317 9324 9318 if (regs) ··· 9333 9313 if (!event->pending_sigtrap) { 9334 9314 event->pending_sigtrap = pending_id; 9335 9315 local_inc(&event->ctx->nr_pending); 9336 - } else if (event->attr.exclude_kernel) { 9316 + } else if (event->attr.exclude_kernel && valid_sample) { 9337 9317 /* 9338 9318 * Should not be able to return to user space without 9339 9319 * consuming pending_sigtrap; with exceptions: ··· 9348 9328 */ 9349 9329 WARN_ON_ONCE(event->pending_sigtrap != pending_id); 9350 9330 } 9351 - event->pending_addr = data->addr; 9331 + 9332 + event->pending_addr = 0; 9333 + if (valid_sample && (data->sample_flags & PERF_SAMPLE_ADDR)) 9334 + event->pending_addr = data->addr; 9352 9335 irq_work_queue(&event->pending_irq); 9353 9336 } 9354 9337