Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4898853imc; Mon, 25 Feb 2019 13:13:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IZIu2QXw8qQSHR7p+bpa/AsEwi41lWWXS2QbP8eUj3o4VwdIottLBt2nD4eIgL92dtDSwuR X-Received: by 2002:a63:591f:: with SMTP id n31mr20553017pgb.304.1551129230779; Mon, 25 Feb 2019 13:13:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551129230; cv=none; d=google.com; s=arc-20160816; b=CqJMesdW+7mxDlXNWEXOe0+AAKvF647KLHfoRAY6qS+tV6lTt9DXcUZmRwz2fpWZDi mQ5Gutu7Lym64Da8xnTFv7W1F2fV+eClAMCNPp8Pq/Fqpa4g0hCYPm/AO5YmPiDVQhHi x2q3JVSP6tFZLTvJHW/MwaTk9qx4e5MluPfeKVAQWwgNEtMw5d12P8ZWu6QOPnt0s8m/ qWYwnUEba3ss4rp7DQoGSJCOCUhRO1UnCq2UzXrzovr0NU0ax/SdhFVb5rDsyXbuZxnl EqD372ciiy1URDb/dUoCYPk3Awr0LHLNIm6VVuLG9pj0TwXgZ3S9Eqh5+3K+q2otV5xB 02kA== 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=gI+d/bLL/SnALhfhss0m+j9KNn82D6hEGyRz0fhqBKo=; b=j7M/USSE4jG5nqW6Xyldts9e7WpIQMFuwrzqLr1SC6nMZEitZHC7CwREo+fCjBCCtE bhthbQgnrrTO48T1UHSD9+13EBQtRTrIHWAV/RMg+gMf5C4uFREttLJqU5Zs4kGvg3cg lOIY4s3QAXme+Vn6zhygIUltZ1N1UO48nzks9sW6dFlOvmAuQE6jArutjM6uNoLrEgxa /q/tA53FBTRY2LjNMAu67VXuFxSr3AHGvhXHul5QpjL7a975cJAqWlbhQKYbkJ0ehOCJ JDsKsyDWZilm3O+R2/4uorGXt3rQZW4QPzQ9dA/eny5PWX9yDaHYd9SWv9OH4eIC0Rh3 iFUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L7+R95r4; 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 b8si10045313plr.54.2019.02.25.13.13.35; Mon, 25 Feb 2019 13:13:50 -0800 (PST) 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=L7+R95r4; 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 S1728706AbfBYVNA (ORCPT + 99 others); Mon, 25 Feb 2019 16:13:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:43366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726575AbfBYVM6 (ORCPT ); Mon, 25 Feb 2019 16:12:58 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 DB0A62084D; Mon, 25 Feb 2019 21:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551129177; bh=1xzOjj50nD6ELpGI0EAzbM5MH63Y5EA2BFtOg2aMANM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L7+R95r4XI2ZehqJFL/5h4qX/rr77fzaANmxFbDS4iq48QE55/Ov//NWB808VeUHp +k9Z9n9Uy0UZ6GHkdjmzYQWfaFYPb5+bsezRw9PwBARUcNklXu8VtS3fyIu1pa7i6d v4bDJdk1PvvdrGg2y1V1nn1Ihj6l0+J45kr/rgSQ= 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 4.9 04/63] numa: change get_mempolicy() to use nr_node_ids instead of MAX_NUMNODES Date: Mon, 25 Feb 2019 22:11:04 +0100 Message-Id: <20190225195036.048077356@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195035.713274200@linuxfoundation.org> References: <20190225195035.713274200@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 4.9-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 @@ -1327,7 +1327,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) @@ -1488,7 +1488,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); @@ -1517,7 +1517,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)