linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Luis Felipe Sandoval Castro <luis.felipe.sandoval.castro@intel.com>
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
	<luis.felipe.sandoval.castro@intel.com>
Subject: [PATCH v1] mm/mempolicy.c: Fix get_nodes() off-by-one error.
Date: Fri,  6 Oct 2017 08:36:34 -0500	[thread overview]
Message-ID: <1507296994-175620-2-git-send-email-luis.felipe.sandoval.castro@intel.com> (raw)
In-Reply-To: <1507296994-175620-1-git-send-email-luis.felipe.sandoval.castro@intel.com>

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 <luis.felipe.sandoval.castro@intel.com>
---
 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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-10-06 21:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06 13:36 [PATCH v1][cover-letter] " Luis Felipe Sandoval Castro
2017-10-06 13:36 ` Luis Felipe Sandoval Castro [this message]
2017-10-12  8:46   ` [PATCH v1] " Michal Hocko
2017-10-12  9:14     ` Vlastimil Babka
2017-10-12  9:29       ` Michal Hocko
2017-10-12 15:28     ` Andi Kleen
2017-10-13  8:04       ` Michal Hocko
2017-10-19  3:48         ` Sandoval Castro, Luis Felipe
2017-10-19  4:28           ` Andi Kleen
2017-10-06 22:12 ` [PATCH v1][cover-letter] " Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2017-07-18 13:39 [PATCH v1] " Luis Felipe Sandoval Castro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507296994-175620-2-git-send-email-luis.felipe.sandoval.castro@intel.com \
    --to=luis.felipe.sandoval.castro@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=mingo@kernel.org \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=rientjes@google.com \
    --cc=salls@cs.ucsb.edu \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox