Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2085478ybb; Fri, 29 Mar 2019 18:41:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/JE/QlBomfykLLUkER2IYGSN8tT9q+mpBQpYC5PiMCULK2OVD7S+S7P9igNxCQw/jg9Ao X-Received: by 2002:a17:902:9683:: with SMTP id n3mr52553307plp.333.1553910086621; Fri, 29 Mar 2019 18:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553910086; cv=none; d=google.com; s=arc-20160816; b=Ymf9nkUVPe8l1ZANmJvZa6cLB6IOhm/PptXSudXUbz5iOOMgehZyqkL2Xri87boEw+ 4DM4UJt2DQzvodfJ9vg7rnmWWErt0Z+oP879xCEUUV4c/xX6RxZIFS92qOCjN4dE0XwN kM+DwQVgm1aAs7GOrR/bT3Nl1ey+6FI+CxXjXFIg6fm3hAWMu50ZE8czp4QmWKMro01p R1K/JnaoyLVSDfzBxysv5ccr9yBTmBA8M62wYUTX/ewtA90aQg2b7+9gmFkfwv9T/wzr 93MgvyrmkeC43hPXmii6pRnxtE/pfSa6rgMK4KQgsjvypYnyoMPpAbzljaatxedzZ1aj 3+1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/jph8oHmuegVXi5aXmd3w/0IUF97neYA8buZ5Wobdyc=; b=xZ06QUFk1sB85fQcEaKr31adCieNSt1E8MqflZXq88VJ0Qhzy5mht6aANcp9RVxEz1 VCN3ZPbGy0Cj6YZG/wYkL/jDyH3C22pTRqM9L+g9jfR9tAt2xPgTAyctUt39hWcBrT9O dGQkcc12qroa7K11bVp4K/phkmhgUdiK6gBTkwVBWiF8Iafd81Sivz3koCPLIn360+7P mNFZpPDL44nRTSg705rpy5O1a6c/mvrDLY2QPvXb5IJNvansjtvu1LbN0jEo0FpKiqG/ qwdEl7sdXqyxxzOG5wCa9rcC2zTg9cMpg1dbOBocsLyQFd3oZl+PmI45AzjfATOcRDjp cJuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PBB+Z4zN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si3178389pfe.194.2019.03.29.18.41.11; Fri, 29 Mar 2019 18:41:26 -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; dkim=pass header.i=@kernel.org header.s=default header.b=PBB+Z4zN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730983AbfC3B3b (ORCPT + 99 others); Fri, 29 Mar 2019 21:29:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:36356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730941AbfC3B33 (ORCPT ); Fri, 29 Mar 2019 21:29:29 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D69E2217F5; Sat, 30 Mar 2019 01:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909368; bh=eBZUywteNKvuDQ3xoiq3Xg8hQIPWQ4S+HTBb1ym2EiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PBB+Z4zN5or8naJMMurz+xp1HuEt8nb5nJDYCv03jPJgzZWuZ5M8nUjLh0dz+TRES XwUBQzIZ/usjhVFX5dULW7gsFALUSNCkNniQnHucawKhix27JrrOSyn86mqHtspqna Fi/7mmmVIIKd/zqSfsIithri0WIYZv9J7pKGr7sc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yanjiang Jin , Linus Walleij , Sasha Levin , linux-gpio@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 15/57] pinctrl: core: make sure strcmp() doesn't get a null parameter Date: Fri, 29 Mar 2019 21:28:08 -0400 Message-Id: <20190330012854.32212-15-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330012854.32212-1-sashal@kernel.org> References: <20190330012854.32212-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yanjiang Jin [ Upstream commit 54a58185bfafb5af5045fb8388c45daa373f90f3 ] Some drivers, for example, QCOM's qdf2xxx, set groups[gpio].name only when gpio is valid, and leave invalid gpio names as null. If we want to access the sys node "pinconf-groups", pinctrl_get_group_selector() -> get_group_name() may return a null pointer if group_selector is invalid, then the below Kernel panic would happen since strcmp() uses this null pointer to do comparison. Unable to handle kernel NULL pointer dereference at ss 00000000 el:Internal error: Oops: 9600000[ 143.080279] SMP CPU: 19 PID: 2493 Comm: read_all Tainted: G O .aarch64 #1 Hardware name: HXT Semiconductor HXT REP-2 System PC is at strcmp+0x18/0x154 LR is at pinctrl_get_group_selector+0x6c/0xe8 Process read_all (pid: 2493, stack limit = Call trace: Exception stack strcmp+0x18/0x154 pin_config_group_get+0x64/0xd8 pinconf_generic_dump_one+0xd8/0x1c0 pinconf_generic_dump_pins+0x94/0xc8 pinconf_groups_show+0xb4/0x104 seq_read+0x178/0x464 full_proxy_read+0x6c/0xac __vfs_read+0x58/0x178 vfs_read+0x94/0x164 SyS_read+0x60/0xc0 __sys_trace_return+0x0/0x4 --[ end trace]-- Kernel panic - not syncing: Fatal exception Signed-off-by: Yanjiang Jin Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index a3dd777e3ce8..c6ff4d5fa482 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -627,7 +627,7 @@ static int pinctrl_generic_group_name_to_selector(struct pinctrl_dev *pctldev, while (selector < ngroups) { const char *gname = ops->get_group_name(pctldev, selector); - if (!strcmp(function, gname)) + if (gname && !strcmp(function, gname)) return selector; selector++; @@ -743,7 +743,7 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, while (group_selector < ngroups) { const char *gname = pctlops->get_group_name(pctldev, group_selector); - if (!strcmp(gname, pin_group)) { + if (gname && !strcmp(gname, pin_group)) { dev_dbg(pctldev->dev, "found group selector %u for %s\n", group_selector, -- 2.19.1