* [PATCH] leds: ledtrig-tty: Fix memory leak in ttyname_store() on timeout
@ 2026-11-30 7:59 Priyanka Mani
2026-11-30 13:15 ` Florian Eckert
0 siblings, 1 reply; 2+ messages in thread
From: Priyanka Mani @ 2026-11-30 7:59 UTC (permalink / raw)
To: Lee Jones, Pavel Machek
Cc: Griffin Kroah-Hartman, Florian Eckert, Greg Kroah-Hartman,
linux-leds, linux-kernel, Priyanka Mani, stable
ttyname_store() duplicates the user supplied name with kmemdup_nul()
before waiting for the trigger work to complete. If the wait times out,
the function returns -ETIMEDOUT without freeing the duplicated name, so
every timed out write to the ttyname attribute leaks that buffer.
Free the buffer before returning on the error path.
Fixes: 76675f69bed5 ("leds: ledtrig-tty: Replace mutex with completion")
Cc: stable@vger.kernel.org
Signed-off-by: Priyanka Mani <priyankamani2100@gmail.com>
---
drivers/leds/trigger/ledtrig-tty.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c
index 3725571144d9..dde0d4172301 100644
--- a/drivers/leds/trigger/ledtrig-tty.c
+++ b/drivers/leds/trigger/ledtrig-tty.c
@@ -94,8 +94,10 @@ static ssize_t ttyname_store(struct device *dev,
reinit_completion(&trigger_data->sysfs);
completion = ledtrig_tty_wait_for_completion(dev);
- if (completion < 0)
+ if (completion < 0) {
+ kfree(ttyname);
return completion;
+ }
kfree(trigger_data->ttyname);
tty_kref_put(trigger_data->tty);
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] leds: ledtrig-tty: Fix memory leak in ttyname_store() on timeout
2026-11-30 7:59 [PATCH] leds: ledtrig-tty: Fix memory leak in ttyname_store() on timeout Priyanka Mani
@ 2026-11-30 13:15 ` Florian Eckert
0 siblings, 0 replies; 2+ messages in thread
From: Florian Eckert @ 2026-11-30 13:15 UTC (permalink / raw)
To: Priyanka Mani
Cc: Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
Greg Kroah-Hartman, linux-leds, linux-kernel, stable
On 2026-11-30 08:59, Priyanka Mani wrote:
> ttyname_store() duplicates the user supplied name with kmemdup_nul()
> before waiting for the trigger work to complete. If the wait times out,
> the function returns -ETIMEDOUT without freeing the duplicated name, so
> every timed out write to the ttyname attribute leaks that buffer.
>
> Free the buffer before returning on the error path.
>
> Fixes: 76675f69bed5 ("leds: ledtrig-tty: Replace mutex with completion")
> Cc: stable@vger.kernel.org
> Signed-off-by: Priyanka Mani <priyankamani2100@gmail.com>
Reviewed-by: Florian Eckert <fe@dev.tdt.de>
> ---
> drivers/leds/trigger/ledtrig-tty.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c
> index 3725571144d9..dde0d4172301 100644
> --- a/drivers/leds/trigger/ledtrig-tty.c
> +++ b/drivers/leds/trigger/ledtrig-tty.c
> @@ -94,8 +94,10 @@ static ssize_t ttyname_store(struct device *dev,
>
> reinit_completion(&trigger_data->sysfs);
> completion = ledtrig_tty_wait_for_completion(dev);
> - if (completion < 0)
> + if (completion < 0) {
> + kfree(ttyname);
> return completion;
> + }
>
> kfree(trigger_data->ttyname);
> tty_kref_put(trigger_data->tty);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 13:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 7:59 [PATCH] leds: ledtrig-tty: Fix memory leak in ttyname_store() on timeout Priyanka Mani
2026-11-30 13:15 ` Florian Eckert
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®