From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by mx.groups.io with SMTP id smtpd.web10.98480.1674811793804468085 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=NZcnV3yV; spf=pass (domain: gmail.com, ip: 209.85.167.41, mailfrom: savvamtr@gmail.com) Received: by mail-lf1-f41.google.com with SMTP id v17so1309963lfd.7 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=5JGFinfQKnvM2hFtw5orW4E1NdoeooqO/rLEs9Hek+U=; b=NZcnV3yVWmwSqaefW1fcZOuRLzewrTUAMpyhk5aMtop8ZYZev0m1ZrdZ0byvf86ow8 ZRK+let5CNKVOs1744OVoocc8caj2nbUtg7utVmDaJQ982LzECap7/Puq52kvekSTomP bXfG7oijYZIc8Qcfj0Cd6guEXOzWzrUSkgcYtv+V0gaRPqwy6Z0J3IBEPr8dkbWLmHFD jY/UPepD3hRYD6kVMi9ie8VWLj0enoHdjR/hjlWX1ssIIsfrG5qECJKeRHyWt0cO3/E3 gXWS4GW6uM69tw62IEK2NPIi5wqZeMyLrUBVW0/1hnbEWto4wlnnZ0j2Fv+uuaVhdLny +ZBQ== 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=5JGFinfQKnvM2hFtw5orW4E1NdoeooqO/rLEs9Hek+U=; b=L0AovG9B4PWrNrQnTVZuydC8BeBNoFSATNPRuYDiXvtiwT6KbfxG3as/TnlieDeIFr +8Rs5T7Gfh8CMteaxGhe30FUR6UU1Z5gCsoV2hXNySKhZbZu4WkB4k1fSzGO4z8cVPlS KvyDcugd1QMYDdCeXBm2dsbyl5VH3OGP0Na847BbMIu8Vcpqw3l7fV6EUixnMfe37jQM 1ulxJe9skn3uJ3UpCBX1onz6K6aFjK7PHHAc3vB434XmqnIVghiHLP4f11DKr59lw2h+ IYQwoZk65tLNjZ+X/olTxw3QeD3LDdEpGFbNr+JppbpDOLODqfasfeV1h4bE3lWCFMfb 7iWg== X-Gm-Message-State: AFqh2ko0xhRQ4YNDPdM+v24jQ1T37wjlHVPV60h0wp1IIYcKGUQlJK3a kLIKmKBV7CeL37ZITb0A3mmIlYKK7u2dNt7L X-Google-Smtp-Source: AMrXdXvn1v+YYCFY25nwCK1x+xq+dGtbWTvVJ++dkaVcWYBB3WWOLxjteQlHrfwUQEbG5J7B7VdGaA== X-Received: by 2002:ac2:55b0:0:b0:4d5:5b50:f8f0 with SMTP id y16-20020ac255b0000000b004d55b50f8f0mr10356242lfg.46.1674811791890; Fri, 27 Jan 2023 01:29:51 -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.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:51 -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 05/11] Ext4Pkg: Fix shift out of bounds in Ext4OpenSuperblock Date: Fri, 27 Jan 2023 15:29:39 +0600 Message-Id: <20230127092945.94389-6-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 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: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") 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 2e489ce4dd86..a23323319a59 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 be3527e4d618..3f56de93c105 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.39.0