From patchwork Thu Oct 10 09:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 13829870 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 217BBCEE323 for ; Thu, 10 Oct 2024 09:45:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.815894.1230124 (Exim 4.92) (envelope-from ) id 1sypjo-0003vW-FR; Thu, 10 Oct 2024 09:45:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 815894.1230124; Thu, 10 Oct 2024 09:45:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sypjo-0003vC-9c; Thu, 10 Oct 2024 09:45:40 +0000 Received: by outflank-mailman (input) for mailman id 815894; Thu, 10 Oct 2024 09:45:38 +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 1sypjm-0003ri-3K for xen-devel@lists.xenproject.org; Thu, 10 Oct 2024 09:45:38 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 66f1eef3-86ec-11ef-a0bd-8be0dac302b0; Thu, 10 Oct 2024 11:45:37 +0200 (CEST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a9968114422so104121466b.2 for ; Thu, 10 Oct 2024 02:45:37 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80dcf0dsm64513266b.175.2024.10.10.02.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 02:45:35 -0700 (PDT) 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: 66f1eef3-86ec-11ef-a0bd-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728553536; x=1729158336; 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=Mfnt+tah//kuTb3yKzY3k7uoRLjpA5A8TSsiJRJV2Sc=; b=RT4XerQIJAVMkjs7HAG4/WyimijOpH2ctxLEbvt3WZ+vZTidXgZS57HNVkhaKZodQs Y2oYgpxQCAyDK+qFvNhzEeoA46P6EMSvHbAdi2kbquCg4GpDWjdwDlTNjaGZhmAKPoEv 29kQjjt6VX9opR4IZNReoMF6lvCmzoeXtr5RU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728553536; x=1729158336; 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=Mfnt+tah//kuTb3yKzY3k7uoRLjpA5A8TSsiJRJV2Sc=; b=LwL3QscuAUOeVy8L7XK17VU9HE9a6ClAwbjXPQsYxRiB+MSK/r4vocfcUPZckGxirq w8SawpaNk65pFgnaZQ8HONoI/WSED9gobirZqUFlEfwJn9cYjai7SaExJKndlKTZfPtB 8QzRSUP09p+G+pwiKOiXs9v+snO3LD5dYblsV6zLifT5M4Ft4tkNUSks9UAmGCqUjn4U xe0zbnPlQw5sMhE7YrH8ZMAj/LwHhVlHV8rR+PjuidfWHKd2Epgw1AsmoE5KLlhcd3rF +21UTTLstIGIugfE9DUNO+Yj1h2y01+jzJtphCl/ei32Sf4LHkINuoWODgCxsCEUYN66 NGqQ== X-Gm-Message-State: AOJu0YxHiszVyGNerTQ33sVxYtp6s2fson9H/y0ng8RdrqdHBzRMoRjf j2NIXucLdM7xnWBpAwg460z8tNPT3U5tsBya0bzVUygV/mDIJtSQWQWy6ZZ9NNw3ZAW1J/7TRDE E X-Google-Smtp-Source: AGHT+IGy49NxfDxb82h0D1MCQV9JIdMmL+xQMfI3Kv1RHdhLC05xp1XHIhzXvR1QzDHxEFW5dLSjUw== X-Received: by 2002:a17:907:3d8f:b0:a99:87ea:e773 with SMTP id a640c23a62f3a-a999e69cacamr270938266b.22.1728553536132; Thu, 10 Oct 2024 02:45:36 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , "Daniel P. Smith" , =?utf-8?q?Marek_Marczykow?= =?utf-8?q?ski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v9 1/2] x86/boot: Align mbi2.c stack to 16 bytes Date: Thu, 10 Oct 2024 10:45:23 +0100 Message-Id: <20241010094524.1836495-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241010094524.1836495-1-frediano.ziglio@cloud.com> References: <20241010094524.1836495-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Doing previous testing with an Alder Lake Intel machine the with "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 --- Changes since v8: - added "Fixes:" line; - typo in commit message: Adler -> Alder; - add ".init" to mbi2.o; - reduce difference. --- 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 $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4) -$(addprefix $(obj)/,$(EFIOBJ-y)): CFLAGS_stack_boundary := $(cflags-stack-boundary) +$(addprefix $(obj)/,$(EFIOBJ-y) mbi2.init.o): CFLAGS_stack_boundary := $(cflags-stack-boundary) obj-y := common-stub.o stub.o obj-$(XEN_BUILD_EFI) := $(filter-out %.init.o,$(EFIOBJ-y)) obj-bin-$(XEN_BUILD_EFI) := $(filter %.init.o,$(EFIOBJ-y)) -obj-bin-y += mbi2.o +obj-bin-y += mbi2.init.o extra-$(XEN_BUILD_EFI) += buildid.o relocs-dummy.o nocov-$(XEN_BUILD_EFI) += stub.o From patchwork Thu Oct 10 09:45:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 13829869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99073CF045C for ; Thu, 10 Oct 2024 09:45:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.815895.1230127 (Exim 4.92) (envelope-from ) id 1sypjo-0003yT-Jv; Thu, 10 Oct 2024 09:45:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 815895.1230127; Thu, 10 Oct 2024 09:45:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sypjo-0003xO-Ft; Thu, 10 Oct 2024 09:45:40 +0000 Received: by outflank-mailman (input) for mailman id 815895; Thu, 10 Oct 2024 09:45:39 +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 1sypjn-0003rE-Dn for xen-devel@lists.xenproject.org; Thu, 10 Oct 2024 09:45:39 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6778b3db-86ec-11ef-99a2-01e77a169b0f; Thu, 10 Oct 2024 11:45:37 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a9944c4d5d4so106023666b.0 for ; Thu, 10 Oct 2024 02:45:37 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80dcf0dsm64513266b.175.2024.10.10.02.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 02:45:36 -0700 (PDT) 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: 6778b3db-86ec-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1728553537; x=1729158337; 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=uxiY7HJDcWw9szQujq2OSXUnYmKhKkJqdPaufkFtzms=; b=ijQg7ejLS4JccZ1C2jD8tfppdA4GxIJhS6mjPanmV/ymU36J/9x/I1Y1tttHd67+93 VSFxdIkM2Jl1gg9kyQkWNwotIoS/GF1K5JQKIy1wmRWb/NVcalSiKzrbh1UXmj/dUamY rAzv2swDlqseT5SNsVrZ3s7blf3ha3fAmrilg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728553537; x=1729158337; 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=uxiY7HJDcWw9szQujq2OSXUnYmKhKkJqdPaufkFtzms=; b=O9jujpnWO4p3L+iJ+oBhdHwxkqLqF/3u0AzrCbgy6Zviqso4+aSpjrfR00PYTOM6SZ xAPwZHsemwZyaW5bNy6pSXSlzcbQhAkLbqCpibYECcwczco3IUpSsP0X8DF7qG2BlqEP N9Q7UcSQo6Wrh8xO7fYEZ9x0ajB0kTcHnUEq6A6MH461q1z8n53YkDVmkVvFEpU35EyG zPQTdeeDV7DzdFn/AJhV3OPbD9BgoZz1vpD9MKf4rWfsqeK4/a9v/MkjkTJsqka61uaB YnY+xUk+CjgQqIcXTtY7eKrvp8CpERdTgJeejVkXyFqko3b4oQIF8wGvzkWjB6e7vQAV BOpQ== X-Gm-Message-State: AOJu0YxLr0EcYY8QQ8BuUZ5asXJd27cC8CO2kWscdGOjXYehNKdnewmJ kYBZBNBYVKhfP3WPXiln6LADxfUs9laqWpOjoEV64iF7IYV4xGuUeyYNot8q2LD7WHLyw6FDo4/ r X-Google-Smtp-Source: AGHT+IErFf/rLgsssczD7bQqSqOxaRQcIiytGlo5I/JIoadnlGjMAZ/eUpI49JDiuoN7o5m25YKDPg== X-Received: by 2002:a17:907:7e97:b0:a99:408c:6a16 with SMTP id a640c23a62f3a-a998d10ba72mr474573866b.12.1728553537075; Thu, 10 Oct 2024 02:45:37 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , "Daniel P. Smith" , =?utf-8?q?Marek_Marczykow?= =?utf-8?q?ski-G=C3=B3recki?= , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v9 2/2] x86/boot: Improve MBI2 structure check Date: Thu, 10 Oct 2024 10:45:24 +0100 Message-Id: <20241010094524.1836495-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241010094524.1836495-1-frediano.ziglio@cloud.com> References: <20241010094524.1836495-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Tag structure should contain at least the tag header. Entire tag structure must be contained inside MBI2 data. Reviewed-by: Jan Beulich Signed-off-by: Frediano Ziglio --- 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). --- 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_fixed_t *mbi) EFI_HANDLE ImageHandle = NULL; EFI_SYSTEM_TABLE *SystemTable = NULL; const char *cmdline = NULL; + const void *const mbi_raw = (const void *)mbi; bool have_bs = false; if ( magic != MULTIBOOT2_BOOTLOADER_MAGIC ) @@ -21,8 +22,10 @@ efi_multiboot2_prelude(uint32_t magic, const multiboot2_fixed_t *mbi) /* Skip Multiboot2 information fixed part. */ tag = _p(ROUNDUP((unsigned long)(mbi + 1), MULTIBOOT2_TAG_ALIGN)); - for ( ; (const void *)tag - (const void *)mbi < mbi->total_size && - tag->type != MULTIBOOT2_TAG_TYPE_END; + for ( ; (const void *)(tag + 1) - mbi_raw <= mbi->total_size && + tag->type != MULTIBOOT2_TAG_TYPE_END && + tag->size >= sizeof(*tag) && + (const void *)tag + tag->size - mbi_raw <= mbi->total_size; tag = _p(ROUNDUP((unsigned long)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) ) {