From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by mx.groups.io with SMTP id smtpd.web11.45005.1670856427796152696 for ; Mon, 12 Dec 2022 06:47:08 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=flWEar4p; spf=pass (domain: gmail.com, ip: 209.85.167.54, mailfrom: savvamtr@gmail.com) Received: by mail-lf1-f54.google.com with SMTP id j4so19029165lfk.0 for ; Mon, 12 Dec 2022 06:47:07 -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=0aY27jGQ4+UtmOkgByN8PBFTSFZGaQdgKwLF3M8jXmc=; b=flWEar4pnhAq8tPyzd3yV+EfEgxLXqAWxij00t0c712a5Je/J4dbb/U5D4zBOgTWfi uLu9MAm543qBMOkaXBkvlRjfY92uAsGEd0FUCXWaRSOu+gYuPkPNUR+ONYcbi/JdOvu+ tsvZhL706VCG3qM7xy0iZN9Y3satHqz2mm7iRvEMEMciS3x21dpQjYJkpEdQDvfv60iH sapBeWBJFRS6+HdHDpxQY2DFNgCmfutJhaTyP7hbvya0g7E12ml4lGB8WU2INSn/BYdf TYfxOsmNt8T6Z7hIXovJapCQQ7mqUR3hcfqr3SGmpdnvHfxzdRjgRWY7NLFI7XhpuN32 uW7w== 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=0aY27jGQ4+UtmOkgByN8PBFTSFZGaQdgKwLF3M8jXmc=; b=b0KHQWwWr9nVg6d2bS53g7Ic34yOut+bqq/pjgZtJffkHXEf3q+Y/LvPz7M4AVKQmu 0mps9rEdZJSYTOUnK38d619+WMiOvPb+LgDTsOLRh8B5MRclM0IKi6sLTSTMscQ1kliM rdKAtZFlPZi9rHD1T7pH4XzAd+QZqI5YiGM/f8QXrdDBaA56lpXBtWqeG5ZH2JLOOmat TVrDYl2y4OS76OzWdmFbzRJJ1HDmBcHhzzPQ84BTB0G1WywqX6Ky2N/UiEymrN5myPrx 9c+Fs/SqMzRUQcpjfaY36V2kHgqsWCcmoWennWujUgKY+y1lfYBhT9hUqk97wTyua+E0 gRag== X-Gm-Message-State: ANoB5plNX2Pb0H1Q7a8+d3xIlGse9I6ag6NNARwerSlkDebjlOsmvMUi idqtceCdJfroBJKIBz49Ccf3wjlDXf4UvzYr X-Google-Smtp-Source: AA0mqf5pxUXNdoriyH6ASrY/OcWt4f7gu7fdjNbQECqE+J+hVjBJAoXHTkvC8v5bGbK7sPxKeUwFCA== X-Received: by 2002:a05:6512:400e:b0:4b5:5f2b:ddf8 with SMTP id br14-20020a056512400e00b004b55f2bddf8mr5122702lfb.7.1670856425998; Mon, 12 Dec 2022 06:47:05 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 06:47:05 -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 07/11] Ext4Pkg: Fix shift out of bounds in Ext4OpenSuperblock Date: Mon, 12 Dec 2022 20:46:50 +0600 Message-Id: <20221212144654.2650-8-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 Missing check for wrong s_log_block_size exponent leads to shift out of bounds. Limit block size to 2 MiB Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: e55f0527dde48a5f139c1b8f35acc4e6b59dd794 Signed-off-by: Savva Mitrofanov --- Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 14 ++++++++++++++ Features/Ext4Pkg/Ext4Dxe/Superblock.c | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index beceb9d60dcb..a7e138e99561 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -40,6 +40,20 @@ #define EXT4_EFI_PATH_MAX 4096=0D #define EXT4_DRIVER_VERSION 0x0000=0D =0D +//=0D +// The EXT4 Specification doesn't strictly limit block size and this value= could be up to 2^31,=0D +// but in practice it is limited by PAGE_SIZE due to performance significa= nt impact.=0D +// Many EXT4 implementations have size of block limited to PAGE_SIZE. In m= any cases it's limited=0D +// to 4096, which is a commonly supported page size on most MMU-capable ha= rdware, and up to 65536.=0D +// So, to take a balance between compatibility and security measures, it i= s decided to use the=0D +// value of 2MiB as the limit, which is equal to page size on new hardware= .=0D +// As for supporting big block sizes, EXT4 has a RO_COMPAT_FEATURE called = BIGALLOC, which changes=0D +// EXT4 to use clustered allocation, so that each bit in the ext4 block al= location bitmap addresses=0D +// a power of two number of blocks. So it would be wiser to implement and = use this feature=0D +// if there is such a need instead of big block size.=0D +//=0D +#define EXT4_LOG_BLOCK_SIZE_MAX 11=0D +=0D /**=0D Opens an ext4 partition and installs the Simple File System protocol.=0D =0D diff --git a/Features/Ext4Pkg/Ext4Dxe/Superblock.c b/Features/Ext4Pkg/Ext4D= xe/Superblock.c index adaf475ea54d..ffe66a8bb847 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Superblock.c +++ b/Features/Ext4Pkg/Ext4Dxe/Superblock.c @@ -248,6 +248,11 @@ Ext4OpenSuperblock ( return EFI_VOLUME_CORRUPTED;=0D }=0D =0D + if (Sb->s_log_block_size > EXT4_LOG_BLOCK_SIZE_MAX) {=0D + DEBUG ((DEBUG_ERROR, "[ext4] SuperBlock s_log_block_size %lu is too bi= g\n", Sb->s_log_block_size));=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D Partition->BlockSize =3D (UINT32)LShiftU64 (1024, Sb->s_log_block_size);= =0D =0D // The size of a block group can also be calculated as 8 * Partition->Bl= ockSize=0D --=20 2.38.1