Skip to contentSkip to conversation

more hardening fixes for s390

PATCH In review Christian Borntraeger 5 participants 20 messages Jul 27 – Jul 28

lore
Share & tools
lore
#0 lore raw

cover more hardening fixes for s390

Cornelia, Eric, Matt,

here are 5 more fixes for hardening QEMU against invalid input. Nothing is strictly a security issues as defined in the policy. For example
https://qemu-project.gitlab.io/qemu/system/security.html says assert /
abort: If triggering the code path requires kernel privileges (or root account access) in the guest, asserts/aborts in QEMU are a self inflicted denial of service. These will not be treated as security flaws, at most hardening bugs.
And if anyone can provide invalid boot loader content it can provide anything to boot if secure boot is not available.
We should fix those anyway, probably even for 11.1

Conny, I did not rebuild the s390-ccw, I assume you will do that?

Christian Borntraeger (1):
hw/char/sclpconsole-lm: avoid guest triggerable assert

Joshua Daley (4):
s390x/ipl: validate num_comp against iplb length before iterating pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size() pc-bios/s390-ccw: bounds-check zipl menu entry index before array
write
pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in
zipl_print_entry

 hw/char/sclpconsole-lm.c    |  3 ++-
 hw/s390x/ipl.h              |  6 ++++++
 pc-bios/s390-ccw/bootmap.c  |  6 ++++--
 pc-bios/s390-ccw/helper.h   | 10 ++++++++++
 pc-bios/s390-ccw/menu.c     | 36 +++++++++++++++++++++++++++++-------
 pc-bios/s390-ccw/s390-ccw.h |  2 +-
 6 files changed, 52 insertions(+), 11 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/5 hw/char/sclpconsole-lm: avoid guest triggerable assert

If a guest uses incorrect message length it can trigger an assert in process_mbd which kills the guest instead of reporting an error. Fix this by adding the correct length check.

Fixes 6a444f8507 ("s390/sclplmconsole: Add support for SCLP line-mode console")
---
 hw/char/sclpconsole-lm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/char/sclpconsole-lm.c +2 -1
index 9a16896d22..f6ed282f1b 100644
@@ -243,7 +243,8 @@ static int write_event_data(SCLPEvent *event, EventBufferHeader *ebh)
     SCLPConsoleLM *scon = SCLPLM_CONSOLE(event);
 
     len = be16_to_cpu(data->mdb.header.length);
-    if (len < sizeof(data->mdb.header)) {
+    if (len < sizeof(data->mdb.header) ||
+        len > be16_to_cpu(data->header.length) - sizeof(EventBufferHeader)) {
         return SCLP_RC_INCONSISTENT_LENGTHS;
     }
     len -= sizeof(data->mdb.header);
Signature · 1 line
2.53.0
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] hw/char/sclpconsole-lm: avoid guest triggerable assert

Quoted 2 lines · Christian Borntraeger

If a guest uses incorrect message length it can trigger an assert in process_mbd which kills the guest instead of reporting an error. Fix

Typo, s/process_mbd/process_mdb/

Maybe can just be fixed when applying?

Quoted 22 lines

this by adding the correct length check.

Fixes 6a444f8507 ("s390/sclplmconsole: Add support for SCLP line-mode console")
---
 hw/char/sclpconsole-lm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/char/sclpconsole-lm.c +2 -1
index 9a16896d22..f6ed282f1b 100644
@@ -243,7 +243,8 @@ static int write_event_data(SCLPEvent *event, EventBufferHeader *ebh)
     SCLPConsoleLM *scon = SCLPLM_CONSOLE(event);
 
     len = be16_to_cpu(data->mdb.header.length);
-    if (len < sizeof(data->mdb.header)) {
+    if (len < sizeof(data->mdb.header) ||
+        len > be16_to_cpu(data->header.length) - sizeof(EventBufferHeader)) {
         return SCLP_RC_INCONSISTENT_LENGTHS;
     }
     len -= sizeof(data->mdb.header);
#3 lore raw

PATCH 2/5 s390x/ipl: validate num_comp against iplb length before iterating

In reply to Christian Borntraeger

From: Joshua Daley <[email protected]>

In ipl_valid_pv_components(), the upper bound of the for loop, ipib_pv->num_comp, is read from guest memory. Before iterating, verify that its value will not cause a read beyond the end of the IplParameterBlock.

Fixes c3347ed0d2ee42a7 ("s390x: protvirt: Support unpack facility")
---
 hw/s390x/ipl.h | 6 ++++++
 1 file changed, 6 insertions(+)
hw/s390x/ipl.h +6 -0
index fac30763df..ef9c063d90 100644
@@ -124,6 +124,12 @@ static inline bool ipl_valid_pv_components(IplParameterBlock *iplb)
         return false;
     }
 
+    if (offsetof(IplParameterBlock, pv.components) +
+        ipib_pv->num_comp * sizeof(IPLBlockPVComp) >
+        be32_to_cpu(iplb->len)) {
+        return false;
+    }
+
     for (i = 0; i < ipib_pv->num_comp; i++) {
         /* Addr must be 4k aligned */
         if (ipib_pv->components[i].addr & ~TARGET_PAGE_MASK) {
Signature · 1 line
2.53.0
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] s390x/ipl: validate num_comp against iplb length before iterating

Quoted 10 lines · Christian Borntraeger

From: Joshua Daley <[email protected]>

In ipl_valid_pv_components(), the upper bound of the for loop, ipib_pv->num_comp, is read from guest memory. Before iterating, verify that its value will not cause a read beyond the end of the IplParameterBlock.

Fixes c3347ed0d2ee42a7 ("s390x: protvirt: Support unpack facility")
Quoted 21 lines
---
 hw/s390x/ipl.h | 6 ++++++
 1 file changed, 6 insertions(+)
hw/s390x/ipl.h +6 -0
index fac30763df..ef9c063d90 100644
@@ -124,6 +124,12 @@ static inline bool ipl_valid_pv_components(IplParameterBlock *iplb)
         return false;
     }
 
+    if (offsetof(IplParameterBlock, pv.components) +
+        ipib_pv->num_comp * sizeof(IPLBlockPVComp) >
+        be32_to_cpu(iplb->len)) {
+        return false;
+    }
+
     for (i = 0; i < ipib_pv->num_comp; i++) {
         /* Addr must be 4k aligned */
         if (ipib_pv->components[i].addr & ~TARGET_PAGE_MASK) {
#5 lore raw

PATCH 3/5 pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size()

In reply to Christian Borntraeger

From: Joshua Daley <[email protected]>

In the dir_rem[level] == 0 case, level is decremented, then a virtio_read() is issued on sec_loc[level]. If level is -1, then the 4 bytes before the static sec_loc array are read, and the virtio_read() is issued on that garbage block number.

Guard the call to virtio_read() against the value of level to prevent this.

Fixes 869648e87eeb ("pc-bios/s390-ccw: El Torito 16-bit boot image size field workaround")
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +1 -1
index 420ee32eff..ed6e8cbbc7 100644
@@ -902,7 +902,7 @@ static inline long iso_get_file_size(uint32_t load_rba)
         if (dir_rem[level] == 0) {
             /* Nothing remaining */
             level--;
-            if (virtio_read(sec_loc[level], temp)) {
+            if (level >= 0 && virtio_read(sec_loc[level], temp)) {
                 puts("Failed to read ISO directory");
                 return -EIO;
             }
Signature · 1 line
2.53.0
Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH 3/5] pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size()

Quoted 7 lines · Christian Borntraeger

From: Joshua Daley <[email protected]>

In the dir_rem[level] == 0 case, level is decremented, then a virtio_read() is issued on sec_loc[level]. If level is -1, then the 4 bytes before the static sec_loc array are read, and the virtio_read() is issued on that garbage block number.

Quoted 6 lines

Guard the call to virtio_read() against the value of level to prevent this.

Fixes 869648e87eeb ("pc-bios/s390-ccw: El Torito 16-bit boot image size field workaround")

Typo in the RB tag, please fix when applying or if there is a v2!

Quoted 17 lines
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +1 -1
index 420ee32eff..ed6e8cbbc7 100644
@@ -902,7 +902,7 @@ static inline long iso_get_file_size(uint32_t load_rba)
         if (dir_rem[level] == 0) {
             /* Nothing remaining */
             level--;
-            if (virtio_read(sec_loc[level], temp)) {
+            if (level >= 0 && virtio_read(sec_loc[level], temp)) {
                 puts("Failed to read ISO directory");
                 return -EIO;
             }
#7 lore raw

PATCH 4/5 pc-bios/s390-ccw: bounds-check zipl menu entry index before array write

In reply to Christian Borntraeger

From: Joshua Daley <[email protected]>

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)")
---
 pc-bios/s390-ccw/menu.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
pc-bios/s390-ccw/menu.c +11 -2
index eeaff78f87..b6a9a56d46 100644
@@ -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) {
Signature · 1 line
2.53.0
Reviewed-by on v1 4/5
#8 lore raw

Re: [PATCH 4/5] pc-bios/s390-ccw: bounds-check zipl menu entry index before array write

Quoted 15 lines · Christian Borntraeger

From: Joshua Daley <[email protected]>

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.

Quoted 5 lines

- 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)")
Quoted 45 lines
---
 pc-bios/s390-ccw/menu.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
pc-bios/s390-ccw/menu.c +11 -2
index eeaff78f87..b6a9a56d46 100644
@@ -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) {
#9 lore raw

PATCH 5/5 pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry

In reply to Christian Borntraeger

From: Joshua Daley <[email protected]>

menu_get_zipl_boot_index() calls strlen() on a pointer into the middle of _s2 with no upper bound, so a stage-2 image whose blocks contain no NUL bytes causes strlen() to walk beyond _s2. The resulting length is then used to size a stack VLA in zipl_print_entry(), risking a stack overflow.

Fix by:

- Implementing strnlen(), a bounded version of strlen().

- Adding a menu_data_end parameter to menu_get_zipl_boot_index() and replacing both strlen() calls with strnlen() bounded by the remaining buffer space. The loop guard also checks that the pointer has not reached menu_data_end. For robustness, the function returns 0 (boot default) if somehow menu_data is initially >= menu_data_end.

- Replacing the VLA char buf[len + 2] in zipl_print_entry() with a fixed ZIPL_ENTRY_MAX + 2 (82-byte) buffer and truncating len before use.

- Passing s2_end (_s2 + sizeof(_s2)) as menu_data_end at the one call site in eckd_get_boot_menu_index(), so the bound is exactly the end of the buffer.

Fixes f7178910845a ("s390-ccw: print zipl boot menu")
---
 pc-bios/s390-ccw/bootmap.c  |  4 +++-
 pc-bios/s390-ccw/helper.h   | 10 ++++++++++
 pc-bios/s390-ccw/menu.c     | 23 ++++++++++++++++++-----
 pc-bios/s390-ccw/s390-ccw.h |  2 +-
 4 files changed, 32 insertions(+), 7 deletions(-)
pc-bios/s390-ccw/bootmap.c +3 -1
index ed6e8cbbc7..81512265ce 100644
@@ -61,6 +61,7 @@ static uint8_t _s2[MAX_SECTOR_SIZE * 3] __attribute__((__aligned__(PAGE_SIZE)));
 static void *s2_prev_blk = _s2;
 static void *s2_cur_blk = _s2 + MAX_SECTOR_SIZE;
 static void *s2_next_blk = _s2 + MAX_SECTOR_SIZE * 2;
+static void *s2_end = _s2 + sizeof(_s2);
 
 static inline int verify_boot_info(BootInfo *bip)
 {
@@ -308,7 +309,8 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
                 }
             }
 
-            return menu_get_zipl_boot_index(s2_cur_blk + banner_offset);
+            return menu_get_zipl_boot_index(s2_cur_blk + banner_offset,
+                                            s2_end);
         }
 
         prev_block_nr = cur_block_nr;
pc-bios/s390-ccw/helper.h +10 -0
index 8e3dfcb6d6..d9b7da444a 100644
@@ -45,4 +45,14 @@ static inline void sleep(unsigned int seconds)
     }
 }
 
+static inline size_t strnlen(const char *s, size_t maxlen)
+{
+    size_t len = 0;
+
+    while (len < maxlen && s[len]) {
+        len++;
+    }
+    return len;
+}
+
 #endif
pc-bios/s390-ccw/menu.c +18 -5
index b6a9a56d46..af96a83de9 100644
@@ -16,6 +16,7 @@
 #include "s390-ccw.h"
 #include "sclp.h"
 #include "s390-time.h"
+#include "helper.h"
 
 #define KEYCODE_NO_INP '\0'
 #define KEYCODE_ESCAPE '\033'
@@ -26,6 +27,9 @@
 #define ZIPL_TIMEOUT_OFFSET 138
 #define ZIPL_FLAG_OFFSET    140
 
+/* Max printable chars for a zipl boot menu entry */
+#define ZIPL_ENTRY_MAX 80
+
 #define TOD_CLOCK_MILLISECOND   0x3e8000
 
 #define LOW_CORE_EXTERNAL_INT_ADDR   0x86
@@ -179,9 +183,13 @@ int menu_get_boot_index(bool *valid_entries)
 /* 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];
+    char buf[ZIPL_ENTRY_MAX + 2];
     const char *p;
 
+    if (len > ZIPL_ENTRY_MAX) {
+        len = ZIPL_ENTRY_MAX;
+    }
+
     ebcdic_to_ascii(data, buf, len);
     buf[len] = '\n';
     buf[len + 1] = '\0';
@@ -196,7 +204,7 @@ static int zipl_print_entry(const char *data, size_t len)
     return atoi(p);
 }
 
-int menu_get_zipl_boot_index(const char *menu_data)
+int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end)
 {
     size_t len;
     int entry;
@@ -212,13 +220,18 @@ int menu_get_zipl_boot_index(const char *menu_data)
         timeout = zipl_timeout * 1000;
     }
 
+    if (menu_data >= menu_data_end) {
+        return 0;
+    }
+
     /* Print banner */
     puts("s390-ccw zIPL Boot Menu\n");
-    menu_data += strlen(menu_data) + 1;
+    len = strnlen(menu_data, menu_data_end - menu_data);
+    menu_data += len + 1;
 
     /* Print entries */
-    while (*menu_data) {
-        len = strlen(menu_data);
+    while (menu_data < menu_data_end && *menu_data) {
+        len = strnlen(menu_data, menu_data_end - menu_data);
         entry = zipl_print_entry(menu_data, len);
         menu_data += len + 1;
 
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 1e1f71775e..f6030a6071 100644
@@ -76,7 +76,7 @@ void jump_to_low_kernel(void);
 
 /* menu.c */
 void menu_set_parms(uint8_t boot_menu_flag, uint32_t boot_menu_timeout);
-int menu_get_zipl_boot_index(const char *menu_data);
+int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end);
 bool menu_is_enabled_zipl(void);
 int menu_get_enum_boot_index(bool *valid_entries);
 bool menu_is_enabled_enum(void);
Signature · 1 line
2.53.0
#10 lore raw

Re: [PATCH 5/5] pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry

Quoted 124 lines · Christian Borntraeger

From: Joshua Daley <[email protected]>

menu_get_zipl_boot_index() calls strlen() on a pointer into the middle of _s2 with no upper bound, so a stage-2 image whose blocks contain no NUL bytes causes strlen() to walk beyond _s2. The resulting length is then used to size a stack VLA in zipl_print_entry(), risking a stack overflow.

Fix by:

- Implementing strnlen(), a bounded version of strlen().

- Adding a menu_data_end parameter to menu_get_zipl_boot_index() and replacing both strlen() calls with strnlen() bounded by the remaining buffer space. The loop guard also checks that the pointer has not reached menu_data_end. For robustness, the function returns 0 (boot default) if somehow menu_data is initially >= menu_data_end.

- Replacing the VLA char buf[len + 2] in zipl_print_entry() with a fixed ZIPL_ENTRY_MAX + 2 (82-byte) buffer and truncating len before use.

- Passing s2_end (_s2 + sizeof(_s2)) as menu_data_end at the one call site in eckd_get_boot_menu_index(), so the bound is exactly the end of the buffer.

Fixes f7178910845a ("s390-ccw: print zipl boot menu")
---
 pc-bios/s390-ccw/bootmap.c  |  4 +++-
 pc-bios/s390-ccw/helper.h   | 10 ++++++++++
 pc-bios/s390-ccw/menu.c     | 23 ++++++++++++++++++-----
 pc-bios/s390-ccw/s390-ccw.h |  2 +-
 4 files changed, 32 insertions(+), 7 deletions(-)
pc-bios/s390-ccw/bootmap.c +3 -1
index ed6e8cbbc7..81512265ce 100644
@@ -61,6 +61,7 @@ static uint8_t _s2[MAX_SECTOR_SIZE * 3] __attribute__((__aligned__(PAGE_SIZE)));
 static void *s2_prev_blk = _s2;
 static void *s2_cur_blk = _s2 + MAX_SECTOR_SIZE;
 static void *s2_next_blk = _s2 + MAX_SECTOR_SIZE * 2;
+static void *s2_end = _s2 + sizeof(_s2);
 
 static inline int verify_boot_info(BootInfo *bip)
 {
@@ -308,7 +309,8 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
                 }
             }
 
-            return menu_get_zipl_boot_index(s2_cur_blk + banner_offset);
+            return menu_get_zipl_boot_index(s2_cur_blk + banner_offset,
+                                            s2_end);
         }
 
         prev_block_nr = cur_block_nr;
pc-bios/s390-ccw/helper.h +10 -0
index 8e3dfcb6d6..d9b7da444a 100644
@@ -45,4 +45,14 @@ static inline void sleep(unsigned int seconds)
     }
 }
 
+static inline size_t strnlen(const char *s, size_t maxlen)
+{
+    size_t len = 0;
+
+    while (len < maxlen && s[len]) {
+        len++;
+    }
+    return len;
+}
+
 #endif
pc-bios/s390-ccw/menu.c +10 -2
index b6a9a56d46..af96a83de9 100644
@@ -16,6 +16,7 @@
 #include "s390-ccw.h"
 #include "sclp.h"
 #include "s390-time.h"
+#include "helper.h"
 
 #define KEYCODE_NO_INP '\0'
 #define KEYCODE_ESCAPE '\033'
@@ -26,6 +27,9 @@
 #define ZIPL_TIMEOUT_OFFSET 138
 #define ZIPL_FLAG_OFFSET    140
 
+/* Max printable chars for a zipl boot menu entry */
+#define ZIPL_ENTRY_MAX 80
+
 #define TOD_CLOCK_MILLISECOND   0x3e8000
 
 #define LOW_CORE_EXTERNAL_INT_ADDR   0x86
@@ -179,9 +183,13 @@ int menu_get_boot_index(bool *valid_entries)
 /* 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];
+    char buf[ZIPL_ENTRY_MAX + 2];
     const char *p;
 
+    if (len > ZIPL_ENTRY_MAX) {
+        len = ZIPL_ENTRY_MAX;
+    }
+
     ebcdic_to_ascii(data, buf, len);
     buf[len] = '\n';
     buf[len + 1] = '\0';
@@ -196,7 +204,7 @@ static int zipl_print_entry(const char *data, size_t len)
     return atoi(p);
 }
 
-int menu_get_zipl_boot_index(const char *menu_data)
+int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end)
 {
     size_t len;
     int entry;
@@ -212,13 +220,18 @@ int menu_get_zipl_boot_index(const char *menu_data)
         timeout = zipl_timeout * 1000;
     }

pc-bios/s390-ccw/menu.c int menu_get_zipl_boot_index(const char *menu_data) · line 230

Quoted 10 lines
pc-bios/s390-ccw/menu.c +6 -1
 
+    if (menu_data >= menu_data_end) {
+        return 0;
+    }
+
     /* Print banner */
     puts("s390-ccw zIPL Boot Menu\n");
-    menu_data += strlen(menu_data) + 1;
+    len = strnlen(menu_data, menu_data_end - menu_data);
+    menu_data += len + 1;

If we've already hit menu_data_end at this point should we bail rather than skipping the while() loop and immediately proceeding into menu_get_boot_index(valid_entries); with an all-false array?

AFAICT the current implementation would print no options and wait for user input.

e.g. something like

if (menu_data >= menu_data_end)
return 0;

Quoted 22 lines
pc-bios/s390-ccw/menu.c +2 -2
     /* Print entries */
-    while (*menu_data) {
-        len = strlen(menu_data);
+    while (menu_data < menu_data_end && *menu_data) {
+        len = strnlen(menu_data, menu_data_end - menu_data);
         entry = zipl_print_entry(menu_data, len);
         menu_data += len + 1;
 
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 1e1f71775e..f6030a6071 100644
@@ -76,7 +76,7 @@ void jump_to_low_kernel(void);
 
 /* menu.c */
 void menu_set_parms(uint8_t boot_menu_flag, uint32_t boot_menu_timeout);
-int menu_get_zipl_boot_index(const char *menu_data);
+int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end);
 bool menu_is_enabled_zipl(void);
 int menu_get_enum_boot_index(bool *valid_entries);
 bool menu_is_enabled_enum(void);
#11 lore raw

Re: [PATCH 5/5] pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry

Quoted 140 lines · Matthew Rosato
Quoted 124 lines · Christian Borntraeger

From: Joshua Daley <[email protected]>

menu_get_zipl_boot_index() calls strlen() on a pointer into the middle of _s2 with no upper bound, so a stage-2 image whose blocks contain no NUL bytes causes strlen() to walk beyond _s2. The resulting length is then used to size a stack VLA in zipl_print_entry(), risking a stack overflow.

Fix by:

- Implementing strnlen(), a bounded version of strlen().

- Adding a menu_data_end parameter to menu_get_zipl_boot_index() and replacing both strlen() calls with strnlen() bounded by the remaining buffer space. The loop guard also checks that the pointer has not reached menu_data_end. For robustness, the function returns 0 (boot default) if somehow menu_data is initially >= menu_data_end.

- Replacing the VLA char buf[len + 2] in zipl_print_entry() with a fixed ZIPL_ENTRY_MAX + 2 (82-byte) buffer and truncating len before use.

- Passing s2_end (_s2 + sizeof(_s2)) as menu_data_end at the one call site in eckd_get_boot_menu_index(), so the bound is exactly the end of the buffer.

Fixes f7178910845a ("s390-ccw: print zipl boot menu")
---
 pc-bios/s390-ccw/bootmap.c  |  4 +++-
 pc-bios/s390-ccw/helper.h   | 10 ++++++++++
 pc-bios/s390-ccw/menu.c     | 23 ++++++++++++++++++-----
 pc-bios/s390-ccw/s390-ccw.h |  2 +-
 4 files changed, 32 insertions(+), 7 deletions(-)
pc-bios/s390-ccw/bootmap.c +3 -1
index ed6e8cbbc7..81512265ce 100644
@@ -61,6 +61,7 @@ static uint8_t _s2[MAX_SECTOR_SIZE * 3] __attribute__((__aligned__(PAGE_SIZE)));
 static void *s2_prev_blk = _s2;
 static void *s2_cur_blk = _s2 + MAX_SECTOR_SIZE;
 static void *s2_next_blk = _s2 + MAX_SECTOR_SIZE * 2;
+static void *s2_end = _s2 + sizeof(_s2);
 
 static inline int verify_boot_info(BootInfo *bip)
 {
@@ -308,7 +309,8 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
                 }
             }
 
-            return menu_get_zipl_boot_index(s2_cur_blk + banner_offset);
+            return menu_get_zipl_boot_index(s2_cur_blk + banner_offset,
+                                            s2_end);
         }
 
         prev_block_nr = cur_block_nr;
pc-bios/s390-ccw/helper.h +10 -0
index 8e3dfcb6d6..d9b7da444a 100644
@@ -45,4 +45,14 @@ static inline void sleep(unsigned int seconds)
     }
 }
 
+static inline size_t strnlen(const char *s, size_t maxlen)
+{
+    size_t len = 0;
+
+    while (len < maxlen && s[len]) {
+        len++;
+    }
+    return len;
+}
+
 #endif
pc-bios/s390-ccw/menu.c +10 -2
index b6a9a56d46..af96a83de9 100644
@@ -16,6 +16,7 @@
 #include "s390-ccw.h"
 #include "sclp.h"
 #include "s390-time.h"
+#include "helper.h"
 
 #define KEYCODE_NO_INP '\0'
 #define KEYCODE_ESCAPE '\033'
@@ -26,6 +27,9 @@
 #define ZIPL_TIMEOUT_OFFSET 138
 #define ZIPL_FLAG_OFFSET    140
 
+/* Max printable chars for a zipl boot menu entry */
+#define ZIPL_ENTRY_MAX 80
+
 #define TOD_CLOCK_MILLISECOND   0x3e8000
 
 #define LOW_CORE_EXTERNAL_INT_ADDR   0x86
@@ -179,9 +183,13 @@ int menu_get_boot_index(bool *valid_entries)
 /* 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];
+    char buf[ZIPL_ENTRY_MAX + 2];
     const char *p;
 
+    if (len > ZIPL_ENTRY_MAX) {
+        len = ZIPL_ENTRY_MAX;
+    }
+
     ebcdic_to_ascii(data, buf, len);
     buf[len] = '\n';
     buf[len + 1] = '\0';
@@ -196,7 +204,7 @@ static int zipl_print_entry(const char *data, size_t len)
     return atoi(p);
 }
 
-int menu_get_zipl_boot_index(const char *menu_data)
+int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end)
 {
     size_t len;
     int entry;
@@ -212,13 +220,18 @@ int menu_get_zipl_boot_index(const char *menu_data)
         timeout = zipl_timeout * 1000;
     }

pc-bios/s390-ccw/menu.c int menu_get_zipl_boot_index(const char *menu_data) · line 230

Quoted 10 lines
pc-bios/s390-ccw/menu.c +6 -1
 
+    if (menu_data >= menu_data_end) {
+        return 0;
+    }
+
     /* Print banner */
     puts("s390-ccw zIPL Boot Menu\n");
-    menu_data += strlen(menu_data) + 1;
+    len = strnlen(menu_data, menu_data_end - menu_data);
+    menu_data += len + 1;

If we've already hit menu_data_end at this point should we bail rather than skipping the while() loop and immediately proceeding into menu_get_boot_index(valid_entries); with an all-false array?

Quoted 7 lines

AFAICT the current implementation would print no options and wait for user input.

e.g. something like

if (menu_data >= menu_data_end)
return 0;

Hm, well, my proposal would still print the s390-ccw zIPL Boot Menu\n message but then quietly use the default boot option.

Maybe it would be better to move the
+ len = strnlen(menu_data, menu_data_end - menu_data);
+ menu_data += len + 1;

up a few lines before the puts and combine it with the menu_data >= menu_data_end check you already added? That way in both cases we silently take the default option without printing anything?

Quoted 24 lines
Quoted 23 lines
pc-bios/s390-ccw/menu.c +2 -2
     /* Print entries */
-    while (*menu_data) {
-        len = strlen(menu_data);
+    while (menu_data < menu_data_end && *menu_data) {
+        len = strnlen(menu_data, menu_data_end - menu_data);
         entry = zipl_print_entry(menu_data, len);
         menu_data += len + 1;
 
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 1e1f71775e..f6030a6071 100644
@@ -76,7 +76,7 @@ void jump_to_low_kernel(void);
 
 /* menu.c */
 void menu_set_parms(uint8_t boot_menu_flag, uint32_t boot_menu_timeout);
-int menu_get_zipl_boot_index(const char *menu_data);
+int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end);
 bool menu_is_enabled_zipl(void);
 int menu_get_enum_boot_index(bool *valid_entries);
 bool menu_is_enabled_enum(void);
#12 lore raw

Re: [PATCH 5/5] pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry

Quoted 141 lines · Matthew Rosato
Quoted 140 lines · Matthew Rosato
Quoted 124 lines · Christian Borntraeger

From: Joshua Daley <[email protected]>

menu_get_zipl_boot_index() calls strlen() on a pointer into the middle of _s2 with no upper bound, so a stage-2 image whose blocks contain no NUL bytes causes strlen() to walk beyond _s2. The resulting length is then used to size a stack VLA in zipl_print_entry(), risking a stack overflow.

Fix by:

- Implementing strnlen(), a bounded version of strlen().

- Adding a menu_data_end parameter to menu_get_zipl_boot_index() and replacing both strlen() calls with strnlen() bounded by the remaining buffer space. The loop guard also checks that the pointer has not reached menu_data_end. For robustness, the function returns 0 (boot default) if somehow menu_data is initially >= menu_data_end.

- Replacing the VLA char buf[len + 2] in zipl_print_entry() with a fixed ZIPL_ENTRY_MAX + 2 (82-byte) buffer and truncating len before use.

- Passing s2_end (_s2 + sizeof(_s2)) as menu_data_end at the one call site in eckd_get_boot_menu_index(), so the bound is exactly the end of the buffer.

Fixes f7178910845a ("s390-ccw: print zipl boot menu")
---
  pc-bios/s390-ccw/bootmap.c  |  4 +++-
  pc-bios/s390-ccw/helper.h   | 10 ++++++++++
  pc-bios/s390-ccw/menu.c     | 23 ++++++++++++++++++-----
  pc-bios/s390-ccw/s390-ccw.h |  2 +-
  4 files changed, 32 insertions(+), 7 deletions(-)
pc-bios/s390-ccw/bootmap.c +3 -1
index ed6e8cbbc7..81512265ce 100644
@@ -61,6 +61,7 @@ static uint8_t _s2[MAX_SECTOR_SIZE * 3] __attribute__((__aligned__(PAGE_SIZE)));
  static void *s2_prev_blk = _s2;
  static void *s2_cur_blk = _s2 + MAX_SECTOR_SIZE;
  static void *s2_next_blk = _s2 + MAX_SECTOR_SIZE * 2;
+static void *s2_end = _s2 + sizeof(_s2);
 
  static inline int verify_boot_info(BootInfo *bip)
  {
@@ -308,7 +309,8 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
                  }
              }
 
-            return menu_get_zipl_boot_index(s2_cur_blk + banner_offset);
+            return menu_get_zipl_boot_index(s2_cur_blk + banner_offset,
+                                            s2_end);
          }
 
          prev_block_nr = cur_block_nr;
pc-bios/s390-ccw/helper.h +10 -0
index 8e3dfcb6d6..d9b7da444a 100644
@@ -45,4 +45,14 @@ static inline void sleep(unsigned int seconds)
      }
  }
 
+static inline size_t strnlen(const char *s, size_t maxlen)
+{
+    size_t len = 0;
+
+    while (len < maxlen && s[len]) {
+        len++;
+    }
+    return len;
+}
+
  #endif
pc-bios/s390-ccw/menu.c +10 -2
index b6a9a56d46..af96a83de9 100644
@@ -16,6 +16,7 @@
  #include "s390-ccw.h"
  #include "sclp.h"
  #include "s390-time.h"
+#include "helper.h"
 
  #define KEYCODE_NO_INP '\0'
  #define KEYCODE_ESCAPE '\033'
@@ -26,6 +27,9 @@
  #define ZIPL_TIMEOUT_OFFSET 138
  #define ZIPL_FLAG_OFFSET    140
 
+/* Max printable chars for a zipl boot menu entry */
+#define ZIPL_ENTRY_MAX 80
+
  #define TOD_CLOCK_MILLISECOND   0x3e8000
 
  #define LOW_CORE_EXTERNAL_INT_ADDR   0x86
@@ -179,9 +183,13 @@ int menu_get_boot_index(bool *valid_entries)
  /* 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];
+    char buf[ZIPL_ENTRY_MAX + 2];
      const char *p;
 
+    if (len > ZIPL_ENTRY_MAX) {
+        len = ZIPL_ENTRY_MAX;
+    }
+
      ebcdic_to_ascii(data, buf, len);
      buf[len] = '\n';
      buf[len + 1] = '\0';
@@ -196,7 +204,7 @@ static int zipl_print_entry(const char *data, size_t len)
      return atoi(p);
  }
 
-int menu_get_zipl_boot_index(const char *menu_data)
+int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end)
  {
      size_t len;
      int entry;
@@ -212,13 +220,18 @@ int menu_get_zipl_boot_index(const char *menu_data)
          timeout = zipl_timeout * 1000;
      }

pc-bios/s390-ccw/menu.c int menu_get_zipl_boot_index(const char *menu_data) · line 230

Quoted 10 lines
pc-bios/s390-ccw/menu.c +6 -1
 
+    if (menu_data >= menu_data_end) {
+        return 0;
+    }
+
      /* Print banner */
      puts("s390-ccw zIPL Boot Menu\n");
-    menu_data += strlen(menu_data) + 1;
+    len = strnlen(menu_data, menu_data_end - menu_data);
+    menu_data += len + 1;

If we've already hit menu_data_end at this point should we bail rather than skipping the while() loop and immediately proceeding into menu_get_boot_index(valid_entries); with an all-false array?

Quoted 2 lines
Quoted 2 lines

AFAICT the current implementation would print no options and wait for user input.

Right.

Quoted 13 lines
Quoted 5 lines

e.g. something like

if (menu_data >= menu_data_end)
return 0;

Hm, well, my proposal would still print the s390-ccw zIPL Boot Menu\n message but then quietly use the default boot option.

Maybe it would be better to move the

pc-bios/s390-ccw/menu.c +2 -0
+    len = strnlen(menu_data, menu_data_end - menu_data);
+    menu_data += len + 1;
Quoted 4 lines

up a few lines before the puts and combine it with the menu_data >= menu_data_end check you already added? That way in both cases we silently take the default option without printing anything?

I agree with your assessment. Need another check after the "banner skip" and before the puts().

if (menu_data >= menu_data_end) {
return 0; /* Boot default */
}

/* Skip banner */
len = strnlen(menu_data, menu_data_end - menu_data); menu_data += len + 1;

if (menu_data >= menu_data_end || !(*menu_data)) {
return 0; /* No entries, boot default */
}

/* Print banner */
puts("s390-ccw zIPL Boot Menu\n");

/* Print entries */
while (menu_data < menu_data_end && *menu_data) {
...

Quoted 26 lines
Quoted 25 lines
Quoted 24 lines
pc-bios/s390-ccw/menu.c +2 -2
      /* Print entries */
-    while (*menu_data) {
-        len = strlen(menu_data);
+    while (menu_data < menu_data_end && *menu_data) {
+        len = strnlen(menu_data, menu_data_end - menu_data);
          entry = zipl_print_entry(menu_data, len);
          menu_data += len + 1;
 
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 1e1f71775e..f6030a6071 100644
@@ -76,7 +76,7 @@ void jump_to_low_kernel(void);
 
  /* menu.c */
  void menu_set_parms(uint8_t boot_menu_flag, uint32_t boot_menu_timeout);
-int menu_get_zipl_boot_index(const char *menu_data);
+int menu_get_zipl_boot_index(const char *menu_data, const char *menu_data_end);
  bool menu_is_enabled_zipl(void);
  int menu_get_enum_boot_index(bool *valid_entries);
  bool menu_is_enabled_enum(void);
#13 lore raw

Re: [PATCH 5/5] pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry

Quoted 178 lines · Joshua Daley
Quoted 139 lines · Matthew Rosato
Quoted 138 lines · Matthew Rosato
Quoted 122 lines · Christian Borntraeger

From: Joshua Daley <[email protected]>

menu_get_zipl_boot_index() calls strlen() on a pointer into the middle of _s2 with no upper bound, so a stage-2 image whose blocks contain no NUL bytes causes strlen() to walk beyond _s2. The resulting length is then used to size a stack VLA in zipl_print_entry(), risking a stack overflow.

Fix by:

- Implementing strnlen(), a bounded version of strlen().

- Adding a menu_data_end parameter to menu_get_zipl_boot_index() and replacing both strlen() calls with strnlen() bounded by the remaining buffer space. The loop guard also checks that the pointer has not reached menu_data_end. For robustness, the function returns 0 (boot default) if somehow menu_data is initially >= menu_data_end.

- Replacing the VLA char buf[len + 2] in zipl_print_entry() with a fixed
   ZIPL_ENTRY_MAX + 2 (82-byte) buffer and truncating len before use.

- Passing s2_end (_s2 + sizeof(_s2)) as menu_data_end at the one call site in eckd_get_boot_menu_index(), so the bound is exactly the end of the buffer.

Fixes f7178910845a ("s390-ccw: print zipl boot menu")

---
  pc-bios/s390-ccw/bootmap.c  |  4 +++- pc-bios/s390-ccw/helper.h   | 10 ++++++++++ pc-bios/s390-ccw/menu.c     | 23 ++++++++++++++++++----- pc-bios/s390-ccw/s390-ccw.h |  2 +-

  4 files changed, 32 insertions(+), 7 deletions(-)
pc-bios/s390-ccw/bootmap.c +3 -1
index ed6e8cbbc7..81512265ce 100644
@@ -61,6 +61,7 @@ static uint8_t _s2[MAX_SECTOR_SIZE * 3] 
 __attribute__((__aligned__(PAGE_SIZE)));
   static void *s2_prev_blk = _s2;
   static void *s2_cur_blk = _s2 + MAX_SECTOR_SIZE;
   static void *s2_next_blk = _s2 + MAX_SECTOR_SIZE * 2;
+static void *s2_end = _s2 + sizeof(_s2);
   static inline int verify_boot_info(BootInfo *bip)
   {
@@ -308,7 +309,8 @@ static int 
 eckd_get_boot_menu_index(block_number_t s1b_block_nr)
                   }
               }
-            return menu_get_zipl_boot_index(s2_cur_blk + 
 banner_offset);
+            return menu_get_zipl_boot_index(s2_cur_blk + 
 banner_offset,
+                                            s2_end);
           }

          prev_block_nr = cur_block_nr;

pc-bios/s390-ccw/helper.h +10 -0
index 8e3dfcb6d6..d9b7da444a 100644
@@ -45,4 +45,14 @@ static inline void sleep(unsigned int seconds)
       }
   }
+static inline size_t strnlen(const char *s, size_t maxlen)
+{
+    size_t len = 0;
+
+    while (len < maxlen && s[len]) {
+        len++;
+    }
+    return len;
+}
+
   #endif
pc-bios/s390-ccw/menu.c +10 -2
index b6a9a56d46..af96a83de9 100644
@@ -16,6 +16,7 @@
   #include "s390-ccw.h"
   #include "sclp.h"
   #include "s390-time.h"
+#include "helper.h"
   #define KEYCODE_NO_INP '\0'
   #define KEYCODE_ESCAPE '\033'
@@ -26,6 +27,9 @@
   #define ZIPL_TIMEOUT_OFFSET 138
   #define ZIPL_FLAG_OFFSET    140
+/* Max printable chars for a zipl boot menu entry */
+#define ZIPL_ENTRY_MAX 80
+
   #define TOD_CLOCK_MILLISECOND   0x3e8000
   #define LOW_CORE_EXTERNAL_INT_ADDR   0x86
@@ -179,9 +183,13 @@ int menu_get_boot_index(bool *valid_entries)
   /* 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];
+    char buf[ZIPL_ENTRY_MAX + 2];
       const char *p;
+    if (len > ZIPL_ENTRY_MAX) {
+        len = ZIPL_ENTRY_MAX;
+    }
+
       ebcdic_to_ascii(data, buf, len);
       buf[len] = '\n';
       buf[len + 1] = '\0';
@@ -196,7 +204,7 @@ static int zipl_print_entry(const char *data, 
 size_t len)
       return atoi(p);
   }
-int menu_get_zipl_boot_index(const char *menu_data)
+int menu_get_zipl_boot_index(const char *menu_data, const char 
 *menu_data_end)
   {
       size_t len;

      int entry;

pc-bios/s390-ccw/menu.c +0 -0
@@ -212,13 +220,18 @@ int menu_get_zipl_boot_index(const char 
 *menu_data)
           timeout = zipl_timeout * 1000;

pc-bios/s390-ccw/menu.c int menu_get_zipl_boot_index(const char · line 230

Quoted 10 lines
pc-bios/s390-ccw/menu.c +6 -1
       }
+    if (menu_data >= menu_data_end) {
+        return 0;
+    }
+
       /* Print banner */
       puts("s390-ccw zIPL Boot Menu\n");
-    menu_data += strlen(menu_data) + 1;
+    len = strnlen(menu_data, menu_data_end - menu_data);
+    menu_data += len + 1;

If we've already hit menu_data_end at this point should we bail rather than skipping the while() loop and immediately proceeding into menu_get_boot_index(valid_entries); with an all-false array?

Quoted 2 lines
Quoted 2 lines

AFAICT the current implementation would print no options and wait for user input.

Right.

Quoted 9 lines
Quoted 5 lines

e.g. something like

     if (menu_data >= menu_data_end)
         return 0;

Hm, well, my proposal would still print the s390-ccw zIPL Boot Menu\n message but then quietly use the default boot option.

Quoted 8 lines

Maybe it would be better to move the
+    len = strnlen(menu_data, menu_data_end - menu_data); +    menu_data += len + 1;

up a few lines before the puts and combine it with the menu_data >= menu_data_end check you already added?  That way in both cases we silently take the default option without printing anything?

I agree with your assessment. Need another check after the "banner skip" and before the puts().

if (menu_data >= menu_data_end) {
    return 0; /* Boot default */
}

/* Skip banner */
len = strnlen(menu_data, menu_data_end - menu_data); menu_data += len + 1;

if (menu_data >= menu_data_end || !(*menu_data)) {
    return 0; /* No entries, boot default */
}

Quoted 6 lines

/* Print banner */
puts("s390-ccw zIPL Boot Menu\n");

/* Print entries */
while (menu_data < menu_data_end && *menu_data) {
...

@Joshua, can you send a v2 of just this patch? I'll pick up the first four with the little edits.

Quoted 27 lines
Quoted 25 lines
Quoted 24 lines
Quoted 23 lines
pc-bios/s390-ccw/menu.c +2 -2
       /* Print entries */
-    while (*menu_data) {
-        len = strlen(menu_data);
+    while (menu_data < menu_data_end && *menu_data) {
+        len = strnlen(menu_data, menu_data_end - menu_data);
           entry = zipl_print_entry(menu_data, len);
           menu_data += len + 1;
pc-bios/s390-ccw/s390-ccw.h +1 -1
index 1e1f71775e..f6030a6071 100644
@@ -76,7 +76,7 @@ void jump_to_low_kernel(void);
   /* menu.c */
   void menu_set_parms(uint8_t boot_menu_flag, uint32_t boot_menu_timeout);
-int menu_get_zipl_boot_index(const char *menu_data);
+int menu_get_zipl_boot_index(const char *menu_data, const char 
 *menu_data_end);
   bool menu_is_enabled_zipl(void);
   int menu_get_enum_boot_index(bool *valid_entries);
   bool menu_is_enabled_enum(void);
Reviewed-by on the v1 series
#14 lore raw
In reply to Christian Borntraeger
Quoted 26 lines · Christian Borntraeger

Cornelia, Eric, Matt,

here are 5 more fixes for hardening QEMU against invalid input. Nothing is strictly a security issues as defined in the policy. For example
https://qemu-project.gitlab.io/qemu/system/security.html says assert /
abort: If triggering the code path requires kernel privileges (or root account access) in the guest, asserts/aborts in QEMU are a self inflicted denial of service. These will not be treated as security flaws, at most hardening bugs.
And if anyone can provide invalid boot loader content it can provide anything to boot if secure boot is not available.
We should fix those anyway, probably even for 11.1

Conny, I did not rebuild the s390-ccw, I assume you will do that?

Christian Borntraeger (1):
hw/char/sclpconsole-lm: avoid guest triggerable assert

Joshua Daley (4):
s390x/ipl: validate num_comp against iplb length before iterating pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size() pc-bios/s390-ccw: bounds-check zipl menu entry index before array
write
pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in
zipl_print_entry

Quoted 8 lines
  hw/char/sclpconsole-lm.c    |  3 ++-
  hw/s390x/ipl.h              |  6 ++++++
  pc-bios/s390-ccw/bootmap.c  |  6 ++++--
  pc-bios/s390-ccw/helper.h   | 10 ++++++++++
  pc-bios/s390-ccw/menu.c     | 36 +++++++++++++++++++++++++++++-------
  pc-bios/s390-ccw/s390-ccw.h |  2 +-
  6 files changed, 52 insertions(+), 11 deletions(-)

These have been running on our systems the last few days. For the series:

#15 lore raw
In reply to Christian Borntraeger
Quoted 12 lines · Christian Borntraeger

Cornelia, Eric, Matt,

here are 5 more fixes for hardening QEMU against invalid input. Nothing is strictly a security issues as defined in the policy. For example
https://qemu-project.gitlab.io/qemu/system/security.html says assert /
abort: If triggering the code path requires kernel privileges (or root account access) in the guest, asserts/aborts in QEMU are a self inflicted denial of service. These will not be treated as security flaws, at most hardening bugs.
And if anyone can provide invalid boot loader content it can provide anything to boot if secure boot is not available.
We should fix those anyway, probably even for 11.1

Fixing: yes. For 11.1: how easy are they to trigger? For the bios fixes, I assume you need a broken/crafted disk image; I assume that for the other two, you need some buggy/misbehaving guest. Did you actually manage to trigger this via some kind of test case?

Quoted 2 lines

Conny, I did not rebuild the s390-ccw, I assume you will do that?

Yes, the bios rebuild will be done by whoever ends up applying the patches.

Quoted 19 lines

Christian Borntraeger (1):
hw/char/sclpconsole-lm: avoid guest triggerable assert

Joshua Daley (4):
s390x/ipl: validate num_comp against iplb length before iterating pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size() pc-bios/s390-ccw: bounds-check zipl menu entry index before array
write
pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in
zipl_print_entry

 hw/char/sclpconsole-lm.c    |  3 ++-
 hw/s390x/ipl.h              |  6 ++++++
 pc-bios/s390-ccw/bootmap.c  |  6 ++++--
 pc-bios/s390-ccw/helper.h   | 10 ++++++++++
 pc-bios/s390-ccw/menu.c     | 36 +++++++++++++++++++++++++++++-------
 pc-bios/s390-ccw/s390-ccw.h |  2 +-
 6 files changed, 52 insertions(+), 11 deletions(-)
#16 lore raw

Am 27.07.26 um 14:14 schrieb Cornelia Huck:

Quoted 15 lines · Christian Borntraeger
Quoted 13 lines

Cornelia, Eric, Matt,

here are 5 more fixes for hardening QEMU against invalid input. Nothing is strictly a security issues as defined in the policy. For example
https://qemu-project.gitlab.io/qemu/system/security.html says assert /
abort: If triggering the code path requires kernel privileges (or root account access) in the guest, asserts/aborts in QEMU are a self inflicted denial of service. These will not be treated as security flaws, at most hardening bugs.
And if anyone can provide invalid boot loader content it can provide anything to boot if secure boot is not available.
We should fix those anyway, probably even for 11.1

Quoted 4 lines

Fixing: yes. For 11.1: how easy are they to trigger? For the bios fixes, I assume you need a broken/crafted disk image; I assume that for the other two, you need some buggy/misbehaving guest. Did you actually manage to trigger this via some kind of test case?

Easy to trigger, but only with modified guests or modified zipls. Normal guests will not trigger those.

#17 lore raw
Quoted 16 lines · Christian Borntraeger

Am 27.07.26 um 14:14 schrieb Cornelia Huck:

Quoted 15 lines · Christian Borntraeger
Quoted 13 lines

Cornelia, Eric, Matt,

here are 5 more fixes for hardening QEMU against invalid input. Nothing is strictly a security issues as defined in the policy. For example
https://qemu-project.gitlab.io/qemu/system/security.html says assert /
abort: If triggering the code path requires kernel privileges (or root account access) in the guest, asserts/aborts in QEMU are a self inflicted denial of service. These will not be treated as security flaws, at most hardening bugs.
And if anyone can provide invalid boot loader content it can provide anything to boot if secure boot is not available.
We should fix those anyway, probably even for 11.1

Quoted 7 lines
Quoted 4 lines

Fixing: yes. For 11.1: how easy are they to trigger? For the bios fixes, I assume you need a broken/crafted disk image; I assume that for the other two, you need some buggy/misbehaving guest. Did you actually manage to trigger this via some kind of test case?

Easy to trigger, but only with modified guests or modified zipls. Normal guests will not trigger those.

Ok, so I think these would be suitable for the next release, but maybe with a cc:stable.

#18 lore raw

Am 27.07.26 um 17:06 schrieb Cornelia Huck:

Quoted 23 lines · Christian Borntraeger
Quoted 22 lines

Am 27.07.26 um 14:14 schrieb Cornelia Huck:

Quoted 19 lines · Christian Borntraeger
Quoted 13 lines

Cornelia, Eric, Matt,

here are 5 more fixes for hardening QEMU against invalid input. Nothing is strictly a security issues as defined in the policy. For example
https://qemu-project.gitlab.io/qemu/system/security.html says assert /
abort: If triggering the code path requires kernel privileges (or root account access) in the guest, asserts/aborts in QEMU are a self inflicted denial of service. These will not be treated as security flaws, at most hardening bugs.
And if anyone can provide invalid boot loader content it can provide anything to boot if secure boot is not available.
We should fix those anyway, probably even for 11.1

Fixing: yes. For 11.1: how easy are they to trigger? For the bios fixes, I assume you need a broken/crafted disk image; I assume that for the other two, you need some buggy/misbehaving guest. Did you actually manage to trigger this via some kind of test case?

Quoted 5 lines
Quoted 2 lines

Easy to trigger, but only with modified guests or modified zipls. Normal guests will not trigger those.

Ok, so I think these would be suitable for the next release, but maybe with a cc:stable.

Ok with me.

#19 lore raw
In reply to Christian Borntraeger
Quoted 15 lines · Christian Borntraeger

Cornelia, Eric, Matt,

here are 5 more fixes for hardening QEMU against invalid input. Nothing is strictly a security issues as defined in the policy. For example
https://qemu-project.gitlab.io/qemu/system/security.html says assert /
abort: If triggering the code path requires kernel privileges (or root account access) in the guest, asserts/aborts in QEMU are a self inflicted denial of service. These will not be treated as security flaws, at most hardening bugs.
And if anyone can provide invalid boot loader content it can provide anything to boot if secure boot is not available.
We should fix those anyway, probably even for 11.1

Conny, I did not rebuild the s390-ccw, I assume you will do that?

Quoted 8 lines

Christian Borntraeger (1):
hw/char/sclpconsole-lm: avoid guest triggerable assert

Joshua Daley (4):
s390x/ipl: validate num_comp against iplb length before iterating pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size() pc-bios/s390-ccw: bounds-check zipl menu entry index before array
write

Applied these four for 11.2, with the two typos fixed as Matt mentioned, and cc'd qemu-stable.

Quoted 2 lines

pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in
zipl_print_entry

Will wait for a v2 on this one.

Thanks!

Quoted 9 lines
  hw/char/sclpconsole-lm.c    |  3 ++-
  hw/s390x/ipl.h              |  6 ++++++
  pc-bios/s390-ccw/bootmap.c  |  6 ++++--
  pc-bios/s390-ccw/helper.h   | 10 ++++++++++
  pc-bios/s390-ccw/menu.c     | 36 +++++++++++++++++++++++++++++-------
  pc-bios/s390-ccw/s390-ccw.h |  2 +-
  6 files changed, 52 insertions(+), 11 deletions(-)