Skip to content

Commit 9e0bced

Browse files
onikombroz
authored andcommitted
Harden LUKS2 volume key compare helper.
1 parent 6123ea2 commit 9e0bced

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/setup.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,10 +3215,15 @@ static int _compare_volume_keys_luks2(struct volume_key *svk, struct volume_key
32153215
if (crypt_volume_key_length(svk) != crypt_volume_key_length(tvk))
32163216
return 1;
32173217

3218-
if (crypt_volume_key_is_set(svk) && crypt_volume_key_is_set(tvk))
3219-
return crypt_backend_memeq(crypt_volume_key_get_key(svk),
3220-
crypt_volume_key_get_key(tvk),
3221-
crypt_volume_key_length(svk));
3218+
if ((!crypt_volume_key_is_set(svk) && !crypt_volume_key_description(svk)) ||
3219+
(!crypt_volume_key_is_set(tvk) && !crypt_volume_key_description(tvk)))
3220+
return 1;
3221+
3222+
if (crypt_volume_key_is_set(svk) && crypt_volume_key_is_set(tvk) &&
3223+
crypt_backend_memeq(crypt_volume_key_get_key(svk),
3224+
crypt_volume_key_get_key(tvk),
3225+
crypt_volume_key_length(svk)))
3226+
return 1;
32223227

32233228
if (crypt_volume_key_description(svk) && crypt_volume_key_description(tvk))
32243229
return (crypt_volume_key_kernel_key_type(svk) != crypt_volume_key_kernel_key_type(tvk) ||

0 commit comments

Comments
 (0)