* [PATCH] tools/leds/uledmon: force NUL-termination of device name
@ 2026-11-06 10:06 Gu Bin
2026-11-06 10:09 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Gu Bin @ 2026-11-06 10:06 UTC (permalink / raw)
To: lee; +Cc: pavel, david, linux-leds, linux-kernel
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.
Force NUL-termination after the strncpy.
Fixes: fa7f32422ea1 ("tools/leds: Add uledmon program for monitoring userspace LEDs")
Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
---
tools/leds/uledmon.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/leds/uledmon.c b/tools/leds/uledmon.c
index c15a39c1f271..6df35b817233 100644
--- a/tools/leds/uledmon.c
+++ b/tools/leds/uledmon.c
@@ -32,6 +32,7 @@ int main(int argc, char const *argv[])
}
strncpy(uleds_dev.name, argv[1], LED_MAX_NAME_SIZE);
+ uleds_dev.name[LED_MAX_NAME_SIZE - 1] = '\0';
uleds_dev.max_brightness = 100;
fd = open("/dev/uleds", O_RDWR);
--
2.55.0.windows.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] tools/leds/uledmon: force NUL-termination of device name
2026-11-06 10:06 [PATCH] tools/leds/uledmon: force NUL-termination of device name Gu Bin
@ 2026-11-06 10:09 ` sashiko-bot
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
2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-06 10:09 UTC (permalink / raw)
To: Gu Bin; +Cc: linux-leds, lee
> 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.
>
> Force NUL-termination after the strncpy.
>
> Fixes: fa7f32422ea1 ("tools/leds: Add uledmon program for monitoring userspace LEDs")
> Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261106100614.2312-1-gubin@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tools/leds/uledmon: force NUL-termination of device name
2026-11-06 10:06 [PATCH] tools/leds/uledmon: force NUL-termination of device name Gu Bin
2026-11-06 10:09 ` sashiko-bot
@ 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
2 siblings, 0 replies; 5+ messages in thread
From: David Lechner @ 2026-11-06 14:05 UTC (permalink / raw)
To: Gu Bin, lee; +Cc: pavel, linux-leds, linux-kernel
On 11/6/26 4:06 AM, 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.
>
> Force NUL-termination after the strncpy.
>
> Fixes: fa7f32422ea1 ("tools/leds: Add uledmon program for monitoring userspace LEDs")
> Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
> ---
> tools/leds/uledmon.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/leds/uledmon.c b/tools/leds/uledmon.c
> index c15a39c1f271..6df35b817233 100644
> --- a/tools/leds/uledmon.c
> +++ b/tools/leds/uledmon.c
> @@ -32,6 +32,7 @@ int main(int argc, char const *argv[])
> }
>
> strncpy(uleds_dev.name, argv[1], LED_MAX_NAME_SIZE);
> + uleds_dev.name[LED_MAX_NAME_SIZE - 1] = '\0';
> uleds_dev.max_brightness = 100;
>
> fd = open("/dev/uleds", O_RDWR);
This works, but maybe better to just print an error and exit with error code
rather than silently truncating the name?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] tools/leds/uledmon: reject device names that are too long
2026-11-06 10:06 [PATCH] tools/leds/uledmon: force NUL-termination of device name Gu Bin
2026-11-06 10:09 ` sashiko-bot
2026-11-06 14:05 ` David Lechner
@ 2026-11-09 7:05 ` Gu Bin
2026-11-09 7:11 ` sashiko-bot
2 siblings, 1 reply; 5+ messages in thread
From: Gu Bin @ 2026-11-09 7:05 UTC (permalink / raw)
To: lee; +Cc: pavel, david, linux-leds, linux-kernel
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]);
uleds_dev.max_brightness = 100;
fd = open("/dev/uleds", O_RDWR);
--
2.55.0.windows.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tools/leds/uledmon: reject device names that are too long
2026-11-09 7:05 ` [PATCH v2] tools/leds/uledmon: reject device names that are too long Gu Bin
@ 2026-11-09 7:11 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-09 7:11 UTC (permalink / raw)
To: Gu Bin; +Cc: linux-leds, lee
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109070539.1922-1-gubin@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-09 7:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06 10:06 [PATCH] tools/leds/uledmon: force NUL-termination of device name Gu Bin
2026-11-06 10:09 ` sashiko-bot
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-09 7:11 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox