Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2469929imm; Mon, 28 May 2018 08:41:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoYuS2wqTdztsUzXG6qukTWVUel6SD70jYf6hAkJZhadggIvn2ber2YhKHwdcFnLN3smeJP X-Received: by 2002:a17:902:700a:: with SMTP id y10-v6mr12719983plk.249.1527522063101; Mon, 28 May 2018 08:41:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527522063; cv=none; d=google.com; s=arc-20160816; b=cUHp0uhAJUOjc04zdH2X8T/w4skht06zHb/AmGAZCImxVweMEW6Lqe93ht3iulgn3z +HxG5bgCmQaEaSXkVQdu/ik8LC2RDvcer/8B13/bTNHxEYgdrtCwyzRaJk9VJ8RQobq4 q1Vuo6mLAWuggoJJycQr/8iu7cYJNNpo/5sF+aX/G7Tu6vcoQCsHMniZjwZ9UgnKo+VX eaOz8t9qhIuxyBGF9mEGcbN5SMRQHm7nis8CdMUrzHjSJOHq+myBXuhrnn0l40JzvYpZ CHAzK4hOwvzjJ2Odtfh3I8joIzhs/o9C2EnYzIwzOUcGGHCzMkBZbIy8J2KG9JfapO4H Cj4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=XKXsPfWFCoRrQwSMjXEE0/4q5n3ohCuatti9ZrvF6+k=; b=xiL0ZtPolSZsJKSkqaZw+oC9XsFhSjlmFSkMV7oJmktrRR71BWyvvJ11JF5J2Vdkty ygYSyEufyoMmmqI4YbVrhtwWavtjpgnPjlc4zEmNlEpYmO3KOrCEsGyavd892Gp/qkkV 0C/fuEpaeXPkYCWp0UWJwwN8FaXTZbIAqPL/86Kn4xo+2vrFrFdQcOQzjSWrzhod3jnO Uwepm6qEGscTi+cTeSz93cfyzZIYTcEAlxLraIjIRw2T8dNwgYKt0rVq7rqMZ2167XQ1 1YzS0H07cHVFmSRApIJbWcjls2iUAXCkMkI4NlO2JxURU5S355tbU5pIDbiRANbxH/Vy iqmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NNfNw2lx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3-v6si31222483plf.436.2018.05.28.08.40.48; Mon, 28 May 2018 08:41:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NNfNw2lx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030906AbeE1KRu (ORCPT + 99 others); Mon, 28 May 2018 06:17:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:37834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030444AbeE1KRl (ORCPT ); Mon, 28 May 2018 06:17:41 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F17EF208A5; Mon, 28 May 2018 10:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502660; bh=RkXMbG5+Ryi96Xg/xDQWa3wU1M2gzNHOIJHT3A88ODI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NNfNw2lx0U8rmOZea/IF4D+SokpiHtWpgONNhlcU1VwyMLyr2N1I3y3HbPiwy1VAj 3EbbgiZZAZCYjTiEMsV8pc4oFBdRcfS6S8DhYdRhGA/Vex0BPFMhxHGXblMxtkZ9L+ 8eMOGNYPMZx9qiIdSPqebAPpzAom/xK/NgE67H20= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yisheng Xie , Vlastimil Babka , Andi Kleen , Chris Salls , Christopher Lameter , David Rientjes , Ingo Molnar , Naoya Horiguchi , Tan Xiaojun , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.4 050/268] mm/mempolicy: add nodes_empty check in SYSC_migrate_pages Date: Mon, 28 May 2018 12:00:24 +0200 Message-Id: <20180528100207.654271725@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yisheng Xie [ Upstream commit 0486a38bcc4749808edbc848f1bcf232042770fc ] As in manpage of migrate_pages, the errno should be set to EINVAL when none of the node IDs specified by new_nodes are on-line and allowed by the process's current cpuset context, or none of the specified nodes contain memory. However, when test by following case: new_nodes = 0; old_nodes = 0xf; ret = migrate_pages(pid, old_nodes, new_nodes, MAX); The ret will be 0 and no errno is set. As the new_nodes is empty, we should expect EINVAL as documented. To fix the case like above, this patch check whether target nodes AND current task_nodes is empty, and then check whether AND node_states[N_MEMORY] is empty. Link: http://lkml.kernel.org/r/1510882624-44342-4-git-send-email-xieyisheng1@huawei.com Signed-off-by: Yisheng Xie Acked-by: Vlastimil Babka Cc: Andi Kleen Cc: Chris Salls Cc: Christopher Lameter Cc: David Rientjes Cc: Ingo Molnar Cc: Naoya Horiguchi Cc: Tan Xiaojun Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- mm/mempolicy.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1410,10 +1410,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi goto out_put; } - if (!nodes_subset(*new, node_states[N_MEMORY])) { - err = -EINVAL; + task_nodes = cpuset_mems_allowed(current); + nodes_and(*new, *new, task_nodes); + if (nodes_empty(*new)) + goto out_put; + + nodes_and(*new, *new, node_states[N_MEMORY]); + if (nodes_empty(*new)) goto out_put; - } err = security_task_movememory(task); if (err)