Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2212398ybb; Mon, 30 Mar 2020 01:33:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsqaK034GN8QY7IVdZI8C3xkG4DdAFzVEaKmOpp2K+uyXliR3zbDyUMRzLLCXrP9bXoo9mU X-Received: by 2002:a9d:6292:: with SMTP id x18mr8449808otk.241.1585557227736; Mon, 30 Mar 2020 01:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585557227; cv=none; d=google.com; s=arc-20160816; b=L3fExXXt+Nmkxn5/3JBkSD2nqlqFORe68JddfqMYMJasn48WGvqtksRLUSD0SQEg9K cqRuZlmRU99NJAXeNDXI/fMnbOQQJNkAkdy7w20eroQDXmE/ncr3n2ILJNy3msz6Q+Xz 3IhjcFh8X2CnVisq08VxabAkAYIcMErvDYtXo+EkrxnVSr4SzVqQun3Mr/rHiDyQ8dcK cy9DQrkjtEfDbylV9Nmu7g0WGVvjAZCkQhZ9boqlmSaBnpmG2GjIRchc7MqeYzgDOtgF dX7bFmIILo9SMYQvb7lXyl4GWIvXK/LD8xo73joA4dkYmz22hF1cBocyKuX6xRdGQ7dS /b7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:to:from:date; bh=fIGiSXYWTXCk/qfuxhHhtxZjaukadzQl9hlzAYPhluU=; b=0yfQyxqNyki9HdVRdwGkAt4w4EdMTjejuubWoqLX0tFIccWMijJglQIw/cIbgZFgMS WbCDp2D27hqK9m5qBEd8EOoD48kKIsWT+TRiqaMXY/u4yk4aqtTZFb72VUPM6pXVcfAb IXJqq8Pxupn8f91FxvAcID6/MJybC7F4dcvh+zdsrvlZp+oNOjEg9QyyXTsnqsChuWiY pslPRo5uYQK0Rn2F+xgZhcewXd+4RUuh23TtnR0YOQbs1wH5mwxNKnMBE0Ds1PH9pdTk hQWlPnNedm90ClhBmzvloRofu5lWyeIqNMjr9NI6GL3UcaEuGew0Jd2JghACbU/iUCNC YCOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d12si5903088oom.31.2020.03.30.01.33.35; Mon, 30 Mar 2020 01:33:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729663AbgC3IcB (ORCPT + 99 others); Mon, 30 Mar 2020 04:32:01 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:60517 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729576AbgC3IcB (ORCPT ); Mon, 30 Mar 2020 04:32:01 -0400 Received: from clip-os.org (unknown [78.194.159.98]) (Authenticated sender: thibaut.sautereau@clip-os.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 3D35D20000D; Mon, 30 Mar 2020 08:31:58 +0000 (UTC) Date: Mon, 30 Mar 2020 10:31:58 +0200 From: Thibaut Sautereau To: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: NULL pointer dereference in coredump code Message-ID: <20200330083158.GA21845@clip-os.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="FL5UXtIhxfXey3p5" Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --FL5UXtIhxfXey3p5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline I hit a kernel NULL pointer dereference caused by the following call chain: do_coredump() file_start_write(cprm.file) # cprm.file is NULL file_inode(file) # NULL ptr deref The `ispipe` path is followed in do_coredump(), and: # cat /proc/sys/kernel/core_pattern |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h It seems that cprm.file can be NULL after the call to the usermode helper, especially when setting CONFIG_STATIC_USERMODEHELPER=y and CONFIG_STATIC_USERMODEHELPER_PATH="", which is the case for me. One may say it's a strange combination of configuration options but I think it should not crash the kernel anyway. As I don't know much about coredumps in general and this code, I don't know what's the best way to fix this issue in a clean and comprehensive way. I attached the patch I used to temporarily work around this issue, if that can clarify anything. Thanks, -- Thibaut Sautereau CLIP OS developer --FL5UXtIhxfXey3p5 Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0001-coredump-FIXUP.patch" From 613dfc60429c1fc5fc19e1c8662648620dc103af Mon Sep 17 00:00:00 2001 From: Thibaut Sautereau Date: Fri, 27 Mar 2020 16:34:59 +0100 Subject: [PATCH] coredump: FIXUP --- fs/coredump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/coredump.c b/fs/coredump.c index b1ea7dfbd149..d0177b81345f 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -686,7 +686,7 @@ void do_coredump(const kernel_siginfo_t *siginfo) UMH_WAIT_EXEC); kfree(helper_argv); - if (retval) { + if (retval || !cprm.file) { printk(KERN_INFO "Core dump to |%s pipe failed\n", cn.corename); goto close_fail; -- 2.26.0 --FL5UXtIhxfXey3p5--