public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: joeyli <jlee@suse.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: "Lee, Chun-Yi" <joeyli.kernel@gmail.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
	Linux PM <linux-pm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] thermal/int340x_thermal: handle data_vault when the value is ZERO_SIZE_PTR
Date: Wed, 24 Aug 2022 15:13:03 +0800	[thread overview]
Message-ID: <20220824071303.GE5247@linux-l9pv.suse> (raw)
In-Reply-To: <CAJZ5v0ig8mkNSrwsUhNVVGeBgB9TMmTDZQQmf_tCV4oJ85VPRA@mail.gmail.com>

On Tue, Aug 23, 2022 at 07:53:18PM +0200, Rafael J. Wysocki wrote:
> On Mon, Aug 8, 2022 at 3:22 PM Lee, Chun-Yi <joeyli.kernel@gmail.com> wrote:
> >
> > In some case, the GDDV returns a package with a buffer which has
> > zero length. It causes that kmemdup() returns ZERO_SIZE_PTR (0x10).
> >
> > Then the data_vault_read() got NULL point dereference problem when
> > accessing the 0x10 value in data_vault.
> >
> > [   71.024560] BUG: kernel NULL pointer dereference, address:
> > 0000000000000010
> >
> > This patch uses ZERO_OR_NULL_PTR() for checking ZERO_SIZE_PTR or
> > NULL value in data_vault.
> >
> > Signed-off-by: "Lee, Chun-Yi" <jlee@suse.com>
> 
> Applied as 6.0-rc material, thanks!

Thanks for Rafael's help!

Joey Lee

> 
> > ---
> >  drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > index 80d4e0676083..365489bf4b8c 100644
> > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > @@ -527,7 +527,7 @@ static void int3400_setup_gddv(struct int3400_thermal_priv *priv)
> >         priv->data_vault = kmemdup(obj->package.elements[0].buffer.pointer,
> >                                    obj->package.elements[0].buffer.length,
> >                                    GFP_KERNEL);
> > -       if (!priv->data_vault)
> > +       if (ZERO_OR_NULL_PTR(priv->data_vault))
> >                 goto out_free;
> >
> >         bin_attr_data_vault.private = priv->data_vault;
> > @@ -597,7 +597,7 @@ static int int3400_thermal_probe(struct platform_device *pdev)
> >                         goto free_imok;
> >         }
> >
> > -       if (priv->data_vault) {
> > +       if (!ZERO_OR_NULL_PTR(priv->data_vault)) {
> >                 result = sysfs_create_group(&pdev->dev.kobj,
> >                                             &data_attribute_group);
> >                 if (result)
> > @@ -615,7 +615,8 @@ static int int3400_thermal_probe(struct platform_device *pdev)
> >  free_sysfs:
> >         cleanup_odvp(priv);
> >         if (priv->data_vault) {
> > -               sysfs_remove_group(&pdev->dev.kobj, &data_attribute_group);
> > +               if (!ZERO_OR_NULL_PTR(priv->data_vault))
> > +                       sysfs_remove_group(&pdev->dev.kobj, &data_attribute_group);
> >                 kfree(priv->data_vault);
> >         }
> >  free_uuid:
> > @@ -647,7 +648,7 @@ static int int3400_thermal_remove(struct platform_device *pdev)
> >         if (!priv->rel_misc_dev_res)
> >                 acpi_thermal_rel_misc_device_remove(priv->adev->handle);
> >
> > -       if (priv->data_vault)
> > +       if (!ZERO_OR_NULL_PTR(priv->data_vault))
> >                 sysfs_remove_group(&pdev->dev.kobj, &data_attribute_group);
> >         sysfs_remove_group(&pdev->dev.kobj, &uuid_attribute_group);
> >         sysfs_remove_group(&pdev->dev.kobj, &imok_attribute_group);
> > --
> > 2.26.2
> >

      reply	other threads:[~2022-08-24  7:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08 13:21 [PATCH] thermal/int340x_thermal: handle data_vault when the value is ZERO_SIZE_PTR Lee, Chun-Yi
2022-08-23 17:53 ` Rafael J. Wysocki
2022-08-24  7:13   ` joeyli [this message]

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=20220824071303.GE5247@linux-l9pv.suse \
    --to=jlee@suse.com \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=joeyli.kernel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.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