From: Rafael Mendonca <rafaelmendsr@xxxxxxxxx> commit d05ea35e7eea14d32f29fd688d3daeb9089de1a5 upstream. Check if fp->rethook succeeded to be allocated. Otherwise, if rethook_alloc() fails, then we end up dereferencing a NULL pointer in rethook_add_node(). Link: https://lore.kernel.org/all/20221025031209.954836-1-rafaelmendsr@xxxxxxxxx/ Fixes: 5b0ab78998e3 ("fprobe: Add exit_handler support") Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Rafael Mendonca <rafaelmendsr@xxxxxxxxx> Acked-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> Acked-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/trace/fprobe.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -141,6 +141,8 @@ static int fprobe_init_rethook(struct fp return -E2BIG; fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler); + if (!fp->rethook) + return -ENOMEM; for (i = 0; i < size; i++) { struct fprobe_rethook_node *node;