From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mx.groups.io with SMTP id smtpd.web10.44807.1670856428797007688 for ; Mon, 12 Dec 2022 06:47:09 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DVzBS43F; spf=pass (domain: gmail.com, ip: 209.85.167.48, mailfrom: savvamtr@gmail.com) Received: by mail-lf1-f48.google.com with SMTP id 1so18982862lfz.4 for ; Mon, 12 Dec 2022 06:47:08 -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=XUHBDKJrhu+M70j7ksB2oQdKUKCMAn9qyuyGw4FiUKI=; b=DVzBS43FWW4xIDjtUolYq+fqaV/xGw23b6oVp4KgJGLtFr4lndfR35VKrwjFD6vnN5 QdgVUK9U8lgdtYfqknmtf8EObb/rZtZKmtuxbW7Ec1hJpnjavj8k1l0b44AnBYDdg/GZ Zpxuu9fX8Sraf19/twFPKDEwAz5Mp3nE6PjpNwO0/rbUcgpCSNfEC7O/N+ajntqVsmFX 7n4OYHnd/P7B7qpN6YZoSvPXFh8W73pOYr6fEpE+N1tTRLWudQqwcDwdi19xE8K8MJWl S1cDm2f99Tf4Ss4JQ1fVr+qpOy7lqT5erQshTmghxijTmwCGGspuyjtPDl/5pK38U/zm +KmA== 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=XUHBDKJrhu+M70j7ksB2oQdKUKCMAn9qyuyGw4FiUKI=; b=HlIv9rYzM+kgQCSnOW+aYVG6XIy8e0xyMIR+rfGCqWHBdp9gnCon6VwE1ao1mF6IVc JJeyDxZVcE0N/MjTeXhc9cjFG8krxKc1hYPzlpcPFiqoi5/O10A1rpx6cPRR2KRLiSm9 PKPwWJ6ayYXNgmrZHE6/IkTucCvxYo+qxCjwETaEwpbEYbdHL0n2+3NjnpwdbkxvGK+N PR15IhWpsSodj4D9vponc4dcx4UGz3gsPwv5cxqIAZIuLuzIFfPKOPeY02Nu1KWronGq 35WHDAWwYM3k7zQj4c9Fdrau7zEzEfwOe2JeW4SxGku5DWJOHCdLx4Fy7736npSRHRKZ zRkA== X-Gm-Message-State: ANoB5pkNol5XjskBWM1crsnAO9EehPF7PobBruz+oei5krVc4PZ5vZ4a IJBwJfs4jzR+ssrLZydSeFyft5LCRdMzO2mb X-Google-Smtp-Source: AA0mqf4Bj7JiQDatxp13AVUwxSAIzKkrM+SRN4KWxvR17y8I+DM3l1M54KY/7S0RN6V0J8J0FEznBQ== X-Received: by 2002:a05:6512:2186:b0:4a4:68b9:66cc with SMTP id b6-20020a056512218600b004a468b966ccmr4219671lft.23.1670856426983; Mon, 12 Dec 2022 06:47:06 -0800 (PST) Return-Path: Received: from localhost.localdomain ([77.221.215.144]) by smtp.gmail.com with ESMTPSA id t4-20020a056512030400b0049c29292250sm1643313lfp.149.2022.12.12.06.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 06:47:06 -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 v2 08/11] Ext4Pkg: Corrects integer overflow check logic in DiskUtil Date: Mon, 12 Dec 2022 20:46:51 +0600 Message-Id: <20221212144654.2650-9-savvamtr@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212144654.2650-1-savvamtr@gmail.com> References: <20221212144654.2650-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: e55f0527dde48a5f139c1b8f35acc4e6b59dd794 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.38.1