All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org, Daniel Kiper <dkiper@net-space.pl>
Cc: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>,
	Patrick Steinhardt <ps@pks.im>, John Lane <john@lane.uk.net>,
	Glenn Washburn <development@efficientek.com>
Subject: [PATCH 0/4] Cryptomount keyfile support
Date: Fri,  6 May 2022 03:45:56 -0500	[thread overview]
Message-ID: <cover.1651825861.git.development@efficientek.com> (raw)

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



             reply	other threads:[~2022-05-06  8:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06  8:45 Glenn Washburn [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1651825861.git.development@efficientek.com \
    --to=development@efficientek.com \
    --cc=GNUtoo@cyberdimension.org \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    --cc=john@lane.uk.net \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.