]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup: do not assert when unsealing token without salt
authorLuca Boccassi <bluca@debian.org>
Wed, 15 Feb 2023 00:44:01 +0000 (00:44 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 15 Feb 2023 18:01:28 +0000 (18:01 +0000)
Salt was added in v253. We are not checking whether it was actually found
(non-zero size), so when an old tpm+pin enrollment is opened things go boom.
For good measure, check both the buffer and the size in both places.

Assertion 'saltlen > 0' failed at src/shared/tpm2-util.c:2490, function tpm2_util_pbkdf2_hmac_sha256(). Aborting.

src/cryptsetup/cryptsetup-tokens/luks2-tpm2.c
src/cryptsetup/cryptsetup-tpm2.c
src/shared/tpm2-util.c

index 80a2c0d31611114bc1c6c866d941ad2e55acef8b..c4377230cad732c950c94d83f36cdb60eb11e240 100644 (file)
@@ -38,6 +38,7 @@ int acquire_luks2_key(
         _cleanup_(erase_and_freep) char *b64_salted_pin = NULL;
         int r;
 
+        assert(salt || salt_size == 0);
         assert(ret_decrypted_key);
         assert(ret_decrypted_key_size);
 
@@ -58,7 +59,7 @@ int acquire_luks2_key(
         if ((flags & TPM2_FLAGS_USE_PIN) && salt && !pin)
                 return -ENOANO;
 
-        if (pin) {
+        if (pin && salt_size > 0) {
                 uint8_t salted_pin[SHA256_DIGEST_SIZE] = {};
                 CLEANUP_ERASE(salted_pin);
                 r = tpm2_util_pbkdf2_hmac_sha256(pin, strlen(pin), salt, salt_size, salted_pin);
index 2a8a38c593892ac7921fab401db399a2adb0ee83..a375a227586d87383823e430f9ae1c0d94a9c2f0 100644 (file)
@@ -86,6 +86,8 @@ int acquire_tpm2_key(
         const void *blob;
         int r;
 
+        assert(salt || salt_size == 0);
+
         if (!device) {
                 r = tpm2_find_device_auto(LOG_DEBUG, &auto_device);
                 if (r == -ENODEV)
@@ -152,7 +154,7 @@ int acquire_tpm2_key(
                 if (r < 0)
                         return r;
 
-                if (salt) {
+                if (salt_size > 0) {
                         uint8_t salted_pin[SHA256_DIGEST_SIZE] = {};
                         CLEANUP_ERASE(salted_pin);
 
index 6552e66bf4ec0599e4712baea6b426dc0f23a240..259f280e0fca8c1e0f5300da6060bb0fbef7045b 100644 (file)
@@ -2487,6 +2487,7 @@ int tpm2_util_pbkdf2_hmac_sha256(const void *pass,
          */
         static const uint8_t block_cnt[] = { 0, 0, 0, 1 };
 
+        assert (salt);
         assert (saltlen > 0);
         assert (saltlen <= (SIZE_MAX - sizeof(block_cnt)));
         assert (passlen > 0);