From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by mx.groups.io with SMTP id smtpd.web10.5491.1670602284692974264 for ; Fri, 09 Dec 2022 08:11:25 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LBOOVxDE; spf=pass (domain: gmail.com, ip: 209.85.167.43, mailfrom: savvamtr@gmail.com) Received: by mail-lf1-f43.google.com with SMTP id d6so7742979lfs.10 for ; Fri, 09 Dec 2022 08:11:24 -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=7a7xxl5GeZymJqF8AVBUeE0cNURL0usioLW25tbLXVE=; b=LBOOVxDEgdbaTKitwXWkU7LL0E702JOjMssxl0BJAYbFanq70EThPcm99DEzz9HHG0 tICZHpT8Cx+XjF/eSBLIkJNc+O/6doNl1EIQapPJmpyc0Dhzj1oC60wUqDLej16/W+7R usVbiWgkIch/ZZoKZfEMM7cKPhdc8+2F2nGL5pRpOqqdRdgjM0jKL2hcs84i/HJKdhHA es92Xw8W7E2XWDNKz3tvPloawIcJwhgyT0X+HVG4oMJuC8kkFej/7ubZ4K6Ezvg9IHpN FSt+LaIpX+0Dv/uD6ObpkHG6RowT1Kb3M+XikI2OBtu6Wxm/JTDfxAt08qCNFxrB0uPb iPmA== 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=7a7xxl5GeZymJqF8AVBUeE0cNURL0usioLW25tbLXVE=; b=WvuK9vWxVbGha9PZW2gZk++SfT2enVEI2b5GMUYBpc7Pkd9WRc1dmMerqrAVNnAko4 uWT8pGHJUmY6ueFcUtdYpKsjQx4dPYch683FNdThSlYTc1xTNuky1KFXAciMYSQLjCNg t/b3YE0byLVsu7WSmGbAXYorGyRZTmomcaktL4Z8Q981iEgpRsZSO95mBr7Q6YbYVuyP 2HSwqYeCOtTBp3P/PubxDZl7aKejsYIY+h00sZ7Sd/FP6qnVi9MJglaIIylQkf3TCHBo i6j5BsiTJWh5007bfB/7Zmk8pmFm/pvtH4Go7KF3tQArmJyZzFSFo/863BRxLoMXvfCz mjoQ== X-Gm-Message-State: ANoB5pneZlfbYAE8PC+SeZtBucf/u+k5ER6mHwbngYB/QXOw1G09qdXv geP5NMQphmwOFBcoTaPxEFiEfn5NBrP5O7dO X-Google-Smtp-Source: AA0mqf4js2NK6wqVXaq8OBEk8XxOQ516DsblrX6oaXz6snkQZp9xWAvJltQq5RbCsIMM1BE3rmtYEA== X-Received: by 2002:ac2:4c98:0:b0:4b5:688e:ee10 with SMTP id d24-20020ac24c98000000b004b5688eee10mr1637863lfl.16.1670602282709; Fri, 09 Dec 2022 08:11:22 -0800 (PST) Return-Path: Received: from localhost.localdomain ([109.194.121.139]) by smtp.gmail.com with ESMTPSA id v5-20020a05651203a500b00492c663bba2sm318430lfp.124.2022.12.09.08.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 08:11:22 -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 v1 08/12] Ext4Pkg: Fix shift out of bounds in Ext4OpenSuperblock Date: Fri, 9 Dec 2022 22:11:00 +0600 Message-Id: <20221209161104.70220-9-savvamtr@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221209161104.70220-1-savvamtr@gmail.com> References: <20221209161104.70220-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 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 d135892633af..0600a75d6750 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