From: Jani Nikula <jani.nikula@linux.intel.com>
To: Haoyu Li <lihaoyu499@gmail.com>, Lee Jones <lee@kernel.org>,
Daniel Thompson <danielt@kernel.org>,
Jingoo Han <jingoohan1@gmail.com>
Cc: Helge Deller <deller@gmx.de>, Rob Herring <robh@kernel.org>,
dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
linux-kernel@vger.kernel.org, chenyuan0y@gmail.com,
zichenxie0106@gmail.com, Haoyu Li <lihaoyu499@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] drivers: video: backlight: Fix NULL Pointer Dereference in backlight_device_register()
Date: Mon, 03 Feb 2025 15:21:23 +0200 [thread overview]
Message-ID: <87ldun6u5o.fsf@intel.com> (raw)
In-Reply-To: <20250130145228.96679-1-lihaoyu499@gmail.com>
On Thu, 30 Jan 2025, Haoyu Li <lihaoyu499@gmail.com> wrote:
> In the function "wled_probe", the "wled->name" is dynamically allocated
> (wled_probe -> wled_configure -> devm_kasprintf), which is possible
> to be null.
>
> In the call trace: wled_probe -> devm_backlight_device_register
> -> backlight_device_register, this "name" variable is directly
> dereferenced without checking. We add a null-check statement.
>
> Fixes: f86b77583d88 ("backlight: pm8941: Convert to using %pOFn instead of device_node.name")
> Signed-off-by: Haoyu Li <lihaoyu499@gmail.com>
> Cc: stable@vger.kernel.org
IMO whoever allocates should be responsible for checking NULL instead of
passing NULL around and expecting everyone check their input for NULL.
BR,
Jani.
> ---
> drivers/video/backlight/backlight.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
> index f699e5827ccb..b21670bd86de 100644
> --- a/drivers/video/backlight/backlight.c
> +++ b/drivers/video/backlight/backlight.c
> @@ -414,6 +414,8 @@ struct backlight_device *backlight_device_register(const char *name,
> struct backlight_device *new_bd;
> int rc;
>
> + if (!name)
> + return ERR_PTR(-EINVAL);
> pr_debug("backlight_device_register: name=%s\n", name);
>
> new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL);
--
Jani Nikula, Intel
next prev parent reply other threads:[~2025-02-03 13:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 14:52 [PATCH] drivers: video: backlight: Fix NULL Pointer Dereference in backlight_device_register() Haoyu Li
2025-02-03 13:21 ` Jani Nikula [this message]
2025-02-13 21:07 ` Daniel Thompson
2025-02-19 12:29 ` Haoyu Li
2025-04-01 14:29 ` Daniel Thompson
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=87ldun6u5o.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=chenyuan0y@gmail.com \
--cc=danielt@kernel.org \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=jingoohan1@gmail.com \
--cc=lee@kernel.org \
--cc=lihaoyu499@gmail.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=zichenxie0106@gmail.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;
as well as URLs for NNTP newsgroup(s).