All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Liang He" <windhl@126.com>
To: "Pavel Machek" <pavel@denx.de>
Cc: "Sasha Levin" <sashal@kernel.org>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
	yangtiezhu@loongson.cn, linux-mips@vger.kernel.org
Subject: Re:Re: [PATCH AUTOSEL 4.9 11/13] mips/pic32/pic32mzda: Fix refcount leak bugs
Date: Wed, 29 Jun 2022 21:23:01 +0800 (CST)	[thread overview]
Message-ID: <120f6850.7be3.181afa11f50.Coremail.windhl@126.com> (raw)
In-Reply-To: <20220629130617.GE13395@duo.ucw.cz>





At 2022-06-29 21:06:17, "Pavel Machek" <pavel@denx.de> wrote:
>Hi!
>
>> From: Liang He <windhl@126.com>
>> 
>> [ Upstream commit eb9e9bc4fa5fb489c92ec588b3fb35f042ba6d86 ]
>> 
>> of_find_matching_node(), of_find_compatible_node() and
>> of_find_node_by_path() will return node pointers with refcout
>> incremented. We should call of_node_put() when they are not
>> used anymore.
>
>It looks like this may introduces an use-after-free bug:
>
>> +++ b/arch/mips/pic32/pic32mzda/init.c
>> @@ -131,13 +131,18 @@ static int __init pic32_of_prepare_platform_data(struct of_dev_auxdata *lookup)
>>  		np = of_find_compatible_node(NULL, NULL, lookup->compatible);
>>  		if (np) {
>>  			lookup->name = (char *)np->name;
>> -			if (lookup->phys_addr)
>> +			if (lookup->phys_addr) {
>> +				of_node_put(np);
>>  				continue;
>> +			}
>>  			if (!of_address_to_resource(np, 0, &res))
>>  				lookup->phys_addr = res.start;
>> +			of_node_put(np);
>>  		}
>>  	}
>
>lookup->name now contains pointer taken from np->name, but we did
>put() on the np. What guarantees np->name is not freed?
>
>Best regards,
>								Pavel

Hi, Pavel.

Thanks for you to review this patched code.

In fact, the |PUT| on 'np' will not lead to the |FREE|.
First, before calling of_find_compatible_node(), the target object's refcount must be >= 1, as the object is alive.
Then, after calling of_find_compatible_node(), its refcount must be >=2.
So, after calling of_node_put(np), its refcount must be still >=1.

In fact, these |PUT|s are just used to keep refcount balance for the |GET| in of_find_compatible_node().

If there is anything wrong, please correct me.

Thans very much to review my patch code.

Liang

>-- 
>DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
>HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

  reply	other threads:[~2022-06-29 13:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28  2:26 [PATCH AUTOSEL 4.9 01/13] spi: spi-cadence: Fix SPI CS gets toggling sporadically Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 02/13] spi: cadence: Detect transmit FIFO depth Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 03/13] drm/vc4: crtc: Use an union to store the page flip callback Sasha Levin
2022-06-28  2:26   ` Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 04/13] drivers/net/ethernet/neterion/vxge: Fix a use-after-free bug in vxge-main.c Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 05/13] video: fbdev: skeletonfb: Fix syntax errors in comments Sasha Levin
2022-06-28  2:26   ` Sasha Levin
2022-06-29 13:03   ` Pavel Machek
2022-06-29 13:03     ` Pavel Machek
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 06/13] video: fbdev: intelfb: Use aperture size from pci_resource_len Sasha Levin
2022-06-28  2:26   ` Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 07/13] video: fbdev: pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write Sasha Levin
2022-06-28  2:26   ` Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 08/13] video: fbdev: simplefb: Check before clk_put() not needed Sasha Levin
2022-06-28  2:26   ` Sasha Levin
2022-06-29 13:04   ` Pavel Machek
2022-06-29 13:04     ` Pavel Machek
2022-06-30 19:31   ` Geert Uytterhoeven
2022-06-30 19:31     ` Geert Uytterhoeven
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 09/13] mips: lantiq: falcon: Fix refcount leak bug in sysctrl Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 10/13] mips: lantiq: xway: " Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 11/13] mips/pic32/pic32mzda: Fix refcount leak bugs Sasha Levin
2022-06-29 13:06   ` Pavel Machek
2022-06-29 13:23     ` Liang He [this message]
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 12/13] mips: lantiq: Add missing of_node_put() in irq.c Sasha Levin
2022-06-28  2:26 ` [PATCH AUTOSEL 4.9 13/13] arm: mach-spear: Add missing of_node_put() in time.c Sasha Levin
2022-06-28  2:26   ` Sasha Levin

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=120f6850.7be3.181afa11f50.Coremail.windhl@126.com \
    --to=windhl@126.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=pavel@denx.de \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    --cc=yangtiezhu@loongson.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.