* [PATCH] sparc/led: prevent buffer underflow on zero-length write
@ 2025-10-30 7:21 Miaoqian Lin
2026-01-14 8:40 ` Andreas Larsson
0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2025-10-30 7:21 UTC (permalink / raw)
To: David S. Miller, Andreas Larsson, Ingo Molnar, Thomas Gleixner,
Lars Kotthoff, sparclinux, linux-kernel
Cc: linmq006, stable
Fix out-of-bounds access in led_proc_write() when count is 0.
Accessing buf[count - 1] with count=0 reads/writes buf[-1].
Check for count==0 and return -EINVAL early to fix this.
Found via static analysis and code review.
Fixes: ee1858d3122d ("[SPARC]: Add sun4m LED driver.")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
arch/sparc/kernel/led.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c
index f4fb82b019bb..aa0ca0d8d0e2 100644
--- a/arch/sparc/kernel/led.c
+++ b/arch/sparc/kernel/led.c
@@ -70,6 +70,9 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,
{
char *buf = NULL;
+ if (count == 0)
+ return -EINVAL;
+
if (count > LED_MAX_LENGTH)
count = LED_MAX_LENGTH;
--
2.39.5 (Apple Git-154)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] sparc/led: prevent buffer underflow on zero-length write
2025-10-30 7:21 [PATCH] sparc/led: prevent buffer underflow on zero-length write Miaoqian Lin
@ 2026-01-14 8:40 ` Andreas Larsson
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Larsson @ 2026-01-14 8:40 UTC (permalink / raw)
To: Miaoqian Lin, David S. Miller, Ingo Molnar, Thomas Gleixner,
Lars Kotthoff, sparclinux, linux-kernel
Cc: stable
On 2025-10-30 08:21, Miaoqian Lin wrote:
> Fix out-of-bounds access in led_proc_write() when count is 0.
> Accessing buf[count - 1] with count=0 reads/writes buf[-1].
>
> Check for count==0 and return -EINVAL early to fix this.
>
> Found via static analysis and code review.
>
> Fixes: ee1858d3122d ("[SPARC]: Add sun4m LED driver.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> arch/sparc/kernel/led.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c
> index f4fb82b019bb..aa0ca0d8d0e2 100644
> --- a/arch/sparc/kernel/led.c
> +++ b/arch/sparc/kernel/led.c
> @@ -70,6 +70,9 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,
> {
> char *buf = NULL;
>
> + if (count == 0)
> + return -EINVAL;
> +
> if (count > LED_MAX_LENGTH)
> count = LED_MAX_LENGTH;
>
Thank you for the patch.
I see no need to fail on the empty string in particular when further
down we have a default case:
} else {
auxio_set_led(AUXIO_LED_OFF);
}
for any string not matching particular cases.
Instead, please stop the incorrect buffer access with something like:
diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c
index f4fb82b019bb9..9b53ac1fe533d 100644
--- a/arch/sparc/kernel/led.c
+++ b/arch/sparc/kernel/led.c
@@ -78,7 +78,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,
return PTR_ERR(buf);
/* work around \n when echo'ing into proc */
- if (buf[count - 1] == '\n')
+ if (count > 0 && buf[count - 1] == '\n')
buf[count - 1] = '\0';
/* before we change anything we want to stop any running timers,
Thanks,
Andreas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-14 8:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-30 7:21 [PATCH] sparc/led: prevent buffer underflow on zero-length write Miaoqian Lin
2026-01-14 8:40 ` Andreas Larsson
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®