From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by mx.groups.io with SMTP id smtpd.web12.4492.1623289394442307426 for ; Wed, 09 Jun 2021 18:43:14 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PbN4zph2; spf=pass (domain: gmail.com, ip: 209.85.215.182, mailfrom: kuqin12@gmail.com) Received: by mail-pg1-f182.google.com with SMTP id e22so21226485pgv.10 for ; Wed, 09 Jun 2021 18:43:14 -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=4jiW2aj46ir0t6S0h2reZRQSgfnvLYqQ6xN60UnqmHs=; b=PbN4zph21wQLnTUykmSW73GvFM5M/T6E8VaHBjW9e6axX/iboj/nig301+Mai5ztSf ATxPDv+J0YjyM7voqVZXe6mSkJX1yYaXOuAbTqIiw/q4AfTk65U+zz7oO06SncmMywgV E0699G8wupy35KRXiNaBNAUftqqUmXM79Ia0IuWqQT/wu0cgb9x7BLr3AbO3EOgE/ywJ LoEDn6GoTxJrIVS4Y5Lgr9H9gWV9So9cGUgeIseoWTtAEoPkfmgSPPaQL80X82Pn9etk tLqe0NurPmyEhPX2dbOk6wBrP05S8eOV16Y8wjx5WKU+4C8Ofx/Uj7F667i4TBDG0BXx +p2A== 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=4jiW2aj46ir0t6S0h2reZRQSgfnvLYqQ6xN60UnqmHs=; b=LLwfa7YaDU9ciLGY6iJxJW2sPsXVrc/FtryInRnsCPZSlysmylVB/RBfg8gDeV8H4K DXIYQs9no/b1nsrTD+BnL9Tw1e+QTJvxsSQf42wav4U3F0+nMSPUUgSFaopMw9l9MmG+ cyaIJXSUegiVjv2bXlAl37rclAwT6j32g19gN+jRvmzqVRrSlhn8n7ygoUKnXV4Q35V2 VXXakGmk0AQ6rYa57Uwf2H7tGwC30Oq/Qebo6cSfdDshGgvwqyVYbWVg5xubfjO3rkPz u8cYei8+JUnbBtmd11V6k36EmXCznrykHAPbMeowyNIDiAHOuXeJgAIffuHea4J2cKUh u69g== X-Gm-Message-State: AOAM531tvKWZX1wqTJ/uDVRg4FxiiLfHnt00I8EkNUtzK+G++vIIhQcw iQKagmF5osPUq4SPhQc1HxWGtAPy+zWiug== X-Google-Smtp-Source: ABdhPJyE1E7gAwOj7PtpeACogQicvJYOj9RHR4Hlaa9d+lK4d4Tk4/Nnnw5ccgdIiTh4TJFP7ceffA== X-Received: by 2002:a63:9f19:: with SMTP id g25mr2503199pge.265.1623289393813; Wed, 09 Jun 2021 18:43:13 -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:13 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu Subject: [PATCH v1 3/5] MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation Date: Wed, 9 Jun 2021 18:42:57 -0700 Message-Id: <20210610014259.1151-4-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 Signed-off-by: Kun Qin --- MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c index 191c31068545..39ed8b2e0484 100644 --- a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c +++ b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c @@ -1190,7 +1190,9 @@ GetSmramProfileData ( CommRecordingState->Header.ReturnStatus = (UINT64)-1; CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_DISABLE; - 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)) { DEBUG ((EFI_D_ERROR, "SmramProfile: SmmCommunication - %r\n", Status)); @@ -1213,7 +1215,9 @@ GetSmramProfileData ( CommRecordingState->Header.ReturnStatus = (UINT64)-1; CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_DISABLE; - 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; SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize); } @@ -1230,7 +1234,9 @@ GetSmramProfileData ( CommGetProfileInfo->Header.ReturnStatus = (UINT64)-1; CommGetProfileInfo->ProfileSize = 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); ASSERT_EFI_ERROR (Status); @@ -1261,7 +1267,9 @@ GetSmramProfileData ( CommGetProfileData->Header.DataLength = sizeof (*CommGetProfileData); CommGetProfileData->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; @@ -1320,7 +1328,9 @@ GetSmramProfileData ( CommRecordingState->Header.ReturnStatus = (UINT64)-1; CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_ENABLE; - 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; SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize); } -- 2.31.1.windows.1