The runtime nodemask conversion limits source iteration and weight calculations in do_migrate_pages() to the runtime node range. Reject userspace source masks containing node IDs at or above nr_node_ids instead of silently ignoring those bits during migration selection. Check the full MAX_NUMNODES-wide mask after copying old_nodes and return -EINVAL if any source bit lies outside the runtime range. Keep the existing destination permission checks and the do_migrate_pages() API. Signed-off-by: Yury Norov --- mm/mempolicy.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index ffe4e45cc97d..67e258c62527 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1905,6 +1905,12 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode, if (err) goto out; + /* Source node IDs must fit within the runtime nodemask. */ + if (__next_node(nr_node_ids - 1, old, MAX_NUMNODES) < MAX_NUMNODES) { + err = -EINVAL; + goto out; + } + err = get_nodes(new, new_nodes, maxnode); if (err) goto out; -- 2.53.0