From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mx.groups.io with SMTP id smtpd.web09.5406.1624006977811444495 for ; Fri, 18 Jun 2021 02:02:57 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Vgis0/C5; spf=pass (domain: gmail.com, ip: 209.85.216.51, mailfrom: kuqin12@gmail.com) Received: by mail-pj1-f51.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso5476174pjb.4 for ; Fri, 18 Jun 2021 02:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0bm2QqCp+fxhDsFk2vYSe6ZhwZzme1vK9INWnNczx7I=; b=Vgis0/C59cNsJ0IY0JcrP0S7MTTtSEXukFnijselOkBg8tXDQY9tZUTI8cnREP5Ta5 GqJB/vJ1HejaWOmH8GxDeKVITPlDyBz4SbIlgP+v/KpYQWNTUSmXwtCHsZtN3u0DCjSI mQ8us/W/B9gUBbxnNME3iro9wZ/rHgG3vmWhyjbp8kwi3sHgT2VA+BZmCg9V6yjUUEyZ /t9Hoaj1uEG0KA6HO5y3CG9AubBvYPDj86GIRzfWjGflGAooy2YnWKBb17alUEsiRJlb pSnrt2J+GJVdyRQXi040NgFiagN+3eft9GR6IjUu++gY8vWMEGIYi7MYZ3FhxqW0AnRq vaNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0bm2QqCp+fxhDsFk2vYSe6ZhwZzme1vK9INWnNczx7I=; b=pGSAHWjy/Kbb5Y344rO+Z7vzTNQxN8XyMIgxe7e1eh6L2Kpc/0cTetTfKNEDYniMl2 UdAphcsEvtKStH/vEHUGcpxwaJyjgoQpwVwWP/3+Kcsm/FOzfOp3y/75En28r+cf32DZ baeBFKRgpztnpgdxv40hNvCZ7HBB46UV07TJ+ReMtkp+pgx62rEAl2vbXeiFCOcF4oO9 RRFBb4O2vLTbSBV1NJ2bxvR8ehkMWzOmoh9VaMRf2nI85LNB3Vzspb4bcUNKR2iOF+dn Xrn+8ZGrA0EmpWiAm5JpgVk2x0VFsCSFNLLCaleFuyMuZ8L3N2rAsyfEAp6D+Au2RVOx DhZg== X-Gm-Message-State: AOAM5311yolNTDlPFZRUaH3kHGcvDeCfgz++PUctm8n/UZ6RGLSo9GKD 0A2Z7aipnFQW7PYH9o3ejIjXGo7PZuvWBw== X-Google-Smtp-Source: ABdhPJzA5rui73V8FZnAyT+Q4VFcnbPWs9sfKiPuXCTOktFliaoHozQHaxcvtLlysznGjLUTceRa6w== X-Received: by 2002:a17:902:b203:b029:11b:1549:da0d with SMTP id t3-20020a170902b203b029011b1549da0dmr3776024plr.48.1624006977200; Fri, 18 Jun 2021 02:02:57 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([50.35.88.161]) by smtp.gmail.com with ESMTPSA id b1sm7702512pgb.91.2021.06.18.02.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 02:02:56 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Eric Dong , Ray Ni Subject: [PATCH v2 2/6] MdeModulePkg: PiSmmIpl: Update MessageLength calculation for MmCommunicate Date: Fri, 18 Jun 2021 02:02:39 -0700 Message-Id: <20210618090243.2517-3-kuqin12@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20210618090243.2517-1-kuqin12@gmail.com> References: <20210618090243.2517-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3398 This change updated calculation routine for MM communication in PiSmmIpl. It removes ambiguity brought in by UINTN variables from this routine and paves way for updating definition of field MessageLength in EFI_MM_COMMUNICATE_HEADER to definitive size. Cc: Jian J Wang Cc: Hao A Wu Cc: Eric Dong Cc: Ray Ni Signed-off-by: Kun Qin Reviewed-by: Hao A Wu --- Notes: v2: - Removed "BZ" tags from comments and variables [Hao] - Added "Reviewed-by" tag [Hao] MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c | 11 ++++++++++- MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c index 599a0cd01d80..01cde6cfc3e4 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "PiSmmCorePrivateData.h" @@ -515,6 +516,7 @@ SmmCommunicationCommunicate ( EFI_STATUS Status; EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader; BOOLEAN OldInSmm; + UINT64 LongCommSize; UINTN TempCommSize; // @@ -527,7 +529,14 @@ SmmCommunicationCommunicate ( CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer; if (CommSize == NULL) { - TempCommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + CommunicateHeader->MessageLength; + Status = SafeUint64Add (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data), CommunicateHeader->MessageLength, &LongCommSize); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + Status = SafeUint64ToUintn (LongCommSize, &TempCommSize); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } } else { TempCommSize = *CommSize; // diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf index 6109d6b5449c..ddeb39cee266 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf @@ -46,6 +46,7 @@ [LibraryClasses] DxeServicesLib PcdLib ReportStatusCodeLib + SafeIntLib [Protocols] gEfiSmmBase2ProtocolGuid ## PRODUCES -- 2.31.1.windows.1