Skip to content

Commit e091cc1

Browse files
KAGA-KOKOgregkh
authored andcommitted
perf/core: Don't leak AUX buffer refcount on allocation failure
commit 5468c0f upstream. Failure of the AUX buffer allocation leaks the reference count. Set the reference count to 1 only when the allocation succeeds. Fixes: 45bfb2e ("perf/core: 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 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1998919 commit e091cc1

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

kernel/events/core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6988,8 +6988,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
69886988
ret = 0;
69896989
goto unlock;
69906990
}
6991-
6992-
atomic_set(&rb->aux_mmap_count, 1);
69936991
}
69946992

69956993
user_lock_limit = sysctl_perf_event_mlock >> (PAGE_SHIFT - 10);
@@ -7056,8 +7054,10 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
70567054
} else {
70577055
ret = rb_alloc_aux(rb, event, vma->vm_pgoff, nr_pages,
70587056
event->attr.aux_watermark, flags);
7059-
if (!ret)
7057+
if (!ret) {
7058+
atomic_set(&rb->aux_mmap_count, 1);
70607059
rb->aux_mmap_locked = extra;
7060+
}
70617061
}
70627062

70637063
unlock:
@@ -7067,6 +7067,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
70677067

70687068
atomic_inc(&event->mmap_count);
70697069
} else if (rb) {
7070+
/* AUX allocation failed */
70707071
atomic_dec(&rb->mmap_count);
70717072
}
70727073
aux_unlock:

0 commit comments

Comments
 (0)