From nobody Mon Nov 25 05:52:46 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=1727778193; cv=none; d=zohomail.com; s=zohoarc; b=HP6mndoztWgiij6maEmgaNWvdngEjgJIlBbd7hTywWXaM4DeNJbQ7qF1XTTgRjMtMTw0J5HroXFc+2OV9yx8PVXdU6/Ik5OPolX6UIzKjd1doWzsTVc2pt/UQG1ICswGfy4b/QQVAyJB9ENmdPEVspibVZThcPuDrLiJ4S6qtdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727778193; 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=ec7IJ82TAUIZ24f2ims91e1OgLvu1KLsDjKQelIoz6M=; b=lnhVuNwlEaA7e+tc9F93LcCRO8Zhq+aeZGkC4G/A7lw9LtqTsJIbeDHH7Ii8a2yt5w7K1csnqpvJ5c7+y9GD6rcL3U8H52kLDDm/xSS8mlZjW3r8UghLQ0LnX4Y7bVpE2DScejn6OJVbiyogHUT6Bh+Uc99ClMGlQnaPXuGTM5Y= 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 1727778193601104.884260705884; Tue, 1 Oct 2024 03:23:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.807972.1219747 (Exim 4.92) (envelope-from ) id 1sva1u-0001yB-7q; Tue, 01 Oct 2024 10:22:54 +0000 Received: by outflank-mailman (output) from mailman id 807972.1219747; Tue, 01 Oct 2024 10:22:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sva1u-0001y4-5E; Tue, 01 Oct 2024 10:22:54 +0000 Received: by outflank-mailman (input) for mailman id 807972; Tue, 01 Oct 2024 10:22:52 +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 1sva1s-0001jp-Oe for xen-devel@lists.xenproject.org; Tue, 01 Oct 2024 10:22:52 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1d165702-7fdf-11ef-a0ba-8be0dac302b0; Tue, 01 Oct 2024 12:22:51 +0200 (CEST) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a910860e4dcso12575966b.3 for ; Tue, 01 Oct 2024 03:22:51 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c297bceesm681772966b.187.2024.10.01.03.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 03:22:50 -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: 1d165702-7fdf-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1727778171; x=1728382971; 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=ec7IJ82TAUIZ24f2ims91e1OgLvu1KLsDjKQelIoz6M=; b=AxfW4w+Ek5GuRpQAUFLX3Ylx2uWAv66BDdWLSHWUf5Qim9Jjivudazw/TPHTv1GDoO x3Qpn1Hu/0oJazBtRhhYzLxQS+63GyJv6tYwDXdT69FHCwkofJFPexcxYZHk6SDIoc05 /N5tSXASTkc6xQsivUGyUNWP+YSfUw0NemRao= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727778171; x=1728382971; 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=ec7IJ82TAUIZ24f2ims91e1OgLvu1KLsDjKQelIoz6M=; b=jKL6EznCconoWSnirehBToE1JEvItmJZeUcK71Z5XmIaJPXoPjc95EjjxAKrgjBEjq VdTKVg+OipCY5BwjrhoV/bOUR7cZQKzwbwXDSOhYB93zZ/DBf21PmI/xEKUYHG6CCtOT i064mYENkWNT3v5cqn26SJHyIrBbSOgcY4k/zN2Q+s6geGrZ5d6ZRmwopIPRcZE1KnOy dWDODit2Dx0enxFIXEVXiFNkJ9gTD5/gJEOSyNb4zAqgIqS4mSM+S4Z7RYVF2GaaTFzX k7zrJEcfIcv5mOUymGZNNbLCp/qxxFWSvPDgyGhSoG8RXXZNgCX678Odi8L4vu9IO6aT /8Sw== X-Gm-Message-State: AOJu0YzQa5PMq1HYmdqicFivO3KU7YIIsIXomVKCXkaWZl9AFkPVbDAC DsOyVtFBGzp9mtQwtgjl03ktVCoWBi53G7dIJukCOvbqLjyeTfZN4zcvY4pU6A6sdoNbrE4P2Pj i X-Google-Smtp-Source: AGHT+IF1U8NDFlUm54dcpcQqlhSm+jEmpqFqtZ2h9Gbsw0Pp3jHFUvwvT3lgGlczbatDf8BJACaBqw== X-Received: by 2002:a17:907:7e8e:b0:a8d:555f:eeda with SMTP id a640c23a62f3a-a93c48e7fc2mr1768741066b.8.1727778170687; Tue, 01 Oct 2024 03:22:50 -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 v7 2/2] x86/boot: Improve MBI2 structure check Date: Tue, 1 Oct 2024 11:22:39 +0100 Message-Id: <20241001102239.2609631-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001102239.2609631-1-frediano.ziglio@cloud.com> References: <20241001102239.2609631-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1727778194837116600 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 --- Changes since v6: - compare against total_size every time to avoid overflows. --- xen/arch/x86/efi/mbi2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/efi/mbi2.c b/xen/arch/x86/efi/mbi2.c index 55a1777483..935f3ae5d0 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,7 +22,9 @@ efi_multiboot2_prelude(uint32_t magic, const multiboot2_f= ixed_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 && + for ( ; (const void *)(tag + 1) - mbi_raw <=3D mbi->total_size && + tag->size >=3D sizeof(*tag) && + (const void *)tag + tag->size - mbi_raw <=3D mbi->total_size && tag->type !=3D MULTIBOOT2_TAG_TYPE_END; tag =3D _p(ROUNDUP((unsigned long)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) ) --=20 2.34.1