* [PATCH] fscrypt: fix derivation of SipHash keys on big endian CPUs
@ 2021-05-27 22:55 Eric Biggers
2021-06-05 7:29 ` Eric Biggers
0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2021-05-27 22:55 UTC (permalink / raw)
To: linux-fscrypt; +Cc: linux-ext4, linux-f2fs-devel, Daniel Rosenberg, stable
From: Eric Biggers <ebiggers@google.com>
Typically, the cryptographic APIs that fscrypt uses take keys as byte
arrays, which avoids endianness issues. However, siphash_key_t is an
exception. It is defined as 'u64 key[2];', i.e. the 128-bit key is
expected to be given directly as two 64-bit words in CPU endianness.
fscrypt_derive_dirhash_key() forgot to take this into account.
Therefore, the SipHash keys used to index encrypted+casefolded
directories differ on big endian vs. little endian platforms.
This makes such directories non-portable between these platforms.
Fix this by always using the little endian order. This is a breaking
change for big endian platforms, but this should be fine in practice
since the encrypt+casefold support isn't known to actually be used on
any big endian platforms yet.
Fixes: aa408f835d02 ("fscrypt: derive dirhash key for casefolded directories")
Cc: <stable@vger.kernel.org> # v5.6+
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
fs/crypto/keysetup.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c
index 261293fb7097..4d98377c07a7 100644
--- a/fs/crypto/keysetup.c
+++ b/fs/crypto/keysetup.c
@@ -221,6 +221,16 @@ int fscrypt_derive_dirhash_key(struct fscrypt_info *ci,
sizeof(ci->ci_dirhash_key));
if (err)
return err;
+
+ /*
+ * The SipHash APIs expect the key as a pair of 64-bit words, not as a
+ * byte array. Make sure to use a consistent endianness.
+ */
+ BUILD_BUG_ON(sizeof(ci->ci_dirhash_key) != 16);
+ BUILD_BUG_ON(ARRAY_SIZE(ci->ci_dirhash_key.key) != 2);
+ le64_to_cpus(&ci->ci_dirhash_key.key[0]);
+ le64_to_cpus(&ci->ci_dirhash_key.key[1]);
+
ci->ci_dirhash_key_initialized = true;
return 0;
}
--
2.32.0.rc0.204.g9fa02ecfa5-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fscrypt: fix derivation of SipHash keys on big endian CPUs
2021-05-27 22:55 [PATCH] fscrypt: fix derivation of SipHash keys on big endian CPUs Eric Biggers
@ 2021-06-05 7:29 ` Eric Biggers
0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2021-06-05 7:29 UTC (permalink / raw)
To: linux-fscrypt; +Cc: linux-ext4, stable, Daniel Rosenberg, linux-f2fs-devel
On Thu, May 27, 2021 at 03:55:25PM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> Typically, the cryptographic APIs that fscrypt uses take keys as byte
> arrays, which avoids endianness issues. However, siphash_key_t is an
> exception. It is defined as 'u64 key[2];', i.e. the 128-bit key is
> expected to be given directly as two 64-bit words in CPU endianness.
>
> fscrypt_derive_dirhash_key() forgot to take this into account.
> Therefore, the SipHash keys used to index encrypted+casefolded
> directories differ on big endian vs. little endian platforms.
> This makes such directories non-portable between these platforms.
>
> Fix this by always using the little endian order. This is a breaking
> change for big endian platforms, but this should be fine in practice
> since the encrypt+casefold support isn't known to actually be used on
> any big endian platforms yet.
>
> Fixes: aa408f835d02 ("fscrypt: derive dirhash key for casefolded directories")
> Cc: <stable@vger.kernel.org> # v5.6+
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> fs/crypto/keysetup.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
I missed that fscrypt_setup_iv_ino_lblk_32_key() has the same bug too.
I'll send out a new patch which fixes both of these...
- Eric
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-05 7:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 22:55 [PATCH] fscrypt: fix derivation of SipHash keys on big endian CPUs Eric Biggers
2021-06-05 7:29 ` Eric Biggers
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).