Received: by 10.223.185.116 with SMTP id b49csp4230940wrg; Mon, 19 Feb 2018 13:44:37 -0800 (PST) X-Google-Smtp-Source: AH8x227n8M5cFRRXYp+VmNf9jKdSIHlZHgviVw8sUgdbfUVMBFJPVhBWLUGHHyE+iQdX2+t3v8sP X-Received: by 10.98.133.140 with SMTP id m12mr15838232pfk.226.1519076676987; Mon, 19 Feb 2018 13:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519076676; cv=none; d=google.com; s=arc-20160816; b=QUsjiAmEBaK+QLkjonZWnwIcoCbDYQWiRRV3nAdOywegeJkUr5tH2IHofJzZ9a2pTL le4sivkKnaceqiKVKBBH6zr2XqFHeJRywfIkrd/B9oE6pjErEchd4U1Ro3aMuPr85+o0 lPxwELSVOQ/7JgWevSZvd2VsgK5O66TjGyJcae9XEvvFZ8eLY57XYz1iqAjQtkiSG8Rp G8szuzWU35i73IbG17INi7TTXkMzOUBUnMIPHlaUrSSwN3p418xcqynHo4PHoT0IwMbt AD4Ljzl7zzH2aymrWZ8cybDknRWztReL0+uAGKfME0P8LcvzUPySGxouLCqJCokbfp1n 8BcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vF7VlahkfnBbl3Jt2vS/wscLWJ8U7ieJDyDdN4MSZm0=; b=z43xiiwNhM3mILlGEsGm2jEbNIBqmVWAOwWXT8c/4fzrFNvvwxpDBrXLewI8wxvn2r pll6RCY5jwzTxfg82i+UxZjI6UkDsm+f1YbDBSYbfHMKsnAO8HbAcY9yyo2Ms4+xEHCD o86IZ0tpz8vF+YOr+VUkgwQhTmA4lgkLrw2l6MOIM83ma5UA8kSAepN8dQo+rc0Z6vmm Tx32QzuUxjEsjSAbL8FDOewiIawBcCKroyT+tZMA83RGhU0Z6ogmvCeCuk3tg7soijqr ZVC+exY5XYL/SEdFZyC2MzTBVxv0GmCRbIqZ4Hfs91O6dtd+6cxZ+qJ0kCXSPs6q4aAT oGjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=da5tjkJc; 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 o64si4696648pfb.346.2018.02.19.13.44.23; Mon, 19 Feb 2018 13:44:36 -0800 (PST) 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; dkim=fail header.i=@lechnology.com header.s=default header.b=da5tjkJc; 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 S1753882AbeBSVng (ORCPT + 99 others); Mon, 19 Feb 2018 16:43:36 -0500 Received: from vern.gendns.com ([206.190.152.46]:33069 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753726AbeBSVnH (ORCPT ); Mon, 19 Feb 2018 16:43:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=vF7VlahkfnBbl3Jt2vS/wscLWJ8U7ieJDyDdN4MSZm0=; b=da5tjkJcgbQ5LzVR3ap/RN58m NQxCxLgWbO5L0TyqvPa7WsWKQFnhDcu1NlAmEGzKOpIZwmKb9WBRRFvtFOANaDdoar5Ph2bGi3qTC vk/vReAWb/JZf20480fnRejBBJOuUOCF10C4wpok1okSheLWG9m9detTyCdx3al1FcUyz8OAjkycm GDjSb8BkBjnoXaAWQVsC102PphjeUV1DJwjqgFfNjB998mzU66aCOf7cIMls43wFQvtp5Jm8YDQKf LRcUtvMCm8Zen6mhD/tQdgdu0trkTQaWzn5UgCaYmuElskbeK+hCEOMK4gHNFBO/P6t8cwaXr/X0M NKbqUIW1A==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:49808 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1entBy-0049Ue-PN; Mon, 19 Feb 2018 16:41:46 -0500 From: David Lechner To: linux-kernel@vger.kernel.org Cc: David Lechner , Mark Brown , Greg Kroah-Hartman Subject: [PATCH v2] regmap: fix NULL pointer dereference in regmap_name_read_file() Date: Mon, 19 Feb 2018 15:43:01 -0600 Message-Id: <1519076582-7687-2-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519076582-7687-1-git-send-email-david@lechnology.com> References: <1519076582-7687-1-git-send-email-david@lechnology.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This fixes a possible NULL pointer dereference oops in regmap_name_read_file() when the regmap does not have a device associated with it. For example syscon regmaps retrieved with syscon_regmap_lookup_by_compatible() don't have a device. Signed-off-by: David Lechner --- v2 changes: - point out case where this can actually happen in the commit message - print "nodev" instead of "(null)" if there is no device drivers/base/regmap/regmap-debugfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index f326633..7eb512b 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -40,6 +40,7 @@ static ssize_t regmap_name_read_file(struct file *file, loff_t *ppos) { struct regmap *map = file->private_data; + const char *name = "nodev"; int ret; char *buf; @@ -47,7 +48,10 @@ static ssize_t regmap_name_read_file(struct file *file, if (!buf) return -ENOMEM; - ret = snprintf(buf, PAGE_SIZE, "%s\n", map->dev->driver->name); + if (map->dev && map->dev->driver) + name = map->dev->driver->name; + + ret = snprintf(buf, PAGE_SIZE, "%s\n", name); if (ret < 0) { kfree(buf); return ret; -- 2.7.4