File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -7316,6 +7316,21 @@ int perf_event_account_interrupt(struct perf_event *event)
7316
7316
return __perf_event_account_interrupt (event , 1 );
7317
7317
}
7318
7318
7319
+ static bool sample_is_allowed (struct perf_event * event , struct pt_regs * regs )
7320
+ {
7321
+ /*
7322
+ * Due to interrupt latency (AKA "skid"), we may enter the
7323
+ * kernel before taking an overflow, even if the PMU is only
7324
+ * counting user events.
7325
+ * To avoid leaking information to userspace, we must always
7326
+ * reject kernel samples when exclude_kernel is set.
7327
+ */
7328
+ if (event -> attr .exclude_kernel && !user_mode (regs ))
7329
+ return false;
7330
+
7331
+ return true;
7332
+ }
7333
+
7319
7334
/*
7320
7335
* Generic event overflow handling, sampling.
7321
7336
*/
@@ -7336,6 +7351,12 @@ static int __perf_event_overflow(struct perf_event *event,
7336
7351
7337
7352
ret = __perf_event_account_interrupt (event , throttle );
7338
7353
7354
+ /*
7355
+ * For security, drop the skid kernel samples if necessary.
7356
+ */
7357
+ if (!sample_is_allowed (event , regs ))
7358
+ return ret ;
7359
+
7339
7360
/*
7340
7361
* XXX event_limit might not quite work as expected on inherited
7341
7362
* events
You can’t perform that action at this time.
0 commit comments