Skip to contentSkip to conversation

question about drivers/phy/renesas/phy-rcar-gen2.c

DISCUSSION Julia Lawall 2 participants 5 messages Feb 3, 2019 – Feb 27, 2019

lore
Share & tools
lore
#0 lore raw

Hello,

I was wondering whether phy-rcar-gen2.c would use dynamically allocated device nodes? If so, it looks like the following code could cause a use-after-free, due to not incrementing th reference count:

	for_each_child_of_node(dev->of_node, np) {
		struct rcar_gen2_channel *channel = drv->channels + i;
		u32 channel_num;
		int error, n;

		channel->of_node = np;
		...
	}

On the other hand, if the reference cound it incrememnted, preventing memory leaks in the case where the probe function fails would entail some complex rewriting of the code, so I thought it would be better to ask first.

thanks,
julia

#1 lore raw

Hello,
(Sergei made this code, so I added his email as CC)

I'm sorry for the delayed response.

Quoted 6 lines

From: Julia Lawall, Sent: Sunday, February 3, 2019 4:03 PM

Hello,

I was wondering whether phy-rcar-gen2.c would use dynamically allocated device nodes?

I'm sorry, but what is "dynamically allocated device nodes"?

Best regards,
Yoshihiro Shimoda

Quoted 19 lines

If so, it looks like the following code could cause a
use-after-free, due to not incrementing th reference count:

	for_each_child_of_node(dev->of_node, np) {
		struct rcar_gen2_channel *channel = drv->channels + i;
		u32 channel_num;
		int error, n;

		channel->of_node = np;
		...
	}

On the other hand, if the reference cound it incrememnted, preventing memory leaks in the case where the probe function fails would entail some complex rewriting of the code, so I thought it would be better to ask first.

thanks,
julia

#2 lore raw
Quoted 5 lines · Yoshihiro Shimoda

Hello,
(Sergei made this code, so I added his email as CC)

I'm sorry for the delayed response.

Quoted 8 lines
Quoted 6 lines

From: Julia Lawall, Sent: Sunday, February 3, 2019 4:03 PM

Hello,

I was wondering whether phy-rcar-gen2.c would use dynamically allocated device nodes?

I'm sorry, but what is "dynamically allocated device nodes"?

Device nodes for which there will be a meor leak if one doesn't put of_node_put.

julia

Quoted 24 lines

Best regards,
Yoshihiro Shimoda

Quoted 19 lines

If so, it looks like the following code could cause a
use-after-free, due to not incrementing th reference count:

	for_each_child_of_node(dev->of_node, np) {
		struct rcar_gen2_channel *channel = drv->channels + i;
		u32 channel_num;
		int error, n;

		channel->of_node = np;
		...
	}

On the other hand, if the reference cound it incrememnted, preventing memory leaks in the case where the probe function fails would entail some complex rewriting of the code, so I thought it would be better to ask first.

thanks,
julia

#3 lore raw

Hello,

Quoted 13 lines

From: Julia Lawall, Sent: Tuesday, February 26, 2019 6:01 PM

Quoted 9 lines · Yoshihiro Shimoda

Hello,
(Sergei made this code, so I added his email as CC)

I'm sorry for the delayed response.

Quoted 4 lines

From: Julia Lawall, Sent: Sunday, February 3, 2019 4:03 PM

Hello,

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I was wondering whether phy-rcar-gen2.c would use dynamically allocated device nodes?

I'm sorry, but what is "dynamically allocated device nodes"?

Device nodes for which there will be a meor leak if one doesn't put of_node_put.

Thank you. I understood it.

Quoted 15 lines

julia

Quoted 13 lines

Best regards,
Yoshihiro Shimoda

Quoted 9 lines

If so, it looks like the following code could cause a
use-after-free, due to not incrementing th reference count:

	for_each_child_of_node(dev->of_node, np) {
		struct rcar_gen2_channel *channel = drv->channels + i;
		u32 channel_num;
		int error, n;

		channel->of_node = np;

IIUC, since the channel->of_node will be used for comparing the pointer in rcar_gen2_phy_xlate(), it is not use-after-free.
However, the for_each_child_of_node() in rcar_gen2_phy_probe() will return without of_put_node() at error paths. So, I'll submit a bugfix patch later.

Thank you very much for your report!

Best regards,
Yoshihiro Shimoda

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
		...
	}

On the other hand, if the reference cound it incrememnted, preventing memory leaks in the case where the probe function fails would entail some complex rewriting of the code, so I thought it would be better to ask first.

thanks,
julia

#4 lore raw
Quoted 39 lines · Yoshihiro Shimoda

Hello,

Quoted 13 lines

From: Julia Lawall, Sent: Tuesday, February 26, 2019 6:01 PM

Quoted 9 lines · Yoshihiro Shimoda

Hello,
(Sergei made this code, so I added his email as CC)

I'm sorry for the delayed response.

Quoted 4 lines

From: Julia Lawall, Sent: Sunday, February 3, 2019 4:03 PM

Hello,

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I was wondering whether phy-rcar-gen2.c would use dynamically allocated device nodes?

I'm sorry, but what is "dynamically allocated device nodes"?

Device nodes for which there will be a meor leak if one doesn't put of_node_put.

Thank you. I understood it.

Quoted 14 lines

julia

Quoted 12 lines

Best regards,
Yoshihiro Shimoda

Quoted 8 lines

If so, it looks like the following code could cause a
use-after-free, due to not incrementing th reference count:

	for_each_child_of_node(dev->of_node, np) {
		struct rcar_gen2_channel *channel = drv->channels + i;
		u32 channel_num;
		int error, n;
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
		channel->of_node = np;

IIUC, since the channel->of_node will be used for comparing the pointer in rcar_gen2_phy_xlate(), it is not use-after-free.
However, the for_each_child_of_node() in rcar_gen2_phy_probe() will return without of_put_node() at error paths. So, I'll submit a bugfix patch later.

Thank you very much for your report!

Thanks for taking care of it.

julia

Quoted 16 lines

Best regards,
Yoshihiro Shimoda

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
		...
	}

On the other hand, if the reference cound it incrememnted, preventing memory leaks in the case where the probe function fails would entail some complex rewriting of the code, so I thought it would be better to ask first.

thanks,
julia