linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm/mlock: fix potential imbalanced rlimit ucounts adjustment
@ 2022-03-14  6:40 Miaohe Lin
  2022-03-14 15:21 ` Eric W. Biederman
  0 siblings, 1 reply; 7+ messages in thread
From: Miaohe Lin @ 2022-03-14  6:40 UTC (permalink / raw)
  To: akpm, hughd; +Cc: linux-mm, linux-kernel, linmiaohe

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. Fix
this by resetting allowed to 0.

Fixes: d7c9e99aee48 ("Reimplement RLIMIT_MEMLOCK on top of ucounts")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Acked-by: Hugh Dickins <hughd@google.com>
---
v1->v2:
  correct Fixes tag and collect Acked-by tag
  Thanks Hugh for review!
---
 mm/mlock.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/mlock.c b/mm/mlock.c
index 29372c0eebe5..efd2dd2943de 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -733,6 +733,7 @@ int user_shm_lock(size_t size, struct ucounts *ucounts)
 	}
 	if (!get_ucounts(ucounts)) {
 		dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked);
+		allowed = 0;
 		goto out;
 	}
 	allowed = 1;
-- 
2.23.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-03-17  1:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14  6:40 [PATCH v2] mm/mlock: fix potential imbalanced rlimit ucounts adjustment Miaohe Lin
2022-03-14 15:21 ` Eric W. Biederman
2022-03-15 12:17   ` Miaohe Lin
2022-03-15 18:32     ` Eric W. Biederman
2022-03-16  6:55       ` Miaohe Lin
2022-03-16 14:11         ` Eric W. Biederman
2022-03-17  1:50           ` Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox