From: Yisheng Xie Date: Thu, 22 Mar 2018 23:17:02 +0000 (-0700) Subject: mm/mempolicy.c: avoid use uninitialized preferred_node X-Git-Tag: v3.2.102~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c218eb3152efa5b424e3c6951d6796a357a45f05;p=thirdparty%2Fkernel%2Fstable.git mm/mempolicy.c: avoid use uninitialized preferred_node commit 8970a63e965b43288c4f5f40efbc2bbf80de7f16 upstream. Alexander reported a use of uninitialized memory in __mpol_equal(), which is caused by incorrect use of preferred_node. When mempolicy in mode MPOL_PREFERRED with flags MPOL_F_LOCAL, it uses numa_node_id() instead of preferred_node, however, __mpol_equal() uses preferred_node without checking whether it is MPOL_F_LOCAL or not. [akpm@linux-foundation.org: slight comment tweak] Link: http://lkml.kernel.org/r/4ebee1c2-57f6-bcb8-0e2d-1833d1ee0bb7@huawei.com Fixes: fc36b8d3d819 ("mempolicy: use MPOL_F_LOCAL to Indicate Preferred Local Policy") Signed-off-by: Yisheng Xie Reported-by: Alexander Potapenko Tested-by: Alexander Potapenko Reviewed-by: Andrew Morton Cc: Dmitriy Vyukov Cc: Vlastimil Babka Cc: Michal Hocko Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Ben Hutchings --- diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 1ea67ad062db4..b056dc2f73da4 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2019,6 +2019,9 @@ int __mpol_equal(struct mempolicy *a, struct mempolicy *b) case MPOL_INTERLEAVE: return nodes_equal(a->v.nodes, b->v.nodes); case MPOL_PREFERRED: + /* a's ->flags is the same as b's */ + if (a->flags & MPOL_F_LOCAL) + return true; return a->v.preferred_node == b->v.preferred_node; default: BUG();