From nobody Sun Nov 24 03:05:07 2024 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1728980771; cv=none; d=zohomail.com; s=zohoarc; b=iyqA+1ZqUTzHD0DtsEwqjfdLv7ggwCFzoIvqtZASOKL6SzQ3CCDZchufn8FK6rAxVKsqGXO95KCdETXx5/L4qotYQZnMjJ4dZHioZFxFTn3BJK0BZWS8cEFOc42V7jMBOffCmw3VIgnWn0wQ7Ox+fKntdcrHYKvFhr1CiHLobDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728980771; h=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=JPO73Ee+gUhp/QdwEt6rbkUZv+DPxFBuM2HxdwBJt8g=; b=ZyqlEKdpiBZfwmodLZWwTlKW80yWYI6T/Gq7OwkDwQD23nzn4mL2S5F61WxRnE+WeZ4DX3YXAJhdy0sHhd9Cfwiy94Nu7uO8jYx8CVlqTEz3pAcab247hxhmOhhOR/xroOUQHa72c49U9Ko7dM01LwMXaWpSNrmZj4BQwFQGagE= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1728980771770812.2642145843441; Tue, 15 Oct 2024 01:26:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.819031.1232337 (Exim 4.92) (envelope-from ) id 1t0cs0-0003wr-0m; Tue, 15 Oct 2024 08:25:32 +0000 Received: by outflank-mailman (output) from mailman id 819031.1232337; Tue, 15 Oct 2024 08:25:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0crz-0003wI-Td; Tue, 15 Oct 2024 08:25:31 +0000 Received: by outflank-mailman (input) for mailman id 819031; Tue, 15 Oct 2024 08:25:30 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0cry-0003el-Hv for xen-devel@lists.xenproject.org; Tue, 15 Oct 2024 08:25:30 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0767adbb-8acf-11ef-99a2-01e77a169b0f; Tue, 15 Oct 2024 10:25:26 +0200 (CEST) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5c9404c0d50so5240665a12.3 for ; Tue, 15 Oct 2024 01:25:26 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29749663sm41590566b.64.2024.10.15.01.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 01:25:24 -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: 0767adbb-8acf-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728980726; x=1729585526; 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=JPO73Ee+gUhp/QdwEt6rbkUZv+DPxFBuM2HxdwBJt8g=; b=YK7bXFlPcrFqHVQphJJs0eBs2UzaEwmg4u4RlgW8ScV1FP3Mom1wowtS7xGySmOmv0 bcKGd/G6QNpaK3O4aPfQHN+IfbOB1/hCzABWB5OVFAuF6quO6zOKf07JmRZuJv0d4Yfz 3DCm8XfaUTYOYh0a0djQatTZFHroxYPoUMCuc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728980726; x=1729585526; 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=JPO73Ee+gUhp/QdwEt6rbkUZv+DPxFBuM2HxdwBJt8g=; b=Gk6keVAg7nYVaMY3WIp2/ZdalRLoPPE0C+3X8tkSxd/vseLO5mcIARWcO7EXCMxL78 iRRaJd9NBAHgS/lUGGTH55KNp9tZAhLmtP4p/yjlAYBWII5udiDtb6BR12K0gYCNQDV2 FqWdaiCIhDWx4TfG4BfSBCMzCas4camStzXtVPjbpI+j/pXE21XsEvN6liPOgU0+xQD4 foVma7uF7N1czLPnxyVtUo4pU1x0Jhli2XbYdLX1Rtjse34feJbXwL23xr5lOnudNt9h LLIsk5RsaC7K6XGHUiR8HAY0YKFHPtY6TUh7xv3SlRDKMBKO+LFtCQ2gGhUtBYJKwM8l xzUw== X-Gm-Message-State: AOJu0YwfAA6CHpa/dDgWzGGfRyk2C/62rUE/iuoAaGm+1qRwIqTevBYL VGT9kNzvGCpjdpn6FBHvxSFKL8vcLZKPmuakA6qlM1ElPjuniWFu9AGIgzd4+MPL6c/K0Pb81Eq 6 X-Google-Smtp-Source: AGHT+IEpcEqQDW+bs96iXMea6FXPIQJxU+sMVnJveA9vSV+igd1zzb17GQIiKtbznJ5/DbwHk3BbJQ== X-Received: by 2002:a17:907:940e:b0:a99:4152:1cb4 with SMTP id a640c23a62f3a-a99b9585801mr1221023466b.42.1728980725546; Tue, 15 Oct 2024 01:25:25 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , "Daniel P. Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v10 1/2] x86/boot: Align mbi2.c stack to 16 bytes Date: Tue, 15 Oct 2024 09:25:12 +0100 Message-Id: <20241015082513.2477806-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241015082513.2477806-1-frediano.ziglio@cloud.com> References: <20241015082513.2477806-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1728980773871116600 Content-Type: text/plain; charset="utf-8" Doing previous testing with an Alder Lake Intel machine with the "x86/boot: Improve MBI2 structure check" commit test started to fail. Removing the commit makes the tests succeed however there was not apparent reason (looking at the code) for the failure. So I instrumented code to output the structure and tested code with this extracted data with and without the mentioned commit and results were the same. Compiled assembly code from lab was also fine beside not keeping the 16-byte alignment for the stack. Turning on stack alignment solve the problem on Alder Lake machine. Fixes: eb21ce14d709 ('x86/boot: Rewrite EFI/MBI2 code partly in C') Signed-off-by: Frediano Ziglio Reviewed-by: Jan Beulich Acked-by: Marek Marczykowski-G=C3=B3recki --- Changes since v8: - added "Fixes:" line; - typo in commit message: Adler -> Alder; - add ".init" to mbi2.o; - reduce difference. Changes since v9: - minor commit message fix; - added Reviewed-by. --- xen/arch/x86/efi/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile index 7e2b5c07de..c6678652fc 100644 --- a/xen/arch/x86/efi/Makefile +++ b/xen/arch/x86/efi/Makefile @@ -9,11 +9,11 @@ $(obj)/%.o: $(src)/%.ihex FORCE $(obj)/boot.init.o: $(obj)/buildid.o =20 $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary= =3D4) -$(addprefix $(obj)/,$(EFIOBJ-y)): CFLAGS_stack_boundary :=3D $(cflags-stac= k-boundary) +$(addprefix $(obj)/,$(EFIOBJ-y) mbi2.init.o): CFLAGS_stack_boundary :=3D $= (cflags-stack-boundary) =20 obj-y :=3D common-stub.o stub.o obj-$(XEN_BUILD_EFI) :=3D $(filter-out %.init.o,$(EFIOBJ-y)) obj-bin-$(XEN_BUILD_EFI) :=3D $(filter %.init.o,$(EFIOBJ-y)) -obj-bin-y +=3D mbi2.o +obj-bin-y +=3D mbi2.init.o extra-$(XEN_BUILD_EFI) +=3D buildid.o relocs-dummy.o nocov-$(XEN_BUILD_EFI) +=3D stub.o --=20 2.34.1 From nobody Sun Nov 24 03:05:07 2024 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1728980760; cv=none; d=zohomail.com; s=zohoarc; b=f8DWXI/vvp3jakxKOeEYyzqRe5XORvDocoD//8QtVCJ+69VsbTF/ClfmcXe7kJbd+jCwEOIhIY4OAdiJKDVC7cAF9avENGj4RSsohL7Pcnf0Coft9ZplXi0YCFtxJuUfk55Ajk5iok4l3WMZUSdQAbhNrcEkdfd2XP3ktLSNSe4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728980760; h=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=bVfzz9tu1frx+8mGc1UmEwEmJdo4wen9lvWfIRZy8KE=; b=QVvULl7E6STykw2Oiufga4gCc+kApPtVgUA0vWbr2Y+6hntNe5L553zs+D9IadgTPpPvF2HrJfkyLIX3oUPX7mpLoT2PweEPkJSjhgo4tpunGjlgf7gK2Ychr/VihytHDujJpmg06u9nNXFMEzVGqmGCH94VhMJR19c6WYhikx4= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1728980760890140.16213195712487; Tue, 15 Oct 2024 01:26:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.819029.1232323 (Exim 4.92) (envelope-from ) id 1t0cry-0003f3-Hw; Tue, 15 Oct 2024 08:25:30 +0000 Received: by outflank-mailman (output) from mailman id 819029.1232323; Tue, 15 Oct 2024 08:25:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t0cry-0003ew-Cb; Tue, 15 Oct 2024 08:25:30 +0000 Received: by outflank-mailman (input) for mailman id 819029; Tue, 15 Oct 2024 08:25:29 +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 1t0crx-0003em-65 for xen-devel@lists.xenproject.org; Tue, 15 Oct 2024 08:25:29 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 080b3b3c-8acf-11ef-a0be-8be0dac302b0; Tue, 15 Oct 2024 10:25:27 +0200 (CEST) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5c97cc83832so2270007a12.0 for ; Tue, 15 Oct 2024 01:25:27 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29749663sm41590566b.64.2024.10.15.01.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 01:25:25 -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: 080b3b3c-8acf-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728980726; x=1729585526; 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=bVfzz9tu1frx+8mGc1UmEwEmJdo4wen9lvWfIRZy8KE=; b=XztDqHtfMwHXOFbtWmQC0gVdte+4EmONZqY0I0yfX2TnpT1g1tR0QEKNHZTWZw4Wqs VIvBqVe7J60ZKfTxnxGLOpfIOP/ojqPbxdryLPfO2LOJV84nerfni1FVuaeTH0obzag+ EMqKBAl/x2G6AATDTEfGmc1iXvURVc12gFF8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728980726; x=1729585526; 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=bVfzz9tu1frx+8mGc1UmEwEmJdo4wen9lvWfIRZy8KE=; b=nX/vnWtotpVVisxtBxVENAjN+RiMuQqMm+cSjMGG3guaXwXXFnKpvGY9Ggs6VOYPTa /khcHKxjfz9h+SVYMLEXRf7yzteUnBKi4C3DC1vfGWTd8NFxy57LHJxmO4T6D7wJJXQL S0Z3zL6HJ6Xz+X3t4tzVp/XzUlaiJhDypvD1j/Z5V6yuaUQH+8VkNuSoiPFxKlytD3W8 Goqn5UgFzkDWFESPy6arLwFJrp9jw5XX6i4aTyHHG0qxxBT77A2Q/pdGaFcjt7xDxxPY aoqmpA5htjJDYQqXwI51VsK4X0maWdeWIvJtoCaf+fnqwRAHBV3oHJHwuhVVzGgbkEqc zmPA== X-Gm-Message-State: AOJu0YzCOPb/1vvirc5ojL0VX7A+KGXPQEmI7M3WBa82SmVCpNBDmJKU pk9x+bxFOlvToUt2nkfkw+0ExMK2mpUKsjMdMNi7L+pkUK4v9wpXnVzXRKSvjr6gk33/BvmzWtK R X-Google-Smtp-Source: AGHT+IGKa81QccbMlNajkjv7kazsBkfOAArMnAM0d0M/FBsLRI3BmxYrhvk67/BP07W5olX5S0nv1g== X-Received: by 2002:a17:907:2ce6:b0:a99:ff70:3abd with SMTP id a640c23a62f3a-a99ff703c38mr594417966b.31.1728980726242; Tue, 15 Oct 2024 01:25:26 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , "Daniel P. Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v10 2/2] x86/boot: Improve MBI2 structure check Date: Tue, 15 Oct 2024 09:25:13 +0100 Message-Id: <20241015082513.2477806-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241015082513.2477806-1-frediano.ziglio@cloud.com> References: <20241015082513.2477806-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1728980761999116600 Content-Type: text/plain; charset="utf-8" Tag structure should contain at least the tag header. Entire tag structure must be contained inside MBI2 data. Signed-off-by: Frediano Ziglio Reviewed-by: Jan Beulich Acked-by: Marek Marczykowski-G=C3=B3recki --- Changes since v6: - compare against total_size every time to avoid overflows. Changes since v7: - check for tag type being MULTIBOOT2_TAG_TYPE_END before checking tag size. This allows caller to not fill full tag (type field is before size field). Changes since v9: - fixed tag order. --- xen/arch/x86/efi/mbi2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/efi/mbi2.c b/xen/arch/x86/efi/mbi2.c index 55a1777483..d2f0f0ee61 100644 --- a/xen/arch/x86/efi/mbi2.c +++ b/xen/arch/x86/efi/mbi2.c @@ -13,6 +13,7 @@ efi_multiboot2_prelude(uint32_t magic, const multiboot2_f= ixed_t *mbi) EFI_HANDLE ImageHandle =3D NULL; EFI_SYSTEM_TABLE *SystemTable =3D NULL; const char *cmdline =3D NULL; + const void *const mbi_raw =3D (const void *)mbi; bool have_bs =3D false; =20 if ( magic !=3D MULTIBOOT2_BOOTLOADER_MAGIC ) @@ -21,8 +22,10 @@ efi_multiboot2_prelude(uint32_t magic, const multiboot2_= fixed_t *mbi) /* Skip Multiboot2 information fixed part. */ tag =3D _p(ROUNDUP((unsigned long)(mbi + 1), MULTIBOOT2_TAG_ALIGN)); =20 - for ( ; (const void *)tag - (const void *)mbi < mbi->total_size && - tag->type !=3D MULTIBOOT2_TAG_TYPE_END; + for ( ; (const void *)(tag + 1) - mbi_raw <=3D mbi->total_size && + tag->type !=3D MULTIBOOT2_TAG_TYPE_END && + tag->size >=3D sizeof(*tag) && + (const void *)tag + tag->size - mbi_raw <=3D mbi->total_size; tag =3D _p(ROUNDUP((unsigned long)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) ) { --=20 2.34.1