From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B73117BA3 for ; Thu, 3 Oct 2024 02:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727924185; cv=none; b=tE20ZFTCCG6wnlyxy38xRohXXm12VkcmAKDuR5GAF7rcRqPv5WpTHQmq+a+oI2E1YwBI8n4Ky2EwGiIGFK0tDmYnVTLxuPU+VRuEJCJT3Qb/ord5askVZhLvLsPazjAWiiwp45+1M48HZdFqm4v68GD4AxK4gA2y/vqoY++5WIw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727924185; c=relaxed/simple; bh=kl1fOyX8Mg5UwZoUagBtC6w6Gl2iDoAhVse2GFXBEqA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PfJCZcpx3WXxNdxwCRxbQtBxMQuAtZPwk5EvOggCVnLmlbWgQ0VUftqpYxGjsYKpf4wn+O6SwWgX35ggtr5Hf/oVNJVLBSnUwL7m3x7ptilwa91GCZtmq7RDjI2QfbJcsuHMxuWISrq/venUfFsvJOyUZMazrVvYyD5aqO8dAnw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tenstorrent.com; spf=pass smtp.mailfrom=tenstorrent.com; dkim=pass (2048-bit key) header.d=tenstorrent.com header.i=@tenstorrent.com header.b=RBpOBv6g; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tenstorrent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tenstorrent.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tenstorrent.com header.i=@tenstorrent.com header.b="RBpOBv6g" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2e075ceebdaso382967a91.2 for ; Wed, 02 Oct 2024 19:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tenstorrent.com; s=google; t=1727924183; x=1728528983; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BzabvJfQ/mT0r3c3amjc5i3OTEfJmiDAnNtgqnaCdRU=; b=RBpOBv6gmajN+QL9EEpWxfO+VGffQXa8g9uWSV5Uoms48YF2nIJryWh3pEZfYxXqwG im5QgXntlNIH4OvbfrvpXluoC4IpbqrAntiwqJf4DAhfKMoZlxDj5lyJzMvd167/Vqt9 6GAK3fgKD6SXqbHwIgBEzg9tLKjsYFnzwve6JbA+r2QKHcrcHgmc9ri9HIUR2P1H6Ci+ fvRYht4GB4tW6XT4b8caRcefOBcc1d09x3ZMY2s/yoMLWAxuiQlsfv23Zs35+GxLj4UN S7/CA5Jd0ZKvceYPtDQdLCm850zh+C2dUn42rrB2BjpoALRHvHKj1PpKStES5KG/GUUY EXaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727924183; x=1728528983; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BzabvJfQ/mT0r3c3amjc5i3OTEfJmiDAnNtgqnaCdRU=; b=UCBjZCnAXhIaZUI+OiF+DvFSnL+73J0VF5lcfJzCSpy/vBxt6R0QaLDNTZMgxlHxqA EKIQ+Tuw7m9gIvhQ4n/Az1mMDNn+wVphoxm8ddPHnWLEx6azdS/hucVdQeVut3ltJFyc mj0gFbvjNalCtEV3k8dYnYXg8U6pguMIncOXeCCnHdgZtHkWfKL2FFBd+UMrjhbjM2RL 8dTQY2LxbC/8zHnmPyZqtLVWzSpEPUGQsxGWZ4+VjA4wtuCGnN02/aiL5MumO2+PcyFm 5Mzo/g77ipCw3xkArTOU3Hhyo+P0L1wpHxR8rCE2/DqdIR7Njf5faogfv+LPCnwJtQbc 1yYA== X-Forwarded-Encrypted: i=1; AJvYcCUgKFoRlIzZsY+o6V5RgsGoDFh7t8J+Gkgent9FEBAxCNE4n8ybTbtsmfRf/qXJRpRT/QBxqZg942+E@vger.kernel.org X-Gm-Message-State: AOJu0YxLjljkep/fKq2n+u+fHJ3KIiX0Y0uBwrFRyOLjg4zSpWJOg8Dr /SJ6PlDvmxRYSTICnDubKbEHMKz3WiTDKDisqkzkukBq1em+Uu3vaAmMzFxxVWE= X-Google-Smtp-Source: AGHT+IFXE3gM6q0uiiKf0/18+ft5mNZG0Y2jhcNr77uRDbzfVN1+WvKiV64lUWP2C2WN057Sh63uJA== X-Received: by 2002:a17:90b:368c:b0:2d8:e7db:9996 with SMTP id 98e67ed59e1d1-2e18466e1aemr6024553a91.13.1727924183457; Wed, 02 Oct 2024 19:56:23 -0700 (PDT) Received: from x1 (71-34-69-82.ptld.qwest.net. [71.34.69.82]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e1bfd2a07fsm293022a91.41.2024.10.02.19.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 19:56:23 -0700 (PDT) Date: Wed, 2 Oct 2024 19:56:21 -0700 From: Drew Fustini To: clingfei Cc: drew@pdp7.com, guoren@kernel.org, wefu@redhat.com, linus.walleij@linaro.org, linux-riscv@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] pinctrl: fix Null pointer dereference Message-ID: References: <20241003023307.2138695-1-clf700383@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241003023307.2138695-1-clf700383@gmail.com> On Thu, Oct 03, 2024 at 10:33:07AM +0800, clingfei wrote: > pinmux_generic_get_function may returns NULL, and its retval is > dereferenced without check, which will cause a null pointer dereference. > > Signed-off-by: clingfei > --- > drivers/pinctrl/pinctrl-th1520.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c > index 1bb78b212fd5..9331f4462480 100644 > --- a/drivers/pinctrl/pinctrl-th1520.c > +++ b/drivers/pinctrl/pinctrl-th1520.c > @@ -798,6 +798,8 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev, > struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); > const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel); > > + if (!func) > + return -EINVAL; > return th1520_pinmux_set(thp, thp->desc.pins[gsel].number, > (uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_PAD_MUXDATA, > (uintptr_t)func->data); > -- > 2.34.1 Thanks for fixing the formating in the previous attempt. As Kees Bakker noted [1], I failed to have this check in my v3 patch series. This fix makes pinctrl-th1520 behave the same as other drivers that call pinmux_generic_get_function() like pinctrl-single. I have applied your patch and the driver still works as expected on my LPi4a. Hopefully Linus can apply this fix on top of my v3 series. Reviewed-by: Drew Fustini -Drew [1] https://lore.kernel.org/lkml/87770518-5f63-4adf-b6ea-c7f92b58ce22@ijzerbout.nl/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A58EDCF8552 for ; Thu, 3 Oct 2024 02:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sAqFFIencjWJKll0ypWFwLuquOuQw9Djjirf4UTI+8Q=; b=0sQrmwzbVmrGN+ nQlOXdIr7quDoBfqM+aP2d2uE5T/yS3LulKj1FALcPeuIlHWFIv+Tr09whVhchyqvBr8PvZ+oBWE9 c+9rnRP/DpckcUPMWED6FbqA8OQaUbwY+53SQrVJP5f1txY7+ZayVKlXawsKiZeMV4Ik8Vo2grgdP C/cJ9gq177mL4jBva6EmEJKVz/6u6Nqd9QkrxpuQejjhXqDCUvWk9BdrsMIxeIJrvG4q1t0+7PsUk vHzHiVLUNjJDdrUc9J/z1am5JmxivDA90pOshdGOmudA54VPSCBaSgz7v7L1ImIy0lS/hvOhSH3zW 62qsbbezOkxBPwTELHsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1swC0x-000000081s5-3XBw; Thu, 03 Oct 2024 02:56:27 +0000 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1swC0u-000000081rZ-2sgg for linux-riscv@lists.infradead.org; Thu, 03 Oct 2024 02:56:26 +0000 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-7e6cbf6cd1dso264443a12.3 for ; Wed, 02 Oct 2024 19:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tenstorrent.com; s=google; t=1727924183; x=1728528983; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BzabvJfQ/mT0r3c3amjc5i3OTEfJmiDAnNtgqnaCdRU=; b=gLyWrMop+YZJ63PZTiXR2PgDP6+FEQtqbzFFU19/oEMq1mEgmm4J2xozJ4ACJJtZd3 Fx08Zn41nWAWH98c/fhAAjqFMy5+gZzwD8+8lFSqKPTLGEaqAwRTPg7ozepY134yFkiE G5by017AbVT1zzJUHeBevwMibymIw7sYl+RDrZPAUV8khOzaXGoUZcjyLX5Mm8OXDwOe lxvjITR/upHVQIKFBn5sTy5ChtqwBS9Fn1m0w3LySK4UTltxCkGogO19BX7Q8GkxPq1O 9cNjxTVih0JChGIrx2zQ+ZzFGA6s3auQ9a80VfOVPPuxVsgAm55HT/IeycIE54LNDiJy ad4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727924183; x=1728528983; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BzabvJfQ/mT0r3c3amjc5i3OTEfJmiDAnNtgqnaCdRU=; b=enSGK5cO3mWT1rpwHwTwWZhKANIJK6a5RrKPGmpWX50h6N6P7qOmad4+LL+ZwUEZbS iuEY36bMTsxjeICZT9zyEPin7DH59Oaz0jWqJBJCCFzugAquu+s452ckGhKg9wK9IWC/ uImuAVtx7ObS5dP/5UjlckqCso+HfLGyhJSNltGngx8Vh2+JakVyHiEjnpT0s246mXdb uIasmernrnf9DdgkQRDL7oY67Rl3037d9gKDlmFmN7Icu/ZiYeZlSpWiH9kD7WTGH70G U5pRN2dsQL+GI3qCNOYNyV5nPorzM8yvMQtkLN1ZeVYYGpx9JSoh0FTNZsWIzQIGmAyx csjA== X-Forwarded-Encrypted: i=1; AJvYcCUCfnG12vwkpS40KaUK/4ZzX1Zr5m6H88EXuVzaLoyQVtf/X+hziLFHqa+zOq2217CpvexhHGE5w3IINg==@lists.infradead.org X-Gm-Message-State: AOJu0Yym//w43vEKwupPs+w80l997E1r8xjwAu6svhybmdqlcxomKChs RUl+45c6hh0YgpJn2aMS/kUyAzj7iqrj1PhTdHH4eMfYb5aQ9zmMzZSn8k8szvo= X-Google-Smtp-Source: AGHT+IFXE3gM6q0uiiKf0/18+ft5mNZG0Y2jhcNr77uRDbzfVN1+WvKiV64lUWP2C2WN057Sh63uJA== X-Received: by 2002:a17:90b:368c:b0:2d8:e7db:9996 with SMTP id 98e67ed59e1d1-2e18466e1aemr6024553a91.13.1727924183457; Wed, 02 Oct 2024 19:56:23 -0700 (PDT) Received: from x1 (71-34-69-82.ptld.qwest.net. [71.34.69.82]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e1bfd2a07fsm293022a91.41.2024.10.02.19.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 19:56:23 -0700 (PDT) Date: Wed, 2 Oct 2024 19:56:21 -0700 From: Drew Fustini To: clingfei Cc: drew@pdp7.com, guoren@kernel.org, wefu@redhat.com, linus.walleij@linaro.org, linux-riscv@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] pinctrl: fix Null pointer dereference Message-ID: References: <20241003023307.2138695-1-clf700383@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20241003023307.2138695-1-clf700383@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241002_195624_754638_7824791E X-CRM114-Status: GOOD ( 17.28 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Thu, Oct 03, 2024 at 10:33:07AM +0800, clingfei wrote: > pinmux_generic_get_function may returns NULL, and its retval is > dereferenced without check, which will cause a null pointer dereference. > > Signed-off-by: clingfei > --- > drivers/pinctrl/pinctrl-th1520.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c > index 1bb78b212fd5..9331f4462480 100644 > --- a/drivers/pinctrl/pinctrl-th1520.c > +++ b/drivers/pinctrl/pinctrl-th1520.c > @@ -798,6 +798,8 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev, > struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); > const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel); > > + if (!func) > + return -EINVAL; > return th1520_pinmux_set(thp, thp->desc.pins[gsel].number, > (uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_PAD_MUXDATA, > (uintptr_t)func->data); > -- > 2.34.1 Thanks for fixing the formating in the previous attempt. As Kees Bakker noted [1], I failed to have this check in my v3 patch series. This fix makes pinctrl-th1520 behave the same as other drivers that call pinmux_generic_get_function() like pinctrl-single. I have applied your patch and the driver still works as expected on my LPi4a. Hopefully Linus can apply this fix on top of my v3 series. Reviewed-by: Drew Fustini -Drew [1] https://lore.kernel.org/lkml/87770518-5f63-4adf-b6ea-c7f92b58ce22@ijzerbout.nl/ _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv