From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796459436; b=uzOuP+W/19ij+RRqZHC+di6Zs8k22+6KG475mJxcPtfacnwcIFWyrC1Oz9gFw78QdllJ 4HWBUT5XGKXOhXAVznXVX/eUzT18YagX/eiBkqLLJqO/PTatqLkUH60hkrufn2LcW3JdL 8vQY0b0cjdfJ2Jwyvn6jHTRTiRQLkSZfaudqLs1f0R6C3fan35cj0v92014DCgQDVZAAb pSxL7GNTcNNW3LFtoDcR1h7xAl9RdFO55N8V3ArS/NUV7dzJ8kfjF7plx/+uCLRwAkIy8 mJOnwQ+05NH04OqelapoEPxLkgkmuGCCOIQIxCmMxHueB84d7umA85r3+H3sPNYNF5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459436; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=Iuq/KruD7Zp3BVxpimI+IV04UMzPyLoZBjAv0v6NE3Q=; b=TiHRvr3UtKEWVwPzADA2dpcWSwNRXxLOY691jJuiIEHu4D4SOTfvtVQHHSQ4XyIDzs4v Ym1rsKMPIZwdp+WKYwVlFUIJV0h5fGgT16Rd262YG0EjUlepKTXYvIO3xKkvRIFfjvQFw OPd6ikNCvSKac5x0KLbZtfocQe03571C5MZqTjj23uAT+vDEQdVv0ZI0YzsB9QtJiKCMV AEpGDzTCTG4LeuRA7b5J/LSO5Rikz1fAE30Iz5nwrEK07/ueFba6x28tHm6Sbsl9+9vJc 62hx0iCeWzLOTp5W1jTycvg1ywHsFOxweYpnt5IoxYz35dzf4DQ2Ti95L1kO2vViqGg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=c4wDlwJy; arc=none smtp.remote-ip=74.125.82.47 Received: from mail-dl1-f47.google.com (mail-dl1-f47.google.com [74.125.82.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B211606A322 for ; Sat, 5 Dec 2026 08:30:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6B211606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=c4wDlwJy Received: by mail-dl1-f47.google.com with SMTP id a92af1059eb24-1a3c08d6928so2587740c88.0 for ; Sat, 05 Dec 2026 00:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796459434; x=1797064234; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Iuq/KruD7Zp3BVxpimI+IV04UMzPyLoZBjAv0v6NE3Q=; b=c4wDlwJy4NQq8XG5B9pWcVGdsy4Y89XtiVrDLEn3aRvXKiH1BJ2bGwM99AgLCqmSEK OQOvHCAyJGfAScePtO+yg6YglPks1H3DUJ0r1cG4jbEjIipU0IS/3uDPErq/ZHC9HGA+ xFeFoQr60fDu1lGGZa1Ql7MaHDzwcjCTg7ZmnQDIQK1eY/fNNFEl8jucPWiEtS7ng/5q F4aYxKgNEPOIt7SgiTRAZg6UGel5WF9YotQzwrzouhyJK/UIxok/yQYXlIvesiIe7tOa QQV+LmSwRJVMg9fap5iE2Dc4HQKF9ZMIHkzPhwwHUwpfCTUPcocGBLsD8Quq8ar7jY9W 0SgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796459434; x=1797064234; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Iuq/KruD7Zp3BVxpimI+IV04UMzPyLoZBjAv0v6NE3Q=; b=fz0ygzZw0xSk5rUd6eUq0DKCzTaiPcFskUT5u7S396Vw8+Wx8Nsc0W8BDeN8aFRWm4 1Am4lBlroqPhkeZ4rE5UrKL8FN1+55UW7VNKlSxcJC5RyTtW5eyn3G+w904XGFsRvsDR TDpsLBDmMeS4XG4VsONmcsRbVUrE9L/E97f3rHBKk/+UKpCEIrBcBfxgdNAlLuRV30wo FGYGCrEGcUyLNFQCavl3t7wamdEEN7b3IAEY4HTXojxo4Mzg6jDu8rDmwmW4gsFCYG5x LLxYYVk/d2KhTO2BFC7a3ri0/e3eBf3gwxEKJsRlF8EFvvBBbROBOiidrC/PQa/Xke/4 jK/Q== X-Forwarded-Encrypted: i=1; AL+hErHhedW/+D2YFYvIsGMwEl96nAi5m83ya6BQRFQ9DeoAZadHD3bdoIPujU9gNPOXTvm9/z/ATGIV6uGDkqc=@vger.kernel.org X-Gm-Message-State: APuU4Z8Ho2rJpBksY0bqjuRKDarbJn8XmlbjL8H6RdsOxMrDmnNBaAOr YH4p6KS2uYePzb100aPNdF8n7VM8RKr23VXKD4AuUSBFvKfeKklQ14zx X-Gm-Gg: AZFdTZd0ITnkLP3MY+5VuRHr8uzw9455a8BHGd80fJ+zhpMxJM23IUYzQ95DPz9OzFg epPlsT7FZZQcrofxMLK/nxGjbn062cdLQWrRbA8gSiIPtqL1+TmxEdMKvSKL+aT+jjltqD5CUTg wUdXtMiV9ljbVZHOq8ZVQ3ULbcV6bjIMfufwRX/3G0pqVFGEMEFdKdnvk376/T2ya7l6Aib24gM ICDUKIx8pUgYdBMXnBOcNnA/tSEeHG4mZ8E851tHFG/Rh+DOzSSQUq793twoYKANbjBvme+797S 0hsxW/qKU7OBZV4ehCOePbN+ngixUJzrWRKt+8XYR0jH+vDbSvJJOgTpaY2ijUz+gfBw6fDjHZP xfVHE2P/DSCxkC8t1AlKgvsStpaNUemPNfrcxKBmiai8lVR2T/CU9CRKN/oHwBRXkJSmA4/jlNr Gbndgkm6UCzWFF3glu31I/B5tmJnWaXXO5x5Dhn/3BcwF8mEuR4vB+6FQDq9PTdu378j9B0Z6NR 9y4dxkwaY50jn/TapTAianPmrvYMMhT2nbR9Vrrc6+7OUrV/bc4YLrqXiLt6B9RUCzJ5eHD9+Kr 6jlN8yLRNvxX/Uf5T2DzEdPK1VjAte+D80P+YjdxE2Xfszz/IANx8cH9Jv+yd1TS2S9MKiS5w5F tKM8QpgJB0WBd X-Received: by 2002:a05:7023:e4b:10b0:1b5:5a81:d388 with SMTP id a92af1059eb24-1b5d706415amr3921733c88.4.1796459434394; Sat, 05 Dec 2026 00:30:34 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e1c55sm14499280eec.16.2026.12.05.00.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 00:30:33 -0800 (PST) From: Praneeth Balasubramanian To: Madhavan Srinivasan , Greg Kroah-Hartman , Jiri Slaby Cc: Praneeth Balasubramanian , stable@vger.kernel.org, Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , "Ritesh Harjani (IBM)" , Shrikanth Hegde , 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 Message-Id: <20261205083025.2602522-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 #include #include +#include #include #include #include @@ -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