Skip to content

Commit 7438239

Browse files
liu-song-6gregkh
authored andcommitted
perf/core: Fix mlock accounting in perf_mmap()
commit 0034615 upstream. Decreasing sysctl_perf_event_mlock between two consecutive perf_mmap()s of a perf ring buffer may lead to an integer underflow in locked memory accounting. This may lead to the undesired behaviors, such as failures in BPF map creation. Address this by adjusting the accounting logic to take into account the possibility that the amount of already locked memory may exceed the current limit. Fixes: c4b7547 ("perf/core: Make the mlock accounting simple again") Suggested-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: <stable@vger.kernel.org> Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> Link: https://lkml.kernel.org/r/20200123181146.2238074-1-songliubraving@fb.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d131803 commit 7438239

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎kernel/events/core.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5823,7 +5823,15 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
58235823
*/
58245824
user_lock_limit *= num_online_cpus();
58255825

5826-
user_locked = atomic_long_read(&user->locked_vm) + user_extra;
5826+
user_locked = atomic_long_read(&user->locked_vm);
5827+
5828+
/*
5829+
* sysctl_perf_event_mlock may have changed, so that
5830+
* user->locked_vm > user_lock_limit
5831+
*/
5832+
if (user_locked > user_lock_limit)
5833+
user_locked = user_lock_limit;
5834+
user_locked += user_extra;
58275835

58285836
if (user_locked <= user_lock_limit) {
58295837
/* charge all to locked_vm */

0 commit comments

Comments
 (0)