]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/mempolicy: fix get_nodes out of bound access
authorTianyu Li <tianyu.li@arm.com>
Wed, 1 Jun 2022 09:32:11 +0000 (17:32 +0800)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 20 Jul 2022 00:15:02 +0000 (20:15 -0400)
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: e130242dc351 ("mm: simplify compat numa syscalls")
Signed-off-by: Tianyu Li <tianyu.li@arm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mempolicy.c

index b879a326bfb7155b07f4cfe67fc498223dc146ad..dc74239d1ac77675ed8f8db3e0ba36285bbe927b 100644 (file)
@@ -1397,7 +1397,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) {