From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org, Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org
Subject: [PATCH v2] powerpc/pseries/hvconsole: Do not read past count in hvc_put_chars()
Date: Sat, 5 Dec 2026 00:30:25 -0800 [thread overview]
Message-ID: <20261205083025.2602522-1-praneethb2002@gmail.com> (raw)
hvc_put_chars() always loads two unsigned long words from the buffer, 16
bytes in total, whatever count its caller passes. Commit 934bda59f286d
("powerpc/pseries/hvconsole: Fix stack overread via udbg") documented
that the buffer must be at least 16 bytes and gave udbg_hvc_putc() a
bounce buffer. Other callers still pass smaller stack objects:
- drivers/tty/hvc/hvsi.c sends a 6 byte struct hvsi_query from
hvsi_query(), a 12 byte struct hvsi_query_response from
hvsi_version_respond() and a 14 byte struct hvsi_control from
hvsi_set_mctrl() and hvsi_close_protocol().
- drivers/tty/hvc/hvsi_lib.c sends the same three packet types through
hvsi_send_packet(). hvc_vio.c passes hvc_put_chars() as its put_chars.
- hvc_poll_put_char() sends a single char through hvterm_raw_put_chars().
Each of these reads up to 15 bytes past the end of the stack object and
passes them to the hypervisor in the H_PUT_TERM_CHAR registers. The HVSI
version query and response happen on every HVSI handshake.
Copy count bytes into a zeroed local buffer and pass that instead. This
fixes every caller at once. Drop the 16 byte requirement from the
comments on hvc_put_chars() and hvterm_raw_put_chars().
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:
Changes in v2:
- v1 was "tty: hvsi: fix stack overread in hvsi_version_respond()". It
copied one packet into a 16 byte buffer. Sashiko pointed out the other
callers that pass short buffers. This version fixes hvc_put_chars()
itself, so it is a powerpc patch with a new subject.
v1: https://lore.kernel.org/all/20261205063536.2519566-2-praneethb2002@gmail.com/
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. v1 was drafted with GLM-5.3 and checked with Claude
Opus 5.5. This version was written with Claude Opus 5.5 after it checked
the Sashiko review of v1 against the source. I reviewed the patch and
take responsibility for it.
Testing: builds without new warnings with W=1 (powerpc pseries_defconfig
with HVC_OLD_HVSI=y), clang 23. checkpatch.pl is clean. Not
runtime-tested, and there is no reproducer. I do not have this hardware.
arch/powerpc/platforms/pseries/hvconsole.c | 8 ++++++--
drivers/tty/hvc/hvc_vio.c | 4 +---
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/hvconsole.c b/arch/powerpc/platforms/pseries/hvconsole.c
index 8803c947998e..3190cb7f9a16 100644
--- a/arch/powerpc/platforms/pseries/hvconsole.c
+++ b/arch/powerpc/platforms/pseries/hvconsole.c
@@ -13,6 +13,7 @@
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/errno.h>
+#include <linux/string.h>
#include <asm/hvcall.h>
#include <asm/hvconsole.h>
#include <asm/plpar_wrappers.h>
@@ -49,12 +50,12 @@ EXPORT_SYMBOL(hvc_get_chars);
* @vtermno: The vtermno or unit_address of the adapter from which the data
* originated.
* @buf: The character buffer that contains the character data to send to
- * firmware. Must be at least 16 bytes, even if count is less than 16.
+ * firmware.
* @count: Send this number of characters.
*/
ssize_t hvc_put_chars(uint32_t vtermno, const u8 *buf, size_t count)
{
- unsigned long *lbuf = (unsigned long *) buf;
+ unsigned long lbuf[2] = { 0 };
long ret;
@@ -62,6 +63,9 @@ ssize_t hvc_put_chars(uint32_t vtermno, const u8 *buf, size_t count)
if (count > MAX_VIO_PUT_CHARS)
count = MAX_VIO_PUT_CHARS;
+ /* The hcall takes 16 bytes in two registers; do not read past count. */
+ memcpy(lbuf, buf, count);
+
ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count,
cpu_to_be64(lbuf[0]),
cpu_to_be64(lbuf[1]));
diff --git a/drivers/tty/hvc/hvc_vio.c b/drivers/tty/hvc/hvc_vio.c
index 14c6a5564617..f385978baa9e 100644
--- a/drivers/tty/hvc/hvc_vio.c
+++ b/drivers/tty/hvc/hvc_vio.c
@@ -110,9 +110,7 @@ static ssize_t hvterm_raw_get_chars(uint32_t vtermno, u8 *buf, size_t count)
/**
* hvterm_raw_put_chars: send characters to firmware for given vterm adapter
* @vtermno: The virtual terminal number.
- * @buf: The characters to send. Because of the underlying hypercall in
- * hvc_put_chars(), this buffer must be at least 16 bytes long, even if
- * you are sending fewer chars.
+ * @buf: The characters to send.
* @count: number of chars to send.
*/
static ssize_t hvterm_raw_put_chars(uint32_t vtermno, const u8 *buf,
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
--
2.25.1
next reply other threads:[~2026-12-05 8:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 8:30 Praneeth Balasubramanian [this message]
2026-12-05 8:46 ` [PATCH v2] powerpc/pseries/hvconsole: Do not read past count in hvc_put_chars() 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=20261205083025.2602522-1-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=chleroy@kernel.org \
--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=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=sshegde@linux.ibm.com \
--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.