* + mm-mlock-fix-two-bugs-in-user_shm_lock.patch added to -mm tree
@ 2022-03-26 2:05 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2022-03-26 2:05 UTC (permalink / raw)
To: mm-commits, legion, hughd, ebiederm, linmiaohe, akpm
The patch titled
Subject: mm/mlock: fix two bugs in user_shm_lock()
has been added to the -mm tree. Its filename is
mm-mlock-fix-two-bugs-in-user_shm_lock.patch
This patch should soon appear at
https://ozlabs.org/~akpm/mmots/broken-out/mm-mlock-fix-two-bugs-in-user_shm_lock.patch
and later at
https://ozlabs.org/~akpm/mmotm/broken-out/mm-mlock-fix-two-bugs-in-user_shm_lock.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated
there every 3-4 working days
------------------------------------------------------
From: Miaohe Lin <linmiaohe@huawei.com>
Subject: mm/mlock: fix two bugs in user_shm_lock()
user_shm_lock forgets to set allowed to 0 when get_ucounts fails. So the
later user_shm_unlock might do the extra dec_rlimit_ucounts. Also in the
RLIM_INFINITY case, user_shm_lock will success regardless of the value of
memlock where memblock == LONG_MAX && !capable(CAP_IPC_LOCK) should fail.
Fix all of these by changing the code to leave lock_limit at ULONG_MAX aka
RLIM_INFINITY, leave "allowed" initialized to 0 and remove the special
case of RLIM_INFINITY as nothing can be greater than ULONG_MAX.
Credit goes to Eric W. Biederman for proposing simplifying the code and
thus catching the later bug.
Link: https://lkml.kernel.org/r/20220322080918.59861-1-linmiaohe@huawei.com
Fixes: d7c9e99aee48 ("Reimplement RLIMIT_MEMLOCK on top of ucounts")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Alexey Gladkov <legion@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/mlock.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
--- a/mm/mlock.c~mm-mlock-fix-two-bugs-in-user_shm_lock
+++ a/mm/mlock.c
@@ -721,13 +721,12 @@ int user_shm_lock(size_t size, struct uc
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;
}
_
Patches currently in -mm which might be from linmiaohe@huawei.com are
mm-mremap-use-helper-mlock_future_check.patch
mm-mlock-fix-two-bugs-in-user_shm_lock.patch
mm-compaction-use-helper-isolation_suitable.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-26 2:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-26 2:05 + mm-mlock-fix-two-bugs-in-user_shm_lock.patch added to -mm tree Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.