verifiers: File type for fine-grained signature-verification controlling

Let's provide file type info to the I/O layer. This way verifiers
framework and its users will be able to differentiate files and verify
only required ones.

This is preparatory patch.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
This commit is contained in:
Vladimir Serbinenko 2013-11-20 02:28:29 +01:00 committed by Vincent Batts
parent e1bc2b23f1
commit aebe31c375
70 changed files with 292 additions and 221 deletions

View file

@ -219,7 +219,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
b = grub_efi_system_table->boot_services;
file = grub_file_open (filename);
file = grub_file_open (filename, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE);
if (! file)
goto fail;

View file

@ -1457,7 +1457,7 @@ grub_bsd_load (int argc, char *argv[])
goto fail;
}
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
if (!file)
goto fail;
@ -1534,7 +1534,7 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
if (err)
return err;
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
if (! file)
return grub_errno;
@ -1693,7 +1693,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
{
grub_file_t file;
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
if (! file)
return grub_errno;
@ -1802,7 +1802,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
goto fail;
}
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_ENV);
if ((!file) || (!file->size))
goto fail;
@ -1907,7 +1907,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),
return 0;
}
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE);
if ((!file) || (!file->size))
goto fail;
@ -1958,7 +1958,7 @@ grub_netbsd_module_load (char *filename, grub_uint32_t type)
void *src;
grub_err_t err;
file = grub_file_open (filename);
file = grub_file_open (filename, GRUB_FILE_TYPE_NETBSD_MODULE);
if ((!file) || (!file->size))
goto fail;
@ -2048,7 +2048,7 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)),
return 0;
}
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE_ELF);
if (!file)
return grub_errno;
if (!file->size)
@ -2088,7 +2088,7 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)),
if (!openbsd_ramdisk.max_size)
return grub_error (GRUB_ERR_BAD_OS, "your kOpenBSD doesn't support ramdisk");
file = grub_file_open (args[0]);
file = grub_file_open (args[0], GRUB_FILE_TYPE_OPENBSD_RAMDISK);
if (! file)
return grub_errno;

View file

@ -439,7 +439,7 @@ grub_cmd_chain (grub_command_t cmd __attribute__ ((unused)),
grub_loader_unset ();
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_COREBOOT_CHAINLOADER);
if (!file)
return grub_errno;

View file

@ -656,7 +656,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
goto fail;
}
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
if (! file)
goto fail;

View file

@ -172,8 +172,8 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
grub_dl_ref (my_mod);
grub_file_filter_disable_compression ();
file = grub_file_open (filename);
file = grub_file_open (filename, GRUB_FILE_TYPE_PCCHAINLOADER
| GRUB_FILE_TYPE_NO_DECOMPRESS);
if (! file)
goto fail;

View file

@ -110,7 +110,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)),
if (!rel)
goto fail;
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEDOS);
if (! file)
goto fail;

View file

@ -141,7 +141,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
goto fail;
}
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
if (! file)
goto fail;

View file

@ -90,7 +90,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)),
if (!rel)
goto fail;
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_NTLDR);
if (! file)
goto fail;

View file

@ -413,7 +413,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
if (!rel)
goto fail;
fill_ctx.file = grub_file_open (argv[0]);
fill_ctx.file = grub_file_open (argv[0], GRUB_FILE_TYPE_PLAN9_KERNEL);
if (! fill_ctx.file)
goto fail;

View file

@ -99,7 +99,7 @@ grub_cmd_pxechain (grub_command_t cmd __attribute__ ((unused)),
if (!rel)
goto fail;
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_PXECHAINLOADER);
if (! file)
goto fail;

View file

@ -99,7 +99,7 @@ grub_cmd_truecrypt (grub_command_t cmd __attribute__ ((unused)),
grub_dl_ref (my_mod);
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_TRUECRYPT);
if (! file)
goto fail;

View file

@ -648,7 +648,7 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),
(char *) xen_state.next_start.cmd_line,
sizeof (xen_state.next_start.cmd_line) - 1);
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
if (!file)
return grub_errno;
@ -895,9 +895,8 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
xen_state.max_addr = ALIGN_UP (xen_state.max_addr, PAGE_SIZE);
if (nounzip)
grub_file_filter_disable_compression ();
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_INITRD |
(nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : GRUB_FILE_TYPE_NONE));
if (!file)
return grub_errno;
size = grub_file_size (file);

View file

@ -90,7 +90,7 @@ grub_xen_file_and_cmdline (grub_file_t file,
Trim it. */
if (grub_memcmp (magic, XZ_MAGIC, sizeof (XZ_MAGIC) - 1) == 0)
payload_length -= 4;
off_file = grub_file_offset_open (file, payload_offset,
off_file = grub_file_offset_open (file, GRUB_FILE_TYPE_LINUX_KERNEL, payload_offset,
payload_length);
if (!off_file)
goto fail;

View file

@ -487,7 +487,7 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)),
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
file = grub_file_open (args[0]);
file = grub_file_open (args[0], GRUB_FILE_XNU_DEVPROP);
if (! file)
return grub_errno;
size = grub_file_size (file);

View file

@ -174,7 +174,6 @@ grub_initrd_init (int argc, char *argv[],
eptr = grub_strchr (ptr, ':');
if (eptr)
{
grub_file_filter_disable_compression ();
initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr);
if (!initrd_ctx->components[i].newc_name)
{
@ -199,8 +198,9 @@ grub_initrd_init (int argc, char *argv[],
root = 0;
newc = 0;
}
grub_file_filter_disable_compression ();
initrd_ctx->components[i].file = grub_file_open (fname);
initrd_ctx->components[i].file = grub_file_open (fname,
GRUB_FILE_TYPE_LINUX_INITRD
| GRUB_FILE_TYPE_NO_DECOMPRESS);
if (!initrd_ctx->components[i].file)
{
grub_initrd_close (initrd_ctx);

View file

@ -188,12 +188,12 @@ fail:
}
grub_macho_t
grub_macho_open (const char *name, int is_64bit)
grub_macho_open (const char *name, enum grub_file_type type, int is_64bit)
{
grub_file_t file;
grub_macho_t macho;
file = grub_file_open (name);
file = grub_file_open (name, type);
if (! file)
return 0;

View file

@ -237,7 +237,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
elf = grub_elf_open (argv[0]);
elf = grub_elf_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
if (! elf)
return grub_errno;

View file

@ -322,7 +322,7 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)),
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_KERNEL);
if (! file)
return grub_errno;
@ -388,10 +388,8 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
return grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("you need to load the kernel first"));
if (nounzip)
grub_file_filter_disable_compression ();
file = grub_file_open (argv[0]);
file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_MODULE
| (nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : GRUB_FILE_TYPE_NONE));
if (! file)
return grub_errno;

View file

@ -351,7 +351,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
grub_xnu_unload ();
macho = grub_macho_open (args[0], 0);
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 0);
if (! macho)
return grub_errno;
@ -456,7 +456,7 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
grub_xnu_unload ();
macho = grub_macho_open (args[0], 1);
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 1);
if (! macho)
return grub_errno;
@ -674,7 +674,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile,
macho = 0;
if (infoplistname)
infoplist = grub_file_open (infoplistname);
infoplist = grub_file_open (infoplistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
else
infoplist = 0;
grub_errno = GRUB_ERR_NONE;
@ -771,7 +771,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
file = grub_file_open (args[0]);
file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_MKEXT);
if (! file)
return grub_errno;
@ -885,7 +885,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
file = grub_file_open (args[0]);
file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_RAMDISK);
if (! file)
return grub_errno;
@ -925,7 +925,7 @@ grub_xnu_check_os_bundle_required (char *plistname,
if (binname)
*binname = 0;
file = grub_file_open (plistname);
file = grub_file_open (plistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
if (! file)
return 0;
@ -1210,7 +1210,7 @@ grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired,
grub_strcpy (binname + grub_strlen (binname), "/");
grub_strcpy (binname + grub_strlen (binname), binsuffix);
grub_dprintf ("xnu", "%s:%s\n", ctx.plistname, binname);
binfile = grub_file_open (binname);
binfile = grub_file_open (binname, GRUB_FILE_TYPE_XNU_KEXT);
if (! binfile)
grub_errno = GRUB_ERR_NONE;
@ -1253,7 +1253,7 @@ grub_cmd_xnu_kext (grub_command_t cmd __attribute__ ((unused)),
/* User explicitly specified plist and binary. */
if (grub_strcmp (args[1], "-") != 0)
{
binfile = grub_file_open (args[1]);
binfile = grub_file_open (args[1], GRUB_FILE_TYPE_XNU_KEXT);
if (! binfile)
return grub_errno;
}

View file

@ -53,8 +53,8 @@ grub_xnu_resume (char *imagename)
grub_addr_t target_image;
grub_err_t err;
grub_file_filter_disable_compression ();
file = grub_file_open (imagename);
file = grub_file_open (imagename, GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE
| GRUB_FILE_TYPE_NO_DECOMPRESS);
if (! file)
return 0;