From: Eric Farman <farman@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, Matthew Rosato <mjrosato@linux.ibm.com>,
Cornelia Huck <cohuck@redhat.com>,
Joshua Daley <jdaley@linux.ibm.com>,
qemu-stable@nongnu.org, Eric Farman <farman@linux.ibm.com>
Subject: [PULL 08/15] pc-bios/s390-ccw: bounds-check zipl menu entry index before array write
Date: Wed, 12 Aug 2026 13:17:00 -0400 [thread overview]
Message-ID: <20260812171707.1605637-9-farman@linux.ibm.com> (raw)
In-Reply-To: <20260812171707.1605637-1-farman@linux.ibm.com>
From: Joshua Daley <jdaley@linux.ibm.com>
menu_get_zipl_boot_index() iterates NUL-separated strings from the
zipl stage-2 boot-menu block, passes each to zipl_print_entry() which
converts EBCDIC to ASCII and returns atoi(), then writes true into
valid_entries[entry]. valid_entries is a MAX_BOOT_ENTRIES element
stack array, but entry was never bounds-checked, so a crafted on-disk
value could index arbitrarily beyond the array.
Fix this in two places:
- zipl_print_entry() now validates that the first significant character
(after an optional leading space) is a digit. Entries that fail this
check return -1 without printing.
- menu_get_zipl_boot_index() skips any entry whose index is outside
[0, MAX_BOOT_ENTRIES) before writing to valid_entries[].
Fixes: 7385e947fc65 ("pc-bios/s390-ccw: fix non-sequential boot entries (eckd)")
Cc: qemu-stable@nongnu.org
Signed-off-by: Joshua Daley <jdaley@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Eric Farman <farman@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20260727115052.24289-5-borntraeger@linux.ibm.com
[farman@linux.ibm.com: Added qemu-stable]
Signed-off-by: Eric Farman <farman@linux.ibm.com>
---
| 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
--git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c
index eeaff78f87..b6a9a56d46 100644
--- a/pc-bios/s390-ccw/menu.c
+++ b/pc-bios/s390-ccw/menu.c
@@ -176,18 +176,24 @@ int menu_get_boot_index(bool *valid_entries)
return boot_index;
}
-/* Returns the entry number that was printed */
+/* Returns the entry number that was printed, or -1 on invalid entry */
static int zipl_print_entry(const char *data, size_t len)
{
char buf[len + 2];
+ const char *p;
ebcdic_to_ascii(data, buf, len);
buf[len] = '\n';
buf[len + 1] = '\0';
+ p = (buf[0] == ' ') ? buf + 1 : buf;
+ if (!isdigit((unsigned char)*p)) {
+ return -1;
+ }
+
printf("%s", buf);
- return buf[0] == ' ' ? atoi(buf + 1) : atoi(buf);
+ return atoi(p);
}
int menu_get_zipl_boot_index(const char *menu_data)
@@ -216,6 +222,9 @@ int menu_get_zipl_boot_index(const char *menu_data)
entry = zipl_print_entry(menu_data, len);
menu_data += len + 1;
+ if (entry < 0 || entry >= MAX_BOOT_ENTRIES) {
+ continue;
+ }
valid_entries[entry] = true;
if (entry == 0) {
--
2.55.0
next prev parent reply other threads:[~2026-08-12 17:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 17:16 [PULL 00/15] s390x queue Eric Farman
2026-08-12 17:16 ` [PULL 01/15] target/s390x: Make PRNO TRNG interruptible Eric Farman
2026-08-12 17:16 ` [PULL 02/15] tests/tcg/s390x: Test PRNO TRNG interruptibility Eric Farman
2026-08-12 17:16 ` [PULL 03/15] target/s390x: Fix DR/D INT64_MIN / -1 host crash Eric Farman
2026-08-12 17:16 ` [PULL 04/15] tests/tcg/s390x: Test DR overflow (INT64_MIN / -1) Eric Farman
2026-08-12 17:16 ` [PULL 05/15] hw/char/sclpconsole-lm: avoid guest triggerable assert Eric Farman
2026-08-12 17:16 ` [PULL 06/15] s390x/ipl: validate num_comp against iplb length before iterating Eric Farman
2026-08-12 17:16 ` [PULL 07/15] pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size() Eric Farman
2026-08-12 17:17 ` Eric Farman [this message]
2026-08-12 17:17 ` [PULL 09/15] pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry Eric Farman
2026-08-12 17:17 ` [PULL 10/15] pc-bios/s390-ccw: Fix off-by-one errors with loadparm and boot entries Eric Farman
2026-08-12 17:17 ` [PULL 11/15] target/s390x/tcg: Set STCK/STCKF condition code after the store Eric Farman
2026-08-12 17:17 ` [PULL 12/15] tests/tcg/s390x: Test STCKF condition code on a faulting store Eric Farman
2026-08-12 17:17 ` [PULL 13/15] target/s390x: Allow 2G hugepages guest backing Eric Farman
2026-08-12 17:17 ` [PULL 14/15] hw: add compat machines for 11.2 Eric Farman
2026-08-12 17:17 ` [PULL 15/15] pc-bios/s390-ccw.img: update s390x bios Eric Farman
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=20260812171707.1605637-9-farman@linux.ibm.com \
--to=farman@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=jdaley@linux.ibm.com \
--cc=mjrosato@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=qemu-stable@nongnu.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.