From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com []) by mx.groups.io with SMTP id smtpd.web10.11039.1594689784136109203 for ; Mon, 13 Jul 2020 18:23:04 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: zhichao.gao@intel.com) IronPort-SDR: uPOdKfdAWwEoEENhwnE9VHOaiO4G2dxkI1w33ll9ChNINqYXMNqfbqDN/f9A3spFmEXV+R6kUn ERTGX7zC7zGw== X-IronPort-AV: E=McAfee;i="6000,8403,9681"; a="148762704" X-IronPort-AV: E=Sophos;i="5.75,349,1589266800"; d="scan'208";a="148762704" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2020 18:23:04 -0700 IronPort-SDR: rZE69lACWwOhkbmHiMsorOpvYgDpIgpw5V1Mpgj9KZoZVKV2ATOqUrCsZoOlCCgDgRVfFRwjpF /RtzV8DxOwkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,349,1589266800"; d="scan'208";a="285590329" Received: from fieedk001.ccr.corp.intel.com ([10.239.33.114]) by orsmga006.jf.intel.com with ESMTP; 13 Jul 2020 18:23:03 -0700 From: "Gao, Zhichao" To: devel@edk2.groups.io Cc: Hao A Wu , Ray Ni Subject: [PATCH V3 1/3] MdeModulePkg/PartitionDxe: Correct the MBR last block value Date: Tue, 14 Jul 2020 09:22:57 +0800 Message-Id: <20200714012259.30504-2-zhichao.gao@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200714012259.30504-1-zhichao.gao@intel.com> References: <20200714012259.30504-1-zhichao.gao@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2823 PartitionValidMbr function's second parameter should be the last sector of the device. For MBR partition, the block size is sector size, i.e. 512 bytes. The original value is media block last LBA which is counted by the media block size. And media block size is not always 512 bytes, it may be larger which would cause the MBR boundary check incorrect. The boundary check is based on the partition entry start LBA and size of LBA which are both counted by the sector number (512 bytes). Cc: Hao A Wu Cc: Ray Ni Signed-off-by: Zhichao Gao --- MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c index dac451a144..f0c92aa09a 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c @@ -135,14 +135,17 @@ PartitionInstallMbrChildHandles ( EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode; UINT32 BlockSize; UINT32 MediaId; - EFI_LBA LastBlock; + EFI_LBA LastSector; EFI_PARTITION_INFO_PROTOCOL PartitionInfo; Found = EFI_NOT_FOUND; - BlockSize = BlockIo->Media->BlockSize; - MediaId = BlockIo->Media->MediaId; - LastBlock = BlockIo->Media->LastBlock; + BlockSize = BlockIo->Media->BlockSize; + MediaId = BlockIo->Media->MediaId; + LastSector = DivU64x32 ( + MultU64x32 (BlockIo->Media->LastBlock + 1, BlockSize), + MBR_SIZE + ) - 1; // // Ensure the block size can hold the MBR @@ -167,7 +170,7 @@ PartitionInstallMbrChildHandles ( Found = Status; goto Done; } - if (!PartitionValidMbr (Mbr, LastBlock)) { + if (!PartitionValidMbr (Mbr, LastSector)) { goto Done; } // -- 2.21.0.windows.1