[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86/bzimage: Check that the payload lies within the image


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stefano Stabellini <stefano.stabellini@xxxxxxx>
  • Date: Tue, 20 Oct 2026 14:48:25 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lWfJxBnbFCN8jfpoKTdBHh0yaVi1TS/lq8L8UsyMq8I=; b=tBiQNkRauRQ18m5Vy68JVtcpXMUgyI2eHPH6LQMNl5GFhyOid62znwwn8x4GP+qRckE3Jlz7zB5xLU1CfXHyrzxOFTlyTcOnVEXlw6wpJIBPV+b2H59V4Q069X80FrBrXPgjcFU7he1aLeC/iwDgH5WKLqkgdquEMv5dOPDe6u7A/HBkUjkVjlHoHOKtU5D+aNSJk1HHgzk8fI0b8NDmqDaymZBHGp8i8oxz6emFqM3ngd7fFbfO1v8Rm+FQBb5Hukx/Uiao7NewSoKrrxM53/67oweyS45L6kOSlp9N+QfbXNiywpsEWmzYAfAlkRJHg5AO54dWcbmstAtip1Mgjw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=woNk6nEOSMDBxgreeVSUbDBT6U5cMRFcAYdG30X3x2kU2Rie04LjaIlaksjXLslR75HGfSH2VEGo4We/zc0WmWwCrk+XHaOZXkq7k3YUGQLYG7gTYkb8PHVfOCpZux7uWJpVN7Cyq83jURuMN/eLZngixdfxb2KvB2UyBiM9eRJpokoY4Oka8OhW3XLU5OFB2JilIiCwVKJiU9EZlb5DFWHC6r/2YVebjVsbI5xsWpKP6Lj9IOW4ofJOZ58e2Ck2oPDTTXNFdSHaSVSrnFZ8B9U+jICuwKXZeQK/gLrLCIejGQ0lMFGJIwYlt81ZkAMvnniDRyqa/bp9PvQVP/JggA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: <jbeulich@xxxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <roger@xxxxxxxxxxxxxx>, <jason.andryuk@xxxxxxx>, <teddy.astie@xxxxxxxxxx>, <stefano.stabellini@xxxxxxx>
  • Delivery-date: Tue, 20 Oct 2026 21:48:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

bzimage_check() doesn't validate setup_sects, payload_offset or
payload_length against the image size.  A truncated or malformed bzImage
therefore makes bzimage_headroom() and bzimage_parse() read beyond the
end of the boot module, which shows up as a fatal page fault, a bogus
headroom, or a decompression failure, rather than as a bad image.

Reject such a header up front.  bzimage_parse() passes bzimage_check() a
length which includes the decompression headroom in front of the image,
so subtract it to check against the image alone.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxx>
---
 xen/arch/x86/bzimage.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/bzimage.c b/xen/arch/x86/bzimage.c
index 66f648f311..a5c48755b6 100644
--- a/xen/arch/x86/bzimage.c
+++ b/xen/arch/x86/bzimage.c
@@ -54,6 +54,8 @@ struct __packed setup_header {
 
 static __init int bzimage_check(struct setup_header *hdr, unsigned long len)
 {
+    unsigned long payload_start;
+
     if ( len < sizeof(struct setup_header) )
         return 0;
 
@@ -65,6 +67,15 @@ static __init int bzimage_check(struct setup_header *hdr, 
unsigned long len)
            hdr->version >> 8, hdr->version & 0xff);
         return -EINVAL;
     }
+
+    payload_start = (hdr->setup_sects + 1) * 512UL + hdr->payload_offset;
+    if ( payload_start > len || hdr->payload_length > len - payload_start )
+    {
+        printk("bzImage payload %#x@%#lx exceeds the %#lx byte image\n",
+               hdr->payload_length, payload_start, len);
+        return -EINVAL;
+    }
+
     return 1;
 }
 
@@ -107,7 +118,8 @@ int __init bzimage_parse(void *image_base, void 
**image_start,
                          unsigned long *image_len)
 {
     struct setup_header *hdr = (struct setup_header *)(*image_start);
-    int err = bzimage_check(hdr, *image_len);
+    /* *image_len also counts the headroom ahead of *image_start. */
+    int err = bzimage_check(hdr, *image_len - (*image_start - image_base));
     unsigned long output_len;
 
     if ( err < 0 )
-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.