Skip to content

Commit 0034615

Browse files
liu-song-6Ingo Molnar
authored andcommitted
perf/core: Fix mlock accounting in perf_mmap()
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 <[email protected]> Signed-off-by: Song Liu <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: <[email protected]> Acked-by: Alexander Shishkin <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b0be0ef commit 0034615

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

kernel/events/core.c

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

5919-
user_locked = atomic_long_read(&user->locked_vm) + user_extra;
5919+
user_locked = atomic_long_read(&user->locked_vm);
5920+
5921+
/*
5922+
* sysctl_perf_event_mlock may have changed, so that
5923+
* user->locked_vm > user_lock_limit
5924+
*/
5925+
if (user_locked > user_lock_limit)
5926+
user_locked = user_lock_limit;
5927+
user_locked += user_extra;
59205928

59215929
if (user_locked > user_lock_limit) {
59225930
/*

0 commit comments

Comments
 (0)