linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: Fix xxhash on big endian machines
@ 2020-03-16  9:05 Nikolay Borisov
  2020-03-16  9:26 ` Johannes Thumshirn
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nikolay Borisov @ 2020-03-16  9:05 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Johannes.Thumshirn, 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.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=206835
Fixes: f070ece2e98f ("btrfs-progs: add xxhash64 to mkfs")
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 crypto/hash.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/crypto/hash.c b/crypto/hash.c
index 48623c798739..4009e84e8b2c 100644
--- a/crypto/hash.c
+++ b/crypto/hash.c
@@ -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


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

* Re: [PATCH] btrfs-progs: Fix xxhash on big endian machines
  2020-03-16  9:05 [PATCH] btrfs-progs: Fix xxhash on big endian machines Nikolay Borisov
@ 2020-03-16  9:26 ` Johannes Thumshirn
  2020-03-16 22:56 ` David Sterba
  2020-03-17 20:34 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2020-03-16  9:26 UTC (permalink / raw)
  To: Nikolay Borisov, linux-btrfs

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH] btrfs-progs: Fix xxhash on big endian machines
  2020-03-16  9:05 [PATCH] btrfs-progs: Fix xxhash on big endian machines Nikolay Borisov
  2020-03-16  9:26 ` Johannes Thumshirn
@ 2020-03-16 22:56 ` David Sterba
  2020-03-17 20:34 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2020-03-16 22:56 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs, Johannes.Thumshirn

On Mon, Mar 16, 2020 at 11:05:12AM +0200, Nikolay Borisov wrote:
> 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.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=206835
> Fixes: f070ece2e98f ("btrfs-progs: add xxhash64 to mkfs")
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Added to devel, thanks.

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

* Re: [PATCH] btrfs-progs: Fix xxhash on big endian machines
  2020-03-16  9:05 [PATCH] btrfs-progs: Fix xxhash on big endian machines Nikolay Borisov
  2020-03-16  9:26 ` Johannes Thumshirn
  2020-03-16 22:56 ` David Sterba
@ 2020-03-17 20:34 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2020-03-17 20:34 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs, Johannes.Thumshirn

On Mon, Mar 16, 2020 at 11:05:12AM +0200, Nikolay Borisov wrote:
> 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.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=206835
> Fixes: f070ece2e98f ("btrfs-progs: add xxhash64 to mkfs")
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>  crypto/hash.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/crypto/hash.c b/crypto/hash.c
> index 48623c798739..4009e84e8b2c 100644
> --- a/crypto/hash.c
> +++ b/crypto/hash.c
> @@ -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.

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

end of thread, other threads:[~2020-03-17 20:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16  9:05 [PATCH] btrfs-progs: Fix xxhash on big endian machines Nikolay Borisov
2020-03-16  9:26 ` Johannes Thumshirn
2020-03-16 22:56 ` David Sterba
2020-03-17 20:34 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).