From nobody Sat May 4 11:44:56 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1491810222332393.58977508931264; Mon, 10 Apr 2017 00:43:42 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4D7D721939304; Mon, 10 Apr 2017 00:43:40 -0700 (PDT) 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) 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 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 X-Original-To: edk2-devel@lists.01.org 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==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,181,1488873600"; d="scan'208";a="844016753" From: Hao Wu To: edk2-devel@lists.01.org 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: [edk2] [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: , Cc: Hao Wu , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In function GetMediaInfo(), the following expression: ScsiDiskDevice->BlkIo.Media->LastBlock =3D (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/Bu= s/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. =20 -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; =20 if (!ScsiDiskDevice->Cdb16Byte) { - ScsiDiskDevice->BlkIo.Media->LastBlock =3D (Capacity10->LastLba3 << 2= 4) | + ScsiDiskDevice->BlkIo.Media->LastBlock =3D ((UINT32) Capacity10->Last= Lba3 << 24) | (Capacity10->LastLba2 << 16)= | (Capacity10->LastLba1 << 8) = | Capacity10->LastLba0; --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel