Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp575825img; Fri, 22 Mar 2019 04:22:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwYUNBtjOoTrhYVIPzn/B5DaZvxpBC7Sd/pgkmuN8bdBnbeehzM0MqPipI+nsODHm8ZyOW X-Received: by 2002:a17:902:5c5:: with SMTP id f63mr6081301plf.64.1553253743311; Fri, 22 Mar 2019 04:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553253743; cv=none; d=google.com; s=arc-20160816; b=AtgranUuQ+QDa7XlUq9fJZ28BrUbItuwG6tnqIXgi6BVI4WzKxauNdnBPqjazbcNTx KYfDcZiU2GR0BXsrLXYtL00ug3xZmpCzPYe/EMvegzcQHoAgnluAwa4DsjZEpu1SEVfc rmMTaZBb+fXtIEUSvsICbOp8Gv10jEJ97EYoOAvmxXCHPOoPnZcMiKb4vh/8L8hVCxw1 g+LfzmHFmKGpZCZakJ3MZKG4WbXH/CoFslnHCAXWGs+qvafhIgNHXKRsn1FdQ8Dq6ZLl DniJAz8A3NVMVbP//QjjTFPpYYoMFidTD7e0febLvfme5/p5O9IRhZ344n3sXc+ETX0O NueQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6FZKToYLQIdHoJ3bIJCJqm//ds7nvebXT8fmkdPvIG4=; b=BRLNHRDqiuWpUvIM1ERE1cXT0l+FUy7D7xiPqavq8KODneU7AYr+Jo8ivcZWwLYgD9 ZCPfuwIbVZdgjO7VmYj3XNxWfut7fryJAATU8esrQirwukfqmF/0BLT4qmPHLnoSbkZs 8lWtrrwapPGUJJ2+8c6r8+ZQBhOKJ2h7XgRjDoLpscyCNxoU8OgcUtzSTwzz1lYDk2V+ liMGBQvhOT7cmXrkyAMu10ZZwvCy1Z6OK2YN22EnSQv7no5oMWR2oaZBCM2jQJCXQV8l Oi0RxYq9pneebhbf7kzRd3QwSgB3RDnSL9e9Fg2V+mTJYiTP2thUa6gz2CoyHcsNNjyI xVZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Grz4gk9f; 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 d8si6233001pgv.53.2019.03.22.04.22.08; Fri, 22 Mar 2019 04:22:23 -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=Grz4gk9f; 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 S1728292AbfCVLUE (ORCPT + 99 others); Fri, 22 Mar 2019 07:20:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:46460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728273AbfCVLUD (ORCPT ); Fri, 22 Mar 2019 07:20:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 6CBF9218A2; Fri, 22 Mar 2019 11:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553253601; bh=6ivpWA4uSWqJVJhEoEo8O8cJKOCmVYelnNdwlGAqVD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Grz4gk9fG808gQNG9SAQ2zOup86CTc0/g4B9gqMI9HtRoy6W3VVODCUcuL/7hIEz+ WcQo31+bO73SksQuvKBqM7binIqlHHQbeYRvDv8Q5fiJt+shOiBYyw2KvCz+bEi2OT 8ZJdhfYhiVvH28VWT1ifIubWVW7PBaS3fQCNRLAU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ralph Campbell , Alexander Duyck , Waiman Long , Andrew Morton , Linus Torvalds Subject: [PATCH 3.18 002/134] numa: change get_mempolicy() to use nr_node_ids instead of MAX_NUMNODES Date: Fri, 22 Mar 2019 12:13:35 +0100 Message-Id: <20190322111210.552368844@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111210.465931067@linuxfoundation.org> References: <20190322111210.465931067@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Ralph Campbell commit 050c17f239fd53adb55aa768d4f41bc76c0fe045 upstream. The system call, get_mempolicy() [1], passes an unsigned long *nodemask pointer and an unsigned long maxnode argument which specifies the length of the user's nodemask array in bits (which is rounded up). The manual page says that if the maxnode value is too small, get_mempolicy will return EINVAL but there is no system call to return this minimum value. To determine this value, some programs search /proc//status for a line starting with "Mems_allowed:" and use the number of digits in the mask to determine the minimum value. A recent change to the way this line is formatted [2] causes these programs to compute a value less than MAX_NUMNODES so get_mempolicy() returns EINVAL. Change get_mempolicy(), the older compat version of get_mempolicy(), and the copy_nodes_to_user() function to use nr_node_ids instead of MAX_NUMNODES, thus preserving the defacto method of computing the minimum size for the nodemask array and the maxnode argument. [1] http://man7.org/linux/man-pages/man2/get_mempolicy.2.html [2] https://lore.kernel.org/lkml/1545405631-6808-1-git-send-email-longman@redhat.com Link: http://lkml.kernel.org/r/20190211180245.22295-1-rcampbell@nvidia.com Fixes: 4fb8e5b89bcbbbb ("include/linux/nodemask.h: use nr_node_ids (not MAX_NUMNODES) in __nodemask_pr_numnodes()") Signed-off-by: Ralph Campbell Suggested-by: Alexander Duyck Cc: Waiman Long Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/mempolicy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1349,7 +1349,7 @@ static int copy_nodes_to_user(unsigned l nodemask_t *nodes) { unsigned long copy = ALIGN(maxnode-1, 64) / 8; - const int nbytes = BITS_TO_LONGS(MAX_NUMNODES) * sizeof(long); + unsigned int nbytes = BITS_TO_LONGS(nr_node_ids) * sizeof(long); if (copy > nbytes) { if (copy > PAGE_SIZE) @@ -1510,7 +1510,7 @@ SYSCALL_DEFINE5(get_mempolicy, int __use int uninitialized_var(pval); nodemask_t nodes; - if (nmask != NULL && maxnode < MAX_NUMNODES) + if (nmask != NULL && maxnode < nr_node_ids) return -EINVAL; err = do_get_mempolicy(&pval, &nodes, addr, flags); @@ -1539,7 +1539,7 @@ COMPAT_SYSCALL_DEFINE5(get_mempolicy, in unsigned long nr_bits, alloc_size; DECLARE_BITMAP(bm, MAX_NUMNODES); - nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES); + nr_bits = min_t(unsigned long, maxnode-1, nr_node_ids); alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8; if (nmask)