Skip to content

Commit 5468c0f

Browse files
committed
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: 45bfb2e ("perf: Add AUX area to ring buffer for raw data streams") Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Cc: [email protected]
1 parent 54473e0 commit 5468c0f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/events/core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7051,8 +7051,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
70517051
ret = 0;
70527052
goto unlock;
70537053
}
7054-
7055-
atomic_set(&rb->aux_mmap_count, 1);
70567054
}
70577055

70587056
user_lock_limit = sysctl_perf_event_mlock >> (PAGE_SHIFT - 10);
@@ -7119,8 +7117,10 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
71197117
} else {
71207118
ret = rb_alloc_aux(rb, event, vma->vm_pgoff, nr_pages,
71217119
event->attr.aux_watermark, flags);
7122-
if (!ret)
7120+
if (!ret) {
7121+
atomic_set(&rb->aux_mmap_count, 1);
71237122
rb->aux_mmap_locked = extra;
7123+
}
71247124
}
71257125

71267126
unlock:
@@ -7130,6 +7130,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
71307130

71317131
atomic_inc(&event->mmap_count);
71327132
} else if (rb) {
7133+
/* AUX allocation failed */
71337134
atomic_dec(&rb->mmap_count);
71347135
}
71357136
aux_unlock:

0 commit comments

Comments
 (0)