Skip to contentSkip to conversation

luks2: Improve error reporting when decrypting/verifying key

PATCH In review Patrick Steinhardt 2 participants 9 messages Apr 16, 2020 – May 30, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 luks2: Improve error reporting when decrypting/verifying key

While we already set up error messages in both luks2_verify_key() and luks2_decrypt_key(), we do not ever print them. This makes it really hard to discover why a given key actually failed to decrypt a disk.

Improve this by including the error message in the user-visible output.

---
 grub-core/disk/luks2.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
grub-core/disk/luks2.c +5 -3
index 65c4f0aac..a48bddf5d 100644
@@ -487,7 +487,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
   ret = grub_disk_read (disk, 0, k->area.offset, k->area.size, split_key);
   if (ret)
     {
-      grub_dprintf ("luks2", "Read error: %s\n", grub_errmsg);
+      grub_error (GRUB_ERR_IO, "Read error: %s\n", grub_errmsg);
       goto err;
     }
 
@@ -610,14 +610,16 @@ luks2_recover_key (grub_disk_t disk,
 			       (const grub_uint8_t *) passphrase, grub_strlen (passphrase));
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed\n", i);
+	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed: %s\n",
+			i, grub_errmsg);
 	  continue;
 	}
 
       ret = luks2_verify_key (&digest, candidate_key, keyslot.key_size);
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE"\n", i);
+	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE": %s\n",
+			i, grub_errmsg);
 	  continue;
 	}
 
Signature · 1 line
2.26.1
#1 lore raw
Quoted 16 lines · Patrick Steinhardt

While we already set up error messages in both luks2_verify_key() and luks2_decrypt_key(), we do not ever print them. This makes it really hard to discover why a given key actually failed to decrypt a disk.

Improve this by including the error message in the user-visible output.

---
 grub-core/disk/luks2.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
grub-core/disk/luks2.c +0 -0
index 65c4f0aac..a48bddf5d 100644

grub-core/disk/luks2.c luks2_decrypt_key (grub_uint8_t *out_key, · line 492

Quoted 7 lines
grub-core/disk/luks2.c +1 -1
@@ -487,7 +487,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
   ret = grub_disk_read (disk, 0, k->area.offset, k->area.size, split_key);
   if (ret)
     {
-      grub_dprintf ("luks2", "Read error: %s\n", grub_errmsg);
+      grub_error (GRUB_ERR_IO, "Read error: %s\n", grub_errmsg);
       goto err;
     }

AIUI the commit message says about this change but...

Quoted 7 lines
grub-core/disk/luks2.c +2 -1
@@ -610,14 +610,16 @@ luks2_recover_key (grub_disk_t disk,
 			       (const grub_uint8_t *) passphrase, grub_strlen (passphrase));
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed\n", i);
+	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed: %s\n",
+			i, grub_errmsg);

grub-core/disk/luks2.c luks2_recover_key (grub_disk_t disk, · line 623

Quoted 10 lines
grub-core/disk/luks2.c +2 -1
 	  continue;
 	}
 
       ret = luks2_verify_key (&digest, candidate_key, keyslot.key_size);
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE"\n", i);
+	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE": %s\n",
+			i, grub_errmsg);
 	  continue;

...it does not say anything about these changes. If you update commit message you can add Reviewed-by: Daniel Kiper <[email protected]>

Daniel

#2 lore raw
Quoted 48 lines · Daniel Kiper
Quoted 16 lines · Patrick Steinhardt

While we already set up error messages in both luks2_verify_key() and luks2_decrypt_key(), we do not ever print them. This makes it really hard to discover why a given key actually failed to decrypt a disk.

Improve this by including the error message in the user-visible output.

---
 grub-core/disk/luks2.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
grub-core/disk/luks2.c +0 -0
index 65c4f0aac..a48bddf5d 100644

grub-core/disk/luks2.c luks2_decrypt_key (grub_uint8_t *out_key, · line 492

Quoted 7 lines
grub-core/disk/luks2.c +1 -1
@@ -487,7 +487,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
   ret = grub_disk_read (disk, 0, k->area.offset, k->area.size, split_key);
   if (ret)
     {
-      grub_dprintf ("luks2", "Read error: %s\n", grub_errmsg);
+      grub_error (GRUB_ERR_IO, "Read error: %s\n", grub_errmsg);
       goto err;
     }

AIUI the commit message says about this change but...

Quoted 7 lines
grub-core/disk/luks2.c +2 -1
@@ -610,14 +610,16 @@ luks2_recover_key (grub_disk_t disk,
 			       (const grub_uint8_t *) passphrase, grub_strlen (passphrase));
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed\n", i);
+	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed: %s\n",
+			i, grub_errmsg);

grub-core/disk/luks2.c luks2_recover_key (grub_disk_t disk, · line 623

Quoted 10 lines
grub-core/disk/luks2.c +2 -1
 	  continue;
 	}
 
       ret = luks2_verify_key (&digest, candidate_key, keyslot.key_size);
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE"\n", i);
+	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE": %s\n",
+			i, grub_errmsg);
 	  continue;

...it does not say anything about these changes. If you update commit message you can add Reviewed-by: Daniel Kiper <[email protected]>

Quoted 1 line

Daniel

Does the following commit message clear things up?

luks2: Improve error reporting when recovering keys

While we already set up error messages in both luks2_verify_key() and luks2_decrypt_key(), we do not ever print them in the calling function luks2_recover_key(). This makes it really hard to discover why a given key actually failed to decrypt a disk.

Improve this by including the error message in the user-visible output. While at it, fix one error path in luks2_decrypt_key() that printed the error directly instead of returning it.

Patrick

#3 lore raw
Quoted 60 lines · Patrick Steinhardt
Quoted 48 lines · Daniel Kiper
Quoted 16 lines · Patrick Steinhardt

While we already set up error messages in both luks2_verify_key() and luks2_decrypt_key(), we do not ever print them. This makes it really hard to discover why a given key actually failed to decrypt a disk.

Improve this by including the error message in the user-visible output.

---
 grub-core/disk/luks2.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
grub-core/disk/luks2.c +0 -0
index 65c4f0aac..a48bddf5d 100644

grub-core/disk/luks2.c luks2_decrypt_key (grub_uint8_t *out_key, · line 492

Quoted 7 lines
grub-core/disk/luks2.c +1 -1
@@ -487,7 +487,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
   ret = grub_disk_read (disk, 0, k->area.offset, k->area.size, split_key);
   if (ret)
     {
-      grub_dprintf ("luks2", "Read error: %s\n", grub_errmsg);
+      grub_error (GRUB_ERR_IO, "Read error: %s\n", grub_errmsg);
       goto err;
     }

AIUI the commit message says about this change but...

Quoted 7 lines
grub-core/disk/luks2.c +2 -1
@@ -610,14 +610,16 @@ luks2_recover_key (grub_disk_t disk,
 			       (const grub_uint8_t *) passphrase, grub_strlen (passphrase));
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed\n", i);
+	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed: %s\n",
+			i, grub_errmsg);

grub-core/disk/luks2.c luks2_recover_key (grub_disk_t disk, · line 623

Quoted 10 lines
grub-core/disk/luks2.c +2 -1
 	  continue;
 	}
 
       ret = luks2_verify_key (&digest, candidate_key, keyslot.key_size);
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE"\n", i);
+	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE": %s\n",
+			i, grub_errmsg);
 	  continue;

...it does not say anything about these changes. If you update commit message you can add Reviewed-by: Daniel Kiper <[email protected]>

Quoted 1 line

Daniel

Does the following commit message clear things up?

luks2: Improve error reporting when recovering keys

While we already set up error messages in both luks2_verify_key() and luks2_decrypt_key(), we do not ever print them in the calling function luks2_recover_key(). This makes it really hard to discover why a given key actually failed to decrypt a disk.

Quoted 5 lines

Improve this by including the error message in the user-visible output. While at it, fix one error path in luks2_decrypt_key() that printed the error directly instead of returning it.

Much better. However, after seeing this I think that this patch should be split into two separate ones. If you do that and split the commit message accordingly feel free to add Reviewed-by: Daniel Kiper <[email protected]>.

Daniel

#4 lore raw

v2 cover Improve LUKS2 error reporting

In reply to Patrick Steinhardt

Hi,

this is the second version of my patch that has the aim of improving error reporting for LUKS2 in case decryption of the disk fails. There's no functional changes, but I've split up the single patch into two as proposed by Daniel.

@Daniel: Note that I've added your Reviewed-by to the second patch, but not to the first one as it's message is completely new.

Patrick

Patrick Steinhardt (2):
luks2: Propagate error when reading area key fails
luks2: Improve error reporting when recovering keys

 grub-core/disk/luks2.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.1
#5 lore raw

PATCH v2 1/2 luks2: Propagate error when reading area key fails

When decrypting a given keyslot, all error cases except for one set up an error and return the error code. The only exception is when we try to read the area key: instead of setting up an error message, we directly print it via grub_dprintf().

Convert the outlier to use grub_error() to allow more uniform handling of errors.

---
 grub-core/disk/luks2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/disk/luks2.c +1 -1
index 65c4f0aac..e3ff7c83d 100644
@@ -487,7 +487,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
   ret = grub_disk_read (disk, 0, k->area.offset, k->area.size, split_key);
   if (ret)
     {
-      grub_dprintf ("luks2", "Read error: %s\n", grub_errmsg);
+      grub_error (GRUB_ERR_IO, "Read error: %s\n", grub_errmsg);
       goto err;
     }
 
Signature · 1 line
2.26.1
#6 lore raw

PATCH v2 2/2 luks2: Improve error reporting when recovering keys

In reply to Patrick Steinhardt

While we already set up error messages in both luks2_verify_key() and luks2_decrypt_key(), we do not ever print them in the calling function luks2_recover_key(). This makes it really hard to discover why a given key actually failed to decrypt a disk.

Improve this by including the error message in the user-visible output.

---
 grub-core/disk/luks2.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
grub-core/disk/luks2.c +4 -2
index e3ff7c83d..a48bddf5d 100644
@@ -610,14 +610,16 @@ luks2_recover_key (grub_disk_t disk,
 			       (const grub_uint8_t *) passphrase, grub_strlen (passphrase));
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed\n", i);
+	  grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed: %s\n",
+			i, grub_errmsg);
 	  continue;
 	}
 
       ret = luks2_verify_key (&digest, candidate_key, keyslot.key_size);
       if (ret)
 	{
-	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE"\n", i);
+	  grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE": %s\n",
+			i, grub_errmsg);
 	  continue;
 	}
 
Signature · 1 line
2.26.1
#7 lore raw

Re: [PATCH v2 0/2] Improve LUKS2 error reporting

In reply to Patrick Steinhardt
Quoted 9 lines · Patrick Steinhardt

Hi,

this is the second version of my patch that has the aim of improving error reporting for LUKS2 in case decryption of the disk fails. There's no functional changes, but I've split up the single patch into two as proposed by Daniel.

@Daniel: Note that I've added your Reviewed-by to the second patch, but not to the first one as it's message is completely new.

LGTM, Reviewed-by: Daniel Kiper <[email protected]> for both...

Thanks,

Daniel

#8 lore raw

Re: [PATCH v2 0/2] Improve LUKS2 error reporting

Quoted 8 lines · Daniel Kiper
Quoted 7 lines · Patrick Steinhardt

Hi,

this is the second version of my patch that has the aim of improving error reporting for LUKS2 in case decryption of the disk fails. There's no functional changes, but I've split up the single patch into two as proposed by Daniel.

Quoted 8 lines
Quoted 2 lines

@Daniel: Note that I've added your Reviewed-by to the second patch, but not to the first one as it's message is completely new.

LGTM, Reviewed-by: Daniel Kiper <[email protected]> for both...

Thanks,

Daniel

I see you pulled in commit c543d6781 (luks2: Propagate error when reading area key fails, 2020-04-16), but didn't pull in the second patch to improve error reporting when recovering keys fails. Was this by accident or intentionally?

Patrick