Skip to contentSkip to conversation

btrfs-progs: Fix xxhash on big endian machines

PATCH In review Nikolay Borisov 3 participants 4 messages Mar 16, 2020 – Mar 17, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: Fix xxhash on big endian machines

xxhash's state and results are always in little, but in progs after the hash was calculated it was copied to the final buffer via memcpy, meaning it'd be parsed as a big endian number on big endian machines. This is incompatible with the kernel implementation of xxhash which results in erroneous "checksum didn't match" errors on mount.

Fix it by using put_unaligned_le64 which always ensures the resulting checksum will be copied in little endian format as the kernel expects it.

Fixes f070ece2e98f ("btrfs-progs: add xxhash64 to mkfs")
---
 crypto/hash.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
crypto/hash.c +1 -6
index 48623c798739..4009e84e8b2c 100644
@@ -19,12 +19,7 @@ int hash_xxhash(const u8 *buf, size_t length, u8 *out)
 	XXH64_hash_t hash;
 
 	hash = XXH64(buf, length, 0);
-	/*
-	 * NOTE: we're not taking the canonical form here but the plain hash to
-	 * be compatible with the kernel implementation!
-	 */
-	memcpy(out, &hash, 8);
-
+	put_unaligned_le64(&hash, out);
 	return 0;
 }
 

--
2.17.1

#2 lore raw
In reply to Nikolay Borisov
Quoted 6 lines · Nikolay Borisov

xxhash's state and results are always in little, but in progs after the hash was calculated it was copied to the final buffer via memcpy, meaning it'd be parsed as a big endian number on big endian machines. This is incompatible with the kernel implementation of xxhash which results in erroneous "checksum didn't match" errors on mount.

Quoted 7 lines

Fix it by using put_unaligned_le64 which always ensures the resulting checksum will be copied in little endian format as the kernel expects it.

Fixes f070ece2e98f ("btrfs-progs: add xxhash64 to mkfs")

Added to devel, thanks.

#3 lore raw
In reply to Nikolay Borisov
Quoted 22 lines · Nikolay Borisov

xxhash's state and results are always in little, but in progs after the hash was calculated it was copied to the final buffer via memcpy, meaning it'd be parsed as a big endian number on big endian machines. This is incompatible with the kernel implementation of xxhash which results in erroneous "checksum didn't match" errors on mount.

Fix it by using put_unaligned_le64 which always ensures the resulting checksum will be copied in little endian format as the kernel expects it.

Fixes f070ece2e98f ("btrfs-progs: add xxhash64 to mkfs")
---
 crypto/hash.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
crypto/hash.c +0 -0
index 48623c798739..4009e84e8b2c 100644

crypto/hash.c int hash_xxhash(const u8 *buf, size_t length, u8 *out) · line 22

Quoted 10 lines
crypto/hash.c +1 -6
@@ -19,12 +19,7 @@ int hash_xxhash(const u8 *buf, size_t length, u8 *out)
 	XXH64_hash_t hash;
 
 	hash = XXH64(buf, length, 0);
-	/*
-	 * NOTE: we're not taking the canonical form here but the plain hash to
-	 * be compatible with the kernel implementation!
-	 */
-	memcpy(out, &hash, 8);
-
+	put_unaligned_le64(&hash, out);

This does not work, the test mkfs/019 fails.