All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Rosato <mjrosato@linux.ibm.com>
To: Christian Borntraeger <borntraeger@linux.ibm.com>,
	Cornelia Huck <cohuck@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	qemu-s390x <qemu-s390x@nongnu.org>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Jason Herne" <jjherne@linux.ibm.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"David Hildenbrand" <david@kernel.org>,
	"Hendrik Brueckner" <brueckner@linux.ibm.com>,
	"Joshua Daley" <jdaley@linux.ibm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Jared Rossi" <jrossi@linux.ibm.com>,
	"Zhuoying Cai" <zycai@linux.ibm.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [PATCH 4/5] pc-bios/s390-ccw: bounds-check zipl menu entry index before array write
Date: Mon, 27 Jul 2026 11:32:47 -0400	[thread overview]
Message-ID: <daff87d9-414d-4aa6-8b13-84d657fdaaef@linux.ibm.com> (raw)
In-Reply-To: <20260727115052.24289-5-borntraeger@linux.ibm.com>

On 7/27/26 7:50 AM, Christian Borntraeger wrote:
> 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)")
> Signed-off-by: Joshua Daley <jdaley@linux.ibm.com>

Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>

> ---
>  pc-bios/s390-ccw/menu.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --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) {



  reply	other threads:[~2026-07-27 15:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 11:50 [PATCH 0/5] more hardening fixes for s390 Christian Borntraeger
2026-07-27 11:50 ` [PATCH 1/5] hw/char/sclpconsole-lm: avoid guest triggerable assert Christian Borntraeger
2026-07-27 14:46   ` Matthew Rosato
2026-07-27 11:50 ` [PATCH 2/5] s390x/ipl: validate num_comp against iplb length before iterating Christian Borntraeger
2026-07-27 15:04   ` Matthew Rosato
2026-07-27 11:50 ` [PATCH 3/5] pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size() Christian Borntraeger
2026-07-27 15:18   ` Matthew Rosato
2026-07-27 11:50 ` [PATCH 4/5] pc-bios/s390-ccw: bounds-check zipl menu entry index before array write Christian Borntraeger
2026-07-27 15:32   ` Matthew Rosato [this message]
2026-07-27 11:50 ` [PATCH 5/5] pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry Christian Borntraeger
2026-07-27 15:51   ` Matthew Rosato
2026-07-27 16:02     ` Matthew Rosato
2026-07-27 17:32       ` Joshua Daley
2026-07-27 20:02         ` Eric Farman
2026-07-27 12:00 ` [PATCH 0/5] more hardening fixes for s390 Eric Farman
2026-07-27 12:14 ` Cornelia Huck
2026-07-27 12:17   ` Christian Borntraeger
2026-07-27 15:06     ` Cornelia Huck

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=daff87d9-414d-4aa6-8b13-84d657fdaaef@linux.ibm.com \
    --to=mjrosato@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=brueckner@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@kernel.org \
    --cc=farman@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=jdaley@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=jrossi@linux.ibm.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=zycai@linux.ibm.com \
    /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.