From: Pavel Machek <pavel@denx.de>
To: wen.yang99@zte.com.cn
Cc: pavel@denx.de, gregkh@linuxfoundation.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
anirudh@xilinx.com, John.Linn@xilinx.com, davem@davemloft.net,
michal.simek@xilinx.com, netdev@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, sashal@kernel.org
Subject: Re: [PATCH 4.19 46/72] net: xilinx: fix possible object referenceleak
Date: Mon, 6 May 2019 19:48:46 +0200 [thread overview]
Message-ID: <20190506174846.GA13326@amd> (raw)
In-Reply-To: <201905051417486865228@zte.com.cn>
[-- Attachment #1: Type: text/plain, Size: 2791 bytes --]
Hi!
> > > [ 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.
> >
> > 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.
> >
>
> Thank you very much for your comments.
> We developed the following coccinelle SmPL to look for places where
> there is an of_node_put on some path but not on others.
I agree that the fix is good. Thanks for doing coccinelle work.
> We use it to detect drivers/net/ethernet/xilinx/xilinx_axienet_main.c and found the following issue:
>
> static int axienet_probe(struct platform_device *pdev)
> {
> ...
> struct device_node *np;
> ...
> if (ret) {
> dev_err(&pdev->dev, "unable to get DMA resource\n");
> goto free_netdev; ---> leaked here
> }
> ...
> if (IS_ERR(lp->dma_regs)) {
> dev_err(&pdev->dev, "could not map DMA regs\n");
> ret = PTR_ERR(lp->dma_regs);
> goto free_netdev; ---> leaked here
> }
> ...
> of_node_put(np); ---> released here
> ...
> free_netdev:
> free_netdev(ndev);
>
> return ret;
> }
>
> If we insmod/rmmod xilinx_emaclite.ko multiple times,
> axienet_probe() may be called multiple times, then a resource leak
> may occur.
Yeah, well. I agree the bug is real. But how much memory will it leak
during each insmod? Kilobyte? (Is it actually anything at all? I'd
expect just reference counter to be increaed.) How often do you
usually insmod?
> At the same time, we also checked the code for handling resource leaks in the current kernel
> and found that the regular of_node_put mode is commonly used in
> addition to the goto target mode.
Ok, so this uglyness happens elsewhere. But I'd really prefer to use
goto if it is already used in the function.
Thanks,
Pavel
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2019-05-06 17:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190502143333.437607839@linuxfoundation.org>
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
[not found] ` <201905051417486865228@zte.com.cn>
2019-05-06 17:48 ` Pavel Machek [this message]
2019-05-02 15:21 ` [PATCH 4.19 47/72] net: ibm: " Greg Kroah-Hartman
2019-05-02 15:21 ` [PATCH 4.19 48/72] net: ethernet: ti: " 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=20190506174846.GA13326@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).