stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@denx.de>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Wen Yang <wen.yang99@zte.com.cn>,
	Anirudha Sarangi <anirudh@xilinx.com>,
	John Linn <John.Linn@xilinx.com>,
	"David S. Miller" <davem@davemloft.net>,
	Michal Simek <michal.simek@xilinx.com>,
	netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	"Sasha Levin (Microsoft)" <sashal@kernel.org>
Subject: Re: [PATCH 4.19 46/72] net: xilinx: fix possible object reference leak
Date: Fri, 3 May 2019 12:08:16 +0200	[thread overview]
Message-ID: <20190503100816.GD5834@amd> (raw)
In-Reply-To: <20190502143337.107638265@linuxfoundation.org>

[-- Attachment #1: Type: text/plain, Size: 3519 bytes --]

On Thu 2019-05-02 17:21:08, Greg Kroah-Hartman wrote:
> [ Upstream commit fa3a419d2f674b431d38748cb58fb7da17ee8949 ]
> 
> The call to of_parse_phandle returns a node pointer with refcount
> incremented thus it must be explicitly decremented after the last
> usage.
> 
> Detected by coccinelle with the following warnings:
> ./drivers/net/ethernet/xilinx/xilinx_axienet_main.c:1624:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 1569, but without a corresponding object release within this function.
> 
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Cc: Anirudha Sarangi <anirudh@xilinx.com>
> Cc: John Linn <John.Linn@xilinx.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Michal Simek <michal.simek@xilinx.com>
> Cc: netdev@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: David S. Miller <davem@davemloft.net>
> Signed-off-by: Sasha Levin (Microsoft) <sashal@kernel.org>

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/net/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 *pdev)
 	ret = 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 = devm_ioremap_resource(&pdev->dev, &dmares);
 	if (IS_ERR(lp->dma_regs)) {
 		dev_err(&pdev->dev, "could not map DMA regs\n");
 		ret = PTR_ERR(lp->dma_regs);
-		of_node_put(np);
-		goto free_netdev;
+		goto free_netdev_put;
 	}
 	lp->rx_irq = irq_of_parse_and_map(np, 1);
 	lp->tx_irq = irq_of_parse_and_map(np, 0);
@@ -1620,6 +1618,8 @@ static int axienet_probe(struct platform_device *pdev)
 
 	return 0;
 
+free_netdev_put:
+	of_node_put(np);
 free_netdev:
 	free_netdev(ndev);
 


> ---
>  drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> 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 = 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 = devm_ioremap_resource(&pdev->dev, &dmares);
>  	if (IS_ERR(lp->dma_regs)) {
>  		dev_err(&pdev->dev, "could not map DMA regs\n");
>  		ret = PTR_ERR(lp->dma_regs);
> +		of_node_put(np);
>  		goto free_netdev;
>  	}
>  	lp->rx_irq = irq_of_parse_and_map(np, 1);

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2019-05-03 10:08 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-02 15:20 [PATCH 4.19 00/72] 4.19.39-stable review Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 01/72] selinux: use kernel linux/socket.h for genheaders and mdp Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 02/72] Revert "ACPICA: Clear status of GPEs before enabling them" Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 03/72] mm: make page ref count overflow check tighter and more explicit Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 04/72] mm: add try_get_page() helper function Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 05/72] mm: prevent get_user_pages() from overflowing page refcount Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 06/72] fs: prevent page refcount overflow in pipe_buf_get Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 07/72] ARM: dts: bcm283x: Fix hdmi hpd gpio pull Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 08/72] s390: limit brk randomization to 32MB Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 09/72] net: ieee802154: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-05-03  8:32   ` Pavel Machek
2019-05-02 15:20 ` [PATCH 4.19 10/72] ieee802154: hwsim: propagate genlmsg_reply return code Greg Kroah-Hartman
2019-05-03  8:33   ` Pavel Machek
2019-05-02 15:20 ` [PATCH 4.19 11/72] net: stmmac: dont set own bit too early for jumbo frames Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 12/72] qlcnic: Avoid potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 13/72] xsk: fix umem memory leak on cleanup Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 14/72] staging: axis-fifo: add CONFIG_OF dependency Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 15/72] staging, mt7621-pci: fix build without pci support Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 16/72] netfilter: nft_set_rbtree: check for inactive element after flag mismatch Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 17/72] netfilter: bridge: set skb transport_header before entering NF_INET_PRE_ROUTING Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 18/72] netfilter: fix NETFILTER_XT_TARGET_TEE dependencies Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 19/72] netfilter: ip6t_srh: fix NULL pointer dereferences Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 20/72] s390/qeth: fix race when initializing the IP address table Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 21/72] ARM: imx51: fix a leaked reference by adding missing of_node_put Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 22/72] sc16is7xx: missing unregister/delete driver on error in sc16is7xx_init() Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 23/72] serial: ar933x_uart: Fix build failure with disabled console Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 24/72] KVM: arm64: Reset the PMU in preemptible context Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 25/72] KVM: arm/arm64: vgic-its: Take the srcu lock when writing to guest memory Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 26/72] KVM: arm/arm64: vgic-its: Take the srcu lock when parsing the memslots Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 27/72] usb: dwc3: pci: add support for Comet Lake PCH ID Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 28/72] usb: gadget: net2280: Fix overrun of OUT messages Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 29/72] usb: gadget: net2280: Fix net2280_dequeue() Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 30/72] usb: gadget: net2272: Fix net2272_dequeue() Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 31/72] ARM: dts: pfla02: increase phy reset duration Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 32/72] i2c: i801: Add support for Intel Comet Lake Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 33/72] net: ks8851: Dequeue RX packets explicitly Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 34/72] net: ks8851: Reassert reset pin if chip ID check fails Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 35/72] net: ks8851: Delay requesting IRQ until opened Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 36/72] net: ks8851: Set initial carrier state to down Greg Kroah-Hartman
2019-05-02 15:20 ` [PATCH 4.19 37/72] staging: rtl8188eu: Fix potential NULL pointer dereference of kcalloc Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 38/72] staging: rtlwifi: rtl8822b: fix to avoid potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 39/72] staging: rtl8712: uninitialized memory in read_bbreg_hdl() Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 40/72] staging: rtlwifi: Fix potential NULL pointer dereference of kzalloc Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 41/72] net: macb: Add null check for PCLK and HCLK Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 42/72] net/sched: dont dereference a->goto_chain to read the chain index Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 43/72] ARM: dts: imx6qdl: Fix typo in imx6qdl-icore-rqs.dtsi Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 44/72] drm/tegra: hub: Fix dereference before check Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 45/72] NFS: Fix a typo in nfs_init_timeout_values() Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 46/72] net: xilinx: fix possible object reference leak Greg Kroah-Hartman
2019-05-03 10:08   ` Pavel Machek [this message]
     [not found]     ` <201905051417486865228@zte.com.cn>
2019-05-06 17:48       ` [PATCH 4.19 46/72] net: xilinx: fix possible object referenceleak Pavel Machek
2019-05-02 15:21 ` [PATCH 4.19 47/72] net: ibm: fix possible object reference leak Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 48/72] net: ethernet: ti: " Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 49/72] drm: Fix drm_release() and device unplug Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 50/72] gpio: aspeed: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 51/72] drm/meson: Fix invalid pointer in meson_drv_unbind() Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 52/72] drm/meson: Uninstall IRQ handler Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 53/72] ARM: davinci: fix build failure with allnoconfig Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 54/72] scsi: mpt3sas: Fix kernel panic during expander reset Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 55/72] scsi: aacraid: Insure we dont access PCIe space during AER/EEH Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 56/72] scsi: qla4xxx: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 57/72] usb: usb251xb: fix to avoid " Greg Kroah-Hartman
2019-05-03 21:32   ` Pavel Machek
2019-05-04  6:45     ` Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 58/72] leds: trigger: netdev: fix refcnt leak on interface rename Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 59/72] x86/realmode: Dont leak the trampoline kernel address Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 60/72] usb: u132-hcd: fix resource leak Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 61/72] ceph: fix use-after-free on symlink traversal Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 62/72] scsi: zfcp: reduce flood of fcrscn1 trace records on multi-element RSCN Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 63/72] x86/mm: Dont exceed the valid physical address space Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 64/72] libata: fix using DMA buffers on stack Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 65/72] gpio: of: Fix of_gpiochip_add() error path Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 66/72] nvme-multipath: relax ANA state check Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 67/72] perf machine: Update kernel map address and re-order properly Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 68/72] kconfig/[mn]conf: handle backspace (^H) key Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 69/72] iommu/amd: Reserve exclusion range in iova-domain Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 70/72] ptrace: take into account saved_sigmask in PTRACE{GET,SET}SIGMASK Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 71/72] leds: pca9532: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 72/72] leds: trigger: netdev: use memcpy in device_name_store Greg Kroah-Hartman
2019-05-02 22:46 ` [PATCH 4.19 00/72] 4.19.39-stable review kernelci.org bot
2019-05-03  7:26 ` Naresh Kamboju
2019-05-03  9:27 ` Jon Hunter
2019-05-03 17:16 ` Guenter Roeck
2019-05-03 21:20 ` shuah
2019-05-04  6:54 ` Pavel Machek
2019-05-04  7:18   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190503100816.GD5834@amd \
    --to=pavel@denx.de \
    --cc=John.Linn@xilinx.com \
    --cc=anirudh@xilinx.com \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=netdev@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wen.yang99@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).