Commit fb445437 authored by Eric Biggers's avatar Eric Biggers Committed by Theodore Ts'o

fscrypto: make XTS tweak initialization endian-independent

The XTS tweak (or IV) was initialized differently on little endian and
big endian systems.  Because the ciphertext depends on the XTS tweak, it
was not possible to use an encrypted filesystem created by a little
endian system on a big endian system and vice versa, even if they shared
the same PAGE_SIZE.  Fix this by always using little endian.

This will break hypothetical big endian users of ext4 or f2fs
encryption.  However, all users we are aware of are little endian, and
it's believed that "real" big endian users are unlikely to exist yet.
So this might as well be fixed now before it's too late.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
parent c4704a4f
...@@ -151,7 +151,10 @@ static int do_page_crypto(struct inode *inode, ...@@ -151,7 +151,10 @@ static int do_page_crypto(struct inode *inode,
struct page *src_page, struct page *dest_page, struct page *src_page, struct page *dest_page,
gfp_t gfp_flags) gfp_t gfp_flags)
{ {
u8 xts_tweak[FS_XTS_TWEAK_SIZE]; struct {
__le64 index;
u8 padding[FS_XTS_TWEAK_SIZE - sizeof(__le64)];
} xts_tweak;
struct skcipher_request *req = NULL; struct skcipher_request *req = NULL;
DECLARE_FS_COMPLETION_RESULT(ecr); DECLARE_FS_COMPLETION_RESULT(ecr);
struct scatterlist dst, src; struct scatterlist dst, src;
...@@ -171,17 +174,15 @@ static int do_page_crypto(struct inode *inode, ...@@ -171,17 +174,15 @@ static int do_page_crypto(struct inode *inode,
req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
page_crypt_complete, &ecr); page_crypt_complete, &ecr);
BUILD_BUG_ON(FS_XTS_TWEAK_SIZE < sizeof(index)); BUILD_BUG_ON(sizeof(xts_tweak) != FS_XTS_TWEAK_SIZE);
memcpy(xts_tweak, &index, sizeof(index)); xts_tweak.index = cpu_to_le64(index);
memset(&xts_tweak[sizeof(index)], 0, memset(xts_tweak.padding, 0, sizeof(xts_tweak.padding));
FS_XTS_TWEAK_SIZE - sizeof(index));
sg_init_table(&dst, 1); sg_init_table(&dst, 1);
sg_set_page(&dst, dest_page, PAGE_SIZE, 0); sg_set_page(&dst, dest_page, PAGE_SIZE, 0);
sg_init_table(&src, 1); sg_init_table(&src, 1);
sg_set_page(&src, src_page, PAGE_SIZE, 0); sg_set_page(&src, src_page, PAGE_SIZE, 0);
skcipher_request_set_crypt(req, &src, &dst, PAGE_SIZE, skcipher_request_set_crypt(req, &src, &dst, PAGE_SIZE, &xts_tweak);
xts_tweak);
if (rw == FS_DECRYPT) if (rw == FS_DECRYPT)
res = crypto_skcipher_decrypt(req); res = crypto_skcipher_decrypt(req);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment