Skip to content

Commit c7a91bc

Browse files
Dan Carpentertorvalds
authored andcommitted
mm/mempolicy.c: fix out of bounds write in mpol_parse_str()
What we are trying to do is change the '=' character to a NUL terminator and then at the end of the function we restore it back to an '='. The problem is there are two error paths where we jump to the end of the function before we have replaced the '=' with NUL. We end up putting the '=' in the wrong place (possibly one element before the start of the buffer). Link: http://lkml.kernel.org/r/[email protected] Reported-by: [email protected] Fixes: 095f1fc ("mempolicy: rework shmem mpol parsing and display") Signed-off-by: Dan Carpenter <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Dmitry Vyukov <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Dan Carpenter <[email protected]> Cc: Lee Schermerhorn <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 68f23b8 commit c7a91bc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mm/mempolicy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,6 +2821,9 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
28212821
char *flags = strchr(str, '=');
28222822
int err = 1, mode;
28232823

2824+
if (flags)
2825+
*flags++ = '\0'; /* terminate mode string */
2826+
28242827
if (nodelist) {
28252828
/* NUL-terminate mode or flags string */
28262829
*nodelist++ = '\0';
@@ -2831,9 +2834,6 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
28312834
} else
28322835
nodes_clear(nodes);
28332836

2834-
if (flags)
2835-
*flags++ = '\0'; /* terminate mode string */
2836-
28372837
mode = match_string(policy_modes, MPOL_MAX, str);
28382838
if (mode < 0)
28392839
goto out;

0 commit comments

Comments
 (0)