perf/ring_buffer: Refuse to begin AUX transaction after rb->aux_mmap_count drops
[cascardo/linux.git] / kernel / events / ring_buffer.c
index c61f0cb..89abf62 100644 (file)
@@ -287,6 +287,13 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
        if (!rb_has_aux(rb) || !atomic_inc_not_zero(&rb->aux_refcount))
                goto err;
 
+       /*
+        * If rb::aux_mmap_count is zero (and rb_has_aux() above went through),
+        * the aux buffer is in perf_mmap_close(), about to get freed.
+        */
+       if (!atomic_read(&rb->aux_mmap_count))
+               goto err;
+
        /*
         * Nesting is not supported for AUX area, make sure nested
         * writers are caught early