From: Lee Jones <lee@kernel.org>
To: Gu Bin <gubin@cmss.chinamobile.com>
Cc: pavel@kernel.org, david@lechnology.com,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tools/leds/uledmon: reject device names that are too long
Date: Wed, 18 Nov 2026 19:53:48 +0000 [thread overview]
Message-ID: <179442104215.44545.2144163087581820120@kernel.org> (raw)
In-Reply-To: <20261109070539.1922-1-gubin@cmss.chinamobile.com>
On Mon, 09 Nov 2026, Gu Bin wrote:
> strncpy() does not NUL-terminate when the source is at least as long
> as the bound. uleds_dev.name is passed to the kernel with
> write(fd, &uleds_dev, sizeof(uleds_dev)), so a >= LED_MAX_NAME_SIZE
> byte argv[1] leaves name without a terminator and the write sends
> trailing bytes that are not part of a valid device name.
>
> Silently truncating such a name would create a device the user did
> not ask for, so error out instead, like the other argument checks
> already do.
>
> Fixes: fa7f32422ea1 ("tools/leds: Add uledmon program for monitoring userspace LEDs")
> Suggested-by: David Lechner <david@lechnology.com>
> Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
> ---
>
> Changes in v2: reject over-long names with an error instead of
> silently truncating them, as suggested by David Lechner.
>
> tools/leds/uledmon.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/tools/leds/uledmon.c b/tools/leds/uledmon.c
> index c15a39c1f271..d38f5716c7f7 100644
> --- a/tools/leds/uledmon.c
> +++ b/tools/leds/uledmon.c
> @@ -31,7 +31,13 @@ int main(int argc, char const *argv[])
> return 1;
> }
>
> - strncpy(uleds_dev.name, argv[1], LED_MAX_NAME_SIZE);
> + if (strlen(argv[1]) >= LED_MAX_NAME_SIZE) {
> + fprintf(stderr, "Device name too long (max %d bytes)\n",
> + LED_MAX_NAME_SIZE - 1);
> + return 1;
> + }
> +
> + strcpy(uleds_dev.name, argv[1]);
Doesn't replacing strcpy() leave the remaining bytes of 'uleds_dev.name'
uninitialised on the stack?
Since 'uleds_dev' is passed to:
write(fd, &uleds_dev, sizeof(uleds_dev))'
... why doesn't this leak uninitialised stack memory to the kernel?
Either zero-initialise 'uleds_dev' or keep strncpy() as it is.
> uleds_dev.max_brightness = 100;
>
> fd = open("/dev/uleds", O_RDWR);
> --
> 2.55.0.windows.3
>
>
>
--
Lee Jones
prev parent reply other threads:[~2026-11-18 19:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 10:06 [PATCH] tools/leds/uledmon: force NUL-termination of device name Gu Bin
2026-11-06 14:05 ` David Lechner
2026-11-09 7:05 ` [PATCH v2] tools/leds/uledmon: reject device names that are too long Gu Bin
2026-11-18 19:53 ` Lee Jones [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=179442104215.44545.2144163087581820120@kernel.org \
--to=lee@kernel.org \
--cc=david@lechnology.com \
--cc=gubin@cmss.chinamobile.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@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®