]> git.baikalelectronics.ru Git - kernel.git/commit
mm/mlock: fix two bugs in user_shm_lock()
authorMiaohe Lin <linmiaohe@huawei.com>
Tue, 22 Mar 2022 08:09:18 +0000 (16:09 +0800)
committerEric W. Biederman <ebiederm@xmission.com>
Wed, 23 Mar 2022 16:16:59 +0000 (11:16 -0500)
commit5aaabbbf06e6ea60762369e5c604921a012de819
treee034a0a6eddcd8b5654efbe3f744949e73e2ff47
parent3736f21af07c26497f15a383d04eb9f7ef73695f
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.

Fixes: a7c994e014b0 ("Reimplement RLIMIT_MEMLOCK on top of ucounts")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: stable@vger.kernel.org
v1: https://lkml.kernel.org/r/20220310132417.41189-1-linmiaohe@huawei.com
v2: https://lkml.kernel.org/r/20220314064039.62972-1-linmiaohe@huawei.com
Link: https://lkml.kernel.org/r/20220322080918.59861-1-linmiaohe@huawei.com
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
mm/mlock.c