Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2528533imm; Mon, 28 May 2018 09:48:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqB79YJvcOjFTBOAzdocEKpnR7E6JNGSX24wkpuIrl6B5FklROESR5X/tM5e0BIDwqZI01f X-Received: by 2002:a17:902:7896:: with SMTP id q22-v6mr14484183pll.243.1527526110670; Mon, 28 May 2018 09:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527526110; cv=none; d=google.com; s=arc-20160816; b=EKcxiC/5QJpH481i2Pg+lptCi+sf3/yC+lHk7saRekmd0uHT0HHsMDSPZ9dgPOYiaB iCxTIKlRd/72fI7W29ELJGEYSyrS6eedpO3Zx8/OirOY639k9Tc3WjRqocvDzX6vPTFI 9UgdMDWaEjuhs0yL0rABJaXjmIVb6DZLF2+ithqYM01m1Yxxz3MNd2JnqvihPHYCW2VA DvY3pXJ4OYKJ2Et2XBcCh1DlzbFG94OA6RGXlRJTvsfUjbpUIKRb6mBP5iYooOhMvZqG Yd2IVb6OLAZ33aUjiLEwmMH11YCgC6WKlOv2ALIZs4m1j/txeKAIGcm4F7v5JzBjiJz4 vlpQ== 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=1Ukx7/R6WC3SN5MYT4IuHGORzXCIdrgqaKa2m2x7OyQ=; b=L0iCcri1YF/7THWz3iaSsBYcZsVFXohc4hcF6xqhiqkUo3pf2PSKjuNKgRS47JVshp kCTFO8FRSPy/L9gIeasnel8XYrYK4Q5jysf3/XuLjZCcyp/g6AZrMyjNQR14Hem/qBYf lKSNgQbOH5RVVH0Jpbv3FChR3ufC+Qt88tbrfHt2cRfq2E8aKgzqoCULKYtd4+7TcXia 9eR0fQPlgF5HBFlgFiiHG577rlB3tRC9Wx0LTCJtbvvuZssLOPpaCxABbIG1paAAJX5T axcdxAPzsXE14K7Pq3WQ/ZnpRm/w96utKXjvl+4oZnsJL/eJmi+D3v4lG+RjTyh6W6fp 1e3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NojWYCRA; 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 g3-v6si19474512pgr.188.2018.05.28.09.48.16; Mon, 28 May 2018 09:48:30 -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=NojWYCRA; 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 S1754767AbeE1QrG (ORCPT + 99 others); Mon, 28 May 2018 12:47:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:54928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754882AbeE1KG5 (ORCPT ); Mon, 28 May 2018 06:06:57 -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 1EFDD208A2; Mon, 28 May 2018 10:06:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502016; bh=CChHCtQjnFoh9KuRFEMMqZGNUnH4XzY0MMC3Rks0tC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NojWYCRAsyE9xwRkmm19sAeYml94ELRlW0e4Dnjaz+9nB3cSMs/ZavSrUw3pVu2v1 xrpN6BBaWeUuqGnW7mLN5fsXu+lFdAGGklChhUudecExoqVySXc6xsA9F/fsiiNG8P 2wDX9kK+0GD3U3gs6MIh2tOgGFKgoOiCEjC2NRhY= 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 3.18 030/185] mm/mempolicy: add nodes_empty check in SYSC_migrate_pages Date: Mon, 28 May 2018 12:01:11 +0200 Message-Id: <20180528100052.390601977@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@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 3.18-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 @@ -1464,10 +1464,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)