From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by mx.groups.io with SMTP id smtpd.web11.98570.1674811791892615145 for ; Fri, 27 Jan 2023 01:29:54 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GU1gxQ4F; spf=pass (domain: gmail.com, ip: 209.85.167.51, mailfrom: savvamtr@gmail.com) Received: by mail-lf1-f51.google.com with SMTP id o20so7236438lfk.5 for ; Fri, 27 Jan 2023 01:29:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zVT76gjROXKJjpaYa3tSVNrXmh1qtv8db7jRyAQalAc=; b=GU1gxQ4FClAgOxqGWncoMTVBR7JPqqo0XPoMoqPVpr3vcy/uKWZahTCnZzo68Hwa7k Q4o57uIbiL+wTyZ8es1/n2AkvSJT8DgJMStdwFuFwpQjCteHWV97XUaOX0HST3VoTqjX yslINebBRNtM63MbO3kG4W+2pKMtZOKIiCkGLVIyG4ITZAL1FteXEBbpI7K2RqBtItnU MGI7zAVN4JZS8U8ZO8dye19SVRVFntI2gLjAWz+HlByN+u7XTWxi1YKx2JVy3n2I9oWx n3dkhO9Ywf5Qy0pxfdxa0eYVmBV8LMKDX/jOUcYauT0mfnubulS2LSJXxurOYFpyCkU9 N3RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zVT76gjROXKJjpaYa3tSVNrXmh1qtv8db7jRyAQalAc=; b=aRRQcOfzOlx0CNg5rk4oi3FDOdZKBunSknDZsvaiLoWBYIs5DWbu1sTg8k/+1D8AIK GLc6KCtbTFjj7zuFcdoi6k29cwHFwbbWEQ4AUkadstx4BT4sp33AQxewnZ5HDpB1j6Gc gwJgihf3wgZt3n9N0U0+ovmd+zGKvXtVr6/clVw7V/2yr0eY6gRRW3nxcdJ/wuuRiGhO smYp3sHKqDYzpkASbkG0Re3siBmNPNuYrj0JODmABKJnMGOhWDzgkpAQOI205LDEDRsB PXYhD7AUtSl4FdU6e5AI7aoLAqB6qvV0m4+hHdfWuWvm9NKxmzTGWAl5dKy4TbZp3mZo bauQ== X-Gm-Message-State: AFqh2kqAsLXN0EITGPB1V0GQdJMJSYSGXjXYmgcPKH5ac/Q+h99lN/eG bFZe0uh1M7C6Y5N5d8TRwoqO0mghv5+4eIoG X-Google-Smtp-Source: AMrXdXsBgCJ5shgEXYr/lKJLL/LJ83cFuK1U7kNQoEaBP1CexF2jA9sIeg7zKL6lJwnRfu6jizN+3w== X-Received: by 2002:ac2:4473:0:b0:4ca:f97f:4a21 with SMTP id y19-20020ac24473000000b004caf97f4a21mr10105563lfl.37.1674811792783; Fri, 27 Jan 2023 01:29:52 -0800 (PST) Return-Path: Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:52 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-platforms][PATCH v3 06/11] Ext4Pkg: Corrects integer overflow check logic in DiskUtil Date: Fri, 27 Jan 2023 15:29:40 +0600 Message-Id: <20230127092945.94389-7-savvamtr@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Corrects multiplication overflow check code Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov --- Features/Ext4Pkg/Ext4Pkg.dsc | 2 +- Features/Ext4Pkg/Ext4Dxe/DiskUtil.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Pkg.dsc b/Features/Ext4Pkg/Ext4Pkg.dsc index 59bc327ebf6e..621c63eaf92d 100644 --- a/Features/Ext4Pkg/Ext4Pkg.dsc +++ b/Features/Ext4Pkg/Ext4Pkg.dsc @@ -46,7 +46,7 @@ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf=0D OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf=0D BaseUcs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf=0D - =0D +=0D #=0D # Required for stack protector support=0D #=0D diff --git a/Features/Ext4Pkg/Ext4Dxe/DiskUtil.c b/Features/Ext4Pkg/Ext4Dxe= /DiskUtil.c index 32da35f7d9f5..c4af956da926 100644 --- a/Features/Ext4Pkg/Ext4Dxe/DiskUtil.c +++ b/Features/Ext4Pkg/Ext4Dxe/DiskUtil.c @@ -60,11 +60,11 @@ Ext4ReadBlocks ( // Check for overflow on the block -> byte conversions.=0D // Partition->BlockSize is never 0, so we don't need to check for that.= =0D =0D - if (Offset > DivU64x32 ((UINT64)-1, Partition->BlockSize)) {=0D + if ((NumberBlocks !=3D 0) && (DivU64x64Remainder (Offset, BlockNumber, N= ULL) !=3D Partition->BlockSize)) {=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D - if (Length > (UINTN)-1/Partition->BlockSize) {=0D + if ((NumberBlocks !=3D 0) && (Length / NumberBlocks !=3D Partition->Bloc= kSize)) {=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D @@ -94,12 +94,12 @@ Ext4AllocAndReadBlocks ( =0D Length =3D NumberBlocks * Partition->BlockSize;=0D =0D - if (Length > (UINTN)-1/Partition->BlockSize) {=0D + // Check for integer overflow=0D + if ((NumberBlocks !=3D 0) && (Length / NumberBlocks !=3D Partition->Bloc= kSize)) {=0D return NULL;=0D }=0D =0D Buf =3D AllocatePool (Length);=0D -=0D if (Buf =3D=3D NULL) {=0D return NULL;=0D }=0D --=20 2.39.0