Blame SOURCES/0332-verifiers-Add-possibility-to-verify-kernel-and-modul.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Vladimir Serbinenko <phcoder@gmail.com>
80913e
Date: Tue, 7 Feb 2017 02:10:14 +0100
80913e
Subject: [PATCH] verifiers: Add possibility to verify kernel and modules
80913e
 command lines
80913e
80913e
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
80913e
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
80913e
(backported from 4d4a8c96e3593d76fe7b025665ccdecc70a53c1f)
80913e
Signed-off-by: Daniel Axtens <dja@axtens.net>
80913e
---
80913e
 grub-core/commands/verifiers.c            | 14 ++++++++++++++
80913e
 grub-core/lib/cmdline.c                   |  7 ++++---
80913e
 grub-core/loader/arm/linux.c              |  8 ++++++--
80913e
 grub-core/loader/arm64/linux.c            | 10 +++++++---
80913e
 grub-core/loader/i386/bsd.c               |  6 ++++++
80913e
 grub-core/loader/i386/linux.c             | 16 +++++++++++-----
80913e
 grub-core/loader/i386/multiboot_mbi.c     | 16 ++++++++++------
80913e
 grub-core/loader/i386/pc/linux.c          | 13 ++++++++-----
80913e
 grub-core/loader/i386/pc/plan9.c          | 11 +++++++++++
80913e
 grub-core/loader/i386/xen.c               |  7 +++++++
80913e
 grub-core/loader/ia64/efi/linux.c         |  7 +++++++
80913e
 grub-core/loader/mips/linux.c             |  8 ++++++++
80913e
 grub-core/loader/multiboot_mbi2.c         |  8 +++-----
80913e
 grub-core/loader/powerpc/ieee1275/linux.c |  5 +++--
80913e
 grub-core/loader/sparc64/ieee1275/linux.c |  5 +++--
80913e
 grub-core/loader/xnu.c                    |  9 +++++++++
80913e
 include/grub/lib/cmdline.h                |  5 +++--
80913e
 include/grub/verify.h                     | 11 +++++++++++
80913e
 18 files changed, 131 insertions(+), 35 deletions(-)
80913e
80913e
diff --git a/grub-core/commands/verifiers.c b/grub-core/commands/verifiers.c
80913e
index fde88318d4c..59ea418a2d9 100644
80913e
--- a/grub-core/commands/verifiers.c
80913e
+++ b/grub-core/commands/verifiers.c
80913e
@@ -186,6 +186,20 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type)
80913e
   return NULL;
80913e
 }
80913e
 
80913e
+grub_err_t
80913e
+grub_verify_string (char *str, enum grub_verify_string_type type)
80913e
+{
80913e
+  struct grub_file_verifier *ver;
80913e
+  FOR_LIST_ELEMENTS(ver, grub_file_verifiers)
80913e
+    {
80913e
+      grub_err_t err;
80913e
+      err = ver->verify_string ? ver->verify_string (str, type) : GRUB_ERR_NONE;
80913e
+      if (err)
80913e
+	return err;
80913e
+    }
80913e
+  return GRUB_ERR_NONE;
80913e
+}
80913e
+
80913e
 GRUB_MOD_INIT(verifiers)
80913e
 {
80913e
   grub_file_filter_register (GRUB_FILE_FILTER_VERIFY, grub_verifiers_open);
80913e
diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
80913e
index d5c12957cad..463c3c65c79 100644
80913e
--- a/grub-core/lib/cmdline.c
80913e
+++ b/grub-core/lib/cmdline.c
80913e
@@ -75,8 +75,9 @@ unsigned int grub_loader_cmdline_size (int argc, char *argv[])
80913e
   return size;
80913e
 }
80913e
 
80913e
-int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
80913e
-				grub_size_t size)
80913e
+grub_err_t
80913e
+grub_create_loader_cmdline (int argc, char *argv[], char *buf,
80913e
+			    grub_size_t size, enum grub_verify_string_type type)
80913e
 {
80913e
   int i, space;
80913e
   unsigned int arg_size;
80913e
@@ -130,5 +131,5 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
80913e
 		    "grub_kernel_cmdline", orig);
80913e
   grub_print_error();
80913e
 
80913e
-  return i;
80913e
+  return grub_verify_string (orig, type);
80913e
 }
80913e
diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
80913e
index ea29d7a724a..beceda52030 100644
80913e
--- a/grub-core/loader/arm/linux.c
80913e
+++ b/grub-core/loader/arm/linux.c
80913e
@@ -28,6 +28,7 @@
80913e
 #include <grub/cpu/linux.h>
80913e
 #include <grub/lib/cmdline.h>
80913e
 #include <grub/linux.h>
80913e
+#include <grub/verify.h>
80913e
 
80913e
 GRUB_MOD_LICENSE ("GPLv3+");
80913e
 
80913e
@@ -383,8 +384,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
 
80913e
   /* Create kernel command line.  */
80913e
   grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
80913e
-  grub_create_loader_cmdline (argc, argv,
80913e
-			      linux_args + sizeof (LINUX_IMAGE) - 1, size);
80913e
+  err = grub_create_loader_cmdline (argc, argv,
80913e
+				    linux_args + sizeof (LINUX_IMAGE) - 1, size,
80913e
+				    GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+  if (err)
80913e
+    goto fail;
80913e
 
80913e
   return GRUB_ERR_NONE;
80913e
 
80913e
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
80913e
index 7a076c13171..48ea66596ad 100644
80913e
--- a/grub-core/loader/arm64/linux.c
80913e
+++ b/grub-core/loader/arm64/linux.c
80913e
@@ -33,6 +33,7 @@
80913e
 #include <grub/efi/pe32.h>
80913e
 #include <grub/i18n.h>
80913e
 #include <grub/lib/cmdline.h>
80913e
+#include <grub/verify.h>
80913e
 
80913e
 GRUB_MOD_LICENSE ("GPLv3+");
80913e
 
80913e
@@ -403,9 +404,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
       goto fail;
80913e
     }
80913e
   grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
80913e
-  grub_create_loader_cmdline (argc, argv,
80913e
-			      linux_args + sizeof (LINUX_IMAGE) - 1,
80913e
-			      cmdline_size);
80913e
+  err = grub_create_loader_cmdline (argc, argv,
80913e
+				    linux_args + sizeof (LINUX_IMAGE) - 1,
80913e
+				    cmdline_size,
80913e
+				    GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+  if (err)
80913e
+    goto fail;
80913e
 
80913e
   if (grub_errno == GRUB_ERR_NONE)
80913e
     {
80913e
diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
80913e
index 8306b415abd..45a71509956 100644
80913e
--- a/grub-core/loader/i386/bsd.c
80913e
+++ b/grub-core/loader/i386/bsd.c
80913e
@@ -36,6 +36,7 @@
80913e
 #include <grub/bsdlabel.h>
80913e
 #include <grub/crypto.h>
80913e
 #include <grub/safemath.h>
80913e
+#include <grub/verify.h>
80913e
 #ifdef GRUB_MACHINE_PCBIOS
80913e
 #include <grub/machine/int.h>
80913e
 #endif
80913e
@@ -418,6 +419,8 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
80913e
 			      grub_addr_t addr, grub_uint32_t size)
80913e
 {
80913e
   const char *name;
80913e
+  grub_err_t err;
80913e
+
80913e
   name = grub_strrchr (filename, '/');
80913e
   if (name)
80913e
     name++;
80913e
@@ -471,6 +474,9 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
80913e
 	      *(p++) = ' ';
80913e
 	    }
80913e
 	  *p = 0;
80913e
+	  err = grub_verify_string (cmdline, GRUB_VERIFY_MODULE_CMDLINE);
80913e
+	  if (err)
80913e
+	    return err;
80913e
 	}
80913e
     }
80913e
 
80913e
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
80913e
index aa2cbc4e7eb..ef8fcb9e1b6 100644
80913e
--- a/grub-core/loader/i386/linux.c
80913e
+++ b/grub-core/loader/i386/linux.c
80913e
@@ -1039,11 +1039,17 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
   if (!linux_cmdline)
80913e
     goto fail;
80913e
   grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
80913e
-  grub_create_loader_cmdline (argc, argv,
80913e
-			      linux_cmdline
80913e
-			      + sizeof (LINUX_IMAGE) - 1,
80913e
-			      maximal_cmdline_size
80913e
-			      - (sizeof (LINUX_IMAGE) - 1));
80913e
+  {
80913e
+    grub_err_t err;
80913e
+    err = grub_create_loader_cmdline (argc, argv,
80913e
+				      linux_cmdline
80913e
+				      + sizeof (LINUX_IMAGE) - 1,
80913e
+				      maximal_cmdline_size
80913e
+				      - (sizeof (LINUX_IMAGE) - 1),
80913e
+				      GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+    if (err)
80913e
+      goto fail;
80913e
+  }
80913e
 
80913e
   len = prot_file_size;
80913e
   grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
80913e
diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
80913e
index 9d3466d6ace..525446b5687 100644
80913e
--- a/grub-core/loader/i386/multiboot_mbi.c
80913e
+++ b/grub-core/loader/i386/multiboot_mbi.c
80913e
@@ -676,10 +676,8 @@ grub_multiboot_init_mbi (int argc, char *argv[])
80913e
     return grub_errno;
80913e
   cmdline_size = len;
80913e
 
80913e
-  grub_create_loader_cmdline (argc, argv, cmdline,
80913e
-			      cmdline_size);
80913e
-
80913e
-  return GRUB_ERR_NONE;
80913e
+  return grub_create_loader_cmdline (argc, argv, cmdline,
80913e
+				     cmdline_size, GRUB_VERIFY_KERNEL_CMDLINE);
80913e
 }
80913e
 
80913e
 grub_err_t
80913e
@@ -688,6 +686,7 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
80913e
 {
80913e
   struct module *newmod;
80913e
   grub_size_t len = 0;
80913e
+  grub_err_t err;
80913e
 
80913e
   newmod = grub_malloc (sizeof (*newmod));
80913e
   if (!newmod)
80913e
@@ -707,8 +706,13 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
80913e
   newmod->cmdline_size = len;
80913e
   total_modcmd += ALIGN_UP (len, 4);
80913e
 
80913e
-  grub_create_loader_cmdline (argc, argv, newmod->cmdline,
80913e
-			      newmod->cmdline_size);
80913e
+  err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
80913e
+				    newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE);
80913e
+  if (err)
80913e
+    {
80913e
+      grub_free (newmod);
80913e
+      return grub_errno;
80913e
+    }
80913e
 
80913e
   if (modules_last)
80913e
     modules_last->next = newmod;
80913e
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
80913e
index b5c28c6580e..f631225f59b 100644
80913e
--- a/grub-core/loader/i386/pc/linux.c
80913e
+++ b/grub-core/loader/i386/pc/linux.c
80913e
@@ -348,11 +348,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
   /* Create kernel command line.  */
80913e
   grub_memcpy ((char *)grub_linux_real_chunk + GRUB_LINUX_CL_OFFSET,
80913e
 		LINUX_IMAGE, sizeof (LINUX_IMAGE));
80913e
-  grub_create_loader_cmdline (argc, argv,
80913e
-			      (char *)grub_linux_real_chunk
80913e
-			      + GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1,
80913e
-			      maximal_cmdline_size
80913e
-			      - (sizeof (LINUX_IMAGE) - 1));
80913e
+  err = grub_create_loader_cmdline (argc, argv,
80913e
+				    (char *)grub_linux_real_chunk
80913e
+				    + GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1,
80913e
+				    maximal_cmdline_size
80913e
+				    - (sizeof (LINUX_IMAGE) - 1),
80913e
+				    GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+  if (err)
80913e
+    goto fail;
80913e
 
80913e
   if (grub_linux_is_bzimage)
80913e
     grub_linux_prot_target = GRUB_LINUX_BZIMAGE_ADDR;
80913e
diff --git a/grub-core/loader/i386/pc/plan9.c b/grub-core/loader/i386/pc/plan9.c
80913e
index 0351090daf8..37550155df7 100644
80913e
--- a/grub-core/loader/i386/pc/plan9.c
80913e
+++ b/grub-core/loader/i386/pc/plan9.c
80913e
@@ -33,6 +33,7 @@
80913e
 #include <grub/mm.h>
80913e
 #include <grub/cpu/relocator.h>
80913e
 #include <grub/extcmd.h>
80913e
+#include <grub/verify.h>
80913e
 
80913e
 GRUB_MOD_LICENSE ("GPLv3+");
80913e
 
80913e
@@ -505,6 +506,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
80913e
   configptr = grub_stpcpy (configptr, "bootfile=");
80913e
   configptr = grub_stpcpy (configptr, bootpath);
80913e
   *configptr++ = '\n';
80913e
+  char *cmdline = configptr;
80913e
   {
80913e
     int i;
80913e
     for (i = 1; i < argc; i++)
80913e
@@ -513,6 +515,15 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
80913e
 	*configptr++ = '\n';
80913e
       }
80913e
   }
80913e
+
80913e
+  {
80913e
+    grub_err_t err;
80913e
+    *configptr = '\0';
80913e
+    err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+    if (err)
80913e
+      goto fail;
80913e
+  }
80913e
+
80913e
   configptr = grub_stpcpy (configptr, fill_ctx.pmap);
80913e
 
80913e
   {
80913e
diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c
80913e
index 82350d3a178..07a4837c532 100644
80913e
--- a/grub-core/loader/i386/xen.c
80913e
+++ b/grub-core/loader/i386/xen.c
80913e
@@ -41,6 +41,7 @@
80913e
 #include <grub/linux.h>
80913e
 #include <grub/i386/memory.h>
80913e
 #include <grub/safemath.h>
80913e
+#include <grub/verify.h>
80913e
 
80913e
 GRUB_MOD_LICENSE ("GPLv3+");
80913e
 
80913e
@@ -649,6 +650,9 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),
80913e
   grub_create_loader_cmdline (argc - 1, argv + 1,
80913e
 			      (char *) xen_state.next_start.cmd_line,
80913e
 			      sizeof (xen_state.next_start.cmd_line) - 1);
80913e
+  err = grub_verify_string (xen_state.next_start.cmd_line, GRUB_VERIFY_MODULE_CMDLINE);
80913e
+  if (err)
80913e
+    return err;
80913e
 
80913e
   file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
80913e
   if (!file)
80913e
@@ -916,6 +920,9 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
80913e
 
80913e
   grub_create_loader_cmdline (argc - 1, argv + 1,
80913e
 			      get_virtual_current_address (ch), cmdline_len);
80913e
+  err = grub_verify_string (get_virtual_current_address (ch), GRUB_VERIFY_MODULE_CMDLINE);
80913e
+  if (err)
80913e
+    goto fail;
80913e
 
80913e
   xen_state.module_info_page[xen_state.n_modules].cmdline =
80913e
     xen_state.max_addr - xen_state.modules_target_start;
80913e
diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c
80913e
index 750330d4572..e325fe0ee83 100644
80913e
--- a/grub-core/loader/ia64/efi/linux.c
80913e
+++ b/grub-core/loader/ia64/efi/linux.c
80913e
@@ -33,6 +33,7 @@
80913e
 #include <grub/i18n.h>
80913e
 #include <grub/env.h>
80913e
 #include <grub/linux.h>
80913e
+#include <grub/verify.h>
80913e
 
80913e
 GRUB_MOD_LICENSE ("GPLv3+");
80913e
 
80913e
@@ -543,6 +544,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
       p = grub_stpcpy (p, argv[i]);
80913e
     }
80913e
   cmdline[10] = '=';
80913e
+
80913e
+  *p = '\0';
80913e
+
80913e
+  err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+  if (err)
80913e
+    goto fail;
80913e
   
80913e
   boot_param->command_line = (grub_uint64_t) cmdline;
80913e
   boot_param->efi_systab = (grub_uint64_t) grub_efi_system_table;
80913e
diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c
80913e
index 10358854458..20135ce253d 100644
80913e
--- a/grub-core/loader/mips/linux.c
80913e
+++ b/grub-core/loader/mips/linux.c
80913e
@@ -327,6 +327,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
   linux_argv++;
80913e
   linux_args += ALIGN_UP (sizeof ("a0"), 4);
80913e
 
80913e
+  char *params = linux_args;
80913e
+
80913e
 #ifdef GRUB_MACHINE_MIPS_LOONGSON
80913e
   {
80913e
     unsigned mtype = grub_arch_machine;
80913e
@@ -352,6 +354,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
       linux_args += ALIGN_UP (grub_strlen (argv[i]) + 1, 4);
80913e
     }
80913e
 
80913e
+  *linux_args = '\0';
80913e
+
80913e
+  err = grub_verify_string (params, GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+  if (err)
80913e
+    return err;
80913e
+
80913e
   /* Reserve space for rd arguments.  */
80913e
   rd_addr_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground;
80913e
   linux_args += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4);
80913e
diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
80913e
index 3cfb47650a0..f64a857e394 100644
80913e
--- a/grub-core/loader/multiboot_mbi2.c
80913e
+++ b/grub-core/loader/multiboot_mbi2.c
80913e
@@ -1077,10 +1077,8 @@ grub_multiboot2_init_mbi (int argc, char *argv[])
80913e
     return grub_errno;
80913e
   cmdline_size = len;
80913e
 
80913e
-  grub_create_loader_cmdline (argc, argv, cmdline,
80913e
-			      cmdline_size);
80913e
-
80913e
-  return GRUB_ERR_NONE;
80913e
+  return grub_create_loader_cmdline (argc, argv, cmdline, cmdline_size,
80913e
+				     GRUB_VERIFY_KERNEL_CMDLINE);
80913e
 }
80913e
 
80913e
 grub_err_t
80913e
@@ -1109,7 +1107,7 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size,
80913e
   total_modcmd += ALIGN_UP (len, MULTIBOOT_TAG_ALIGN);
80913e
 
80913e
   err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
80913e
-				    newmod->cmdline_size);
80913e
+				    newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE);
80913e
   if (err)
80913e
     {
80913e
       grub_free (newmod->cmdline);
80913e
diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c
80913e
index 6e814649f31..c114e7df4fb 100644
80913e
--- a/grub-core/loader/powerpc/ieee1275/linux.c
80913e
+++ b/grub-core/loader/powerpc/ieee1275/linux.c
80913e
@@ -302,8 +302,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
 
80913e
   /* Create kernel command line.  */
80913e
   grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
80913e
-  grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
80913e
-			      size);
80913e
+  if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
80913e
+				  size))
80913e
+    goto out;
80913e
 
80913e
 out:
80913e
 
80913e
diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c
80913e
index 67ef0488324..abe46faa012 100644
80913e
--- a/grub-core/loader/sparc64/ieee1275/linux.c
80913e
+++ b/grub-core/loader/sparc64/ieee1275/linux.c
80913e
@@ -340,8 +340,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
80913e
 
80913e
   /* Create kernel command line.  */
80913e
   grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
80913e
-  grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
80913e
-			      size);
80913e
+  if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
80913e
+				  size, GRUB_VERIFY_KERNEL_CMDLINE))
80913e
+    goto out;
80913e
 
80913e
 out:
80913e
   if (elf)
80913e
diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c
80913e
index 9f78abb05f9..5944dc5eafc 100644
80913e
--- a/grub-core/loader/xnu.c
80913e
+++ b/grub-core/loader/xnu.c
80913e
@@ -35,6 +35,7 @@
80913e
 #include <grub/i18n.h>
80913e
 #include <grub/efi/sb.h>
80913e
 #include <grub/safemath.h>
80913e
+#include <grub/verify.h>
80913e
 
80913e
 GRUB_MOD_LICENSE ("GPLv3+");
80913e
 
80913e
@@ -429,6 +430,10 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
80913e
   if (ptr != grub_xnu_cmdline)
80913e
     *(ptr - 1) = 0;
80913e
 
80913e
+  err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+  if (err)
80913e
+    return err;
80913e
+
80913e
 #if defined (__i386) && !defined (GRUB_MACHINE_EFI)
80913e
   err = grub_efiemu_autocore ();
80913e
   if (err)
80913e
@@ -538,6 +543,10 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
80913e
   if (ptr != grub_xnu_cmdline)
80913e
     *(ptr - 1) = 0;
80913e
 
80913e
+  err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
80913e
+  if (err)
80913e
+    return err;
80913e
+
80913e
 #if defined (__i386) && !defined (GRUB_MACHINE_EFI)
80913e
   err = grub_efiemu_autocore ();
80913e
   if (err)
80913e
diff --git a/include/grub/lib/cmdline.h b/include/grub/lib/cmdline.h
80913e
index 1fe8d017971..cdca09b7a16 100644
80913e
--- a/include/grub/lib/cmdline.h
80913e
+++ b/include/grub/lib/cmdline.h
80913e
@@ -21,11 +21,12 @@
80913e
 #define GRUB_CMDLINE_HEADER	1
80913e
 
80913e
 #include <grub/types.h>
80913e
+#include <grub/verify.h>
80913e
 
80913e
 #define LINUX_IMAGE "BOOT_IMAGE="
80913e
 
80913e
 unsigned int grub_loader_cmdline_size (int argc, char *argv[]);
80913e
-int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
80913e
-				grub_size_t size);
80913e
+grub_err_t grub_create_loader_cmdline (int argc, char *argv[], char *buf,
80913e
+				       grub_size_t size, enum grub_verify_string_type type);
80913e
 
80913e
 #endif /* ! GRUB_CMDLINE_HEADER */
80913e
diff --git a/include/grub/verify.h b/include/grub/verify.h
80913e
index 298120f5776..9f892d8fedb 100644
80913e
--- a/include/grub/verify.h
80913e
+++ b/include/grub/verify.h
80913e
@@ -25,6 +25,12 @@ enum grub_verify_flags
80913e
     GRUB_VERIFY_FLAGS_SINGLE_CHUNK	= 2
80913e
   };
80913e
 
80913e
+enum grub_verify_string_type
80913e
+  {
80913e
+    GRUB_VERIFY_KERNEL_CMDLINE,
80913e
+    GRUB_VERIFY_MODULE_CMDLINE,
80913e
+  };
80913e
+
80913e
 struct grub_file_verifier
80913e
 {
80913e
   struct grub_file_verifier *next;
80913e
@@ -48,6 +54,8 @@ struct grub_file_verifier
80913e
 
80913e
   grub_err_t (*fini) (void *context);
80913e
   void (*close) (void *context);
80913e
+
80913e
+  grub_err_t (*verify_string) (char *str, enum grub_verify_string_type type);
80913e
 };
80913e
 
80913e
 extern struct grub_file_verifier *grub_file_verifiers;
80913e
@@ -63,3 +71,6 @@ grub_verifier_unregister (struct grub_file_verifier *ver)
80913e
 {
80913e
   grub_list_remove (GRUB_AS_LIST (ver));
80913e
 }
80913e
+
80913e
+grub_err_t
80913e
+grub_verify_string (char *str, enum grub_verify_string_type type);