From nobody Thu May 16 22:25:45 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+110817+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+110817+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1699338533; cv=none; d=zohomail.com; s=zohoarc; b=KZa/gzyl5UKkqHp3cSIXfHP5gOdcHN5a3RBbb+x0PSfoitNQdyOhikby9q6mS2jQt/IHMVfLoJbN3Lz4e8sy2akaeY98HUp37CednzLoEEi/e3XGXSsGc9oSSdqlUlncMKxrgXZvptfwplh7a9AusMOjT443WiPBPrWhSc7ZliI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699338533; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=/q9+6lHxNA67MDFp6y4infSc/+j06TDjYR8t6VRMWaM=; b=exXE/KOkuJERNE3+0PokIiE0rW4nWCXf4Kp2TgCBaowEEKamqxJWuYsv0Pv6lAokg7FqEN84a/tevv3sV35TRCRupoa72ssoaYpXuO3Oq5Oj2T91fV2wdnlJIb4zQ4d1cYRF0z9Cn1mHbb5D+GvSr8hKhGfJI5Xcce2lrOXOQ+s= 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+110817+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1699338533054205.5940430931497; Mon, 6 Nov 2023 22:28:53 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=aC5Dmhw5pr4eX00ZrcF2wkkrgO8EPJzf+2Bz4y17wwU=; 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=1699338532; v=1; b=aL6PamRjYitfnfyyPUqzPROle0qrG1PgJxP01exxwpqvBkpZEyukhqKlDD56FW1LRmkx72AX NKYZXVs3A03i/tH+cHUe8+K58VJhGauoikbhM4x0+LgsLqBcUoW9NMBmUFN1IJcCEq4HdDwP50O VVsdQBFwyFP3jVe5XAz4Hj4s= X-Received: by 127.0.0.2 with SMTP id nWEmYY1788612xa65Ia0hL8b; Mon, 06 Nov 2023 22:28:52 -0800 X-Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) by mx.groups.io with SMTP id smtpd.web11.4718.1699338532047465844 for ; Mon, 06 Nov 2023 22:28:52 -0800 X-Received: by mail-il1-f174.google.com with SMTP id e9e14a558f8ab-359472f74c5so20944665ab.0 for ; Mon, 06 Nov 2023 22:28:51 -0800 (PST) X-Gm-Message-State: 5pdNLJfT8igpecDNds5q5RTGx1787277AA= X-Google-Smtp-Source: AGHT+IFoFYzHQ2ZL/yvoMVf28ntT2Rliue+aygYLGxKyHbsCBdyDWiTuVR67bbUQIK9ccKbprku5jA== X-Received: by 2002:a05:6e02:1c8a:b0:359:42f7:47ea with SMTP id w10-20020a056e021c8a00b0035942f747eamr2134195ill.12.1699338531198; Mon, 06 Nov 2023 22:28:51 -0800 (PST) X-Received: from user-Latitude-5420.dc1.ventanamicro.com ([2401:4900:1f24:775d:7335:84a5:7d11:9393]) by smtp.gmail.com with ESMTPSA id c7-20020a0290c7000000b00463ff17540fsm1766626jag.78.2023.11.06.22.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 22:28:51 -0800 (PST) From: "Ranbir Singh" To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni , Veeresh Sangolli Subject: [edk2-devel] [PATCH v2 1/2] FatPkg/EnhancedFatDxe: Fix SIGN_EXTENSION Coverity issues Date: Tue, 7 Nov 2023 11:58:41 +0530 Message-Id: <20231107062842.116670-2-rsingh@ventanamicro.com> In-Reply-To: <20231107062842.116670-1-rsingh@ventanamicro.com> References: <20231107062842.116670-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: 1699338533692100007 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 (#110817): https://edk2.groups.io/g/devel/message/110817 Mute This Topic: https://groups.io/mt/102438364/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 Thu May 16 22:25:45 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+110818+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+110818+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1699338535; cv=none; d=zohomail.com; s=zohoarc; b=E15v1Z1bT1T5ibtIwFZ0G++VfDyqYIb4uchwtGHejKIINw0O+LlES45miBjWVv3OOI/pKDN9gysLx2NQD3uF2NJEFjFvZY1Xvv0PjO/ecyK7JZfdvkUQQb0rXKBx6ETYGLt/EDGpFQbNugOTYBlVBbRX293hUt+F1Y14FYuAo2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699338535; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=PC25vHh0ypD0uEFj0m0qucHqEnpBuOq3GQsbB1wwb+w=; b=BewL4DKh5sP4i2n6egfFXrN8CHbiW7pu9YtljqW58nioplg97rnANP2Zk3xvulOpvq1/93LJU7YMjjtlThK1LvHqzctdvmgpHoKUKXmDYK8XJxZyeMCI++G7HnUtSIGHvEkI82npNuPglFXqnmIqcqAeXjCa7AN6f39jOVaWFEU= 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+110818+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 169933853589144.98803317672025; Mon, 6 Nov 2023 22:28:55 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=5uKzJPCZFREkxoKyeVdelseavzyR8GJhyqDo2+Ez4vQ=; 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=1699338535; v=1; b=HkWEyNlXXV5F6verG/9pIaLuv+RCT+KB05BvFk+kZwQZu8CGi8Hdg9hxivb6Pkc/z4U5h+RQ YkAuavIOw5mROlkugFKosuAyRyZk+R6BVUphB09SwGqcD2fBY/+v/dfluRjM9KsKFsYfKo9uvi/ pBh95fGt1AUZoalWKE4yxrQU= X-Received: by 127.0.0.2 with SMTP id JydGYY1788612xW6CwsnB9CT; Mon, 06 Nov 2023 22:28:55 -0800 X-Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) by mx.groups.io with SMTP id smtpd.web10.5112.1699338535000684796 for ; Mon, 06 Nov 2023 22:28:55 -0800 X-Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-7a996357550so207751139f.2 for ; Mon, 06 Nov 2023 22:28:54 -0800 (PST) X-Gm-Message-State: v8Wj6CSHO81eOClxfYVQdI8Px1787277AA= X-Google-Smtp-Source: AGHT+IGaE+bywZI/r//TVzV8brCVl/bGoILM6L/gLJyOs5p4WmazRnTFezc+OMkMUM8DLAiogEat1g== X-Received: by 2002:a05:6e02:1909:b0:357:43a5:acf8 with SMTP id w9-20020a056e02190900b0035743a5acf8mr2690839ilu.17.1699338533965; Mon, 06 Nov 2023 22:28:53 -0800 (PST) X-Received: from user-Latitude-5420.dc1.ventanamicro.com ([2401:4900:1f24:775d:7335:84a5:7d11:9393]) by smtp.gmail.com with ESMTPSA id c7-20020a0290c7000000b00463ff17540fsm1766626jag.78.2023.11.06.22.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 22:28:53 -0800 (PST) From: "Ranbir Singh" To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni , Veeresh Sangolli Subject: [edk2-devel] [PATCH v2 2/2] FatPkg/EnhancedFatDxe: Fix OVERFLOW_BEFORE_WIDEN Coverity issue Date: Tue, 7 Nov 2023 11:58:42 +0530 Message-Id: <20231107062842.116670-3-rsingh@ventanamicro.com> In-Reply-To: <20231107062842.116670-1-rsingh@ventanamicro.com> References: <20231107062842.116670-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: 1699338537714100003 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 (#110818): https://edk2.groups.io/g/devel/message/110818 Mute This Topic: https://groups.io/mt/102438365/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-