From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mx.groups.io with SMTP id smtpd.web12.1944.1643139558840333274 for ; Tue, 25 Jan 2022 11:39:18 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dgZ6aDAt; spf=pass (domain: gmail.com, ip: 209.85.215.180, mailfrom: kuqin12@gmail.com) Received: by mail-pg1-f180.google.com with SMTP id v3so13831585pgc.1 for ; Tue, 25 Jan 2022 11:39:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RTXnBWAXlSiDzfEsGpeJD3+o6d77S/ohzXPcMJjvWY8=; b=dgZ6aDAtr/ii/j7/GBNNrfLErxF1sFuJqpZWtjJAxZwNkSwFkDnakThHROCYEemywG oGKmZ0GaJa9vc05380U1ToLKxV+iwNK/L/CpumA2RBHHyaOhccpDeUmPBJPkCEMDDYkp igPjvJnrEQQ6ee9B3f/AxAaQbQWx9ner/8k14JyDBZhkgahdW9GJ7YP45DpAYhliUacL ES668Uu1rb4FgOOYcK4wYHFEiziMSnUlfkNLVHpWbuom0Lxc/TwWSS9orp4mXYEdfH1j 6Dd9V5q1bEAVY67QIYviL0IR0j/LlV+1iD6fLCyz2FOW8jqHTAzcnXaESvilaLkdbKar ZVDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RTXnBWAXlSiDzfEsGpeJD3+o6d77S/ohzXPcMJjvWY8=; b=4jSx+ldH7YnJ1xUHq3OsJA7CSy4LyOiIGMSPk5S/Z0ddOxEUQ3CQg57qH5KqVwjxyK WZTMc3iE9vkI6XTdxfahGZcH+DlGOijffqCtSL7eNxy/s83bytTGXkALKPYjmab9MDe4 hXDQIKPm5EIBP+l8mujBIjigTfd+dH0QCiMv4m6fsRLgIzPhbAIhXuXdYNOsP/ZQnzAQ n0APWFFcuVYoZJ8lyQhQmVjwlZtSfva9Hxr6tT2Shxjp1+GE/hAnxghPt/le+rOfLojV 1REvzCHVC/9Smkg1iuRhLRE2yUJnocAA+kdWMu4wZ0106nx2HSMMJaAAKSj2elcoZEy9 BLcw== X-Gm-Message-State: AOAM5328RuVuvXAcOCCKXVAsKN49fNgoILMj0Vp2z0wn3E1nqRNwQOeh GrpZt/tPKILB8DlBQCcFnYyb0nTUkso= X-Google-Smtp-Source: ABdhPJwAA/0PJdc+VvqM9RL1Pys7alRUwHFSGUq2UBxEI+8OmglQOvlvjLkhqRm7fDCJQhjng7Os/g== X-Received: by 2002:a62:33c7:0:b0:4bd:5aa4:1220 with SMTP id z190-20020a6233c7000000b004bd5aa41220mr19561934pfz.55.1643139558292; Tue, 25 Jan 2022 11:39:18 -0800 (PST) Return-Path: Received: from gem-name-lb-02.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id v8sm1036929pju.51.2022.01.25.11.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 11:39:18 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Bret Barkelew , Michael Kubacki , Sami Mujawar Subject: [PATCH v3 5/6] ArmPkg: MmCommunicationDxe: Update MM communicate `CommSize` check Date: Tue, 25 Jan 2022 11:39:08 -0800 Message-Id: <20220125193909.491-6-kuqin12@gmail.com> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220125193909.491-1-kuqin12@gmail.com> References: <20220125193909.491-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3751 Current MM communicate routine from ArmPkg would conduct few checks prior to proceeding with SMC calls. However, the inspection step is different from PI specification. This patch updated MM communicate input argument inspection routine to assure `CommSize` represents "the size of the data buffer being passed in" instead of the size of the data being used from data buffer, as described by section `EFI_MM_COMMUNICATION2_PROTOCOL.Communicate()` in PI specification. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Bret Barkelew Cc: Michael Kubacki Cc: Sami Mujawar Signed-off-by: Kun Qin Reviewed-by: Sami Mujawar --- Notes: v2: - Splitting patch into 3 of 4 [Ard] v3: - Added cc entry and reviewed-by tag [Sami] ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c index 0283be430dff..2f89b7c5b6c4 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -44,13 +44,18 @@ STATIC EFI_HANDLE mMmCommunicateHandle; @param[in] This The EFI_MM_COMMUNICATION_PROTOCOL instance. @param[in, out] CommBufferPhysical Physical address of the MM communication buffer @param[in, out] CommBufferVirtual Virtual address of the MM communication buffer - @param[in, out] CommSize The size of the data buffer being passed in. On exit, the - size of data being returned. Zero if the handler does not + @param[in, out] CommSize The size of the data buffer being passed in. On input, + when not omitted, the buffer should cover EFI_MM_COMMUNICATE_HEADER + and the value of MessageLength field. On exit, the size + of data being returned. Zero if the handler does not wish to reply with any data. This parameter is optional and may be NULL. @retval EFI_SUCCESS The message was successfully posted. - @retval EFI_INVALID_PARAMETER CommBufferPhysical was NULL or CommBufferVirtual was NULL. + @retval EFI_INVALID_PARAMETER CommBufferPhysical or CommBufferVirtual was NULL, or + integer value pointed by CommSize does not cover + EFI_MM_COMMUNICATE_HEADER and the value of MessageLength + field. @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM implementation. If this error is returned, the MessageLength field in the CommBuffer header or the integer pointed by @@ -96,8 +101,8 @@ MmCommunication2Communicate ( sizeof (CommunicateHeader->HeaderGuid) + sizeof (CommunicateHeader->MessageLength); - // If the length of the CommBuffer is 0 then return the expected length. - if (CommSize != 0) { + // If CommSize is not omitted, perform size inspection before proceeding. + if (CommSize != NULL) { // This case can be used by the consumer of this driver to find out the // max size that can be used for allocating CommBuffer. if ((*CommSize == 0) || @@ -108,9 +113,9 @@ MmCommunication2Communicate ( } // - // CommSize must match MessageLength + sizeof (EFI_MM_COMMUNICATE_HEADER); + // CommSize should cover at least MessageLength + sizeof (EFI_MM_COMMUNICATE_HEADER); // - if (*CommSize != BufferSize) { + if (*CommSize < BufferSize) { return EFI_INVALID_PARAMETER; } } -- 2.34.1.windows.1