From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752923AbdJFVij (ORCPT ); Fri, 6 Oct 2017 17:38:39 -0400 Received: from mga05.intel.com ([192.55.52.43]:42727 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752884AbdJFVid (ORCPT ); Fri, 6 Oct 2017 17:38:33 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,486,1500966000"; d="scan'208";a="159789310" From: Luis Felipe Sandoval Castro To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, mingo@kernel.org, rientjes@google.com, n-horiguchi@ah.jp.nec.com, salls@cs.ucsb.edu, Luis Felipe Sandoval Castro Subject: [PATCH v1] mm/mempolicy.c: Fix get_nodes() off-by-one error. Date: Fri, 6 Oct 2017 08:36:34 -0500 Message-Id: <1507296994-175620-2-git-send-email-luis.felipe.sandoval.castro@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1507296994-175620-1-git-send-email-luis.felipe.sandoval.castro@intel.com> References: <1507296994-175620-1-git-send-email-luis.felipe.sandoval.castro@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org set_mempolicy() and mbind() take as argument a pointer to a bit mask (nodemask) and the number of bits in the mask the kernel will use (maxnode), among others. For instace on a system with 2 NUMA nodes valid masks are: 0b00, 0b01, 0b10 and 0b11 it's clear maxnode=2, however an off-by-one error in get_nodes() the function that copies the node mask from user space requires users to pass maxnode = 3 in this example and maxnode = actual_maxnode + 1 in the general case. This patch fixes such error. Signed-off-by: Luis Felipe Sandoval Castro --- mm/mempolicy.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 006ba62..0c2e3cd 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1265,11 +1265,10 @@ static int get_nodes(nodemask_t *nodes, const unsigned long __user *nmask, unsigned long nlongs; unsigned long endmask; - --maxnode; nodes_clear(*nodes); - if (maxnode == 0 || !nmask) + if (maxnode == 1 || !nmask) return 0; - if (maxnode > PAGE_SIZE*BITS_PER_BYTE) + if (maxnode - 1 > PAGE_SIZE * BITS_PER_BYTE) return -EINVAL; nlongs = BITS_TO_LONGS(maxnode); -- 1.8.3.1