mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] reset: uniphier-glue: Fix possible null-ptr-deref
@ 2022-11-14  0:49 Hui Tang
  2022-11-14  1:09 ` Kunihiko Hayashi
  2023-01-03 10:51 ` Philipp Zabel
  0 siblings, 2 replies; 3+ messages in thread
From: Hui Tang @ 2022-11-14  0:49 UTC (permalink / raw)
  To: p.zabel, hayashi.kunihiko, mhiramat
  Cc: linux-arm-kernel, linux-kernel, weiyongjun1

It will cause null-ptr-deref when resource_size(res) invoked,
if platform_get_resource() returns NULL.

Fixes: 499fef09a323 ("reset: uniphier: add USB3 core reset control")
Signed-off-by: Hui Tang <tanghui20@huawei.com>
---
 drivers/reset/reset-uniphier-glue.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/reset/reset-uniphier-glue.c b/drivers/reset/reset-uniphier-glue.c
index 146fd5d45e99..15abac9fc72c 100644
--- a/drivers/reset/reset-uniphier-glue.c
+++ b/drivers/reset/reset-uniphier-glue.c
@@ -47,7 +47,6 @@ static int uniphier_glue_reset_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct uniphier_glue_reset_priv *priv;
 	struct resource *res;
-	resource_size_t size;
 	int i, ret;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -60,7 +59,6 @@ static int uniphier_glue_reset_probe(struct platform_device *pdev)
 		return -EINVAL;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	size = resource_size(res);
 	priv->rdata.membase = devm_ioremap_resource(dev, res);
 	if (IS_ERR(priv->rdata.membase))
 		return PTR_ERR(priv->rdata.membase);
@@ -96,7 +94,7 @@ static int uniphier_glue_reset_probe(struct platform_device *pdev)
 
 	spin_lock_init(&priv->rdata.lock);
 	priv->rdata.rcdev.owner = THIS_MODULE;
-	priv->rdata.rcdev.nr_resets = size * BITS_PER_BYTE;
+	priv->rdata.rcdev.nr_resets = resource_size(res) * BITS_PER_BYTE;
 	priv->rdata.rcdev.ops = &reset_simple_ops;
 	priv->rdata.rcdev.of_node = dev->of_node;
 	priv->rdata.active_low = true;
-- 
2.17.1


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

* Re: [PATCH] reset: uniphier-glue: Fix possible null-ptr-deref
  2022-11-14  0:49 [PATCH] reset: uniphier-glue: Fix possible null-ptr-deref Hui Tang
@ 2022-11-14  1:09 ` Kunihiko Hayashi
  2023-01-03 10:51 ` Philipp Zabel
  1 sibling, 0 replies; 3+ messages in thread
From: Kunihiko Hayashi @ 2022-11-14  1:09 UTC (permalink / raw)
  To: Hui Tang, p.zabel, mhiramat; +Cc: linux-arm-kernel, linux-kernel, weiyongjun1

On 2022/11/14 9:49, Hui Tang wrote:
> It will cause null-ptr-deref when resource_size(res) invoked,
> if platform_get_resource() returns NULL.
> 
> Fixes: 499fef09a323 ("reset: uniphier: add USB3 core reset control")
> Signed-off-by: Hui Tang <tanghui20@huawei.com>
> ---
>   drivers/reset/reset-uniphier-glue.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/reset/reset-uniphier-glue.c
> b/drivers/reset/reset-uniphier-glue.c
> index 146fd5d45e99..15abac9fc72c 100644
> --- a/drivers/reset/reset-uniphier-glue.c
> +++ b/drivers/reset/reset-uniphier-glue.c
> @@ -47,7 +47,6 @@ static int uniphier_glue_reset_probe(struct
> platform_device *pdev)
>   	struct device *dev = &pdev->dev;
>   	struct uniphier_glue_reset_priv *priv;
>   	struct resource *res;
> -	resource_size_t size;
>   	int i, ret;
>   
>   	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> @@ -60,7 +59,6 @@ static int uniphier_glue_reset_probe(struct
> platform_device *pdev)
>   		return -EINVAL;
>   
>   	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	size = resource_size(res);
>   	priv->rdata.membase = devm_ioremap_resource(dev, res);
>   	if (IS_ERR(priv->rdata.membase))
>   		return PTR_ERR(priv->rdata.membase);
> @@ -96,7 +94,7 @@ static int uniphier_glue_reset_probe(struct
> platform_device *pdev)
>   
>   	spin_lock_init(&priv->rdata.lock);
>   	priv->rdata.rcdev.owner = THIS_MODULE;
> -	priv->rdata.rcdev.nr_resets = size * BITS_PER_BYTE;
> +	priv->rdata.rcdev.nr_resets = resource_size(res) * BITS_PER_BYTE;
>   	priv->rdata.rcdev.ops = &reset_simple_ops;
>   	priv->rdata.rcdev.of_node = dev->of_node;
>   	priv->rdata.active_low = true;

Good catch! resource_size() should refer to res after the check.

Reviewed-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>

Thank you,

---
Best Regards
Kunihiko Hayashi

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

* Re: [PATCH] reset: uniphier-glue: Fix possible null-ptr-deref
  2022-11-14  0:49 [PATCH] reset: uniphier-glue: Fix possible null-ptr-deref Hui Tang
  2022-11-14  1:09 ` Kunihiko Hayashi
@ 2023-01-03 10:51 ` Philipp Zabel
  1 sibling, 0 replies; 3+ messages in thread
From: Philipp Zabel @ 2023-01-03 10:51 UTC (permalink / raw)
  To: Hui Tang, hayashi.kunihiko, mhiramat
  Cc: linux-arm-kernel, linux-kernel, weiyongjun1

On Mo, 2022-11-14 at 08:49 +0800, Hui Tang wrote:
> It will cause null-ptr-deref when resource_size(res) invoked,
> if platform_get_resource() returns NULL.
> 
> Fixes: 499fef09a323 ("reset: uniphier: add USB3 core reset control")
> Signed-off-by: Hui Tang <tanghui20@huawei.com>

Thank you, applied to reset/fixes.

regards
Philipp

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

end of thread, other threads:[~2023-01-03 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-14  0:49 [PATCH] reset: uniphier-glue: Fix possible null-ptr-deref Hui Tang
2022-11-14  1:09 ` Kunihiko Hayashi
2023-01-03 10:51 ` Philipp Zabel

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®