grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 0/4] Cryptomount keyfile support


From: Glenn Washburn
Subject: [PATCH 0/4] Cryptomount keyfile support
Date: Fri, 6 May 2022 03:45:56 -0500

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 via email to

[Prev in Thread] Current Thread [Next in Thread]