0

So I'm making some kind of research on EXT4 checksums.

I found this page and tried to calculate checksum by myself. I've started with Superblock since it is sounds pretty simple: "The entire superblock up to the checksum field".

But it does not work: I can't get the same result as the superblock.

For this task I wrote superblock checksum calculator on Python. You may look at my program on GitHub. I tried a lot of things.

First of all, I tried to read the whole superblock up to checksum (1020 bytes) and put it in CRC32C (algorithm is independent library from pip). Although this was written in wiki, this does not work.

Then I simply reversed the whole superblock. It has not much sense, I think. And I failed again.

After this, I tried more complicated way. I tried to reverse all fields of the superblock separately. It gives another result as you can see:

Raw data: 1F DC 5E 4A

2-byte fields reversed: DC 1F 4A 5E

Full data reverse: 4A 5E DC 1F

And once again, I failed. Here all interpretations of phrase "The entire superblock up to the checksum field" ended.

I tried to add zero-filled checksum field to all algorithms and tried to reverse only little-endian fields (seemed like a good idea actually), without reversing char and u8 fields.

But there is no chance to get the same checksum as the original superblock.

My script makes output like this for superblock:

00c0390000cae600198a0b00c6aca40039a835000000000002000000020000000080000000800000002000001ee68c5c17e68c5c2000ffff53ef01000100000055936d5c000000000000000001000000000000000b000000000100003c000000c60200006b040000d6eb1a5613a44a8a91b66dbfe7cbbca9000000000000000000000000000000002f0061726765740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000800000000000000f00c3000ca7d5363a49944fd9db16c0f95cfab15010140000c0000000000000055936d5c0af3020004000000000000000000000000800000008070000080000000800000000071000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000200020000100000000000000000000000000000000000000040100000d63df0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fe3731ed

ORIGINAL CHECKSUM (not calculated!): 0xfe3731ed

CALCULATED WHOLE SUPERBLOCK: 0xffffffffL - this always happens, some overflow error maybe.

CALCULATED SUPERBLOCK WITHOUT CHECKSUM: 0x12cec801L

CALCULATED FULLY-REVERSED SUPERBLOCK WITHOUT CHECKSUM: 0x7fe225e5L

CALCULATED FIELDS-REVERSED SUPERBLOCK: 0x8cce5045L

I can't find any documentation, and ext4 source code files are poorly commented (and really complicated), I can't make any sense of them.

  • 1
    Note the reason that you always get 0xffffffff when calculating the whole-superblock checksum is not a bug, but rather that the last field in the superblock and in your checksum is always the checksum itself. – LustreOne Mar 20 at 1:24
1

OK. I've got the answer from Reddit (nightbladeofmalice). This man noticed that checksum of the raw superblock without checksum field (0x12cec801) will give reversed (in big-endian) original checksum if you subtract it from 0xFFFFFFFF:

ORIGINAL SUPERBLOCK: 00c0390000cae600198a0b008f99a400e8a53500000000000200000002000000008000000080000000200000082d8e5c012d8e5c2100ffff53ef01000100000055936d5c000000000000000001000000000000000b000000000100003c000000c60200006b040000d6eb1a5613a44a8a91b66dbfe7cbbca9000000000000000000000000000000002f00617267657400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000008000000000000008e013000ca7d5363a49944fd9db16c0f95cfab15010140000c0000000000000055936d5c0af302000400000000000000000000000080000000807000008000000080000000007100000000000000000000000000000000000000000000000000000000000000001000000000000000000000000020002000010000000000000000000000000000000000000004010000df1b5b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015de7cf3

ORIGINAL CHECKSUM (not calculated, big endian!): 0xf37cde15

RAW SUPERBLOCK IN CRC32C WITHOUT CHECKSUM FIELDS (1020 bytes): 0xc8321eaL

INVERTED CHECKSUM (0xFFFFFFFF-previous field): 0xf37cde15L

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.