]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
dm crypt: add middle-endian variant of plain64 IV
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Mon, 27 Aug 2018 16:43:21 +0000 (12:43 -0400)
committerBrian Maly <brian.maly@oracle.com>
Wed, 26 Sep 2018 00:44:13 +0000 (20:44 -0400)
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 <mark.kanda@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Brian Maly <brian.maly@oracle.com>
drivers/md/dm-crypt.c

index f3a8f0eeb0e303afb46a53a08101f7be1766d2b7..b544935ca35bc3d3ce75a04045fbcf42b9b1b295 100644 (file)
@@ -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)