From: Sudip Mukherjee Date: Tue, 21 Apr 2020 01:14:20 +0000 (-0700) Subject: coredump: fix null pointer dereference on coredump X-Git-Tag: v5.15~4006^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db973a7289dad24e6c017dcedc6aee886579dc3a;p=platform%2Fkernel%2Flinux-starfive.git coredump: fix null pointer dereference on coredump If the core_pattern is set to "|" and any process segfaults then we get a null pointer derefernce while trying to coredump. The call stack shows: RIP: do_coredump+0x628/0x11c0 When the core_pattern has only "|" there is no use of trying the coredump and we can check that while formating the corename and exit with an error. After this change I get: format_corename failed Aborting core Fixes: 315c69261dd3 ("coredump: split pipe command whitespace before expanding template") Reported-by: Matthew Ruffell Signed-off-by: Sudip Mukherjee Signed-off-by: Andrew Morton Cc: Paul Wise Cc: Alexander Viro Cc: Neil Horman Cc: Link: http://lkml.kernel.org/r/20200416194612.21418-1-sudipm.mukherjee@gmail.com Signed-off-by: Linus Torvalds --- diff --git a/fs/coredump.c b/fs/coredump.c index f8296a8..408418e 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -211,6 +211,8 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm, return -ENOMEM; (*argv)[(*argc)++] = 0; ++pat_ptr; + if (!(*pat_ptr)) + return -ENOMEM; } /* Repeat as long as we have more pattern to process and more output