Skip to contentSkip to conversation

luks2: Continue trying all keyslots even if there are some failures

PATCH In review Glenn Washburn 3 participants 5 messages Jul 22, 2022 – Aug 20, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 luks2: Continue trying all keyslots even if there are some failures

luks2_get_keyslot can fail for a variety of reasons that do not neccesarily mean the next keyslot should not be tried (eg. a new kdf type). So always try the next slot. This will make GRUB more resilient to non-spec json data that 3rd party systems may add. We do not care if some of the keyslots are unusable, only if there is at least one that is.

---
 grub-core/disk/luks2.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
grub-core/disk/luks2.c +9 -1
index bf741d70f..d8d3180ed 100644
@@ -610,7 +610,15 @@ luks2_recover_key (grub_disk_t source,
       grub_errno = GRUB_ERR_NONE;
       ret = luks2_get_keyslot (&keyslot, &digest, &segment, json, json_idx);
       if (ret)
-	goto err;
+	{
+	  /*
+	   * luks2_get_keyslot can fail for a variety of reasons that do not
+	   * neccesarily mean the next keyslot should not be tried (eg. a new
+	   * kdf type). So always try the next slot.
+	   */
+	  grub_dprintf ("luks2", "Failed to get keyslot %" PRIuGRUB_UINT64_T "\n", keyslot.idx);
+	  continue;
+	}
       if (grub_errno != GRUB_ERR_NONE)
 	  grub_dprintf ("luks2", "Ignoring unhandled error %d from luks2_get_keyslot\n", grub_errno);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Glenn Washburn

luks2_get_keyslot can fail for a variety of reasons that do not neccesarily mean the next keyslot should not be tried (eg. a new kdf type). So always try the next slot. This will make GRUB more resilient to non-spec json data that 3rd party systems may add. We do not care if some of the keyslots are unusable, only if there is at least one that is.

Daniel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Glenn Washburn
Quoted 35 lines · Glenn Washburn

luks2_get_keyslot can fail for a variety of reasons that do not neccesarily mean the next keyslot should not be tried (eg. a new kdf type). So always try the next slot. This will make GRUB more resilient to non-spec json data that 3rd party systems may add. We do not care if some of the keyslots are unusable, only if there is at least one that is.

---
 grub-core/disk/luks2.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
grub-core/disk/luks2.c +9 -1
index bf741d70f..d8d3180ed 100644
@@ -610,7 +610,15 @@ luks2_recover_key (grub_disk_t source,
       grub_errno = GRUB_ERR_NONE;
       ret = luks2_get_keyslot (&keyslot, &digest, &segment, json, json_idx);
       if (ret)
-	goto err;
+	{
+	  /*
+	   * luks2_get_keyslot can fail for a variety of reasons that do not
+	   * neccesarily mean the next keyslot should not be tried (eg. a new
+	   * kdf type). So always try the next slot.
+	   */
+	  grub_dprintf ("luks2", "Failed to get keyslot %" PRIuGRUB_UINT64_T "\n", keyslot.idx);
+	  continue;
+	}
       if (grub_errno != GRUB_ERR_NONE)
 	  grub_dprintf ("luks2", "Ignoring unhandled error %d from luks2_get_keyslot\n", grub_errno);
 
Signature · 1 line
2.34.1
#3 lore raw
Quoted 33 lines · Patrick Steinhardt
Quoted 32 lines · Glenn Washburn

luks2_get_keyslot can fail for a variety of reasons that do not neccesarily mean the next keyslot should not be tried (eg. a new kdf type). So always try the next slot. This will make GRUB more resilient to non-spec json data that 3rd party systems may add. We do not care if some of the keyslots are unusable, only if there is at least one that is.

---
 grub-core/disk/luks2.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
grub-core/disk/luks2.c +9 -1
index bf741d70f..d8d3180ed 100644
@@ -610,7 +610,15 @@ luks2_recover_key (grub_disk_t source,
       grub_errno = GRUB_ERR_NONE;
       ret = luks2_get_keyslot (&keyslot, &digest, &segment, json, json_idx);
       if (ret)
-	goto err;
+	{
+	  /*
+	   * luks2_get_keyslot can fail for a variety of reasons that do not
+	   * neccesarily mean the next keyslot should not be tried (eg. a new
+	   * kdf type). So always try the next slot.
+	   */
+	  grub_dprintf ("luks2", "Failed to get keyslot %" PRIuGRUB_UINT64_T "\n", keyslot.idx);
+	  continue;
+	}
       if (grub_errno != GRUB_ERR_NONE)
 	  grub_dprintf ("luks2", "Ignoring unhandled error %d from luks2_get_keyslot\n", grub_errno);
 
Quoted 5 lines
Quoted 3 lines

--
2.34.1

Thank you for review but I have merged this patch earlier and cannot add your RB now... :-(

Daniel

#4 lore raw
Quoted 40 lines · Daniel Kiper
Quoted 33 lines · Patrick Steinhardt
Quoted 32 lines · Glenn Washburn

luks2_get_keyslot can fail for a variety of reasons that do not neccesarily mean the next keyslot should not be tried (eg. a new kdf type). So always try the next slot. This will make GRUB more resilient to non-spec json data that 3rd party systems may add. We do not care if some of the keyslots are unusable, only if there is at least one that is.

---
 grub-core/disk/luks2.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
grub-core/disk/luks2.c +9 -1
index bf741d70f..d8d3180ed 100644
@@ -610,7 +610,15 @@ luks2_recover_key (grub_disk_t source,
       grub_errno = GRUB_ERR_NONE;
       ret = luks2_get_keyslot (&keyslot, &digest, &segment, json, json_idx);
       if (ret)
-	goto err;
+	{
+	  /*
+	   * luks2_get_keyslot can fail for a variety of reasons that do not
+	   * neccesarily mean the next keyslot should not be tried (eg. a new
+	   * kdf type). So always try the next slot.
+	   */
+	  grub_dprintf ("luks2", "Failed to get keyslot %" PRIuGRUB_UINT64_T "\n", keyslot.idx);
+	  continue;
+	}
       if (grub_errno != GRUB_ERR_NONE)
 	  grub_dprintf ("luks2", "Ignoring unhandled error %d from luks2_get_keyslot\n", grub_errno);
 
Quoted 5 lines
Quoted 3 lines

--
2.34.1

Quoted 4 lines

Thank you for review but I have merged this patch earlier and cannot add your RB now... :-(

Daniel

No worries! I assumed as much when I reviewed this but was too lazy to check ;)

Patrick