Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Lin Tzu Yang <rongh7426@gmail.com>
To: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>
Cc: Griffin Kroah-Hartman <griffin@kroah.com>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH] leds: trigger: tty: fix overflow in ttyname show
Date: Tue,  1 Dec 2026 14:20:37 +0800	[thread overview]
Message-ID: <20261201062037.880601-1-rongh7426@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-01  6:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261201062037.880601-1-rongh7426@gmail.com \
    --to=rongh7426@gmail.com \
    --cc=griffin@kroah.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=stable@vger.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