From nobody Thu Oct 30 22:46:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1752533461; cv=none; d=zohomail.com; s=zohoarc; b=VO3SivTWAIOoGt1ReQu9ZcBK56FWJXhXOzu9PVnFeFOSZNMw+cMQ+6Ia20GOf381wiACuTp9s2lV/5l2pkYl1/k06rIbGg+bj7s87wLtG9vUjNApL+RSj1+gsCMlxr1VasjbDXXL/7ur3J7xUtDEnUhcpT2D65NykgC7UTa+CRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752533461; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CcdR2OMWOJvXCF7+7tgxxw7opJ+1F3OE/BzPvoNcv94=; b=BwCx850EGl/0CREM8Qf+MxKMpTgwTQ6MzoAjYVm0Qvfl02q2p8c5EuMOTi93cyByFdUEIBa+tJwxGhtWk/AFCW/V6oiTmSMSiwY4Vr64/Y7ZQ0m8wIlQQDz65tv+cO9Z8B0YvjVdPRl1wMF5LtgWMlHrs/5ejsYURMsu3u0mGzs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1752533461577109.63421929197932; Mon, 14 Jul 2025 15:51:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1043221.1413383 (Exim 4.92) (envelope-from ) id 1ubS0W-0001Zg-6R; Mon, 14 Jul 2025 22:50:48 +0000 Received: by outflank-mailman (output) from mailman id 1043221.1413383; Mon, 14 Jul 2025 22:50:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ubS0W-0001Z1-1d; Mon, 14 Jul 2025 22:50:48 +0000 Received: by outflank-mailman (input) for mailman id 1043221; Mon, 14 Jul 2025 22:50:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ubRzG-00047A-BH for xen-devel@lists.xenproject.org; Mon, 14 Jul 2025 22:49:30 +0000 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [2a00:1450:4864:20::42a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ccc5f9c1-6104-11f0-a319-13f23c93f187; Tue, 15 Jul 2025 00:49:29 +0200 (CEST) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3a52878d37aso563865f8f.2 for ; Mon, 14 Jul 2025 15:49:29 -0700 (PDT) Received: from lab.home (dynamic-2a00-1028-83a4-4bca-c0bb-96ff-feed-9d50.ipv6.o2.cz. [2a00:1028:83a4:4bca:c0bb:96ff:feed:9d50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d4cbsm13713725f8f.50.2025.07.14.15.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 15:49:26 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ccc5f9c1-6104-11f0-a319-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752533368; x=1753138168; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CcdR2OMWOJvXCF7+7tgxxw7opJ+1F3OE/BzPvoNcv94=; b=AMwHjv/nY+L5c14mT1Ub+1TRdIAz6amrk02+xdbDp99TPKokyjoElgZahClqwyyOGc hhhvYJRwJNDRGD1hmESp9p5SiPK+sNlwzZPWCukisKMEm6NKpwruq6AWSlvE00faBGaC DwoEiZ/CAWEVZd34yjOLOGEseOf9P5XZ52i+gMdGL8PGZdwXMKKzXtKYU8sNjg7/CqfF SizG6YL8F+SxG7JQ9lk2Tq41isJdYSBmPms6hqIcXPUd9J10OwCuM7eHscgvUVX+nmnd Zr12v/dMidYy6qWgSJDlyofXIievURba693Mil5nT/45IZdMRlRo0B4TFewycfn/8jEv vwqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752533368; x=1753138168; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CcdR2OMWOJvXCF7+7tgxxw7opJ+1F3OE/BzPvoNcv94=; b=tdWqFQsLd4HvNu7Pq38dN/piUz5Dkj/+BnTBwWoFpKgEpEM0MYWiHaSwy1mQ/qbF6s 2Z+5dbXv8k+MgQ4n0/LO/2aMmOnb+qNwtIltelr7iqQEWTBocnK4NkyuqPIqOEuV8CIX yiI7Pj2nmryLjONkXNL1gBKKDtHA1vFQZERvs0Ed7iB+noI5BynykheH4/LrKmin2euE EbKLhK8+TYdToK02AxnR6hu7sz36aF0dYvk8a0xBRnLomSEOw1WLtoEBPo7r65SRC3a/ C6DYG/lVEPA6Iu1hrh+NsgbpIyum5jKiLrsWbRz2Kp3Rk18LAo796hbXKmRBBGoHbw7n I6Gw== X-Gm-Message-State: AOJu0YwvIr+bJHvErgxNFlZ4fbjWoJcEjJgHJHQNOOsO9Z6uNeJd8aCq Rp/mAV8gdkd7lWTYeUpYHdnJuqWGKWgbVRa2Pkz4kly0s6pYIQsvHC18kcaKqQ== X-Gm-Gg: ASbGnctNTd1R8czc+OeljwzkqAWlsEk+s9sHOvqINFOx0HmpQ5j0NVh0pLvYUxxiims ltT9Lv9F655XzQ9IzFFshJIsmYCjrSJ/2V+LO1rp/g5CNmPA3jc0Jg5Chw2pX4LoVQR0JQgJXGm 7PnwzCfQRXuEJMVS6hps+4HVBO8K+YtYl8hY2ZPeIUSyj9QyvZlzdHXMn8buzOoWVVCojIWEqiZ yoRUMgmAzsBD6hB88iR5W10B0qGoPH0Dpw86WJum8wFTcY1TZOKXSdaQ5GxQ6Zx7rxRksglCJNG IiANcb750ohjJLUDSPgclsFA3b6oQU5AjH9mdKXYAL85nQ+islxHYY2cogBEH1ZLUZTdKkX5J0A FijIiCBNFsqmsZjaQsuvjTJeU6nhymw2T5kawNcQMEjFw5Br8etYypJGc5Cg2B2jFISjeuaeYDV Uww3lMmeGbKD3VeqyRarIlUg== X-Google-Smtp-Source: AGHT+IHA4LWeAVjEO+r2peTO50wnnWwNN8Mse9AdBHWGDit1Fg/lmR7cqT+IlIVhWoQDcyqgs6duRg== X-Received: by 2002:a05:600c:46c3:b0:442:e608:12a6 with SMTP id 5b1f17b1804b1-454ec28092cmr53766085e9.1.1752533368031; Mon, 14 Jul 2025 15:49:28 -0700 (PDT) From: "=?UTF-8?q?Petr=20Bene=C5=A1?=" X-Google-Original-From: =?UTF-8?q?Petr=20Bene=C5=A1?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Petr=20Bene=C5=A1?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Anthony PERARD Subject: [PATCH v2 1/3] hvmloader: clean up SMBIOS code style and formatting Date: Mon, 14 Jul 2025 22:49:21 +0000 Message-Id: <8ab4c14518b4ae4eb327fb147058f0eec3ff29c7.1752533080.git.w1benny@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1752533463074116600 From: Petr Bene=C5=A1 *=C2=A0Removed trailing whitespaces *=C2=A0Removed unnecessary pointer casts * Added whitespaces around && * Removed superfluous parentheses * Use variables in sizeof() where applicable No functional change. Signed-off-by: Petr Bene=C5=A1 Acked-by: Jan Beulich --- tools/firmware/hvmloader/smbios.c | 162 +++++++++++++++--------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/s= mbios.c index 97a054e9e3..077c88c41c 100644 --- a/tools/firmware/hvmloader/smbios.c +++ b/tools/firmware/hvmloader/smbios.c @@ -67,7 +67,7 @@ static void * smbios_type_0_init(void *start, const char *xen_version, uint32_t xen_major_version, uint32_t xen_minor_version); static void * -smbios_type_1_init(void *start, const char *xen_version,=20 +smbios_type_1_init(void *start, const char *xen_version, uint8_t uuid[16]); static void * smbios_type_2_init(void *start); @@ -242,8 +242,8 @@ get_memsize(void) sz +=3D (((uint64_t)hvm_info->high_mem_pgend << PAGE_SHIFT) - GB(4= )); =20 /* - * Round up to the nearest MB. The user specifies domU pseudo-physica= l=20 - * memory in megabytes, so not doing this could easily lead to reporti= ng=20 + * Round up to the nearest MB. The user specifies domU pseudo-physical + * memory in megabytes, so not doing this could easily lead to reporti= ng * one less MB than the user specified. */ return (sz + MB(1) - 1) >> 20; @@ -378,24 +378,24 @@ static void * smbios_type_0_init(void *start, const char *xen_version, uint32_t xen_major_version, uint32_t xen_minor_version) { - struct smbios_type_0 *p =3D (struct smbios_type_0 *)start; + struct smbios_type_0 *p =3D start; static const char *smbios_release_date =3D __SMBIOS_DATE__; const char *s; void *pts; uint32_t length; =20 pts =3D get_smbios_pt_struct(0, &length); - if ( (pts !=3D NULL)&&(length > 0) ) + if ( pts !=3D NULL && length > 0 ) { memcpy(start, pts, length); p->header.handle =3D SMBIOS_HANDLE_TYPE0; - return (start + length); + return start + length; } =20 memset(p, 0, sizeof(*p)); =20 p->header.type =3D 0; - p->header.length =3D sizeof(struct smbios_type_0); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE0; =20 p->vendor_str =3D 1; @@ -411,12 +411,12 @@ smbios_type_0_init(void *start, const char *xen_versi= on, /* Extended Characteristics: Enable Targeted Content Distribution. */ p->characteristics_extension_bytes[1] =3D 0x04; =20 - p->major_release =3D (uint8_t) xen_major_version; - p->minor_release =3D (uint8_t) xen_minor_version; + p->major_release =3D (uint8_t)xen_major_version; + p->minor_release =3D (uint8_t)xen_minor_version; p->embedded_controller_major =3D 0xff; p->embedded_controller_minor =3D 0xff; =20 - start +=3D sizeof(struct smbios_type_0); + start +=3D sizeof(*p); s =3D xenstore_read(HVM_XS_BIOS_VENDOR, "Xen"); strcpy((char *)start, s); start +=3D strlen(s) + 1; @@ -434,42 +434,42 @@ smbios_type_0_init(void *start, const char *xen_versi= on, =20 /* Type 1 -- System Information */ static void * -smbios_type_1_init(void *start, const char *xen_version,=20 +smbios_type_1_init(void *start, const char *xen_version, uint8_t uuid[16]) { char uuid_str[37]; - struct smbios_type_1 *p =3D (struct smbios_type_1 *)start; + struct smbios_type_1 *p =3D start; const char *s; void *pts; uint32_t length; =20 pts =3D get_smbios_pt_struct(1, &length); - if ( (pts !=3D NULL)&&(length > 0) ) + if ( pts !=3D NULL && length > 0 ) { memcpy(start, pts, length); p->header.handle =3D SMBIOS_HANDLE_TYPE1; - return (start + length); + return start + length; } =20 memset(p, 0, sizeof(*p)); =20 p->header.type =3D 1; - p->header.length =3D sizeof(struct smbios_type_1); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE1; =20 p->manufacturer_str =3D 1; p->product_name_str =3D 2; p->version_str =3D 3; p->serial_number_str =3D 4; - =20 + memcpy(p->uuid, uuid, 16); =20 p->wake_up_type =3D 0x06; /* power switch */ p->sku_str =3D 0; p->family_str =3D 0; =20 - start +=3D sizeof(struct smbios_type_1); - =20 + start +=3D sizeof(*p); + s =3D xenstore_read(HVM_XS_SYSTEM_MANUFACTURER, "Xen"); strcpy((char *)start, s); start +=3D strlen(s) + 1; @@ -482,21 +482,21 @@ smbios_type_1_init(void *start, const char *xen_versi= on, strcpy((char *)start, s); start +=3D strlen(s) + 1; =20 - uuid_to_string(uuid_str, uuid);=20 + uuid_to_string(uuid_str, uuid); s =3D xenstore_read(HVM_XS_SYSTEM_SERIAL_NUMBER, uuid_str); strcpy((char *)start, s); start +=3D strlen(s) + 1; =20 *((uint8_t *)start) =3D 0; - =20 - return start+1;=20 + + return start+1; } =20 /* Type 2 -- System Board */ static void * smbios_type_2_init(void *start) { - struct smbios_type_2 *p =3D (struct smbios_type_2 *)start; + struct smbios_type_2 *p =3D start; const char *s; uint8_t *ptr; void *pts; @@ -504,7 +504,7 @@ smbios_type_2_init(void *start) unsigned int counter =3D 0; =20 pts =3D get_smbios_pt_struct(2, &length); - if ( (pts !=3D NULL)&&(length > 0) ) + if ( pts !=3D NULL && length > 0 ) { memcpy(start, pts, length); p->header.handle =3D SMBIOS_HANDLE_TYPE2; @@ -517,12 +517,12 @@ smbios_type_2_init(void *start) *((uint16_t*)ptr) =3D SMBIOS_HANDLE_TYPE3; } =20 - return (start + length); + return start + length; } =20 memset(p, 0, sizeof(*p)); p->header.type =3D 2; - p->header.length =3D sizeof(struct smbios_type_2); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE2; p->feature_flags =3D 0x09; /* Board is a hosting board and replaceable= */ p->chassis_handle =3D SMBIOS_HANDLE_TYPE3; @@ -530,7 +530,7 @@ smbios_type_2_init(void *start) start +=3D sizeof(*p); =20 s =3D xenstore_read(HVM_XS_BASEBOARD_MANUFACTURER, NULL); - if ( (s !=3D NULL) && (*s !=3D '\0') ) + if ( s !=3D NULL && *s !=3D '\0' ) { strcpy(start, s); start +=3D strlen(s) + 1; @@ -538,7 +538,7 @@ smbios_type_2_init(void *start) } =20 s =3D xenstore_read(HVM_XS_BASEBOARD_PRODUCT_NAME, NULL); - if ( (s !=3D NULL) && (*s !=3D '\0') ) + if ( s !=3D NULL && *s !=3D '\0' ) { strcpy(start, s); start +=3D strlen(s) + 1; @@ -546,7 +546,7 @@ smbios_type_2_init(void *start) } =20 s =3D xenstore_read(HVM_XS_BASEBOARD_VERSION, NULL); - if ( (s !=3D NULL) && (*s !=3D '\0') ) + if ( s !=3D NULL && *s !=3D '\0' ) { strcpy(start, s); start +=3D strlen(s) + 1; @@ -554,7 +554,7 @@ smbios_type_2_init(void *start) } =20 s =3D xenstore_read(HVM_XS_BASEBOARD_SERIAL_NUMBER, NULL); - if ( (s !=3D NULL) && (*s !=3D '\0') ) + if ( s !=3D NULL && *s !=3D '\0' ) { strcpy(start, s); start +=3D strlen(s) + 1; @@ -562,7 +562,7 @@ smbios_type_2_init(void *start) } =20 s =3D xenstore_read(HVM_XS_BASEBOARD_ASSET_TAG, NULL); - if ( (s !=3D NULL) && (*s !=3D '\0') ) + if ( s !=3D NULL && *s !=3D '\0' ) { strcpy(start, s); start +=3D strlen(s) + 1; @@ -570,7 +570,7 @@ smbios_type_2_init(void *start) } =20 s =3D xenstore_read(HVM_XS_BASEBOARD_LOCATION_IN_CHASSIS, NULL); - if ( (s !=3D NULL) && (*s !=3D '\0') ) + if ( s !=3D NULL && *s !=3D '\0' ) { strcpy(start, s); start +=3D strlen(s) + 1; @@ -591,24 +591,24 @@ smbios_type_2_init(void *start) static void * smbios_type_3_init(void *start) { - struct smbios_type_3 *p =3D (struct smbios_type_3 *)start; + struct smbios_type_3 *p =3D start; const char *s; void *pts; uint32_t length; uint32_t counter =3D 0; =20 pts =3D get_smbios_pt_struct(3, &length); - if ( (pts !=3D NULL)&&(length > 0) ) + if ( pts !=3D NULL && length > 0 ) { memcpy(start, pts, length); p->header.handle =3D SMBIOS_HANDLE_TYPE3; - return (start + length); + return start + length; } =20 memset(p, 0, sizeof(*p)); =20 p->header.type =3D 3; - p->header.length =3D sizeof(struct smbios_type_3); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE3; =20 p->manufacturer_str =3D ++counter; @@ -621,22 +621,22 @@ smbios_type_3_init(void *start) p->thermal_state =3D 0x03; /* safe */ p->security_status =3D 0x02; /* unknown */ =20 - start +=3D sizeof(struct smbios_type_3); - =20 + start +=3D sizeof(*p); + s =3D xenstore_read(HVM_XS_ENCLOSURE_MANUFACTURER, "Xen"); strcpy((char *)start, s); start +=3D strlen(s) + 1; =20 /* No internal defaults for following ones if the value is not set */ s =3D xenstore_read(HVM_XS_ENCLOSURE_SERIAL_NUMBER, NULL); - if ( (s !=3D NULL)&&(*s !=3D '\0') ) + if ( s !=3D NULL && *s !=3D '\0' ) { strcpy((char *)start, s); start +=3D strlen(s) + 1; p->serial_number_str =3D ++counter; } s =3D xenstore_read(HVM_XS_ENCLOSURE_ASSET_TAG, NULL); - if ( (s !=3D NULL) && (*s !=3D '\0') ) + if ( s !=3D NULL && *s !=3D '\0' ) { strcpy(start, s); start +=3D strlen(s) + 1; @@ -652,14 +652,14 @@ static void * smbios_type_4_init( void *start, unsigned int cpu_number, char *cpu_manufacturer) { - char buf[80];=20 - struct smbios_type_4 *p =3D (struct smbios_type_4 *)start; + char buf[80]; + struct smbios_type_4 *p =3D start; uint32_t eax, ebx, ecx, edx; =20 memset(p, 0, sizeof(*p)); =20 p->header.type =3D 4; - p->header.length =3D sizeof(struct smbios_type_4); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE4 + cpu_number; =20 p->socket_designation_str =3D 1; @@ -684,7 +684,7 @@ smbios_type_4_init( p->l2_cache_handle =3D 0xffff; /* No cache information structure provi= ded. */ p->l3_cache_handle =3D 0xffff; /* No cache information structure provi= ded. */ =20 - start +=3D sizeof(struct smbios_type_4); + start +=3D sizeof(*p); =20 strncpy(buf, "CPU ", sizeof(buf)); if ( (sizeof(buf) - strlen("CPU ")) >=3D 3 ) @@ -702,9 +702,9 @@ smbios_type_4_init( =20 /* Type 11 -- OEM Strings */ static void * -smbios_type_11_init(void *start)=20 +smbios_type_11_init(void *start) { - struct smbios_type_11 *p =3D (struct smbios_type_11 *)start; + struct smbios_type_11 *p =3D start; char path[20]; const char *s; int i; @@ -712,20 +712,20 @@ smbios_type_11_init(void *start) uint32_t length; =20 pts =3D get_smbios_pt_struct(11, &length); - if ( (pts !=3D NULL)&&(length > 0) ) + if ( pts !=3D NULL && length > 0 ) { memcpy(start, pts, length); p->header.handle =3D SMBIOS_HANDLE_TYPE11; - return (start + length); + return start + length; } =20 p->header.type =3D 11; - p->header.length =3D sizeof(struct smbios_type_11); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE11; =20 p->count =3D 0; =20 - start +=3D sizeof(struct smbios_type_11); + start +=3D sizeof(*p); =20 /* Pull out as many oem-* strings we find in xenstore */ for ( i =3D 1; i < 100; i++ ) @@ -737,7 +737,7 @@ smbios_type_11_init(void *start) start +=3D strlen(s) + 1; p->count++; } - =20 + /* Make sure there's at least one type-11 string */ if ( p->count =3D=3D 0 ) { @@ -754,14 +754,14 @@ smbios_type_11_init(void *start) static void * smbios_type_16_init(void *start, uint32_t memsize, int nr_mem_devs) { - struct smbios_type_16 *p =3D (struct smbios_type_16*)start; + struct smbios_type_16 *p =3D start; =20 memset(p, 0, sizeof(*p)); =20 p->header.type =3D 16; p->header.handle =3D SMBIOS_HANDLE_TYPE16; - p->header.length =3D sizeof(struct smbios_type_16); - =20 + p->header.length =3D sizeof(*p); + p->location =3D 0x01; /* other */ p->use =3D 0x03; /* system memory */ p->error_correction =3D 0x06; /* Multi-bit ECC to make Microsoft happy= */ @@ -769,7 +769,7 @@ smbios_type_16_init(void *start, uint32_t memsize, int = nr_mem_devs) p->memory_error_information_handle =3D 0xfffe; /* none provided */ p->number_of_memory_devices =3D nr_mem_devs; =20 - start +=3D sizeof(struct smbios_type_16); + start +=3D sizeof(*p); *((uint16_t *)start) =3D 0; return start + 2; } @@ -779,12 +779,12 @@ static void * smbios_type_17_init(void *start, uint32_t memory_size_mb, int instance) { char buf[16]; - struct smbios_type_17 *p =3D (struct smbios_type_17 *)start; - =20 + struct smbios_type_17 *p =3D start; + memset(p, 0, sizeof(*p)); =20 p->header.type =3D 17; - p->header.length =3D sizeof(struct smbios_type_17); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE17 + instance; =20 p->physical_memory_array_handle =3D 0x1000; @@ -799,7 +799,7 @@ smbios_type_17_init(void *start, uint32_t memory_size_m= b, int instance) p->memory_type =3D 0x07; /* RAM */ p->type_detail =3D 0; =20 - start +=3D sizeof(struct smbios_type_17); + start +=3D sizeof(*p); strcpy(start, "DIMM "); start +=3D strlen("DIMM "); itoa(buf, instance); @@ -814,12 +814,12 @@ smbios_type_17_init(void *start, uint32_t memory_size= _mb, int instance) static void * smbios_type_19_init(void *start, uint32_t memory_size_mb, int instance) { - struct smbios_type_19 *p =3D (struct smbios_type_19 *)start; - =20 + struct smbios_type_19 *p =3D start; + memset(p, 0, sizeof(*p)); =20 p->header.type =3D 19; - p->header.length =3D sizeof(struct smbios_type_19); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE19 + instance; =20 p->starting_address =3D instance << 24; @@ -827,7 +827,7 @@ smbios_type_19_init(void *start, uint32_t memory_size_m= b, int instance) p->memory_array_handle =3D 0x1000; p->partition_width =3D 1; =20 - start +=3D sizeof(struct smbios_type_19); + start +=3D sizeof(*p); *((uint16_t *)start) =3D 0; return start + 2; } @@ -836,12 +836,12 @@ smbios_type_19_init(void *start, uint32_t memory_size= _mb, int instance) static void * smbios_type_20_init(void *start, uint32_t memory_size_mb, int instance) { - struct smbios_type_20 *p =3D (struct smbios_type_20 *)start; + struct smbios_type_20 *p =3D start; =20 memset(p, 0, sizeof(*p)); =20 p->header.type =3D 20; - p->header.length =3D sizeof(struct smbios_type_20); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE20 + instance; =20 p->starting_address =3D instance << 24; @@ -852,7 +852,7 @@ smbios_type_20_init(void *start, uint32_t memory_size_m= b, int instance) p->interleave_position =3D 0; p->interleaved_data_depth =3D 0; =20 - start +=3D sizeof(struct smbios_type_20); + start +=3D sizeof(*p); =20 *((uint16_t *)start) =3D 0; return start+2; @@ -862,18 +862,18 @@ smbios_type_20_init(void *start, uint32_t memory_size= _mb, int instance) static void * smbios_type_22_init(void *start) { - struct smbios_type_22 *p =3D (struct smbios_type_22 *)start; + struct smbios_type_22 *p =3D start; static const char *smbios_release_date =3D __SMBIOS_DATE__; const char *s; void *pts; uint32_t length; =20 pts =3D get_smbios_pt_struct(22, &length); - if ( (pts !=3D NULL)&&(length > 0) ) + if ( pts !=3D NULL && length > 0 ) { memcpy(start, pts, length); p->header.handle =3D SMBIOS_HANDLE_TYPE22; - return (start + length); + return start + length; } =20 s =3D xenstore_read(HVM_XS_SMBIOS_DEFAULT_BATTERY, "0"); @@ -883,7 +883,7 @@ smbios_type_22_init(void *start) memset(p, 0, sizeof(*p)); =20 p->header.type =3D 22; - p->header.length =3D sizeof(struct smbios_type_22); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE22; =20 p->location_str =3D 1; @@ -902,7 +902,7 @@ smbios_type_22_init(void *start) p->design_capacity_multiplier =3D 0; p->oem_specific =3D 0; =20 - start +=3D sizeof(struct smbios_type_22); + start +=3D sizeof(*p); =20 strcpy((char *)start, "Primary"); start +=3D strlen("Primary") + 1; @@ -920,24 +920,24 @@ smbios_type_22_init(void *start) =20 *((uint8_t *)start) =3D 0; =20 - return start+1;=20 + return start+1; } =20 /* Type 32 -- System Boot Information */ static void * smbios_type_32_init(void *start) { - struct smbios_type_32 *p =3D (struct smbios_type_32 *)start; + struct smbios_type_32 *p =3D start; =20 memset(p, 0, sizeof(*p)); =20 p->header.type =3D 32; - p->header.length =3D sizeof(struct smbios_type_32); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE32; memset(p->reserved, 0, 6); p->boot_status =3D 0; /* no errors detected */ - =20 - start +=3D sizeof(struct smbios_type_32); + + start +=3D sizeof(*p); *((uint16_t *)start) =3D 0; return start+2; } @@ -946,16 +946,16 @@ smbios_type_32_init(void *start) static void * smbios_type_39_init(void *start) { - struct smbios_type_39 *p =3D (struct smbios_type_39 *)start; + struct smbios_type_39 *p =3D start; void *pts; uint32_t length; =20 pts =3D get_smbios_pt_struct(39, &length); - if ( (pts !=3D NULL)&&(length > 0) ) + if ( pts !=3D NULL && length > 0 ) { memcpy(start, pts, length); p->header.handle =3D SMBIOS_HANDLE_TYPE39; - return (start + length); + return start + length; } =20 /* Only present when passed in */ @@ -998,15 +998,15 @@ smbios_type_vendor_oem_init(void *start) static void * smbios_type_127_init(void *start) { - struct smbios_type_127 *p =3D (struct smbios_type_127 *)start; + struct smbios_type_127 *p =3D start; =20 memset(p, 0, sizeof(*p)); =20 p->header.type =3D 127; - p->header.length =3D sizeof(struct smbios_type_127); + p->header.length =3D sizeof(*p); p->header.handle =3D SMBIOS_HANDLE_TYPE127; =20 - start +=3D sizeof(struct smbios_type_127); + start +=3D sizeof(*p); *((uint16_t *)start) =3D 0; return start + 2; } --=20 2.34.1 From nobody Thu Oct 30 22:46:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1752533452; cv=none; d=zohomail.com; s=zohoarc; b=JEQ75CHAX2lxKpaliXi4O+fmi/tLD8Pm3z/P6HzxaTM/WRRuFqT40lb6+EqUxqA7boM/QJrlT44uKb5YrRmH8f257DpBOg/ZtpLDAAAeKse4M4MAVSxjpAhJMg1VAskNxPor6o+EIxYtHbmnDoIi1BWjtMcnGbPUd1Ph0cSxCOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752533452; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cKkryV9+UDN5kxVGjPtTWriGNmK46kznagX67IaJxg0=; b=j9vF+BMMIfHE3qAmON3Ftg6f3F7k6RFr9p11zYVGZXt8oTzpEC4SVwmGqYxsIJZqLxdcbGWz8p0XQRoDNcpDr71trSVVmyUmGthsPm/7eBDQaz9fLDRigH4AHSrm9L7carXUVHUjyzNTiYkp4BXdI65HVG0fyGb+10899UTXySg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1752533452061711.7777539541988; Mon, 14 Jul 2025 15:50:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1043218.1413369 (Exim 4.92) (envelope-from ) id 1ubS0P-0000xw-S7; Mon, 14 Jul 2025 22:50:41 +0000 Received: by outflank-mailman (output) from mailman id 1043218.1413369; Mon, 14 Jul 2025 22:50:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ubS0P-0000x6-Jl; Mon, 14 Jul 2025 22:50:41 +0000 Received: by outflank-mailman (input) for mailman id 1043218; Mon, 14 Jul 2025 22:50:40 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ubRzK-00047A-Hu for xen-devel@lists.xenproject.org; Mon, 14 Jul 2025 22:49:34 +0000 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [2a00:1450:4864:20::42f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cdf97821-6104-11f0-a319-13f23c93f187; Tue, 15 Jul 2025 00:49:31 +0200 (CEST) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3b39c46e1cfso592687f8f.3 for ; Mon, 14 Jul 2025 15:49:31 -0700 (PDT) Received: from lab.home (dynamic-2a00-1028-83a4-4bca-c0bb-96ff-feed-9d50.ipv6.o2.cz. [2a00:1028:83a4:4bca:c0bb:96ff:feed:9d50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d4cbsm13713725f8f.50.2025.07.14.15.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 15:49:29 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cdf97821-6104-11f0-a319-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752533370; x=1753138170; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cKkryV9+UDN5kxVGjPtTWriGNmK46kznagX67IaJxg0=; b=N7dfkbXQ5zxdeljSAGaKUERKAtmlMJ13cOgPjaHvFK8bn2Ed5aFWS9PMrfUGsFJHKM J7Aftfw50zV/wYphY/iuIG71sengzsAtHYVgIKZ8gu8lx41Ed4Mgz9JT5PXBw+LDrnBj fTdNsR1il2rndd1zial2UQsk3D3n0Ax62VJY4drnqJ/6o76QW2tVNPHXn1tchh8464gI kqfQ6DXnyNLEOFz0lajfTdFSICKvmI2jd1DzDIiFVnhnzpizUcrveGwOL/HOYtWi20ML 3bt3ZEO0+gdwhjj1KQk47KWeEMOEV0u/ixb+xodRZutCJvnnyHqgQUS2EuZNQL3Ygpgn IUZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752533370; x=1753138170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cKkryV9+UDN5kxVGjPtTWriGNmK46kznagX67IaJxg0=; b=D//9qpLdA2hFFtMV6ORUDIFascjtTJUlVX3Yw0HS+RJbJkfe4gmu63lkieUqClA1/b 3UjaGUSezjNGYtZSRrELhawylTHIA596FcV2+Wh28qnjpIx//QMeNgwX5Llzv/q0elJM T0DQj1UCN3addOZEr/6/2y71EdqaVUb08XFtDf1f9cBu4yj3f5CwmQpVMkOKbmMeVvcj ZJls/b1bI0GkCjKh214DR5Q6cLSQlfbSm6LvAWvPwxboV13+80LXbk2iLFP05IrWJtUP hNdBy8j8CK9AI6OTAca+CLxhACSwrVvVYTT1W2ypVfZq9+IO2qx3ZuESoyJG0fpFfUR4 Am3A== X-Gm-Message-State: AOJu0YxVJ1sUEQFOoflpaG2gqSfRtdPLzqmgaC/i8g23T+TmYYK5uGD2 GypD3iPSF/wDvBHGzlgU/oh78KQ34B9tvrKztk0FRpThPGuUXf9pNivcoHcgvg== X-Gm-Gg: ASbGncsYAPo0654ivNE2l5uyEBZ/9Q7NPxXm9U90WuR5jkTMUCiua1K5jy7J/zHTuvZ YKJYqVPP/++hNcI8dHPKN3D5+EVVDcG0A2P57e1uJ6sBEqzFAhaNPuQHh/HKW3+vRBJcBArIeu/ FNqWwB0YgiRyY2PWC/IT7cf7zw8iAVcASvRP+kT/6CZEBZI9Ml1h/x+n6rhUgbSAL+59DEbglmP 9TSMC4rlOMWwuQ377hjvGw5vaiQcVbCFJQeUtP7dnskbIvt4CZ4GtvavwnywmaSCK6t+1LVnUQ1 PiQuLvT7V+f2K5Dh96WEVOtzn9LWfQf51BMo1Ld2g4Hhdag2nBLztESYp9cVLxWSp6SknnN8Yf1 o79LWd3qgTIuo3imcGP2LcY8u+SuhEWevb/YXr4gKDvcf0kpoUcjsJzw+rFyNndTgTlCQ0yaisZ a263bzZMS/G5oedQqXhFXOVE9tVliaVCoO X-Google-Smtp-Source: AGHT+IFCPAfdHMRiaLedoXSkA8anV71VAGk7/bAoIMLmb4QPK6JyGT2k/mRwgIJE9QjreOUZ6NAJmA== X-Received: by 2002:a5d:6e5e:0:b0:3a5:8934:4948 with SMTP id ffacd0b85a97d-3b5f18938eamr3999477f8f.12.1752533370380; Mon, 14 Jul 2025 15:49:30 -0700 (PDT) From: "=?UTF-8?q?Petr=20Bene=C5=A1?=" X-Google-Original-From: =?UTF-8?q?Petr=20Bene=C5=A1?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Petr=20Bene=C5=A1?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Anthony PERARD Subject: [PATCH v2 2/3] hvmloader: fix SMBIOS table length checks Date: Mon, 14 Jul 2025 22:49:22 +0000 Message-Id: <9494aa56929b5cb443b9cccb0e671510071b4aab.1752533080.git.w1benny@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1752533452919116600 From: Petr Bene=C5=A1 SMBIOS specification dictates that tables should have a minimal length. This commit introduces further validation for user-input SMBIOS tables. As per SMBIOS Reference Specification: * Type 0: For version 2.3 and later implementations, the length is at least= 14h * Type 1: 1Bh for 2.4 and later * Type 2: at least 08h * Type 3: 0Dh for version 2.1 and later * Type 11: 5h (+ strings) * Type 22: 1Ah (+ strings) * Type 39: a minimum of 10h Notably, this also fixes previously incorrect check for chassis handle in s= mbios_type_2_init. Chassis handle is a WORD, therefore, the condition now correctly checks for= >=3D 13 instead of > 13. hvmloader currently implements version 2.4 Signed-off-by: Petr Bene=C5=A1 --- tools/firmware/hvmloader/smbios.c | 135 ++++++++++++------------ tools/firmware/hvmloader/smbios_types.h | 6 +- 2 files changed, 69 insertions(+), 72 deletions(-) diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/s= mbios.c index 077c88c41c..93bfea3e6e 100644 --- a/tools/firmware/hvmloader/smbios.c +++ b/tools/firmware/hvmloader/smbios.c @@ -47,6 +47,8 @@ static void smbios_pt_init(void); static void* get_smbios_pt_struct(uint8_t type, uint32_t *length_out); +static void * +smbios_pt_copy(void *start, uint8_t type, uint16_t handle, size_t table_si= ze); static void get_cpu_manufacturer(char *buf, int len); static int @@ -154,6 +156,25 @@ get_smbios_pt_struct(uint8_t type, uint32_t *length_ou= t) return NULL; } =20 +static void * +smbios_pt_copy(void *start, uint8_t type, uint16_t handle, size_t table_si= ze) +{ + struct smbios_structure_header *header =3D start; + + void *pts; + uint32_t length; + + pts =3D get_smbios_pt_struct(type, &length); + if ( pts !=3D NULL && length >=3D table_size ) + { + memcpy(start, pts, length); + header->handle =3D handle; + return start + length; + } + + return start; +} + static void get_cpu_manufacturer(char *buf, int len) { @@ -381,16 +402,11 @@ smbios_type_0_init(void *start, const char *xen_versi= on, struct smbios_type_0 *p =3D start; static const char *smbios_release_date =3D __SMBIOS_DATE__; const char *s; - void *pts; - uint32_t length; + void* next; =20 - pts =3D get_smbios_pt_struct(0, &length); - if ( pts !=3D NULL && length > 0 ) - { - memcpy(start, pts, length); - p->header.handle =3D SMBIOS_HANDLE_TYPE0; - return start + length; - } + next =3D smbios_pt_copy(start, 0, SMBIOS_HANDLE_TYPE0, sizeof(*p)); + if ( next !=3D start ) + return next; =20 memset(p, 0, sizeof(*p)); =20 @@ -440,16 +456,11 @@ smbios_type_1_init(void *start, const char *xen_versi= on, char uuid_str[37]; struct smbios_type_1 *p =3D start; const char *s; - void *pts; - uint32_t length; + void* next; =20 - pts =3D get_smbios_pt_struct(1, &length); - if ( pts !=3D NULL && length > 0 ) - { - memcpy(start, pts, length); - p->header.handle =3D SMBIOS_HANDLE_TYPE1; - return start + length; - } + next =3D smbios_pt_copy(start, 1, SMBIOS_HANDLE_TYPE1, sizeof(*p)); + if ( next !=3D start ) + return next; =20 memset(p, 0, sizeof(*p)); =20 @@ -499,25 +510,27 @@ smbios_type_2_init(void *start) struct smbios_type_2 *p =3D start; const char *s; uint8_t *ptr; - void *pts; - uint32_t length; + void *next; unsigned int counter =3D 0; =20 - pts =3D get_smbios_pt_struct(2, &length); - if ( pts !=3D NULL && length > 0 ) - { - memcpy(start, pts, length); - p->header.handle =3D SMBIOS_HANDLE_TYPE2; + /* + * Specification says Type 2 table has length of at least 08h, + * which corresponds with "Asset Tag" field offset. + */ =20 + next =3D smbios_pt_copy(start, 2, SMBIOS_HANDLE_TYPE2, sizeof(*p)); + if ( next !=3D start ) + { /* Set current chassis handle if present */ - if ( p->header.length > 13 ) + if ( p->header.length >=3D offsetof(struct smbios_type_2, board_ty= pe) ) { - ptr =3D ((uint8_t*)start) + 11; =20 + ptr =3D ((uint8_t*)start) + offsetof(struct smbios_type_2, + chassis_handle); if ( *((uint16_t*)ptr) !=3D 0 ) *((uint16_t*)ptr) =3D SMBIOS_HANDLE_TYPE3; } =20 - return start + length; + return next; } =20 memset(p, 0, sizeof(*p)); @@ -593,18 +606,18 @@ smbios_type_3_init(void *start) { struct smbios_type_3 *p =3D start; const char *s; - void *pts; - uint32_t length; + void *next; uint32_t counter =3D 0; =20 - pts =3D get_smbios_pt_struct(3, &length); - if ( pts !=3D NULL && length > 0 ) - { - memcpy(start, pts, length); - p->header.handle =3D SMBIOS_HANDLE_TYPE3; - return start + length; - } - =20 + /* + * Specification says Type 3 table has length of at least 0Dh (for v2.= 1+), + * which corresponds with "OEM-defined" field offset. + */ + + next =3D smbios_pt_copy(start, 3, SMBIOS_HANDLE_TYPE3, sizeof(*p)); + if ( next !=3D start ) + return next; + memset(p, 0, sizeof(*p)); =20 p->header.type =3D 3; @@ -707,17 +720,12 @@ smbios_type_11_init(void *start) struct smbios_type_11 *p =3D start; char path[20]; const char *s; + void *next; int i; - void *pts; - uint32_t length; =20 - pts =3D get_smbios_pt_struct(11, &length); - if ( pts !=3D NULL && length > 0 ) - { - memcpy(start, pts, length); - p->header.handle =3D SMBIOS_HANDLE_TYPE11; - return start + length; - } + next =3D smbios_pt_copy(start, 11, SMBIOS_HANDLE_TYPE11, sizeof(*p)); + if ( next !=3D start ) + return next; =20 p->header.type =3D 11; p->header.length =3D sizeof(*p); @@ -865,16 +873,11 @@ smbios_type_22_init(void *start) struct smbios_type_22 *p =3D start; static const char *smbios_release_date =3D __SMBIOS_DATE__; const char *s; - void *pts; - uint32_t length; + void *next; =20 - pts =3D get_smbios_pt_struct(22, &length); - if ( pts !=3D NULL && length > 0 ) - { - memcpy(start, pts, length); - p->header.handle =3D SMBIOS_HANDLE_TYPE22; - return start + length; - } + next =3D smbios_pt_copy(start, 22, SMBIOS_HANDLE_TYPE22, sizeof(*p)); + if ( next !=3D start ) + return next; =20 s =3D xenstore_read(HVM_XS_SMBIOS_DEFAULT_BATTERY, "0"); if ( strncmp(s, "1", 1) !=3D 0 ) @@ -946,20 +949,14 @@ smbios_type_32_init(void *start) static void * smbios_type_39_init(void *start) { - struct smbios_type_39 *p =3D start; - void *pts; - uint32_t length; - - pts =3D get_smbios_pt_struct(39, &length); - if ( pts !=3D NULL && length > 0 ) - { - memcpy(start, pts, length); - p->header.handle =3D SMBIOS_HANDLE_TYPE39; - return start + length; - } + /* + * Specification says Type 39 table has length of at least 10h, + * which corresponds with "Input Voltage Probe Handle" offset. + */ =20 - /* Only present when passed in */ - return start; + return smbios_pt_copy(start, 39, SMBIOS_HANDLE_TYPE39, + offsetof(struct smbios_type_39, + input_voltage_probe_handle)); } =20 static void * diff --git a/tools/firmware/hvmloader/smbios_types.h b/tools/firmware/hvmlo= ader/smbios_types.h index 7c648ece71..656b2a51ad 100644 --- a/tools/firmware/hvmloader/smbios_types.h +++ b/tools/firmware/hvmloader/smbios_types.h @@ -252,9 +252,9 @@ struct smbios_type_39 { uint8_t revision_level_str; uint16_t max_capacity; uint16_t characteristics; - uint16_t input_voltage_probe_handle; - uint16_t cooling_device_handle; - uint16_t input_current_probe_handle; + uint16_t input_voltage_probe_handle; /* Optional */ + uint16_t cooling_device_handle; /* Optional */ + uint16_t input_current_probe_handle; /* Optional */ } __attribute__ ((packed)); =20 /* SMBIOS type 127 -- End-of-table */ --=20 2.34.1 From nobody Thu Oct 30 22:46:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1752533464; cv=none; d=zohomail.com; s=zohoarc; b=kSYqZ0AtNNq/JwfKAEipPtS64N0x+OEFYqSIct239YOv20qwEO1lTveRSDFBwGrZTzKQqqw95DsYD8DfrJPH+T2uq88Qem8iQmPtzcly6ZVKwow8RjYXCLqjTs7n2jFEpvWxWxIEW4dO6kREb80lq8Bmo9yF/7YOUUnBfeKnuII= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752533464; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kInjRl+dr7QSUuJDw9dx5CY8sUkCe4SOSKHesTOQ5js=; b=U4PTi4/+WkDZibMb3FpfPxsTn0jCoj3WbQwBBE1AwslSi2WfMHf6W/eVpE3yu5gxY2XAZjPUZ8o/rZqRTXSFjqbZFWYkCHRFpt8iyK6NLKQExpYXbSWX6N+okMvtI9bdqfSquaZsOefsipYoTv9Gr9lH4jy3O72441Zf5ergDH8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 175253346408669.05982293675766; Mon, 14 Jul 2025 15:51:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1043229.1413393 (Exim 4.92) (envelope-from ) id 1ubS0b-0002Hy-Bl; Mon, 14 Jul 2025 22:50:53 +0000 Received: by outflank-mailman (output) from mailman id 1043229.1413393; Mon, 14 Jul 2025 22:50:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ubS0b-0002Hn-90; Mon, 14 Jul 2025 22:50:53 +0000 Received: by outflank-mailman (input) for mailman id 1043229; Mon, 14 Jul 2025 22:50:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ubRzM-00047A-CZ for xen-devel@lists.xenproject.org; Mon, 14 Jul 2025 22:49:36 +0000 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [2a00:1450:4864:20::42f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ce898075-6104-11f0-a319-13f23c93f187; Tue, 15 Jul 2025 00:49:32 +0200 (CEST) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3a4eb4dfd8eso721812f8f.2 for ; Mon, 14 Jul 2025 15:49:32 -0700 (PDT) Received: from lab.home (dynamic-2a00-1028-83a4-4bca-c0bb-96ff-feed-9d50.ipv6.o2.cz. [2a00:1028:83a4:4bca:c0bb:96ff:feed:9d50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d4cbsm13713725f8f.50.2025.07.14.15.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 15:49:30 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ce898075-6104-11f0-a319-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752533371; x=1753138171; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kInjRl+dr7QSUuJDw9dx5CY8sUkCe4SOSKHesTOQ5js=; b=E8PFYg1EgKy5HkQpAK0CU7d0y3q1fXd3y4pkowfLj9AFdc0oGt3T/s94A10YLPRAat Wfd0ZrS7yhWaD/wgrkuBbLBisJXupWIS32vHW6OCLEGAzO/Xirbx2H7cxHkEBOdqmM+t 0xxCn5I7x88t/GYT9BXQZBp9K4RCGNrhUvmqY8kzlHLElzfffcftHFKssxGcxLCC/shn RNN2ZipTOiGBle3ROKzbY5c0i31IO/u85AT5yads3U9U/oZaizKdK+ftLFAT1btB6RdO pLdNOWixCq9yLhbNsiFBGxCjzJWQvZ4VRo4+3T6DSCSYwuSeqdpbD46O4EmpVaMKmUmY F9JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752533371; x=1753138171; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kInjRl+dr7QSUuJDw9dx5CY8sUkCe4SOSKHesTOQ5js=; b=te25a1gSluFo13kU4akPi9XDPuhMzslCS+1aq8FPtSeu82WlgOn70dGIdXNttcopG+ QWPUPQNi0gKIMJCydF3tFDuNlgymfW2S2UhRhRIYZ6m+wLisKQg7AAYBEJgY3GtscYYq CEfH9MTbdInw/8pFFAUB/Vei6kBd5Ie4vnM8QVMNh3ZmIJ7EPCVe90bvtsy0JuA0KKT5 HWvsq3Z3eiw6eqwJIN2HggXkBEGeZpZzDUHlXpJMjws+meGNTpZtAzUh2akIG9AxOFTx HVEP1UT9bC023kCqOWq67HkuAdxfwc5v+e0BmegnNHSGm1qk0DW5mCBwXUsCtHy9KH4X xQog== X-Gm-Message-State: AOJu0Yz1sYaE9DTte007DyWglpHmnIdQaff1TiH7j+PApWjmdeykCBUd R4eaRJMzbvmn/ih2h0/BTkysHsnlE1YM7TxZWzrS9GGtsQpn0/JrynUg0DMgrw== X-Gm-Gg: ASbGnctnDL09y7fCyvlnKeAmIyiFUNChxHko1O/WIUDZCdio8waQeHtb1Kx/u/f7XB3 AtqaoTIIlsS6RQXWJ2Vn5NUjziezqWwPzc3RlKqwSkvhUjD+Txsng8hm+uBRF4YGsHu1aRcD1bE JOevjBZHO7w3uiyVfaSMZkF0w5DSu505Hv7PJLGbBiu9XvrQ1en9sXnPUWY10/J1yjup6R+IvsP F4GJAAsGDo43tgFhnCPWJCro5/mAvGLQsByij8dnQAUbs81uNuF4E+flW1mpDqGJyCy8M5Q2qo1 74OPfDH5ZMhtS+v1h0BPqLgJrU09sTpOKepdj97yZUHK3oxh5S23AygfvlAF3s2ULnKeE+EclSt TFWM3uPiWvAdWSpcILx5NYioMBcFed5675jP7GS3kpbr9fWdP/bywMGKzF/0b1s71fmwMxeUpeQ YeDpKoe0ApmDUjKNwiU+OnIg== X-Google-Smtp-Source: AGHT+IF57fBC8JYgL5AsBZizrhwcPPuIL9jDz5yyck9m84enU6YnqTz67Oemd9xh8D4Fnd2L8XhwAQ== X-Received: by 2002:a05:6000:2388:b0:3a3:6e85:a550 with SMTP id ffacd0b85a97d-3b5f185a966mr4950516f8f.5.1752533371293; Mon, 14 Jul 2025 15:49:31 -0700 (PDT) From: "=?UTF-8?q?Petr=20Bene=C5=A1?=" X-Google-Original-From: =?UTF-8?q?Petr=20Bene=C5=A1?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Petr=20Bene=C5=A1?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Anthony PERARD , Anton Belousov Subject: [PATCH v2 3/3] hvmloader: add new SMBIOS tables (7, 8, 9, 26, 27, 28) Date: Mon, 14 Jul 2025 22:49:23 +0000 Message-Id: <07aedca58d88ed741e13e073f39fdc20f29292cc.1752533080.git.w1benny@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1752533465054116600 From: Petr Bene=C5=A1 Some SMBIOS tables are used by certain malware families to detect virtualiz= ed environments via WMI queries. To improve stealth for sandboxing purposes, this patch adds support for populating these SMBIOS tables from an external binary specified via the "smbios_firmware" domain config option: *=C2=A07 - Cache Info * 8 - Port Connector * 9 - System Slots * 26 - Voltage Probe * 27 - Cooling Device * 28 - Temperature Probe If particular table is absent in binary file, then it will not be mapped to memory. This method works for Windows domains as tables 7,8,9,26,27,28 are = not critical for OS boot and runtime. Also if "smbios_firmware" parameter is not provided, these tables will be skipped in write_smbios_tables function. Signed-off-by: Petr Bene=C5=A1 Signed-off-by: Anton Belousov --- tools/firmware/hvmloader/smbios.c | 87 +++++++++++++++++++++++++ tools/firmware/hvmloader/smbios_types.h | 77 ++++++++++++++++++++++ 2 files changed, 164 insertions(+) diff --git a/tools/firmware/hvmloader/smbios.c b/tools/firmware/hvmloader/s= mbios.c index 93bfea3e6e..c67336cffa 100644 --- a/tools/firmware/hvmloader/smbios.c +++ b/tools/firmware/hvmloader/smbios.c @@ -33,12 +33,18 @@ #define SMBIOS_HANDLE_TYPE2 0x0200 #define SMBIOS_HANDLE_TYPE3 0x0300 #define SMBIOS_HANDLE_TYPE4 0x0400 +#define SMBIOS_HANDLE_TYPE7 0x0700 +#define SMBIOS_HANDLE_TYPE8 0x0800 +#define SMBIOS_HANDLE_TYPE9 0x0900 #define SMBIOS_HANDLE_TYPE11 0x0B00 #define SMBIOS_HANDLE_TYPE16 0x1000 #define SMBIOS_HANDLE_TYPE17 0x1100 #define SMBIOS_HANDLE_TYPE19 0x1300 #define SMBIOS_HANDLE_TYPE20 0x1400 #define SMBIOS_HANDLE_TYPE22 0x1600 +#define SMBIOS_HANDLE_TYPE26 0x1A00 +#define SMBIOS_HANDLE_TYPE27 0x1B00 +#define SMBIOS_HANDLE_TYPE28 0x1C00 #define SMBIOS_HANDLE_TYPE32 0x2000 #define SMBIOS_HANDLE_TYPE39 0x2700 #define SMBIOS_HANDLE_TYPE127 0x7f00 @@ -79,6 +85,12 @@ static void * smbios_type_4_init(void *start, unsigned int cpu_number, char *cpu_manufacturer); static void * +smbios_type_7_init(void *start); +static void * +smbios_type_8_init(void *start); +static void * +smbios_type_9_init(void *start); +static void * smbios_type_11_init(void *start); static void * smbios_type_16_init(void *start, uint32_t memory_size_mb, int nr_mem_devs); @@ -91,6 +103,12 @@ smbios_type_20_init(void *start, uint32_t memory_size_m= b, int instance); static void * smbios_type_22_init(void *start); static void * +smbios_type_26_init(void *start); +static void * +smbios_type_27_init(void *start); +static void * +smbios_type_28_init(void *start); +static void * smbios_type_32_init(void *start); static void * smbios_type_39_init(void *start); @@ -226,6 +244,9 @@ write_smbios_tables(void *ep, void *start, do_struct(smbios_type_3_init(p)); for ( cpu_num =3D 1; cpu_num <=3D vcpus; cpu_num++ ) do_struct(smbios_type_4_init(p, cpu_num, cpu_manufacturer)); + do_struct(smbios_type_7_init(p)); + do_struct(smbios_type_8_init(p)); + do_struct(smbios_type_9_init(p)); do_struct(smbios_type_11_init(p)); =20 /* Each 'memory device' covers up to 16GB of address space. */ @@ -242,6 +263,9 @@ write_smbios_tables(void *ep, void *start, } =20 do_struct(smbios_type_22_init(p)); + do_struct(smbios_type_26_init(p)); + do_struct(smbios_type_27_init(p)); + do_struct(smbios_type_28_init(p)); do_struct(smbios_type_32_init(p)); do_struct(smbios_type_39_init(p)); do_struct(smbios_type_vendor_oem_init(p)); @@ -713,6 +737,30 @@ smbios_type_4_init( return start+1; } =20 +/* Type 7 -- Cache Information */ +static void * +smbios_type_7_init(void *start) +{ + return smbios_pt_copy(start, 7, SMBIOS_HANDLE_TYPE7, + sizeof(struct smbios_type_7)); +} + +/* Type 8 -- Port Connector Information */ +static void * +smbios_type_8_init(void *start) +{ + return smbios_pt_copy(start, 8, SMBIOS_HANDLE_TYPE8, + sizeof(struct smbios_type_8)); +} + +/* Type 9 -- System Slots */ +static void * +smbios_type_9_init(void *start) +{ + return smbios_pt_copy(start, 9, SMBIOS_HANDLE_TYPE9, + sizeof(struct smbios_type_9)); +} + /* Type 11 -- OEM Strings */ static void * smbios_type_11_init(void *start) @@ -926,6 +974,45 @@ smbios_type_22_init(void *start) return start+1; } =20 +/* Type 26 -- Voltage Probe */ +static void * +smbios_type_26_init(void *start) +{ + /* + * Specification says Type 26 table has length of at least 14h, + * which corresponds with "Nominal Value" offset. + */ + + return smbios_pt_copy(start, 26, SMBIOS_HANDLE_TYPE26, + offsetof(struct smbios_type_26, nominal_value)); +} + +/* Type 27 -- Cooling Device */ +static void * +smbios_type_27_init(void *start) +{ + /* + * Specification says Type 27 table has length of at least 0Ch, + * which corresponds with "Nominal Speed" offset. + */ + + return smbios_pt_copy(start, 27, SMBIOS_HANDLE_TYPE27, + offsetof(struct smbios_type_27, nominal_speed)); +} + +/* Type 28 -- Temperature Probe */ +static void * +smbios_type_28_init(void *start) +{ + /* + * Specification says Type 28 table has length of at least 14h, + * which corresponds with "Nominal Value" offset. + */ + + return smbios_pt_copy(start, 28, SMBIOS_HANDLE_TYPE28, + offsetof(struct smbios_type_28, nominal_value)); +} + /* Type 32 -- System Boot Information */ static void * smbios_type_32_init(void *start) diff --git a/tools/firmware/hvmloader/smbios_types.h b/tools/firmware/hvmlo= ader/smbios_types.h index 656b2a51ad..1a24ccc55f 100644 --- a/tools/firmware/hvmloader/smbios_types.h +++ b/tools/firmware/hvmloader/smbios_types.h @@ -149,6 +149,44 @@ struct smbios_type_4 { uint8_t part_number_str; } __attribute__ ((packed)); =20 +/* SMBIOS type 7 - Cache Information */ +struct smbios_type_7 { + struct smbios_structure_header header; + uint8_t socket_designation_str; + uint16_t cache_configuration; + uint16_t maximum_cache_size; + uint16_t installed_size; + uint16_t supported_SRAM_type; + uint16_t current_SRAM_type; + uint8_t cache_speed; + uint8_t error_connection_type; + uint8_t system_cache_type; + uint8_t associativity; +} __attribute__ ((packed)); + +/* SMBIOS type 8 - Port Connector Information */ +struct smbios_type_8 { + struct smbios_structure_header header; + uint8_t internal_reference_designator_str; + uint8_t internal_connector_type; + uint8_t external_reference_designator_str; + uint8_t external_connector_type; + uint8_t port_type; +} __attribute__ ((packed)); + +/* SMBIOS type 9 - System Slots */ +struct smbios_type_9 { + struct smbios_structure_header header; + uint8_t slot_designation_str; + uint8_t slot_type; + uint8_t slot_data_bus_width; + uint8_t current_usage; + uint8_t slot_length; + uint16_t slot_id; + uint8_t slot_characteristics_1; + uint8_t slot_characteristics_2; +} __attribute__ ((packed)); + /* SMBIOS type 11 - OEM Strings */ struct smbios_type_11 { struct smbios_structure_header header; @@ -232,6 +270,45 @@ struct smbios_type_22 { uint32_t oem_specific; } __attribute__ ((packed)); =20 +/* SMBIOS type 26 - Voltage Probe */ +struct smbios_type_26 { + struct smbios_structure_header header; + uint8_t description_str; + uint8_t location_and_status; + uint16_t maximum_value; + uint16_t minimum_value; + uint16_t resolution; + uint16_t tolerance; + uint16_t accuracy; + uint32_t oem_defined; + uint16_t nominal_value; /* Optional */ +} __attribute__ ((packed)); + +/* SMBIOS type 27 - Cooling Device */ +struct smbios_type_27 { + struct smbios_structure_header header; + uint16_t temperature_probe_handle; + uint8_t device_type_and_status; + uint8_t cooling_unit_group; + uint32_t oem_defined; + uint16_t nominal_speed; /* Optional */ + uint8_t description_str; /* Optional */ +} __attribute__ ((packed)); + +/* SMBIOS type 28 - Temperature Probe */ +struct smbios_type_28 { + struct smbios_structure_header header; + uint8_t description_str; + uint8_t location_and_status; + uint16_t maximum_value; + uint16_t minimum_value; + uint16_t resolution; + uint16_t tolerance; + uint16_t accuracy; + uint32_t oem_defined; + uint16_t nominal_value; /* Optional */ +} __attribute__ ((packed)); + /* SMBIOS type 32 - System Boot Information */ struct smbios_type_32 { struct smbios_structure_header header; --=20 2.34.1