From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: ruanjinjie <ruanjinjie@huawei.com>,
sre@kernel.org, linus.walleij@linaro.org,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] power: supply: fix null pointer dereferencing in power_supply_get_battery_info
Date: Mon, 5 Dec 2022 19:05:04 +0800 [thread overview]
Message-ID: <ea327ec7-e9f3-b589-43f5-70b5f1a0025a@linux.alibaba.com> (raw)
In-Reply-To: <20221205075153.2830393-1-ruanjinjie@huawei.com>
On 12/5/2022 3:51 PM, ruanjinjie wrote:
> when kmalloc() fail to allocate memory in kasprintf(), propname
> will be NULL, strcmp() called by of_get_property() will cause
> null pointer dereference.
>
> So return ENOMEM if kasprintf() return NULL pointer.
>
> Fixes: 3afb50d7125b ("power: supply: core: Add some helpers to use the battery OCV capacity table")
> Signed-off-by: ruanjinjie <ruanjinjie@huawei.com>
LGTM.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> v2:
> - release resource instead of just returning error number
> ---
> drivers/power/supply/power_supply_core.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 4b5fb172fa99..afbe9eecfc30 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -750,6 +750,11 @@ int power_supply_get_battery_info(struct power_supply *psy,
> int i, tab_len, size;
>
> propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
> + if (!propname) {
> + power_supply_put_battery_info(psy, info);
> + err = -ENOMEM;
> + goto out_put_node;
> + }
> list = of_get_property(battery_np, propname, &size);
> if (!list || !size) {
> dev_err(&psy->dev, "failed to get %s\n", propname);
next prev parent reply other threads:[~2022-12-05 11:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 7:51 ruanjinjie
2022-12-05 11:05 ` Baolin Wang [this message]
2022-12-05 22:25 ` Sebastian Reichel
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=ea327ec7-e9f3-b589-43f5-70b5f1a0025a@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=ruanjinjie@huawei.com \
--cc=sre@kernel.org \
/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®