summaryrefslogtreecommitdiff
path: root/mm/mlock.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2022-03-28 17:10:07 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2022-03-28 17:10:07 -0700
commit0a815d0135f1be20c1a04d07f7573a26272ef846 (patch)
tree22880ee573e2cbe142933345782c478d5c1876ea /mm/mlock.c
parentd717e4cae0fe77e10a27e8545a967b8c379873ac (diff)
parente97824ff663ce3509fe040431c713182c2f058b1 (diff)
downloadlwn-0a815d0135f1be20c1a04d07f7573a26272ef846.tar.gz
lwn-0a815d0135f1be20c1a04d07f7573a26272ef846.zip
Merge tag 'ucount-rlimit-for-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull shm ucounts fix from Eric Biederman: "The introduction of a new failure mode when the code was converted to ucounts resulted in user_shm_lock misbehaving. The change simplifies the code to make the code easier to follow and removes the known misbehaviors" * tag 'ucount-rlimit-for-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: mm/mlock: fix two bugs in user_shm_lock()
Diffstat (limited to 'mm/mlock.c')
-rw-r--r--mm/mlock.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/mm/mlock.c b/mm/mlock.c
index efd2dd2943de..529fbc1f27c8 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -721,13 +721,12 @@ int user_shm_lock(size_t size, struct ucounts *ucounts)
locked = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
lock_limit = rlimit(RLIMIT_MEMLOCK);
- if (lock_limit == RLIM_INFINITY)
- allowed = 1;
- lock_limit >>= PAGE_SHIFT;
+ if (lock_limit != RLIM_INFINITY)
+ lock_limit >>= PAGE_SHIFT;
spin_lock(&shmlock_user_lock);
memlock = inc_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked);
- if (!allowed && (memlock == LONG_MAX || memlock > lock_limit) && !capable(CAP_IPC_LOCK)) {
+ if ((memlock == LONG_MAX || memlock > lock_limit) && !capable(CAP_IPC_LOCK)) {
dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked);
goto out;
}