* [PATCH] leds: trigger: tty: fix overflow in ttyname show
@ 2026-12-01 6:20 Lin Tzu Yang
0 siblings, 0 replies; only message in thread
From: Lin Tzu Yang @ 2026-12-01 6:20 UTC (permalink / raw)
To: Lee Jones, Pavel Machek
Cc: Griffin Kroah-Hartman, linux-leds, linux-kernel, stable
ttyname_store() keeps whatever the user writes, without a length
limit. sysfs passes up to PAGE_SIZE bytes to a store callback, so the
stored name can be 4096 characters long.
ttyname_show() prints it back with sprintf(buf, "%s\n", ...). With a
4095-byte name that is 4097 bytes, with 4096 bytes it is 4098, both
past the PAGE_SIZE sysfs buffer. Reading the attribute after writing
a 4095-byte name gives:
BUG: KASAN: slab-out-of-bounds in vsnprintf+0xdd8/0xdfc
Write of size 1 at addr ffff00001281f000 by task cat/114
...
sprintf+0xb0/0xec
ttyname_show+0xec/0x140
dev_attr_show+0x48/0xbc
sysfs_kf_seq_show+0x160/0x314
followed by the "OOB write or bad count" warning
from sysfs_kf_seq_show().
Use sysfs_emit(), which never writes past PAGE_SIZE. The other show
callbacks in this file already use it.
Fixes: fd4a641ac88f ("leds: trigger: implement a tty trigger")
Cc: stable@vger.kernel.org
Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
---
The bug was found with a small fuzzing script and the fix was
written with AI assistance (Claude); I reviewed and tested it.
The patch is against leds-next; it was tested in QEMU (arm64, KASAN)
on configfs-next (2e0fad9d2eae), where this file is identical, using
a uleds device with the tty trigger. Before: KASAN reports and the
sysfs warning on reading back a 4095- or 4096-byte ttyname. After:
no reports, the read returns 4095 bytes.
drivers/leds/trigger/ledtrig-tty.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c
index 3725571144..3b8b269891 100644
--- a/drivers/leds/trigger/ledtrig-tty.c
+++ b/drivers/leds/trigger/ledtrig-tty.c
@@ -67,7 +67,7 @@ static ssize_t ttyname_show(struct device *dev,
return completion;
if (trigger_data->ttyname)
- len = sprintf(buf, "%s\n", trigger_data->ttyname);
+ len = sysfs_emit(buf, "%s\n", trigger_data->ttyname);
return len;
}
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 6:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 6:20 [PATCH] leds: trigger: tty: fix overflow in ttyname show Lin Tzu Yang
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®