Skip to content

Commit 1856b9f

Browse files
mbrozsnitm
authored andcommitted
dm crypt: fix parsing of extended IV arguments
The dm-crypt cipher specification in a mapping table is defined as: cipher[:keycount]-chainmode-ivmode[:ivopts] or (new crypt API format): capi:cipher_api_spec-ivmode[:ivopts] For ESSIV, the parameter includes hash specification, for example: aes-cbc-essiv:sha256 The implementation expected that additional IV option to never include another dash '-' character. But, with SHA3, there are names like sha3-256; so the mapping table parser fails: dmsetup create test --table "0 8 crypt aes-cbc-essiv:sha3-256 9c1185a5c5e9fc54612808977ee8f5b9e 0 /dev/sdb 0" or (new crypt API format) dmsetup create test --table "0 8 crypt capi:cbc(aes)-essiv:sha3-256 9c1185a5c5e9fc54612808977ee8f5b9e 0 /dev/sdb 0" device-mapper: crypt: Ignoring unexpected additional cipher options device-mapper: table: 253:0: crypt: Error creating IV device-mapper: ioctl: error adding target to table Fix the dm-crypt constructor to ignore additional dash in IV options and also remove a bogus warning (that is ignored anyway). Cc: stable@vger.kernel.org # 4.12+ Signed-off-by: Milan Broz <gmazyland@gmail.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent bfeffd1 commit 1856b9f

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

drivers/md/dm-crypt.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,9 +2414,21 @@ static int crypt_ctr_cipher_new(struct dm_target *ti, char *cipher_in, char *key
24142414
* capi:cipher_api_spec-iv:ivopts
24152415
*/
24162416
tmp = &cipher_in[strlen("capi:")];
2417-
cipher_api = strsep(&tmp, "-");
2418-
*ivmode = strsep(&tmp, ":");
2419-
*ivopts = tmp;
2417+
2418+
/* Separate IV options if present, it can contain another '-' in hash name */
2419+
*ivopts = strrchr(tmp, ':');
2420+
if (*ivopts) {
2421+
**ivopts = '\0';
2422+
(*ivopts)++;
2423+
}
2424+
/* Parse IV mode */
2425+
*ivmode = strrchr(tmp, '-');
2426+
if (*ivmode) {
2427+
**ivmode = '\0';
2428+
(*ivmode)++;
2429+
}
2430+
/* The rest is crypto API spec */
2431+
cipher_api = tmp;
24202432

24212433
if (*ivmode && !strcmp(*ivmode, "lmk"))
24222434
cc->tfms_count = 64;
@@ -2486,11 +2498,8 @@ static int crypt_ctr_cipher_old(struct dm_target *ti, char *cipher_in, char *key
24862498
goto bad_mem;
24872499

24882500
chainmode = strsep(&tmp, "-");
2489-
*ivopts = strsep(&tmp, "-");
2490-
*ivmode = strsep(&*ivopts, ":");
2491-
2492-
if (tmp)
2493-
DMWARN("Ignoring unexpected additional cipher options");
2501+
*ivmode = strsep(&tmp, ":");
2502+
*ivopts = tmp;
24942503

24952504
/*
24962505
* For compatibility with the original dm-crypt mapping format, if

0 commit comments

Comments
 (0)