[edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups

Pedro Falcato posted 1 patch 5 months ago
Failed in applying to current master (apply log)
Features/Ext4Pkg/Ext4Dxe/BlockGroup.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
[edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups
Posted by Pedro Falcato 5 months ago
Old filesystems (around 2008 and older) do not use CRC32c
but rather CRC16-ANSI. Previously, the CalculateCrc16Ansi function was
broken and gave us wrong checksums. Adapt to the new interface.

And while we're at it, fix the checksum algorithm itself - the crc16
algorithm just skips over the bg_checksum, and does not checksum it.

This problem was found out-of-list when older ext4 filesystems
(that use crc16 checksums) failed to mount with "corruption".

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4609
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
Cc: Savva Mitrofanov <savvamtr@gmail.com>
Cc: Marvin Häuser <mhaeuser@posteo.de>
---
 Features/Ext4Pkg/Ext4Dxe/BlockGroup.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c b/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c
index f34cdc5dbad7..d5642a5f155c 100644
--- a/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c
+++ b/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c
@@ -169,14 +169,10 @@ Ext4CalculateBlockGroupDescChecksumGdtCsum (
   )
 {
   UINT16  Csum;
-  UINT16  Dummy;
 
-  Dummy = 0;
-
-  Csum = CalculateCrc16Ansi (Partition->SuperBlock.s_uuid, 16, 0);
+  Csum = CalculateCrc16Ansi (Partition->SuperBlock.s_uuid, 16, CRC16ANSI_INIT);
   Csum = CalculateCrc16Ansi (&BlockGroupNum, sizeof (BlockGroupNum), Csum);
   Csum = CalculateCrc16Ansi (BlockGroupDesc, OFFSET_OF (EXT4_BLOCK_GROUP_DESC, bg_checksum), Csum);
-  Csum = CalculateCrc16Ansi (&Dummy, sizeof (Dummy), Csum);
   Csum =
     CalculateCrc16Ansi (
       &BlockGroupDesc->bg_block_bitmap_hi,
-- 
2.43.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111997): https://edk2.groups.io/g/devel/message/111997
Mute This Topic: https://groups.io/mt/102960519/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups
Posted by Marvin Häuser 5 months ago
Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>

> On Dec 3, 2023, at 23:41, Pedro Falcato <pedro.falcato@gmail.com> wrote:
> 
> Old filesystems (around 2008 and older) do not use CRC32c
> but rather CRC16-ANSI. Previously, the CalculateCrc16Ansi function was
> broken and gave us wrong checksums. Adapt to the new interface.
> 
> And while we're at it, fix the checksum algorithm itself - the crc16
> algorithm just skips over the bg_checksum, and does not checksum it.
> 
> This problem was found out-of-list when older ext4 filesystems
> (that use crc16 checksums) failed to mount with "corruption".
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4609
> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
> Cc: Savva Mitrofanov <savvamtr@gmail.com>
> Cc: Marvin Häuser <mhaeuser@posteo.de>
> ---
> Features/Ext4Pkg/Ext4Dxe/BlockGroup.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c b/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c
> index f34cdc5dbad7..d5642a5f155c 100644
> --- a/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c
> +++ b/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c
> @@ -169,14 +169,10 @@ Ext4CalculateBlockGroupDescChecksumGdtCsum (
>   )
> {
>   UINT16  Csum;
> -  UINT16  Dummy;
> 
> -  Dummy = 0;
> -
> -  Csum = CalculateCrc16Ansi (Partition->SuperBlock.s_uuid, 16, 0);
> +  Csum = CalculateCrc16Ansi (Partition->SuperBlock.s_uuid, 16, CRC16ANSI_INIT);
>   Csum = CalculateCrc16Ansi (&BlockGroupNum, sizeof (BlockGroupNum), Csum);
>   Csum = CalculateCrc16Ansi (BlockGroupDesc, OFFSET_OF (EXT4_BLOCK_GROUP_DESC, bg_checksum), Csum);
> -  Csum = CalculateCrc16Ansi (&Dummy, sizeof (Dummy), Csum);
>   Csum =
>     CalculateCrc16Ansi (
>       &BlockGroupDesc->bg_block_bitmap_hi,
> --
> 2.43.0
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111998): https://edk2.groups.io/g/devel/message/111998
Mute This Topic: https://groups.io/mt/102960519/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups
Posted by Pedro Falcato 5 months ago
On Sun, Dec 3, 2023 at 10:56 PM Marvin Häuser <mhaeuser@posteo.de> wrote:
>
> Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>

Thank you!

Pushed as b95395b.

-- 
Pedro


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111999): https://edk2.groups.io/g/devel/message/111999
Mute This Topic: https://groups.io/mt/102960519/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-