From nobody Fri May 17 09:01:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+109139+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+109139+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1695887210; cv=none; d=zohomail.com; s=zohoarc; b=J1qp9vpDoAo6MYcQfqZ0RvjD+feX4YiOCvH3V8WO+Lvu+GBW1Xc7i9lTH5fugC7xod+fGh/VG6dIYiYMYxUNEtGbEz7eJxZ/AtsItaDAm8SoSre0OK9XwXSFPJrg1dWB1OtT4WxX6ehijOSBNXg1nZclI9OcTrd8kg/7VR8Y9p8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695887210; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=/nN3Ozqgv3UFHsd3UXPF+Xxq0LftbLCi7cs+jtAPSbg=; b=IvmwXyVXIlpGYW/K+l3Z7TiyZpMPFEuGLxe3MoZnuhw/VAaCXq6QE2NRnr7VWybYiGzJ6z7tVnnbh80Y6btcvaczZhpRW/xM5JqWo9VLdPvxISO+0cQgY+1FQFrbhuZ6y17INCuTk49FzuOIFzRP5bHcgRSY2gyXtYDS+1INesQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+109139+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1695887210478685.1892330951309; Thu, 28 Sep 2023 00:46:50 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=qDGOUAwSyEThVztz3LHs/41f5Gr6mOLntWUKMniXeMQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1695887210; v=1; b=eQA9bQxPX2E06tzNIZnPLYQKZCJRN6Ssu+50U3+ry/e8Dh/8T5AySLZM5KYv1Q8Pe/HXXJ1M gbWlqZHQlSxdnCzj+cRl30OsbBYWdKjYml6o+Hc4qgsyCxzBUZmzGNUG6YdxC7CkdGMhlRKbKtD eS9zSNemJk/CV8ifEdZnWP4I= X-Received: by 127.0.0.2 with SMTP id YHX1YY1788612xGSbQVOynHO; Thu, 28 Sep 2023 00:46:50 -0700 X-Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) by mx.groups.io with SMTP id smtpd.web11.8857.1695887209655896630 for ; Thu, 28 Sep 2023 00:46:49 -0700 X-Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-3513c435465so21775325ab.0 for ; Thu, 28 Sep 2023 00:46:49 -0700 (PDT) X-Gm-Message-State: EcvbhkPkXL2ayGf89GEkSzmIx1787277AA= X-Google-Smtp-Source: AGHT+IGhvavgeeKorf2IuAY4MyQOf/BtA/DjOkHtJqmOewmXDLKhHSXhpv5mU2+nmO/Jc5tO/vxAMQ== X-Received: by 2002:a05:6e02:1c46:b0:351:33b0:176e with SMTP id d6-20020a056e021c4600b0035133b0176emr425657ilg.12.1695887208775; Thu, 28 Sep 2023 00:46:48 -0700 (PDT) X-Received: from user-Latitude-5420.dc1.ventanamicro.com ([2401:4900:1cbc:99f:6dc7:3128:6646:ac3f]) by smtp.gmail.com with ESMTPSA id y13-20020a02ce8d000000b0043a1f6dc8d4sm4342751jaq.4.2023.09.28.00.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 00:46:48 -0700 (PDT) From: "Ranbir Singh" To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni , Veeresh Sangolli Subject: [edk2-devel] [PATCH v1 1/2] FatPkg/EnhancedFatDxe: Fix SIGN_EXTENSION Coverity issues Date: Thu, 28 Sep 2023 13:16:38 +0530 Message-Id: <20230928074639.561998-2-rsingh@ventanamicro.com> In-Reply-To: <20230928074639.561998-1-rsingh@ventanamicro.com> References: <20230928074639.561998-1-rsingh@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rsingh@ventanamicro.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1695887212323100005 Content-Type: text/plain; charset="utf-8" From: Ranbir Singh The functions FatGetDirEntInfo and FatOpenDirEnt contains the code statements Cluster =3D (Entry->FileClusterHigh << 16) | Entry->FileCl= uster; and OFile->FileCluster =3D ((DirEnt->Entry.FileClusterHigh) << 16) | (Dir= Ent->Entry.FileCluster); respectively. As per Coverity report, in both these statements, there is an "Operand1" with type "UINT16" (16 bits, unsigned) which is promoted in "(Operand1 << 16) | Operand2" to type "int" (32 bits, signed), then sign- extended to type "unsigned long long" (64 bits, unsigned). If the result of "(Operand1 << 16) | Operand2" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1. So to avoid sign-extension, typecast the Operand1 and then the inter- -mediate result after << 16 operation with UINTN. Note - UINTN is the data type of the variable on the LHS of the assignment. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4249 Cc: Ray Ni Co-authored-by: Veeresh Sangolli Signed-off-by: Ranbir Singh Signed-off-by: Ranbir Singh --- FatPkg/EnhancedFatDxe/DirectoryManage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FatPkg/EnhancedFatDxe/DirectoryManage.c b/FatPkg/EnhancedFatDx= e/DirectoryManage.c index 723fc35f38db..a21b7973cd21 100644 --- a/FatPkg/EnhancedFatDxe/DirectoryManage.c +++ b/FatPkg/EnhancedFatDxe/DirectoryManage.c @@ -474,7 +474,7 @@ FatGetDirEntInfo ( Info =3D Buffer; Info->Size =3D ResultSize; if ((Entry->Attributes & FAT_ATTRIBUTE_DIRECTORY) !=3D 0) { - Cluster =3D (Entry->FileClusterHigh << 16) | Entry->FileC= luster; + Cluster =3D (UINTN)((UINTN)(Entry->FileClusterHigh) << 16= ) | Entry->FileCluster; Info->PhysicalSize =3D FatPhysicalDirSize (Volume, Cluster); Info->FileSize =3D Info->PhysicalSize; } else { @@ -1167,7 +1167,7 @@ FatOpenDirEnt ( // Volume =3D Parent->Volume; OFile->FullPathLen =3D Parent->FullPathLen + 1 + StrLen (DirEnt->Fil= eString); - OFile->FileCluster =3D ((DirEnt->Entry.FileClusterHigh) << 16) | (Di= rEnt->Entry.FileCluster); + OFile->FileCluster =3D (UINTN)((UINTN)(DirEnt->Entry.FileClusterHigh= ) << 16) | (DirEnt->Entry.FileCluster); InsertTailList (&Parent->ChildHead, &OFile->ChildLink); } else { // --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109139): https://edk2.groups.io/g/devel/message/109139 Mute This Topic: https://groups.io/mt/101633788/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 09:01:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+109140+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+109140+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1695887213; cv=none; d=zohomail.com; s=zohoarc; b=iTGzGZ8Q9JlaEcRJRTB55ky+Vzhmc9hkvdzK4Aj/wA/YM4ePnl54ifu2uuT5CSc8g1cGUSrP1H069LIKe7KMrczJ7MAxWgIq2uCf5pzAZau4MK4Req0+JehyhN5MNHoBJKwZP+SPtCM04jsBokY+Sv2Oiq5lRia8Eu083+JoOYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695887213; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Lvv1C1ib2zlKciEjvMfv2COEgJhtilTMDmrDGWodV9c=; b=IYqe25B1YjCMwMft9NY8Wv0PyiMiQVgCZZ8yKR+0moGR25SBH/6TaJEFpvRMOP1dcPut9uvqQJ2Jj2rYS15xDhkyFjEib5ebztNWCbstyOLfT3HCGUspKmttAal3AN0P3pxBha2cHXBwuVnJ7UPxHT0qNngKte6tv4/c6//ZLcA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+109140+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 169588721365118.95836552130504; Thu, 28 Sep 2023 00:46:53 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=ERtMalameduaDiqtVLW+prnzVUMVtNaRMngAJTjHDiY=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1695887213; v=1; b=tEhzFbx5Ecto9I1j0yr69cs5w3ukPfKaz1P4f8JmolkHq0KTRXCWpmgHih5CS4ebl/rWVn77 Odvm8fdOGFdL3gzOPlvb999PETjS9YkRsgBiAPxSHaSkWPFhlCDLomsj2R9KgkfGWXLTMIbmlMS KoTjYi2M5a5m8VxH5iCArPMw= X-Received: by 127.0.0.2 with SMTP id Nc7nYY1788612xcfBnUNV72k; Thu, 28 Sep 2023 00:46:53 -0700 X-Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) by mx.groups.io with SMTP id smtpd.web10.9043.1695887212628450120 for ; Thu, 28 Sep 2023 00:46:52 -0700 X-Received: by mail-il1-f173.google.com with SMTP id e9e14a558f8ab-3512c09355fso30549215ab.0 for ; Thu, 28 Sep 2023 00:46:52 -0700 (PDT) X-Gm-Message-State: xT7q8Z37DDcpJ4dRfimTmiWZx1787277AA= X-Google-Smtp-Source: AGHT+IF8JBQbHVNtAG4s34rRAQG1xLwz32BghLfUXTnsG3KGKjVyE3t67/W4GqrfAz/Vug2bQYQdxA== X-Received: by 2002:a05:6e02:130f:b0:34c:e6e6:80d5 with SMTP id g15-20020a056e02130f00b0034ce6e680d5mr365958ilr.26.1695887211732; Thu, 28 Sep 2023 00:46:51 -0700 (PDT) X-Received: from user-Latitude-5420.dc1.ventanamicro.com ([2401:4900:1cbc:99f:6dc7:3128:6646:ac3f]) by smtp.gmail.com with ESMTPSA id y13-20020a02ce8d000000b0043a1f6dc8d4sm4342751jaq.4.2023.09.28.00.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 00:46:51 -0700 (PDT) From: "Ranbir Singh" To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni , Veeresh Sangolli Subject: [edk2-devel] [PATCH v1 2/2] FatPkg/EnhancedFatDxe: Fix OVERFLOW_BEFORE_WIDEN Coverity issue Date: Thu, 28 Sep 2023 13:16:39 +0530 Message-Id: <20230928074639.561998-3-rsingh@ventanamicro.com> In-Reply-To: <20230928074639.561998-1-rsingh@ventanamicro.com> References: <20230928074639.561998-1-rsingh@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rsingh@ventanamicro.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1695887214266100011 Content-Type: text/plain; charset="utf-8" From: Ranbir Singh The function FatInitializeDiskCache evaluates an expression FAT_DATACACHE_GROUP_COUNT << DiskCache[CacheData].PageAlignment and assigns it to DataCacheSize which is of type UINTN. As per Coverity report, FAT_DATACACHE_GROUP_COUNT << DiskCache[CacheData].PageAlignment is a potentially overflowing expression with type "int" (32 bits, signed) evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "UINTN" (64 bits, unsigned). To avoid overflow, cast "FAT_DATACACHE_GROUP_COUNT" to type "UINTN". REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4249 Cc: Ray Ni Co-authored-by: Veeresh Sangolli Signed-off-by: Ranbir Singh Signed-off-by: Ranbir Singh --- FatPkg/EnhancedFatDxe/DiskCache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FatPkg/EnhancedFatDxe/DiskCache.c b/FatPkg/EnhancedFatDxe/Disk= Cache.c index d1a34a6a646f..d56e338586d8 100644 --- a/FatPkg/EnhancedFatDxe/DiskCache.c +++ b/FatPkg/EnhancedFatDxe/DiskCache.c @@ -477,7 +477,7 @@ FatInitializeDiskCache ( DiskCache[CacheFat].BaseAddress =3D Volume->FatPos; DiskCache[CacheFat].LimitAddress =3D Volume->FatPos + Volume->FatSize; FatCacheSize =3D FatCacheGroupCount << DiskCache[Ca= cheFat].PageAlignment; - DataCacheSize =3D FAT_DATACACHE_GROUP_COUNT << DiskC= ache[CacheData].PageAlignment; + DataCacheSize =3D (UINTN)FAT_DATACACHE_GROUP_COUNT <= < DiskCache[CacheData].PageAlignment; // // Allocate the Fat Cache buffer // --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109140): https://edk2.groups.io/g/devel/message/109140 Mute This Topic: https://groups.io/mt/101633789/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-