public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups
@ 2023-12-03 22:40 Pedro Falcato
  2023-12-03 22:55 ` Marvin Häuser
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Falcato @ 2023-12-03 22:40 UTC (permalink / raw)
  To: devel; +Cc: Pedro Falcato, Savva Mitrofanov, Marvin Häuser

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/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups
  2023-12-03 22:40 [edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups Pedro Falcato
@ 2023-12-03 22:55 ` Marvin Häuser
  2023-12-03 23:37   ` Pedro Falcato
  0 siblings, 1 reply; 3+ messages in thread
From: Marvin Häuser @ 2023-12-03 22:55 UTC (permalink / raw)
  To: Pedro Falcato; +Cc: devel, Savva Mitrofanov

[-- Attachment #1: Type: text/plain, Size: 2194 bytes --]

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/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2422 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups
  2023-12-03 22:55 ` Marvin Häuser
@ 2023-12-03 23:37   ` Pedro Falcato
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Falcato @ 2023-12-03 23:37 UTC (permalink / raw)
  To: Marvin Häuser; +Cc: devel, Savva Mitrofanov

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/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-03 23:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-03 22:40 [edk2-devel] [PATCH] Ext4Pkg: Fix CRC16 checksumming on block groups Pedro Falcato
2023-12-03 22:55 ` Marvin Häuser
2023-12-03 23:37   ` Pedro Falcato

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox