All of lore.kernel.org
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [PATCH 1/4] tty: hvsi: fix stack overread in hvsi_version_respond()
Date: Fri,  4 Dec 2026 22:35:33 -0800	[thread overview]
Message-ID: <20261205063536.2519566-2-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261205063536.2519566-1-praneethb2002@gmail.com>

hvc_put_chars() always loads two unsigned long words from the buffer,
16 bytes in total, whatever count its caller passes. Its comment says
the buffer must be at least 16 bytes. hvsi_version_respond() passes a
struct hvsi_query_response, which is only 12 bytes. The load of the
second word reads 4 bytes past the end of the stack object. This
happens on every HVSI handshake, when the port answers the version
query of the service processor.

Copy the packet into a zeroed, aligned 16 byte buffer and pass that to
hvc_put_chars(). The 4 bytes after the packet are then zero instead of
stack contents. The count stays packet.hdr.len, so the service
processor sees the same bytes as before.

This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by an LLM-based audit, part of research at UCSB SecLab.
    An LLM turned a kernel comment into a rule, and three LLM votes checked
    the code against it. The fix and changelog were drafted with GLM-5.3,
    then checked against the source and partly rewritten with Claude Opus
    5.5. I reviewed the patch and take responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64 allmodconfig;
    powerpc pseries_defconfig), clang 23. checkpatch.pl is clean. Not
    runtime-tested, and there is no reproducer. I do not have this hardware.

 drivers/tty/hvc/hvsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index a94068bce76f..ec91ee42ad8c 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -279,7 +279,9 @@ static void hvsi_recv_response(struct hvsi_struct *hp, uint8_t *packet)
 /* respond to service processor's version query */
 static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
 {
-	struct hvsi_query_response packet __ALIGNED__;
+	struct hvsi_query_response packet;
+	/* hvc_put_chars() reads 16 bytes even if count is smaller. */
+	uint8_t buf[16] __ALIGNED__ = {};
 	int wrote;
 
 	packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
@@ -292,7 +294,8 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
 	pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
 	dbg_dump_hex((uint8_t*)&packet, packet.hdr.len);
 
-	wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.hdr.len);
+	memcpy(buf, &packet, sizeof(packet));
+	wrote = hvc_put_chars(hp->vtermno, buf, packet.hdr.len);
 	if (wrote != packet.hdr.len) {
 		printk(KERN_ERR "hvsi%i: couldn't send query response!\n",
 			hp->index);
-- 
2.25.1


  reply	other threads:[~2026-12-05  6:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  6:35 [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers Praneeth Balasubramanian
2026-12-05  6:35 ` Praneeth Balasubramanian [this message]
2026-12-05  6:53   ` [PATCH 1/4] tty: hvsi: fix stack overread in hvsi_version_respond() sashiko-bot
2026-12-05  8:20     ` Praneeth Balasubramanian
2026-12-05  6:35 ` [PATCH 2/4] serial: men_z135_uart: do not release an unrequested memory region Praneeth Balasubramanian
2026-12-05  6:35 ` [PATCH 3/4] tty: atmel_serial: take the port lock in console write Praneeth Balasubramanian
2026-12-05  6:59   ` sashiko-bot
2026-12-05  8:20     ` Praneeth Balasubramanian
2026-12-05  6:35 ` [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info() Praneeth Balasubramanian
2026-12-05  6:56   ` sashiko-bot
2026-12-05  6:59 ` [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers sashiko-bot

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=20261205063536.2519566-2-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.