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

perf/core: Don't leak AUX buffer refcount on allocation failure

Failure of the AUX buffer allocation leaks the reference count.

Set the reference count to 1 only when the allocation succeeds.

Fixes: 45bfb2e50471 ("perf: Add AUX area to ring buffer for raw data streams")
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: stable@vger.kernel.org

+4 -3
+4 -3
kernel/events/core.c
··· 7051 7051 ret = 0; 7052 7052 goto unlock; 7053 7053 } 7054 - 7055 - atomic_set(&rb->aux_mmap_count, 1); 7056 7054 } 7057 7055 7058 7056 user_lock_limit = sysctl_perf_event_mlock >> (PAGE_SHIFT - 10); ··· 7117 7119 } else { 7118 7120 ret = rb_alloc_aux(rb, event, vma->vm_pgoff, nr_pages, 7119 7121 event->attr.aux_watermark, flags); 7120 - if (!ret) 7122 + if (!ret) { 7123 + atomic_set(&rb->aux_mmap_count, 1); 7121 7124 rb->aux_mmap_locked = extra; 7125 + } 7122 7126 } 7123 7127 7124 7128 unlock: ··· 7130 7130 7131 7131 atomic_inc(&event->mmap_count); 7132 7132 } else if (rb) { 7133 + /* AUX allocation failed */ 7133 7134 atomic_dec(&rb->mmap_count); 7134 7135 } 7135 7136 aux_unlock: