Linux/linux a85dfc3mm mempolicy.c

mm: mempolicy: fix the wrong return value and potential pages leak of mbind

Commit d883544515aa ("mm: mempolicy: make the behavior consistent when
MPOL_MF_MOVE* and MPOL_MF_STRICT were specified") fixed the return value
of mbind() for a couple of corner cases.  But, it altered the errno for
some other cases, for example, mbind() should return -EFAULT when part
or all of the memory range specified by nodemask and maxnode points
outside your accessible address space, or there was an unmapped hole in
the specified memory range specified by addr and len.

Fix this by preserving the errno returned by queue_pages_range().  And,
the pagelist may be not empty even though queue_pages_range() returns
error, put the pages back to LRU since mbind_range() is not called to
really apply the policy so those pages should not be migrated, this is
also the old behavior before the problematic commit.

Link: http://lkml.kernel.org/r/1572454731-3925-1-git-send-email-yang.shi@linux.alibaba.com
Fixes: d883544515aa ("mm: mempolicy: make the behavior consistent when MPOL_MF_MOVE* and MPOL_MF_STRICT were specified")
Signed-off-by: Yang Shi <yang.shi at linux.alibaba.com>
Reported-by: Li Xinhai <lixinhai.lxh at gmail.com>
Reviewed-by: Li Xinhai <lixinhai.lxh at gmail.com>
Cc: Vlastimil Babka <vbabka at suse.cz>
Cc: Michal Hocko <mhocko at suse.com>
Cc: Mel Gorman <mgorman at techsingularity.net>
Cc: <stable at vger.kernel.org>    [4.19 and 5.2+]
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
DeltaFile
+9-5mm/mempolicy.c
+9-51 files

UnifiedSplitRaw