From nobody Mon Sep 28 02:01:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1785246468; cv=none; d=zohomail.com; s=zohoarc; b=WmddWgVfQloYjpM2rkk4bvHZAfZh6WLxKlRWrPtLiEG2l25dl1ZHs0Fg3V+aQ5YLXGr+jVnS7wyu96+pSnrUdyJpChfboadIyzlxQKeL/YCiXTSH26VBF12au89MYDvMZ8t291ZbyZLe8ow5LKfjukMBKi3KwZNyCRv0+qCR+vA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785246468; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rMhSUEAN8Fbx637AD72JAnn4vRZCFE7sWuDOFd6pCFc=; b=WQVZb/ZXUGLiM17nfe7XP1S6eStI08MXIfSRZoAmZZXaJGjHKojzgxxFEi7aJ+CMDcUkR4nvTp+jzTOYEvZg5tuGyEZN/yK5wrGMndtKI3ji84RsgAXoCLWUIhlpF+wILV4rEEmWhX4ywuVxV/z17RWW2xsEjZ0Da6Vkv0Di3Xk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1785246468860654.178918726106; Tue, 28 Jul 2026 06:47:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1woi9P-0005UW-PS; Tue, 28 Jul 2026 09:47:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1woi9O-0005Tw-Iy; Tue, 28 Jul 2026 09:47:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1woi9L-0000Qd-QW; Tue, 28 Jul 2026 09:47:18 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66SBHbbF3258326; Tue, 28 Jul 2026 13:47:10 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4fmuycdekc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jul 2026 13:47:09 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 66SDfQd3013366; Tue, 28 Jul 2026 13:47:09 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fna5y1s4j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jul 2026 13:47:08 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 66SDl5lE51970346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Jul 2026 13:47:05 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 080A320043; Tue, 28 Jul 2026 13:47:05 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BF3A42004B; Tue, 28 Jul 2026 13:47:04 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with SMTP; Tue, 28 Jul 2026 13:47:04 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 56370) id A5934162820; Tue, 28 Jul 2026 15:47:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=rMhSUEAN8Fbx637AD 72JAnn4vRZCFE7sWuDOFd6pCFc=; b=IpSZrSrSK11wZWkb8i3VlTJHG8CL9tKNi l2ma+hipgsc3dnb4MS5y9dvCFaqabNnk8O+gCdeROXDi8Pov88LiYW7egJqmjS6e jGtZZLeCp6RpYem6X6bqNdqhCrak9fFsFI/kmK+u18kxVnqAl3Td6ENxu1JcvzGg GaSAMEzdf1tHMm/nOxUxgHIJgK9nl65afiUSZJjRCrqqOOLpuBg1Guje+yvimHMg LRepvX5bhSscaHkYjnXU+dKyzwdo8xPhZX86Ucii0KY5e0xnOdbvB+MDMwlVOrvN fXXyocVi4ylBb8MivMiO/d5voZy4ncc1Tl2C1nzXven6S7Q64UyrQ== From: Joshua Daley To: farman@linux.ibm.com Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, cohuck@redhat.com, pasic@linux.ibm.com, borntraeger@linux.ibm.com, richard.henderson@linaro.org, iii@linux.ibm.com, david@kernel.org, brueckner@linux.ibm.com, pbonzini@redhat.com, marcandre.lureau@redhat.com, mjrosato@linux.ibm.com, jjherne@linux.ibm.com, jrossi@linux.ibm.com, zycai@linux.ibm.com, jdaley@linux.ibm.com Subject: [PATCH v2 1/1] pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry Date: Tue, 28 Jul 2026 15:47:04 +0200 Message-ID: <20260728134704.2924005-2-jdaley@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260728134704.2924005-1-jdaley@linux.ibm.com> References: <20260728134704.2924005-1-jdaley@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: G0kYXrmPiOURj6nMnUPCoUyhXOI4CA-g X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzI4MDExOCBTYWx0ZWRfXzpE7uE1h5PvI 4GS6JbxCIu0Tb7R7rJqh2Vy4Z6t+gUwn8AVJWshUOj65H1L2APCw4Y7QRSPPfN6IvHoHJ4SUlJo L0CZkVH6zC6vHZ3sYzppkYFpOEi4f1ex7LCaPDz1eefTSnmcaDTaD2V1IQHpyvbo2ZOAm2JXyY9 YHAExW78ur7CxhYvvKKOKEExX20ArJ1+dsA8q0NQai8FWWZogkwJq3yiayHibOgAqqaQXbGjvXe zMXUTn4OzFlXFy4znVDu+JSlpbR7pOpm9Qv0JbIuvvDGdB8gpl7UWuHhe3/6+qM3jf8M37M9l4V qc6xmPBl5018hTSocTFHVkc60fqYCIQ6kn/oVPBBvIUMv2+0gOTXs03/wwEc0QZEszkmqSIIvM9 UggC3ige+ExtMHrxB5iLzxAWRtD2ZFFNso+PVls0uziR5OSGRwR34oOr2dZ61wfWdWOHs6XT+hK mKs7g4wTGLvPq+2UWuw== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzI4MDExOCBTYWx0ZWRfX/qY7CCB9s17m SHTVTmMtngB/ZzisWMHQFmnxHqudxzEvYDjRXL+Qt3GBz6HqQACOsqxHWcLc8AkdhvLGe8oNKe4 DXv3WCEvNbJfOJ1HVFqxLRKemXkVxZ4= X-Authority-Analysis: v=2.4 cv=AZeB2XXG c=1 sm=1 tr=0 ts=6a68b2dd cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=OmDNG2-DsvkCiAtxb_cA:9 X-Proofpoint-GUID: G0kYXrmPiOURj6nMnUPCoUyhXOI4CA-g X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-28_03,2026-07-28_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 phishscore=0 adultscore=0 impostorscore=0 clxscore=1015 malwarescore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607280118 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=jdaley@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1785246470288158500 Content-Type: text/plain; charset="utf-8" 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. The function returns 0 (boot default) if somehow menu_data reaches menu_data_end before printing any entries. - 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") Signed-off-by: Joshua Daley Reviewed-by: Matthew Rosato --- pc-bios/s390-ccw/bootmap.c | 4 +++- pc-bios/s390-ccw/helper.h | 10 ++++++++++ pc-bios/s390-ccw/menu.c | 29 +++++++++++++++++++++++------ pc-bios/s390-ccw/s390-ccw.h | 2 +- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 420ee32eff..662265171b 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -61,6 +61,7 @@ static uint8_t _s2[MAX_SECTOR_SIZE * 3] __attribute__((__= aligned__(PAGE_SIZE))); static void *s2_prev_blk =3D _s2; static void *s2_cur_blk =3D _s2 + MAX_SECTOR_SIZE; static void *s2_next_blk =3D _s2 + MAX_SECTOR_SIZE * 2; +static void *s2_end =3D _s2 + sizeof(_s2); =20 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) } } =20 - return menu_get_zipl_boot_index(s2_cur_blk + banner_offset); + return menu_get_zipl_boot_index(s2_cur_blk + banner_offset, + s2_end); } =20 prev_block_nr =3D cur_block_nr; diff --git a/pc-bios/s390-ccw/helper.h b/pc-bios/s390-ccw/helper.h index 8e3dfcb6d6..d9b7da444a 100644 --- a/pc-bios/s390-ccw/helper.h +++ b/pc-bios/s390-ccw/helper.h @@ -45,4 +45,14 @@ static inline void sleep(unsigned int seconds) } } =20 +static inline size_t strnlen(const char *s, size_t maxlen) +{ + size_t len =3D 0; + + while (len < maxlen && s[len]) { + len++; + } + return len; +} + #endif diff --git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c index b6a9a56d46..9b81154b0e 100644 --- a/pc-bios/s390-ccw/menu.c +++ b/pc-bios/s390-ccw/menu.c @@ -16,6 +16,7 @@ #include "s390-ccw.h" #include "sclp.h" #include "s390-time.h" +#include "helper.h" =20 #define KEYCODE_NO_INP '\0' #define KEYCODE_ESCAPE '\033' @@ -26,6 +27,9 @@ #define ZIPL_TIMEOUT_OFFSET 138 #define ZIPL_FLAG_OFFSET 140 =20 +/* Max printable chars for a zipl boot menu entry */ +#define ZIPL_ENTRY_MAX 80 + #define TOD_CLOCK_MILLISECOND 0x3e8000 =20 #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; =20 + if (len > ZIPL_ENTRY_MAX) { + len =3D ZIPL_ENTRY_MAX; + } + ebcdic_to_ascii(data, buf, len); buf[len] =3D '\n'; buf[len + 1] =3D '\0'; @@ -196,7 +204,7 @@ static int zipl_print_entry(const char *data, size_t le= n) return atoi(p); } =20 -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,22 @@ int menu_get_zipl_boot_index(const char *menu_data) timeout =3D zipl_timeout * 1000; } =20 - /* Print banner */ + if (menu_data >=3D menu_data_end) { + return 0; /* Boot default */ + } + + /* Skip banner */ + len =3D strnlen(menu_data, menu_data_end - menu_data); + menu_data +=3D len + 1; + if (menu_data >=3D menu_data_end || !(*menu_data)) { + return 0; /* No entries, boot default */ + } + puts("s390-ccw zIPL Boot Menu\n"); - menu_data +=3D strlen(menu_data) + 1; =20 /* Print entries */ - while (*menu_data) { - len =3D strlen(menu_data); + while (menu_data < menu_data_end && *menu_data) { + len =3D strnlen(menu_data, menu_data_end - menu_data); entry =3D zipl_print_entry(menu_data, len); menu_data +=3D len + 1; =20 diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h index 1e1f71775e..f6030a6071 100644 --- a/pc-bios/s390-ccw/s390-ccw.h +++ b/pc-bios/s390-ccw/s390-ccw.h @@ -76,7 +76,7 @@ void jump_to_low_kernel(void); =20 /* 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); --=20 2.34.1