Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3092542lqo; Tue, 21 May 2024 06:47:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXajvOY8vYKE7NclCJuYMakxKewNUpCYhOZrWIFUaVPNIjxZ5iEZcqNo9RiDtGf8Hjm7JAitc/D0iicSxUUmiuanOBVanOLGP6ulu1ESA== X-Google-Smtp-Source: AGHT+IG4zZsmhH015L+5wD+iaHmDg8gAbXNv+Ll1JePRloMUJ5WhVt8HTkmJ+ZubOxuh7cu1kPGI X-Received: by 2002:a9d:4d85:0:b0:6ef:8860:b329 with SMTP id 46e09a7af769-6f0e92a6345mr44697722a34.25.1716299275957; Tue, 21 May 2024 06:47:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716299275; cv=pass; d=google.com; s=arc-20160816; b=sNE4Op/jnRdmpxoZ7lGgCZXNsEPtrRaJWxDMtf94QHrvOt47UUDNZqTVbp6rso3bP3 e53FXiLcHytZq147uZFwC4JwuB9hxR/F9PJLTrEnOyYcd2gHt7KtcCvVihKFq+do5Q7k f/HIuqIZ9n+0j73c+kfvJTCBM3tt0FoBjPR8LBsIBNNhQUJumV6OWFJ7GHgL+2A3uY2p 35Gwy3GmKxcnzjsHGf1drpvkJ/xNY3/R5ZsMqcreyq0m2de08shyDjuIlqbdai75HKuM uF1Jo3SlKv+2yAhCYQWBFddxHtAiubUqXVdsDh/ip5yVQWLUMm0MmB61sau/mVNQasm9 zkIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=k3rFlRmL54JATeKxOAmIN17kFay8A0jp8qawnMms36I=; fh=QTqWQCVrKg+GkXE/KDZPFuPPiGC9MSEK6ASaLrtSZ3g=; b=StKxFKdC0EUAH/v1cMe2NcZ3s6salhxFa0B54LUTaFt1DWT5bTO4hxamHqEVDUP0IT yycburCkDOGiIx7u90POGYBYQYvUi2dy2DoJVn9zihbeudh5ZWzs39KMRq4oErZxXsfC bUXBgB4aaNoA4n8xv8gfVp84KeqyUH/fla1prjrU8OEq1vFtQcpjYFwY9BWLj9R8VUWG 05Xa1/TLh9Bed6cjzLhP8qXlyhnmh2HJCKmXzcFrSvYVfXAg+RHbZIebYGrA7H7XcOm0 tlQIPZC+GSpGdV/f9iJrHeEuQJ7zvfTyQ0/CmpMusDWP56PmghvmHtH2ZAYF6YQwvawy +wKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RdnWDP7a; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-185034-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df549f6f1si54196741cf.42.2024.05.21.06.47.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 06:47:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185034-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RdnWDP7a; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-185034-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5E1C21C21833 for ; Tue, 21 May 2024 13:47:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 318C87EF06; Tue, 21 May 2024 13:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RdnWDP7a" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F8C055783; Tue, 21 May 2024 13:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716299265; cv=none; b=PDoljsqvqX+n3LrNxUmiiTaVaW0TjtoPorr8zQICNkHeWjmGp5Una96MX6l4u/g6EhTljrHRr9WxYcKDMoZulNzSx1/TEpgdXyL7ChtfakafPD862DCQX98ynEjCTyR3xDLRkCfe1qIKLKoGedmwnW5SlGI19N9BLaeNEgV74CI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716299265; c=relaxed/simple; bh=Rs0778QKzKCdk0BVA98zOTHQl+mRFeefvwXEHJ/1we8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IByw8ck5vaj1XHI2O2ap/sJNIdV21FiO9lHDyTBb4x8Q+KWkSMT8wTSb2LhzealfEULxF8v0VqnPVYvkqzjxbbYixCmvw8Amvwxz0ezX1JkZEgwAU0u/WXNEsBeG4chMc6fK6iwi2Ri4/cwodsu2HYLeQQs+uKpTPJ+3iMR77B8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RdnWDP7a; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEC6CC2BD11; Tue, 21 May 2024 13:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716299264; bh=Rs0778QKzKCdk0BVA98zOTHQl+mRFeefvwXEHJ/1we8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RdnWDP7adAioYkB3/+Il09h51NgpF8SMAVZyOlo4p1vHsDU8W/MmkscYN3ZaqPUvh LJJyfhttBT1gQbWzZA65iJeGWv8wz+cfco9WKnizzAj4wSwPNVeM6kXOtfvJ4VxIC/ dKTVtxVgFa0pORmupAShSMqwC9XPkDPG0YVZBHckGuCWfwRbis10RHmhNEm6ZftgNK GZp1T6A/upBmVnSxgjJoNZU+xemHpmENftx9Etor5hVqexWIToaxjbOpVh+eYiI2Mm fFfbLAACqP4MQk/LeEay0vniuHCpwirjQeLw/3fxCUglIuP+4KEpcYTmG6SEWS1+Es O1BAaRNoj3u9A== Date: Tue, 21 May 2024 14:47:39 +0100 From: Simon Horman To: Romain Gantois Cc: MD Danish Anwar , Roger Quadros , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Thomas Petazzoni , linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Andrew Lunn , Diogo Ivo , Vignesh Raghavendra Subject: Re: [PATCH net] net: ti: icssg_prueth: Fix NULL pointer dereference in prueth_probe() Message-ID: <20240521134739.GE764145@kernel.org> References: <20240521-icssg-prueth-fix-v1-1-b4b17b1433e9@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@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: <20240521-icssg-prueth-fix-v1-1-b4b17b1433e9@bootlin.com> + Andrew Lunn, Diogo Ivo, Vignesh Raghavendra Not trimming reply to provide context for these people On Tue, May 21, 2024 at 02:44:11PM +0200, Romain Gantois wrote: > In the prueth_probe() function, if one of the calls to emac_phy_connect() > fails due to of_phy_connect() returning NULL, then the subsequent call to > phy_attached_info() will dereference a NULL pointer. > > Check the return code of emac_phy_connect and fail cleanly if there is an > error. > > Fixes: 128d5874c082 ("net: ti: icssg-prueth: Add ICSSG ethernet driver") > Cc: stable@vger.kernel.org > Signed-off-by: Romain Gantois For Networking patches, please consider seeding the CC list using ./scripts/get_maintainer.pl this.patch. I've added the people who seemed to be missing. The patch itself looks good to me. Reviewed-by: Simon Horman > --- > Hello everyone, > > There is a possible NULL pointer dereference in the prueth_probe() function of > the icssg_prueth driver. I discovered this while testing a platform with one > PRUETH MAC enabled out of the two available. > > These are the requirements to reproduce the bug: > > prueth_probe() is called > either eth0_node or eth1_node is not NULL > in emac_phy_connect: of_phy_connect() returns NULL > > Then, the following leads to the NULL pointer dereference: > > prueth->emac[PRUETH_MAC0]->ndev->phydev is set to NULL > prueth->emac[PRUETH_MAC0]->ndev->phydev is passed to phy_attached_info() > -> phy_attached_print() dereferences phydev which is NULL > > This series provides a fix by checking the return code of emac_phy_connect(). > > Best Regards, > > Romain > --- > drivers/net/ethernet/ti/icssg/icssg_prueth.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c > index 7c9e9518f555a..1ea3fbd5e954e 100644 > --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c > +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c > @@ -1039,7 +1039,12 @@ static int prueth_probe(struct platform_device *pdev) > > prueth->registered_netdevs[PRUETH_MAC0] = prueth->emac[PRUETH_MAC0]->ndev; > > - emac_phy_connect(prueth->emac[PRUETH_MAC0]); > + ret = emac_phy_connect(prueth->emac[PRUETH_MAC0]); > + if (ret) { > + dev_err(dev, > + "can't connect to MII0 PHY, error -%d", ret); > + goto netdev_unregister; > + } > phy_attached_info(prueth->emac[PRUETH_MAC0]->ndev->phydev); > } > > @@ -1051,7 +1056,12 @@ static int prueth_probe(struct platform_device *pdev) > } > > prueth->registered_netdevs[PRUETH_MAC1] = prueth->emac[PRUETH_MAC1]->ndev; > - emac_phy_connect(prueth->emac[PRUETH_MAC1]); > + ret = emac_phy_connect(prueth->emac[PRUETH_MAC1]); > + if (ret) { > + dev_err(dev, > + "can't connect to MII1 PHY, error %d", ret); > + goto netdev_unregister; > + } > phy_attached_info(prueth->emac[PRUETH_MAC1]->ndev->phydev); > } > > > --- > base-commit: e4a87abf588536d1cdfb128595e6e680af5cf3ed > change-id: 20240521-icssg-prueth-fix-03b03064c5ce > > Best regards, > -- > Romain Gantois > >