All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Cryptomount keyfile support
@ 2022-05-06  8:45 Glenn Washburn
  2022-05-06  8:45 ` [PATCH 1/4] cryptodisk: luks: Unify grub_cryptodisk_dev function names Glenn Washburn
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Glenn Washburn @ 2022-05-06  8:45 UTC (permalink / raw)
  To: grub-devel, Daniel Kiper
  Cc: Denis 'GNUtoo' Carikli, Patrick Steinhardt, John Lane,
	Glenn Washburn

I'm breaking the keyfile and detached header patch series into two series.
I think that the detached header patches can be improved and I don't want
to hold up the more trivial keyfile support patches. This series is patches
#1, #2, #5, and a split of #7, the documentation patch.

The first two patches are unchanged. The third contains changes addressing
comments by Daniel on the v9 keyfile and detached header patch series. And
the last patch is the same #7 except removing reference to the detached
header option.

Glenn

Denis 'GNUtoo' Carikli (2):
  cryptodisk: luks: Unify grub_cryptodisk_dev function names
  cryptodisk: geli: Unify grub_cryptodisk_dev function names

Glenn Washburn (1):
  docs: Add documentation on keyfile option to cryptomount

John Lane (1):
  cryptodisk: Add options to cryptomount to support keyfiles

 docs/grub.texi              | 14 +++---
 grub-core/disk/cryptodisk.c | 86 ++++++++++++++++++++++++++++++++++++-
 grub-core/disk/geli.c       |  8 ++--
 grub-core/disk/luks.c       |  4 +-
 include/grub/cryptodisk.h   |  2 +
 include/grub/file.h         |  2 +
 6 files changed, 104 insertions(+), 12 deletions(-)

Interdiff:
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
index 45f6d7231..19af4fa49 100644
--- a/grub-core/disk/cryptodisk.c
+++ b/grub-core/disk/cryptodisk.c
@@ -1179,33 +1179,29 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args)
     {
       const char *p = NULL;
       grub_file_t keyfile;
-      int keyfile_offset;
-      grub_size_t keyfile_size = 0;
-
+      unsigned long long keyfile_offset = 0, keyfile_size = 0;
 
       if (state[5].set) /* keyfile-offset */
 	{
-	  keyfile_offset = grub_strtoul (state[5].arg, &p, 0);
+	  keyfile_offset = grub_strtoull (state[5].arg, &p, 0);
 
 	  if (grub_errno != GRUB_ERR_NONE)
 	    return grub_errno;
 
-	  if (*p != '\0')
+	  if (state[5].arg[0] == '\0' || *p != '\0')
 	    return grub_error (GRUB_ERR_BAD_ARGUMENT,
-			       N_("unrecognized number"));
-	}
-      else
-	{
-	  keyfile_offset = 0;
+			       N_("non-numeric or invalid keyfile offset `%s'"),
+			       state[5].arg);
 	}
 
       if (state[6].set) /* keyfile-size */
 	{
 	  keyfile_size = grub_strtoul (state[6].arg, &p, 0);
 
-	  if (*p != '\0')
+	  if (state[6].arg[0] == '\0' || *p != '\0')
 	    return grub_error (GRUB_ERR_BAD_ARGUMENT,
-			       N_("unrecognized number"));
+			       N_("non-numeric or invalid keyfile size `%s'"),
+			       state[6].arg);
 
 	  if (grub_errno != GRUB_ERR_NONE)
 	    return grub_errno;
@@ -1224,16 +1220,23 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args)
       if (keyfile == NULL)
 	return grub_errno;
 
-      if (grub_file_seek (keyfile, keyfile_offset) == (grub_off_t)-1)
+      if (keyfile_offset > keyfile->size)
+	{
+	  keyfile_offset = keyfile->size;
+	  grub_dprintf ("cryptodisk","Keyfile offset, %llu, is greater than"
+				     "keyfile size, %" PRIuGRUB_UINT64_T "\n",
+				     keyfile_offset, keyfile->size);
+	}
+
+      if (grub_file_seek (keyfile, (grub_off_t) keyfile_offset) == (grub_off_t) -1)
 	return grub_errno;
 
       if (keyfile_size > 0)
 	{
 	  if (keyfile_size > (keyfile->size - keyfile_offset))
 	    return grub_error (GRUB_ERR_FILE_READ_ERROR,
-			       N_("keyfile is too small: "
-				  "requested %" PRIuGRUB_SIZE " bytes, "
-				  "but the file only has %" PRIuGRUB_UINT64_T
+			       N_("keyfile is too small: requested %llu bytes,"
+				  " but the file only has %" PRIuGRUB_UINT64_T
 				  " bytes"),
 			       keyfile_size,
 			       keyfile->size);
@@ -1241,9 +1244,7 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args)
 	  cargs.key_len = keyfile_size;
 	}
       else
-	{
-	  cargs.key_len = keyfile->size - keyfile_offset;
-	}
+	cargs.key_len = keyfile->size - keyfile_offset;
 
       cargs.key_data = grub_malloc (cargs.key_len);
       if (cargs.key_data == NULL)
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-05-13 16:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-06  8:45 [PATCH 0/4] Cryptomount keyfile support Glenn Washburn
2022-05-06  8:45 ` [PATCH 1/4] cryptodisk: luks: Unify grub_cryptodisk_dev function names Glenn Washburn
2022-05-06  8:45 ` [PATCH 2/4] cryptodisk: geli: " Glenn Washburn
2022-05-06  8:45 ` [PATCH 3/4] cryptodisk: Add options to cryptomount to support keyfiles Glenn Washburn
2022-05-12 17:45   ` Daniel Kiper
2022-05-12 18:53     ` Glenn Washburn
2022-05-13 11:12       ` Daniel Kiper
2022-05-13 16:39         ` Glenn Washburn
2022-05-13 16:56         ` Glenn Washburn
2022-05-06  8:46 ` [PATCH 4/4] docs: Add documentation on keyfile option to cryptomount Glenn Washburn
2022-05-12 17:47   ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.