]> git.ipfire.org Git - people/arne_f/kernel.git/blobdiff - kernel/events/core.c
Merge tag 'v4.9.32' into linux-4.9.x-grsecurity-3.1
[people/arne_f/kernel.git] / kernel / events / core.c
index 26e027195a76749bc7a86239a6a6f152ab20e8b9..927cde53d5709a746276e0a352920fda3efde68e 100644 (file)
@@ -7070,6 +7070,21 @@ static void perf_log_itrace_start(struct perf_event *event)
        perf_output_end(&handle);
 }
 
+static bool sample_is_allowed(struct perf_event *event, struct pt_regs *regs)
+{
+       /*
+        * Due to interrupt latency (AKA "skid"), we may enter the
+        * kernel before taking an overflow, even if the PMU is only
+        * counting user events.
+        * To avoid leaking information to userspace, we must always
+        * reject kernel samples when exclude_kernel is set.
+        */
+       if (event->attr.exclude_kernel && !user_mode(regs))
+               return false;
+
+       return true;
+}
+
 /*
  * Generic event overflow handling, sampling.
  */
@@ -7116,6 +7131,12 @@ static int __perf_event_overflow(struct perf_event *event,
                        perf_adjust_period(event, delta, hwc->last_period, true);
        }
 
+       /*
+        * For security, drop the skid kernel samples if necessary.
+        */
+       if (!sample_is_allowed(event, regs))
+               return ret;
+
        /*
         * XXX event_limit might not quite work as expected on inherited
         * events