2019-03-12 07:33:25

by Kangjie Lu

[permalink] [raw]
Subject: [PATCH] net: stmmac: fix a potential NULL pointer dereference

In case of_device_get_match_data fails, the fix return -ENOMEM
to avoid the NULL pointer dereference.

Signed-off-by: Kangjie Lu <[email protected]>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
index 3256e5cbad27..344ead5949b1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
@@ -485,6 +485,8 @@ static int dwc_eth_dwmac_remove(struct platform_device *pdev)
int err;

data = of_device_get_match_data(&pdev->dev);
+ if (!data)
+ return -EINVAL;

err = stmmac_dvr_remove(&pdev->dev);
if (err < 0)
--
2.17.1



2019-03-12 08:28:55

by Chen-Yu Tsai

[permalink] [raw]
Subject: Re: [PATCH] net: stmmac: fix a potential NULL pointer dereference

On Tue, Mar 12, 2019 at 3:32 PM Kangjie Lu <[email protected]> wrote:
>
> In case of_device_get_match_data fails, the fix return -ENOMEM
> to avoid the NULL pointer dereference.
>
> Signed-off-by: Kangjie Lu <[email protected]>
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
> index 3256e5cbad27..344ead5949b1 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
> @@ -485,6 +485,8 @@ static int dwc_eth_dwmac_remove(struct platform_device *pdev)
> int err;
>
> data = of_device_get_match_data(&pdev->dev);
> + if (!data)
> + return -EINVAL;

You say -ENOMEM in the commit message, but -EINVAL here.

Also, all compatible strings within this driver have data attached
to them. The only possible case for this to return NULL is if the
user is screwing around with the kernel, such as creating a platform
device matching the driver name. This is not the intended way to
use it, and IMHO the kernel has the right to blow up in the user's
face.

ChenYu

>
> err = stmmac_dvr_remove(&pdev->dev);
> if (err < 0)
> --
> 2.17.1
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

2019-03-27 13:43:41

by Mukesh Ojha

[permalink] [raw]
Subject: Re: [PATCH] net: stmmac: fix a potential NULL pointer dereference


On 3/12/2019 1:02 PM, Kangjie Lu wrote:
> In case of_device_get_match_data fails, the fix return -ENOMEM

s/-ENOMEM/-EINVAL


Otherwise looks good to me.
Make the above correction.
Reviewed-by: Mukesh Ojha <[email protected]>

-Mukesh

> to avoid the NULL pointer dereference.
>
> Signed-off-by: Kangjie Lu <[email protected]>
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
> index 3256e5cbad27..344ead5949b1 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
> @@ -485,6 +485,8 @@ static int dwc_eth_dwmac_remove(struct platform_device *pdev)
> int err;
>
> data = of_device_get_match_data(&pdev->dev);
> + if (!data)
> + return -EINVAL;
>
> err = stmmac_dvr_remove(&pdev->dev);
> if (err < 0)