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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD383C46470 for ; Fri, 3 May 2019 10:08:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 880A32075C for ; Fri, 3 May 2019 10:08:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727489AbfECKIU (ORCPT ); Fri, 3 May 2019 06:08:20 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:54085 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725816AbfECKIT (ORCPT ); Fri, 3 May 2019 06:08:19 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id B2436802D6; Fri, 3 May 2019 12:08:06 +0200 (CEST) Date: Fri, 3 May 2019 12:08:16 +0200 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Wen Yang , Anirudha Sarangi , John Linn , "David S. Miller" , Michal Simek , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "Sasha Levin (Microsoft)" Subject: Re: [PATCH 4.19 46/72] net: xilinx: fix possible object reference leak Message-ID: <20190503100816.GD5834@amd> References: <20190502143333.437607839@linuxfoundation.org> <20190502143337.107638265@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="a2FkP9tdjPU2nyhF" Content-Disposition: inline In-Reply-To: <20190502143337.107638265@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --a2FkP9tdjPU2nyhF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu 2019-05-02 17:21:08, Greg Kroah-Hartman wrote: > [ Upstream commit fa3a419d2f674b431d38748cb58fb7da17ee8949 ] >=20 > The call to of_parse_phandle returns a node pointer with refcount > incremented thus it must be explicitly decremented after the last > usage. >=20 > Detected by coccinelle with the following warnings: > ./drivers/net/ethernet/xilinx/xilinx_axienet_main.c:1624:1-7: ERROR: miss= ing of_node_put; acquired a node pointer with refcount incremented on line = 1569, but without a corresponding object release within this function. >=20 > Signed-off-by: Wen Yang > Cc: Anirudha Sarangi > Cc: John Linn > Cc: "David S. Miller" > Cc: Michal Simek > Cc: netdev@vger.kernel.org > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: David S. Miller > Signed-off-by: Sasha Levin (Microsoft) Bug is real, but fix is horrible. This already uses gotos for error handling, so use them.... This fixes it up. Plus... I do not think these "of_node_put" fixes belong in stable. They are theoretical bugs; so we hold reference to device tree structure. a) it is small, b) it stays in memory, anyway. This does not fix any real problem. Pavel diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/ne= t/ethernet/xilinx/xilinx_axienet_main.c index 4041c75..490d440 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -1575,15 +1575,13 @@ static int axienet_probe(struct platform_device *pd= ev) ret =3D of_address_to_resource(np, 0, &dmares); if (ret) { dev_err(&pdev->dev, "unable to get DMA resource\n"); - of_node_put(np); - goto free_netdev; + goto free_netdev_put; } lp->dma_regs =3D devm_ioremap_resource(&pdev->dev, &dmares); if (IS_ERR(lp->dma_regs)) { dev_err(&pdev->dev, "could not map DMA regs\n"); ret =3D PTR_ERR(lp->dma_regs); - of_node_put(np); - goto free_netdev; + goto free_netdev_put; } lp->rx_irq =3D irq_of_parse_and_map(np, 1); lp->tx_irq =3D irq_of_parse_and_map(np, 0); @@ -1620,6 +1618,8 @@ static int axienet_probe(struct platform_device *pdev) =20 return 0; =20 +free_netdev_put: + of_node_put(np); free_netdev: free_netdev(ndev); =20 > --- > drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 ++ > 1 file changed, 2 insertions(+) >=20 > diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/= net/ethernet/xilinx/xilinx_axienet_main.c > index f24f48f33802..7cfd7ff38e86 100644 > --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > @@ -1574,12 +1574,14 @@ static int axienet_probe(struct platform_device *= pdev) > ret =3D of_address_to_resource(np, 0, &dmares); > if (ret) { > dev_err(&pdev->dev, "unable to get DMA resource\n"); > + of_node_put(np); > goto free_netdev; > } > lp->dma_regs =3D devm_ioremap_resource(&pdev->dev, &dmares); > if (IS_ERR(lp->dma_regs)) { > dev_err(&pdev->dev, "could not map DMA regs\n"); > ret =3D PTR_ERR(lp->dma_regs); > + of_node_put(np); > goto free_netdev; > } > lp->rx_irq =3D irq_of_parse_and_map(np, 1); --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --a2FkP9tdjPU2nyhF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlzMExAACgkQMOfwapXb+vIrQACfRGO7B7c76iqFSkLanh93OYhc YB8AnjX80JqCdvKDKa6YoJRJg3pTE41w =GJN0 -----END PGP SIGNATURE----- --a2FkP9tdjPU2nyhF-- 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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F12D8C43219 for ; Fri, 3 May 2019 10:08:32 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id BB7F52075C for ; Fri, 3 May 2019 10:08:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="M7VEbf2y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB7F52075C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RpCiCyEb/H54LUUk6/6iWAyaZQ2h8biEJCN5CDf8muw=; b=M7VEbf2yRGDC0uFq+Luw6cbJ1 DdgL+pfMRiOv1z3Q/OcTyAD+W8wQzYcZ/IiU3lZNpVR0SivI7CjL+jiFy5xs+o1cDldshyfJEUqIA HoUUyR6Qv8sj8vxAOlB/4TGZeDvnji9+DOxmdf/hHrSvX64D544Gtmd+9v4yr8YtklWXEjO4/Fm0U HFGtFHvhzBgL2n6Wl8y8imLBIKqS2ReSKE1l7GzcxWGKd4fQcAEnah5rWjhgaZjDLzkSOlBN4l2vl tjO6ZOH65J86WrM1thO7fqXFFKT8qc4vLbosGiyqMe7wyrwM2Ce3if5OjyDpLGJBz531qFtIUxrhZ jpIHnCDqw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMV7D-0002o0-U2; Fri, 03 May 2019 10:08:27 +0000 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMV7A-0002nD-8h for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2019 10:08:26 +0000 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id B2436802D6; Fri, 3 May 2019 12:08:06 +0200 (CEST) Date: Fri, 3 May 2019 12:08:16 +0200 From: Pavel Machek To: Greg Kroah-Hartman Subject: Re: [PATCH 4.19 46/72] net: xilinx: fix possible object reference leak Message-ID: <20190503100816.GD5834@amd> References: <20190502143333.437607839@linuxfoundation.org> <20190502143337.107638265@linuxfoundation.org> MIME-Version: 1.0 In-Reply-To: <20190502143337.107638265@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_030824_618729_589BB04B X-CRM114-Status: GOOD ( 20.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Sasha Levin \(Microsoft\)" , Wen Yang , netdev@vger.kernel.org, Michal Simek , linux-kernel@vger.kernel.org, stable@vger.kernel.org, John Linn , Anirudha Sarangi , "David S. Miller" , linux-arm-kernel@lists.infradead.org Content-Type: multipart/mixed; boundary="===============3473446321343938800==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============3473446321343938800== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="a2FkP9tdjPU2nyhF" Content-Disposition: inline --a2FkP9tdjPU2nyhF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu 2019-05-02 17:21:08, Greg Kroah-Hartman wrote: > [ Upstream commit fa3a419d2f674b431d38748cb58fb7da17ee8949 ] >=20 > The call to of_parse_phandle returns a node pointer with refcount > incremented thus it must be explicitly decremented after the last > usage. >=20 > Detected by coccinelle with the following warnings: > ./drivers/net/ethernet/xilinx/xilinx_axienet_main.c:1624:1-7: ERROR: miss= ing of_node_put; acquired a node pointer with refcount incremented on line = 1569, but without a corresponding object release within this function. >=20 > Signed-off-by: Wen Yang > Cc: Anirudha Sarangi > Cc: John Linn > Cc: "David S. Miller" > Cc: Michal Simek > Cc: netdev@vger.kernel.org > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: David S. Miller > Signed-off-by: Sasha Levin (Microsoft) Bug is real, but fix is horrible. This already uses gotos for error handling, so use them.... This fixes it up. Plus... I do not think these "of_node_put" fixes belong in stable. They are theoretical bugs; so we hold reference to device tree structure. a) it is small, b) it stays in memory, anyway. This does not fix any real problem. Pavel diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/ne= t/ethernet/xilinx/xilinx_axienet_main.c index 4041c75..490d440 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -1575,15 +1575,13 @@ static int axienet_probe(struct platform_device *pd= ev) ret =3D of_address_to_resource(np, 0, &dmares); if (ret) { dev_err(&pdev->dev, "unable to get DMA resource\n"); - of_node_put(np); - goto free_netdev; + goto free_netdev_put; } lp->dma_regs =3D devm_ioremap_resource(&pdev->dev, &dmares); if (IS_ERR(lp->dma_regs)) { dev_err(&pdev->dev, "could not map DMA regs\n"); ret =3D PTR_ERR(lp->dma_regs); - of_node_put(np); - goto free_netdev; + goto free_netdev_put; } lp->rx_irq =3D irq_of_parse_and_map(np, 1); lp->tx_irq =3D irq_of_parse_and_map(np, 0); @@ -1620,6 +1618,8 @@ static int axienet_probe(struct platform_device *pdev) =20 return 0; =20 +free_netdev_put: + of_node_put(np); free_netdev: free_netdev(ndev); =20 > --- > drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 ++ > 1 file changed, 2 insertions(+) >=20 > diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/= net/ethernet/xilinx/xilinx_axienet_main.c > index f24f48f33802..7cfd7ff38e86 100644 > --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > @@ -1574,12 +1574,14 @@ static int axienet_probe(struct platform_device *= pdev) > ret =3D of_address_to_resource(np, 0, &dmares); > if (ret) { > dev_err(&pdev->dev, "unable to get DMA resource\n"); > + of_node_put(np); > goto free_netdev; > } > lp->dma_regs =3D devm_ioremap_resource(&pdev->dev, &dmares); > if (IS_ERR(lp->dma_regs)) { > dev_err(&pdev->dev, "could not map DMA regs\n"); > ret =3D PTR_ERR(lp->dma_regs); > + of_node_put(np); > goto free_netdev; > } > lp->rx_irq =3D irq_of_parse_and_map(np, 1); --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --a2FkP9tdjPU2nyhF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlzMExAACgkQMOfwapXb+vIrQACfRGO7B7c76iqFSkLanh93OYhc YB8AnjX80JqCdvKDKa6YoJRJg3pTE41w =GJN0 -----END PGP SIGNATURE----- --a2FkP9tdjPU2nyhF-- --===============3473446321343938800== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============3473446321343938800==--