From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F0D912194235A for ; Mon, 10 Apr 2017 00:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491810218; x=1523346218; h=from:to:cc:subject:date:message-id; bh=Low/cHc6LdArsfaqSxV1D5Hz4tKMD8HVCOGsPqjIb2Y=; b=YZYAvY/dUv6SQE2/NXHZlPU/1miuWvriscAP52yFRo+tZbV3PPZAMFfv fQhjtpf8Mq4Z+fTMMYLyTsdXT54opQ==; Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Apr 2017 00:43:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,181,1488873600"; d="scan'208";a="844016753" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by FMSMGA003.fm.intel.com with ESMTP; 10 Apr 2017 00:43:37 -0700 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Feng Tian Date: Mon, 10 Apr 2017 15:43:24 +0800 Message-Id: <20170410074324.16340-1-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 Subject: [PATCH] MdeModulePkg/ScsiDiskDxe: Fix potential implicit sign extension X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Apr 2017 07:43:39 -0000 In function GetMediaInfo(), the following expression: ScsiDiskDevice->BlkIo.Media->LastBlock = (Capacity10->LastLba3 << 24) | (Capacity10->LastLba2 << 16) | (Capacity10->LastLba1 << 8) | Capacity10->LastLba0; will involve implicit sign extension. Since Capacity10->LastLbaX is of type UINT8, and ScsiDiskDevice->BlkIo.Media->LastBlock is of type UINT64. Therefore, Capacity10->LastLbaX will be promoted to int (32 bits, signed) first, perform the bit shift and or. Then the result will be sign-extended to type UINT64. If bit 7 of Capacity10->LastLba3 is 1, then the high 32 bits of ScsiDiskDevice->BlkIo.Media->LastBlock will all be set to 1. This commit will add an explicit UINT32 type cast for Capacity10->LastLba3 to resolve this issue. Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c index b5eff25b9b..2289f20152 100644 --- a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c +++ b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c @@ -1,7 +1,7 @@ /** @file SCSI disk driver that layers on every SCSI IO protocol in the system. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -2754,7 +2754,7 @@ GetMediaInfo ( UINT8 *Ptr; if (!ScsiDiskDevice->Cdb16Byte) { - ScsiDiskDevice->BlkIo.Media->LastBlock = (Capacity10->LastLba3 << 24) | + ScsiDiskDevice->BlkIo.Media->LastBlock = ((UINT32) Capacity10->LastLba3 << 24) | (Capacity10->LastLba2 << 16) | (Capacity10->LastLba1 << 8) | Capacity10->LastLba0; -- 2.12.0.windows.1