mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: renesas: fix a potential NULL pointer dereference
@ 2019-03-11  7:01 Kangjie Lu
  2019-03-11  7:43 ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Kangjie Lu @ 2019-03-11  7:01 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Sergei Shtylyov, David S. Miller, Vladimir Zapolskiy,
	Geert Uytterhoeven, Vladimir Barinov, Chris Brandt, netdev,
	linux-renesas-soc, linux-kernel

In case of_get_phy_mode fails, the fix returns NULL to avoid
the NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/net/ethernet/renesas/sh_eth.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 339b2eae2100..b119587ec673 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -3187,6 +3187,8 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
 		return NULL;
 
 	pdata->phy_interface = of_get_phy_mode(np);
+	if (unlikely(!pdata->phy_interface))
+		return NULL;
 
 	mac_addr = of_get_mac_address(np);
 	if (mac_addr)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: renesas: fix a potential NULL pointer dereference
  2019-03-11  7:01 [PATCH] net: renesas: fix a potential NULL pointer dereference Kangjie Lu
@ 2019-03-11  7:43 ` Geert Uytterhoeven
  2019-03-11 10:43   ` Sergei Shtylyov
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2019-03-11  7:43 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: pakki001, Sergei Shtylyov, David S. Miller, Vladimir Zapolskiy,
	Geert Uytterhoeven, Vladimir Barinov, Chris Brandt, netdev,
	Linux-Renesas, Linux Kernel Mailing List

Hi Kangjie,

On Mon, Mar 11, 2019 at 8:01 AM Kangjie Lu <kjlu@umn.edu> wrote:
> In case of_get_phy_mode fails, the fix returns NULL to avoid
> the NULL pointer dereference.
>
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>

Thanks for your patch!

> --- a/drivers/net/ethernet/renesas/sh_eth.c
> +++ b/drivers/net/ethernet/renesas/sh_eth.c
> @@ -3187,6 +3187,8 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
>                 return NULL;
>
>         pdata->phy_interface = of_get_phy_mode(np);
> +       if (unlikely(!pdata->phy_interface))
> +               return NULL;

of_get_phy_mode() does not return a pointer, but a phy mode index.
Hence zero is a valid value.

So I'm wondering where is the potential NULL pointer dereference?

Perhaps we do need to check for negative error codes?
Or is this already handled later, by {of_,}phy_connect()?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: renesas: fix a potential NULL pointer dereference
  2019-03-11  7:43 ` Geert Uytterhoeven
@ 2019-03-11 10:43   ` Sergei Shtylyov
  0 siblings, 0 replies; 3+ messages in thread
From: Sergei Shtylyov @ 2019-03-11 10:43 UTC (permalink / raw)
  To: Geert Uytterhoeven, Kangjie Lu
  Cc: pakki001, David S. Miller, Vladimir Zapolskiy,
	Geert Uytterhoeven, Vladimir Barinov, Chris Brandt, netdev,
	Linux-Renesas, Linux Kernel Mailing List

Hello!

On 03/11/2019 10:43 AM, Geert Uytterhoeven wrote:

>> In case of_get_phy_mode fails, the fix returns NULL to avoid
>> the NULL pointer dereference.
>>
>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> 
> Thanks for your patch!
> 
>> --- a/drivers/net/ethernet/renesas/sh_eth.c
>> +++ b/drivers/net/ethernet/renesas/sh_eth.c
>> @@ -3187,6 +3187,8 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
>>                 return NULL;
>>
>>         pdata->phy_interface = of_get_phy_mode(np);
>> +       if (unlikely(!pdata->phy_interface))
>> +               return NULL;
> 
> of_get_phy_mode() does not return a pointer, but a phy mode index.
> Hence zero is a valid value.
> 
> So I'm wondering where is the potential NULL pointer dereference?

   Hm, not seeing NULL deref as well...

> Perhaps we do need to check for negative error codes?
> Or is this already handled later, by {of_,}phy_connect()?

   Not seeing such handling too...
   The v2 patch seems good though, as the "phy-mode" prop is mandatory anyway.

> Gr{oetje,eeting}s,
> 
>                         Geert

MBR, Sergei

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-11 10:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-11  7:01 [PATCH] net: renesas: fix a potential NULL pointer dereference Kangjie Lu
2019-03-11  7:43 ` Geert Uytterhoeven
2019-03-11 10:43   ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®