Linux-mm Archive on
 help / color / Atom feed
From: Randy Dunlap <>
To: Entropy Moe <>,,,
Subject: [PATCH] mm: mempolicy: require at least one nodeid for MPOL_PREFERRED
Date: Wed, 25 Mar 2020 17:45:26 -0700
Message-ID: <> (raw)
In-Reply-To: <>

From: Randy Dunlap <>

Using an empty (malformed) nodelist that is not caught during
mount option parsing leads to a stack-out-of-bounds access.

The option string that was used was: "mpol=prefer:,".
However, MPOL_PREFERRED requires a single node number,
which is not being provided here.

Add a check that 'nodes' is not empty after parsing for

Fixes: 095f1fc4ebf3 ("mempolicy: rework shmem mpol parsing and display")
Reported-by: Entropy Moe <>
Signed-off-by: Randy Dunlap <>
Cc: Andrew Morton <>
Cc: Lee Schermerhorn <>
 mm/mempolicy.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- lnx-56-rc6.orig/mm/mempolicy.c
+++ lnx-56-rc6/mm/mempolicy.c
@@ -2841,7 +2841,9 @@ int mpol_parse_str(char *str, struct mem
 	switch (mode) {
-		 * Insist on a nodelist of one node only
+		 * Insist on a nodelist of one node only, although later
+		 * we use first_node(nodes) to grab a single node, so here
+		 * nodelist (or nodes) cannot be empty.
 		if (nodelist) {
 			char *rest = nodelist;
@@ -2849,6 +2851,8 @@ int mpol_parse_str(char *str, struct mem
 			if (*rest)
 				goto out;
+			if (nodes_empty(nodes))
+				goto out;

      parent reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-15 19:57 KASAN: stack-out-of-bounds Write in mpol_to_str Entropy Moe
2020-03-16 18:46 ` Randy Dunlap
2020-03-20  8:36   ` Entropy Moe
2020-03-21  6:45     ` Andrew Morton
2020-03-26  0:54     ` Randy Dunlap
2020-03-26  0:45 ` Randy Dunlap [this message]

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:

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

  git send-email \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-mm Archive on

Archives are clonable:
	git clone --mirror linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ \
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone