From: Konrad Rzeszutek Wilk Date: Mon, 27 Aug 2018 16:43:21 +0000 (-0400) Subject: dm crypt: add middle-endian variant of plain64 IV X-Git-Tag: v4.1.12-124.31.3~521 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=03f9b8c23f31b03d712d7b064e4d5d4620781e01;p=users%2Fjedix%2Flinux-maple.git dm crypt: add middle-endian variant of plain64 IV The big-endian IV (plain64be) backend implementation has bugs and ended up with a weird middle endian (left shift by 32). Adding a new module for this. The middle endian is this weirdness where the value is shifted to the middle (and also wraps): iv: 00000000000000010000000000000000 instead of: iv: 00000000000000000000000000000001 Orabug: 28604628 Reviewed-by: Mark Kanda Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Brian Maly --- diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index f3a8f0eeb0e30..b544935ca35bc 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -271,6 +271,16 @@ static int crypt_iv_plain64be_gen(struct crypt_config *cc, u8 *iv, return 0; } +static int crypt_iv_plain64me_gen(struct crypt_config *cc, u8 *iv, + struct dm_crypt_request *dmreq) +{ + memset(iv, 0, cc->iv_size); + /* iv_size is at least of size u64; usually it is 16 bytes */ + *(__be64 *)&iv[0] = cpu_to_be64(dmreq->iv_sector); + + return 0; +} + /* Initialise ESSIV - compute salt but no local memory allocations */ static int crypt_iv_essiv_init(struct crypt_config *cc) { @@ -780,6 +790,10 @@ static struct crypt_iv_operations crypt_iv_plain64be_ops = { .generator = crypt_iv_plain64be_gen }; +static struct crypt_iv_operations crypt_iv_plain64me_ops = { + .generator = crypt_iv_plain64me_gen +}; + static struct crypt_iv_operations crypt_iv_essiv_ops = { .ctr = crypt_iv_essiv_ctr, .dtr = crypt_iv_essiv_dtr, @@ -1659,6 +1673,8 @@ static int crypt_ctr_cipher(struct dm_target *ti, cc->iv_gen_ops = &crypt_iv_plain_ops; else if (strcmp(ivmode, "plain64") == 0) cc->iv_gen_ops = &crypt_iv_plain64_ops; + else if (strcmp(ivmode, "plain64me") == 0) + cc->iv_gen_ops = &crypt_iv_plain64me_ops; else if (strcmp(ivmode, "plain64be") == 0) cc->iv_gen_ops = &crypt_iv_plain64be_ops; else if (strcmp(ivmode, "essiv") == 0)