From: Tianyu Li Date: Wed, 1 Jun 2022 09:32:11 +0000 (+0800) Subject: mm/mempolicy: fix get_nodes out of bound access X-Git-Tag: baikal/mips/sdk5.9~323 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=fcbca57cacb586c7b2a26c9813bb16a496c7c67e;p=kernel.git mm/mempolicy: fix get_nodes out of bound access [ Upstream commit 01697af165bbe2a3e4ac8f4a985c71b2025f9549 ] When user specified more nodes than supported, get_nodes will access nmask array out of bounds. Link: https://lkml.kernel.org/r/20220601093211.2970565-1-tianyu.li@arm.com Fixes: 4ed2e8d12f40 ("mm: simplify compat numa syscalls") Signed-off-by: Tianyu Li Cc: Arnd Bergmann Cc: Mark Rutland Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 9db0158155e1a..4472be6f123db 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1389,7 +1389,7 @@ static int get_nodes(nodemask_t *nodes, const unsigned long __user *nmask, unsigned long bits = min_t(unsigned long, maxnode, BITS_PER_LONG); unsigned long t; - if (get_bitmap(&t, &nmask[maxnode / BITS_PER_LONG], bits)) + if (get_bitmap(&t, &nmask[(maxnode - 1) / BITS_PER_LONG], bits)) return -EFAULT; if (maxnode - bits >= MAX_NUMNODES) {