2021-06-04 09:29:59

by Yang Yingliang

[permalink] [raw]
Subject: [PATCH net-next] net: mscc: ocelot: check return value after calling platform_get_resource()

It will cause null-ptr-deref if platform_get_resource() returns NULL,
we need check the return value.

Signed-off-by: Yang Yingliang <[email protected]>
---
drivers/net/dsa/ocelot/seville_vsc9953.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c
index 84f93a874d50..b514e2d05b6f 100644
--- a/drivers/net/dsa/ocelot/seville_vsc9953.c
+++ b/drivers/net/dsa/ocelot/seville_vsc9953.c
@@ -1206,6 +1206,10 @@ static int seville_probe(struct platform_device *pdev)
felix->info = &seville_info_vsc9953;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ err = -EINVAL;
+ dev_err(&pdev->dev, "Invalid resource\n");
+ }
felix->switch_base = res->start;

ds = kzalloc(sizeof(struct dsa_switch), GFP_KERNEL);
--
2.25.1


2021-06-04 10:08:40

by Wei Yongjun

[permalink] [raw]
Subject: Re: [PATCH net-next] net: mscc: ocelot: check return value after calling platform_get_resource()


> It will cause null-ptr-deref if platform_get_resource() returns NULL,
> we need check the return value.
>
> Signed-off-by: Yang Yingliang <[email protected]>
> ---
> drivers/net/dsa/ocelot/seville_vsc9953.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c
> index 84f93a874d50..b514e2d05b6f 100644
> --- a/drivers/net/dsa/ocelot/seville_vsc9953.c
> +++ b/drivers/net/dsa/ocelot/seville_vsc9953.c
> @@ -1206,6 +1206,10 @@ static int seville_probe(struct platform_device *pdev)
> felix->info = &seville_info_vsc9953;
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!res) {
> + err = -EINVAL;
> + dev_err(&pdev->dev, "Invalid resource\n");


should 'goto err_alloc_felix;'


> + }
> felix->switch_base = res->start;
>
> ds = kzalloc(sizeof(struct dsa_switch), GFP_KERNEL);