Skip to content

Commit 229e225

Browse files
Gregory Priceakpm00
authored andcommitted
mm/migrate: fix do_pages_move for compat pointers
do_pages_move does not handle compat pointers for the page list. correctly. Add in_compat_syscall check and appropriate get_user fetch when iterating the page list. It makes the syscall in compat mode (32-bit userspace, 64-bit kernel) work the same way as the native 32-bit syscall again, restoring the behavior before my broken commit 5b1b561 ("mm: simplify compat_sys_move_pages"). More specifically, my patch moved the parsing of the 'pages' array from the main entry point into do_pages_stat(), which left the syscall working correctly for the 'stat' operation (nodes = NULL), while the 'move' operation (nodes != NULL) is now missing the conversion and interprets 'pages' as an array of 64-bit pointers instead of the intended 32-bit userspace pointers. It is possible that nobody noticed this bug because the few applications that actually call move_pages are unlikely to run in compat mode because of their large memory requirements, but this clearly fixes a user-visible regression and should have been caught by ltp. Link: https://lkml.kernel.org/r/[email protected] Fixes: 5b1b561 ("mm: simplify compat_sys_move_pages") Signed-off-by: Gregory Price <[email protected]> Reported-by: Arnd Bergmann <[email protected]> Co-developed-by: Arnd Bergmann <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1de195d commit 229e225

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mm/migrate.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
21622162
const int __user *nodes,
21632163
int __user *status, int flags)
21642164
{
2165+
compat_uptr_t __user *compat_pages = (void __user *)pages;
21652166
int current_node = NUMA_NO_NODE;
21662167
LIST_HEAD(pagelist);
21672168
int start, i;
@@ -2174,8 +2175,17 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
21742175
int node;
21752176

21762177
err = -EFAULT;
2177-
if (get_user(p, pages + i))
2178-
goto out_flush;
2178+
if (in_compat_syscall()) {
2179+
compat_uptr_t cp;
2180+
2181+
if (get_user(cp, compat_pages + i))
2182+
goto out_flush;
2183+
2184+
p = compat_ptr(cp);
2185+
} else {
2186+
if (get_user(p, pages + i))
2187+
goto out_flush;
2188+
}
21792189
if (get_user(node, nodes + i))
21802190
goto out_flush;
21812191

0 commit comments

Comments
 (0)