From: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
To: Hui Tang <tanghui20@huawei.com>,
p.zabel@pengutronix.de, mhiramat@kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, weiyongjun1@huawei.com
Subject: Re: [PATCH] reset: uniphier-glue: Fix possible null-ptr-deref
Date: Mon, 14 Nov 2022 10:09:47 +0900 [thread overview]
Message-ID: <32291d3a-25f8-ff5f-d149-180fbb82278d@socionext.com> (raw)
In-Reply-To: <20221114004958.258513-1-tanghui20@huawei.com>
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
next prev parent reply other threads:[~2022-11-14 1:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 0:49 Hui Tang
2022-11-14 1:09 ` Kunihiko Hayashi [this message]
2023-01-03 10:51 ` Philipp Zabel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32291d3a-25f8-ff5f-d149-180fbb82278d@socionext.com \
--to=hayashi.kunihiko@socionext.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=tanghui20@huawei.com \
--cc=weiyongjun1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®