From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by mx.groups.io with SMTP id smtpd.web09.4467.1623289395591395149 for ; Wed, 09 Jun 2021 18:43:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nCTKX8Ej; spf=pass (domain: gmail.com, ip: 209.85.216.41, mailfrom: kuqin12@gmail.com) Received: by mail-pj1-f41.google.com with SMTP id h16so2684755pjv.2 for ; Wed, 09 Jun 2021 18:43:15 -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=JbQvHni/vN8DMuOB5ZafXK+/RdY7yAIM8pRzHs+cBtc=; b=nCTKX8Ej2GW6j/RI97YnCQoCk+PN5xZUGxao3Czfb+x8E9c3xa6BKUB5c/YnBFH0qe Xp7Gv/r/+XwfHCMEdiLeY4FQge8zuCvEAqPUYyHWVwME/gIFSgCnvknPFBibrMOaNZ3r qBBjjLtUDvCPP8JWMRwo/ny1UkmZ78Dx3AJf8WAqGDTA4UJzwA545hbFwsw+r25yNBMB mllWmrYRovUUI06JYCzs4T7a/b0PFgRhCGIE2ZjsOaIyB3ux+xr22e4tlJlqXs6EE9ec 4UFNvIn5vnoUdMnzLBb42snEjGn3uoPvXTr/yNDcdcXn7sAVEgmmgfrmdQNymblEvyF7 ZRBw== 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=JbQvHni/vN8DMuOB5ZafXK+/RdY7yAIM8pRzHs+cBtc=; b=sdKEUsdK4m6suxBzcDj2nd2ZmbAE8XYm/IW759QF2yC3jgthZG4co5znVfSUuOEB6j zSnJzfMwk5rJFIaO/NxtAfG0pmmmMBUC3fk4lWcmCWvlyiR2iVyQgpSe6CwSFYwIZmtC 8TWJWhjheDW3rhAoZs+kY89v/RQWNa/CgqODVlRe6ZQdKlixY3Qm6d3vERwPfYZ7yU2i 4DPI8xMU/PnSXQZ1UIAcOidnqZ7txX7J+ODFkX6lnfFbMWeODnjbVDzVL0VVuxKh1mng 5r8HL4A3O5FToqz0U4WfyiVvOy09BhI+bOPpPb3hzwNFaGKDYv3RLclJdeRZql4D/44w 0pUw== X-Gm-Message-State: AOAM530JcST4kRi+bAheUM05iZqiVZLFVsPkuji4XQUnL56vdoVbSfHq cuZf7ip0LItMPt+TyLweTsCp+aplxawU7w== X-Google-Smtp-Source: ABdhPJyKMccADQtUtj7DGPgmelQbtwO/R5mmzZJiRrmytrj8lEs2E4aMn+9kRXAKDwrA1UTVQHZBxA== X-Received: by 2002:a17:90a:17c6:: with SMTP id q64mr54730pja.56.1623289394919; Wed, 09 Jun 2021 18:43:14 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([50.35.88.161]) by smtp.gmail.com with ESMTPSA id p20sm624990pff.204.2021.06.09.18.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 18:43:14 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Eric Dong , Ray Ni Subject: [PATCH v1 4/5] MdeModulePkg: SmiHandlerProfileInfo: Updated MessageLength calculation Date: Wed, 9 Jun 2021 18:42:58 -0700 Message-Id: <20210610014259.1151-5-kuqin12@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20210610014259.1151-1-kuqin12@gmail.com> References: <20210610014259.1151-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3398 This change replaced the calculation of communication buffer size from explicitly adding the size of each member with the OFFSET macro function. This will make the structure field defition change transparent to consumers. Cc: Jian J Wang Cc: Hao A Wu Cc: Eric Dong Cc: Ray Ni Signed-off-by: Kun Qin --- MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c index 4153074b7a80..56d80d1a9ce1 100644 --- a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c +++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c @@ -116,7 +116,9 @@ GetSmiHandlerProfileDatabase( CommGetInfo->Header.ReturnStatus = (UINT64)-1; CommGetInfo->DataSize = 0; - CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLength; + // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64. + // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here. + CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength; Status = SmmCommunication->Communicate(SmmCommunication, CommBuffer, &CommSize); if (EFI_ERROR(Status)) { Print(L"SmiHandlerProfile: SmmCommunication - %r\n", Status); @@ -149,7 +151,9 @@ GetSmiHandlerProfileDatabase( CommGetData->Header.DataLength = sizeof(*CommGetData); CommGetData->Header.ReturnStatus = (UINT64)-1; - CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLength; + // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64. + // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here. + CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength; Buffer = (UINT8 *)CommHeader + CommSize; Size -= CommSize; -- 2.31.1.windows.1