Skip to content
Snippets Groups Projects
Commit 465c8e37 authored by Rocky Automation's avatar Rocky Automation :tv:
Browse files

import grub2-2.02-87.el8_2

parent 512acd7c
No related branches found
Tags imports/r8/grub2-2.02-148.el8_8.1
No related merge requests found
Showing
with 2149 additions and 0 deletions
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 10 Jul 2018 16:54:02 -0400
Subject: [PATCH] Force everything to use python3
But this still means you need to do PYTHON=python=3 ./autogen.sh if you
run the world's worst tooling before you patch.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
conf/Makefile.common | 4 ++--
gentpl.py | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/conf/Makefile.common b/conf/Makefile.common
index c75848f5c06..1ecb921db65 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -128,11 +128,11 @@ BUILT_SOURCES =
.PRECIOUS: $(top_srcdir)/Makefile.util.am
$(top_srcdir)/Makefile.util.am: $(top_srcdir)/gentpl.py $(top_srcdir)/Makefile.util.def $(top_srcdir)/Makefile.utilgcry.def
- python $^ > $@.new || (rm -f $@.new; exit 1)
+ python3 $^ > $@.new || (rm -f $@.new; exit 1)
mv $@.new $@
.PRECIOUS: $(top_srcdir)/grub-core/Makefile.core.am
$(top_srcdir)/grub-core/Makefile.core.am: $(top_srcdir)/gentpl.py $(top_srcdir)/grub-core/Makefile.core.def $(top_srcdir)/grub-core/Makefile.gcry.def
if [ "x$$GRUB_CONTRIB" != x ]; then echo "You need to run ./autogen.sh manually." >&2; exit 1; fi
- python $^ > $@.new || (rm -f $@.new; exit 1)
+ python3 $^ > $@.new || (rm -f $@.new; exit 1)
mv $@.new $@
diff --git a/gentpl.py b/gentpl.py
index baac6a2af69..6409736e81c 100644
--- a/gentpl.py
+++ b/gentpl.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#! /usr/bin/env python3
# GRUB -- GRand Unified Bootloader
# Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
#
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 26 Jul 2018 14:54:44 -0400
Subject: [PATCH] Fix an 8 year old typo.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
configure.ac | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 5f47a9265f3..9ab683fefac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -307,7 +307,7 @@ fi
AC_SUBST(bootdirname)
AC_DEFINE_UNQUOTED(GRUB_BOOT_DIR_NAME, "$bootdirname",
- [Default boot directory name]")
+ [Default boot directory name])
AC_ARG_WITH([grubdir],
AS_HELP_STRING([--with-grubdir=DIR],
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 26 Jul 2018 15:47:48 -0400
Subject: [PATCH] autogen: don't run autoreconf in the topdir
Signed-off-by: Peter Jones <pjones@redhat.com>
---
autogen.sh | 2 --
1 file changed, 2 deletions(-)
diff --git a/autogen.sh b/autogen.sh
index 7537561ad0d..f608b9467a0 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -82,6 +82,4 @@ done
echo "Saving timestamps..."
echo timestamp > stamp-h.in
-echo "Running autoreconf..."
-autoreconf -vi
exit 0
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 26 Jun 2018 17:16:06 -0400
Subject: [PATCH] Make it so we can tell configure which cflags utils are built
with
This lets us have kernel.img be built with TARGET_CFLAGS but grub-mkimage and
friends built with HOST_CFLAGS. That in turn lets us build with an ARM compiler
that only has hard-float ABI versions of crt*.o and libgcc*, but still use soft
float for grub.efi.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
configure.ac | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
conf/Makefile.common | 23 ++++++++++++-----------
gentpl.py | 8 ++++----
3 files changed, 64 insertions(+), 16 deletions(-)
diff --git a/configure.ac b/configure.ac
index 9ab683fefac..819212095ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -850,11 +850,23 @@ if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$p
TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow"
fi
+# Should grub utils get the host CFLAGS, or the target CFLAGS?
+AC_ARG_WITH([utils],
+ AS_HELP_STRING([--with-utils=host|target|build],
+ [choose which flags to build utilities with. (default=target)]),
+ [have_with_utils=y],
+ [have_with_utils=n])
+if test x"$have_with_utils" = xy ; then
+ with_utils="$withval"
+else
+ with_utils=target
+fi
+
# GRUB doesn't use float or doubles at all. Yet some toolchains may decide
# that floats are a good fit to run instead of what's written in the code.
# Given that floating point unit is disabled (if present to begin with)
# when GRUB is running which may result in various hard crashes.
-if test x"$platform" != xemu ; then
+if test x"$platform" != xemu -a x"$with_utils" == xtarget ; then
AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [
grub_cv_target_cc_soft_float=no
if test "x$target_cpu" = xarm64; then
@@ -1939,6 +1951,41 @@ HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include"
+case "$with_utils" in
+ host)
+ UTILS_CFLAGS=$HOST_CFLAGS
+ UTILS_CPPFLAGS=$HOST_CPPFLAGS
+ UTILS_CCASFLAGS=$HOST_CCASFLAGS
+ UTILS_LDFLAGS=$HOST_LDFLAGS
+ ;;
+ target)
+ UTILS_CFLAGS=$TARGET_CFLAGS
+ UTILS_CPPFLAGS=$TARGET_CPPFLAGS
+ UTILS_CCASFLAGS=$TARGET_CCASFLAGS
+ UTILS_LDFLAGS=$TARGET_LDFLAGS
+ ;;
+ build)
+ UTILS_CFLAGS=$BUILD_CFLAGS
+ UTILS_CPPFLAGS=$BUILD_CPPFLAGS
+ UTILS_CCASFLAGS=$BUILD_CCASFLAGS
+ UTILS_LDFLAGS=$BUILD_LDFLAGS
+ ;;
+ *)
+ AC_MSG_ERROR([--with-utils must be either host, target, or build])
+ ;;
+esac
+AC_MSG_NOTICE([Using $with_utils flags for utilities.])
+
+unset CFLAGS
+unset CPPFLAGS
+unset CCASFLAGS
+unset LDFLAGS
+
+AC_SUBST(UTILS_CFLAGS)
+AC_SUBST(UTILS_CPPFLAGS)
+AC_SUBST(UTILS_CCASFLAGS)
+AC_SUBST(UTILS_LDFLAGS)
+
GRUB_TARGET_CPU="${target_cpu}"
GRUB_PLATFORM="${platform}"
diff --git a/conf/Makefile.common b/conf/Makefile.common
index 1ecb921db65..b93879804c0 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -40,24 +40,25 @@ CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1
CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx -R .note.gnu.property -R .gnu.build.attributes
-CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding
-LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d
-CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM)
-CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
+CFLAGS_MODULE = $(TARGET_CFLAGS) $(CFLAGS_PLATFORM) -ffreestanding
+LDFLAGS_MODULE = $(TARGET_LDFLAGS) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d
+CPPFLAGS_MODULE = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT) $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM)
+CCASFLAGS_MODULE = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT) $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
CFLAGS_IMAGE = $(CFLAGS_PLATFORM) -fno-builtin
LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-S
CPPFLAGS_IMAGE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM)
CCASFLAGS_IMAGE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
-CFLAGS_PROGRAM =
-LDFLAGS_PROGRAM =
-CPPFLAGS_PROGRAM =
-CCASFLAGS_PROGRAM =
+CFLAGS_PROGRAM = $(UTILS_CFLAGS)
+LDFLAGS_PROGRAM = $(UTILS_LDFLAGS)
+CPPFLAGS_PROGRAM = $(UTILS_CPPFLAGS)
+CCASFLAGS_PROGRAM = $(UTILS_CCASFLAGS)
-CFLAGS_LIBRARY =
-CPPFLAGS_LIBRARY =
-CCASFLAGS_LIBRARY =
+CFLAGS_LIBRARY = $(UTILS_CFLAGS)
+LDFLAGS_LIBRARY = $(UTILS_LDFLAGS)
+CPPFLAGS_LIBRARY = $(UTILS_CPPFLAGS)
+CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS)
# Other variables
diff --git a/gentpl.py b/gentpl.py
index 6409736e81c..1e4635f4426 100644
--- a/gentpl.py
+++ b/gentpl.py
@@ -694,10 +694,10 @@ def module(defn, platform):
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform) + " ## platform sources")
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources")
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
- var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_MODULE) " + platform_cflags(defn, platform))
- var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_MODULE) " + platform_ldflags(defn, platform))
- var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform))
- var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform))
+ var_set(cname(defn) + "_CFLAGS", "$(CFLAGS_MODULE) " + platform_cflags(defn, platform))
+ var_set(cname(defn) + "_LDFLAGS", "$(LDFLAGS_MODULE) " + platform_ldflags(defn, platform))
+ var_set(cname(defn) + "_CPPFLAGS", "$(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform))
+ var_set(cname(defn) + "_CCASFLAGS", "$(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform))
var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF) " + platform_dependencies(defn, platform))
gvar_add("dist_noinst_DATA", extra_dist(defn))
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 1 Aug 2018 10:24:52 -0400
Subject: [PATCH] module-verifier: make it possible to run checkers on
grub-module-verifierxx.c
This makes it so you can treat grub-module-verifierxx.c as a file you can
build directly, so syntax checkers like vim's "syntastic" plugin, which uses
"gcc -x c -fsyntax-only" to build it, will work.
One still has to do whatever setup is required to make it pick the right
include dirs, which -W options we use, etc., but this makes it so you can do
the checking on the file you're editing, rather than on a different file.
v2: fix the typo in the #else clause in util/grub-module-verifierXX.c
Signed-off-by: Peter Jones <pjones@redhat.com>
---
util/grub-module-verifier32.c | 2 ++
util/grub-module-verifier64.c | 2 ++
util/grub-module-verifierXX.c | 9 +++++++++
3 files changed, 13 insertions(+)
diff --git a/util/grub-module-verifier32.c b/util/grub-module-verifier32.c
index 257229f8f08..ba7d41aafea 100644
--- a/util/grub-module-verifier32.c
+++ b/util/grub-module-verifier32.c
@@ -1,2 +1,4 @@
#define MODULEVERIFIER_ELF32 1
+#ifndef GRUB_MODULE_VERIFIERXX
#include "grub-module-verifierXX.c"
+#endif
diff --git a/util/grub-module-verifier64.c b/util/grub-module-verifier64.c
index 4db6b4bedd1..fc23ef800b3 100644
--- a/util/grub-module-verifier64.c
+++ b/util/grub-module-verifier64.c
@@ -1,2 +1,4 @@
#define MODULEVERIFIER_ELF64 1
+#ifndef GRUB_MODULE_VERIFIERXX
#include "grub-module-verifierXX.c"
+#endif
diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c
index 1feaafc9b9e..597ded14362 100644
--- a/util/grub-module-verifierXX.c
+++ b/util/grub-module-verifierXX.c
@@ -1,3 +1,12 @@
+#define GRUB_MODULE_VERIFIERXX
+#if !defined(MODULEVERIFIER_ELF32) && !defined(MODULEVERIFIER_ELF64)
+#if __SIZEOF_POINTER__ == 8
+#include "grub-module-verifier64.c"
+#else
+#include "grub-module-verifier32.c"
+#endif
+#endif
+
#include <string.h>
#include <grub/elf.h>
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 1 Aug 2018 10:12:47 -0400
Subject: [PATCH] grub-module-verifier: report the filename or modname in
errors.
Make it so that when grub-module-verifier complains of an issue, it tells you
which module the issue was with.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
util/grub-module-verifier.c | 6 ++---
util/grub-module-verifierXX.c | 58 ++++++++++++++++++++++--------------------
include/grub/module_verifier.h | 4 +--
3 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c
index a79271f6631..03ba1ab437a 100644
--- a/util/grub-module-verifier.c
+++ b/util/grub-module-verifier.c
@@ -157,7 +157,7 @@ main (int argc, char **argv)
if (strcmp(archs[arch].name, argv[2]) == 0)
break;
if (arch == ARRAY_SIZE(archs))
- grub_util_error("unknown arch: %s", argv[2]);
+ grub_util_error("%s: unknown arch: %s", argv[1], argv[2]);
for (whitelist = 0; whitelist < ARRAY_SIZE(whitelists); whitelist++)
if (strcmp(whitelists[whitelist].arch, argv[2]) == 0
@@ -169,8 +169,8 @@ main (int argc, char **argv)
module_size = grub_util_get_image_size (argv[1]);
module_img = grub_util_read_image (argv[1]);
if (archs[arch].voidp_sizeof == 8)
- grub_module_verify64(module_img, module_size, &archs[arch], whitelist_empty);
+ grub_module_verify64(argv[1], module_img, module_size, &archs[arch], whitelist_empty);
else
- grub_module_verify32(module_img, module_size, &archs[arch], whitelist_empty);
+ grub_module_verify32(argv[1], module_img, module_size, &archs[arch], whitelist_empty);
return 0;
}
diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c
index 597ded14362..a98e2f9b1ac 100644
--- a/util/grub-module-verifierXX.c
+++ b/util/grub-module-verifierXX.c
@@ -160,14 +160,15 @@ find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const c
}
static void
-check_license (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
+check_license (const char * const filename,
+ const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
{
Elf_Shdr *s = find_section (arch, e, ".module_license");
if (s && (strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3") == 0
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3+") == 0
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv2+") == 0))
return;
- grub_util_error ("incompatible license");
+ grub_util_error ("%s: incompatible license", filename);
}
static Elf_Sym *
@@ -233,10 +234,10 @@ check_symbols (const struct grub_module_verifier_arch *arch,
s = find_section (arch, e, ".moddeps");
if (!s)
- grub_util_error ("no symbol table and no .moddeps section");
+ grub_util_error ("%s: no symbol table and no .moddeps section", modname);
if (!s->sh_size)
- grub_util_error ("no symbol table and empty .moddeps section");
+ grub_util_error ("%s: no symbol table and empty .moddeps section", modname);
return;
}
@@ -257,7 +258,7 @@ check_symbols (const struct grub_module_verifier_arch *arch,
break;
default:
- return grub_util_error ("unknown symbol type `%d'", (int) type);
+ return grub_util_error ("%s: unknown symbol type `%d'", modname, (int) type);
}
}
}
@@ -283,7 +284,8 @@ is_symbol_local(Elf_Sym *sym)
}
static void
-section_check_relocations (const struct grub_module_verifier_arch *arch, void *ehdr,
+section_check_relocations (const char * const modname,
+ const struct grub_module_verifier_arch *arch, void *ehdr,
Elf_Shdr *s, size_t target_seg_size)
{
Elf_Rel *rel, *max;
@@ -292,7 +294,7 @@ section_check_relocations (const struct grub_module_verifier_arch *arch, void *e
symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize);
if (!symtab)
- grub_util_error ("relocation without symbol table");
+ grub_util_error ("%s: relocation without symbol table", modname);
for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)),
max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size));
@@ -303,7 +305,7 @@ section_check_relocations (const struct grub_module_verifier_arch *arch, void *e
unsigned i;
if (target_seg_size < grub_target_to_host (rel->r_offset))
- grub_util_error ("reloc offset is out of the segment");
+ grub_util_error ("%s: reloc offset is out of the segment", modname);
grub_uint32_t type = ELF_R_TYPE (grub_target_to_host (rel->r_info));
@@ -316,17 +318,17 @@ section_check_relocations (const struct grub_module_verifier_arch *arch, void *e
if (arch->supported_relocations[i] != -1)
continue;
if (!arch->short_relocations)
- grub_util_error ("unsupported relocation 0x%x", type);
+ grub_util_error ("%s: unsupported relocation 0x%x", modname, type);
for (i = 0; arch->short_relocations[i] != -1; i++)
if (type == arch->short_relocations[i])
break;
if (arch->short_relocations[i] == -1)
- grub_util_error ("unsupported relocation 0x%x", type);
+ grub_util_error ("%s: unsupported relocation 0x%x", modname, type);
sym = (Elf_Sym *) ((char *) symtab + symtabentsize * ELF_R_SYM (grub_target_to_host (rel->r_info)));
if (is_symbol_local (sym))
continue;
- grub_util_error ("relocation 0x%x is not module-local", type);
+ grub_util_error ("%s: relocation 0x%x is not module-local", modname, type);
}
#if defined(MODULEVERIFIER_ELF64)
if (arch->machine == EM_AARCH64)
@@ -351,11 +353,11 @@ section_check_relocations (const struct grub_module_verifier_arch *arch, void *e
&& ELF_R_TYPE (rel2->r_info) == R_AARCH64_LD64_GOT_LO12_NC)
break;
if (rel2 >= (Elf_Rela *) max)
- grub_util_error ("ADR_GOT_PAGE without matching LD64_GOT_LO12_NC");
+ grub_util_error ("%s: ADR_GOT_PAGE without matching LD64_GOT_LO12_NC", modname);
break;
case R_AARCH64_LD64_GOT_LO12_NC:
if (unmatched_adr_got_page == 0)
- grub_util_error ("LD64_GOT_LO12_NC without matching ADR_GOT_PAGE");
+ grub_util_error ("%s: LD64_GOT_LO12_NC without matching ADR_GOT_PAGE", modname);
unmatched_adr_got_page--;
break;
}
@@ -365,7 +367,8 @@ section_check_relocations (const struct grub_module_verifier_arch *arch, void *e
}
static void
-check_relocations (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
+check_relocations (const char * const modname,
+ const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
{
Elf_Shdr *s;
unsigned i;
@@ -378,21 +381,22 @@ check_relocations (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
Elf_Shdr *ts;
if (grub_target_to_host32 (s->sh_type) == SHT_REL && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_REL))
- grub_util_error ("unsupported SHT_REL");
+ grub_util_error ("%s: unsupported SHT_REL", modname);
if (grub_target_to_host32 (s->sh_type) == SHT_RELA && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_RELA))
- grub_util_error ("unsupported SHT_RELA");
+ grub_util_error ("%s: unsupported SHT_RELA", modname);
/* Find the target segment. */
if (grub_target_to_host32 (s->sh_info) >= grub_target_to_host16 (e->e_shnum))
- grub_util_error ("orphaned reloc section");
+ grub_util_error ("%s: orphaned reloc section", modname);
ts = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host32 (s->sh_info) * grub_target_to_host16 (e->e_shentsize));
- section_check_relocations (arch, e, s, grub_target_to_host (ts->sh_size));
+ section_check_relocations (modname, arch, e, s, grub_target_to_host (ts->sh_size));
}
}
void
-SUFFIX(grub_module_verify) (void *module_img, size_t size,
+SUFFIX(grub_module_verify) (const char * const filename,
+ void *module_img, size_t size,
const struct grub_module_verifier_arch *arch,
const char **whitelist_empty)
{
@@ -400,7 +404,7 @@ SUFFIX(grub_module_verify) (void *module_img, size_t size,
/* Check the header size. */
if (size < sizeof (Elf_Ehdr))
- grub_util_error ("ELF header smaller than expected");
+ grub_util_error ("%s: ELF header smaller than expected", filename);
/* Check the magic numbers. */
if (e->e_ident[EI_MAG0] != ELFMAG0
@@ -409,36 +413,36 @@ SUFFIX(grub_module_verify) (void *module_img, size_t size,
|| e->e_ident[EI_MAG3] != ELFMAG3
|| e->e_ident[EI_VERSION] != EV_CURRENT
|| grub_target_to_host32 (e->e_version) != EV_CURRENT)
- grub_util_error ("invalid arch-independent ELF magic");
+ grub_util_error ("%s: invalid arch-independent ELF magic", filename);
if (e->e_ident[EI_CLASS] != ELFCLASSXX
|| e->e_ident[EI_DATA] != (arch->bigendian ? ELFDATA2MSB : ELFDATA2LSB)
|| grub_target_to_host16 (e->e_machine) != arch->machine)
- grub_util_error ("invalid arch-dependent ELF magic");
+ grub_util_error ("%s: invalid arch-dependent ELF magic", filename);
if (grub_target_to_host16 (e->e_type) != ET_REL)
{
- grub_util_error ("this ELF file is not of the right type");
+ grub_util_error ("%s: this ELF file is not of the right type", filename);
}
/* Make sure that every section is within the core. */
if (size < grub_target_to_host (e->e_shoff)
+ (grub_uint32_t) grub_target_to_host16 (e->e_shentsize) * grub_target_to_host16(e->e_shnum))
{
- grub_util_error ("ELF sections outside core");
+ grub_util_error ("%s: ELF sections outside core", filename);
}
- check_license (arch, e);
+ check_license (filename, arch, e);
Elf_Shdr *s;
const char *modname;
s = find_section (arch, e, ".modname");
if (!s)
- grub_util_error ("no module name found");
+ grub_util_error ("%s: no module name found", filename);
modname = (const char *) e + grub_target_to_host (s->sh_offset);
check_symbols(arch, e, modname, whitelist_empty);
- check_relocations(arch, e);
+ check_relocations(modname, arch, e);
}
diff --git a/include/grub/module_verifier.h b/include/grub/module_verifier.h
index f4870cb9c2d..ba21c75e2eb 100644
--- a/include/grub/module_verifier.h
+++ b/include/grub/module_verifier.h
@@ -16,5 +16,5 @@ struct grub_module_verifier_arch {
const int *short_relocations;
};
-void grub_module_verify64(void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char **whitelist_empty);
-void grub_module_verify32(void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char **whitelist_empty);
+void grub_module_verify64(const char * const filename, void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char **whitelist_empty);
+void grub_module_verify32(const char * const filename, void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char **whitelist_empty);
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 11 Jul 2018 13:50:00 -0400
Subject: [PATCH] Make efi_netfs not duplicate symbols from efinet
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/Makefile.core.def | 6 ------
1 file changed, 6 deletions(-)
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index aa44d66aca4..e35217b8668 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -2186,12 +2186,6 @@ module = {
module = {
name = efi_netfs;
common = net/efi/efi_netfs.c;
- common = net/efi/net.c;
- common = net/efi/http.c;
- common = net/efi/pxe.c;
- common = net/efi/ip4_config.c;
- common = net/efi/ip6_config.c;
- common = net/efi/dhcp.c;
enable = efi;
};
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 12 Jul 2018 11:00:45 -0400
Subject: [PATCH] Rework how the fdt command builds.
Trying to avoid all variants of:
cat syminfo.lst | sort | gawk -f ../../grub-core/genmoddep.awk > moddep.lst || (rm -f moddep.lst; exit 1)
grub_fdt_install in linux is not defined
grub_fdt_load in linux is not defined
grub_fdt_unload in linux is not defined
grub_fdt_install in xen_boot is not defined
grub_fdt_load in xen_boot is not defined
grub_fdt_unload in xen_boot is not defined
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/Makefile.core.def | 5 ++---
grub-core/lib/fdt.c | 2 --
grub-core/loader/efi/fdt.c | 2 ++
include/grub/fdt.h | 4 ++++
grub-core/Makefile.am | 1 +
5 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index e35217b8668..cf3d549d212 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -166,7 +166,6 @@ kernel = {
arm_coreboot = kern/arm/coreboot/init.c;
arm_coreboot = kern/arm/coreboot/timer.c;
arm_coreboot = kern/arm/coreboot/coreboot.S;
- arm_coreboot = lib/fdt.c;
arm_coreboot = bus/fdt.c;
arm_coreboot = term/ps2.c;
arm_coreboot = term/arm/pl050.c;
@@ -317,6 +316,8 @@ kernel = {
arm64 = kern/arm64/dl.c;
arm64 = kern/arm64/dl_helper.c;
+ fdt = lib/fdt.c;
+
emu = disk/host.c;
emu = kern/emu/cache_s.S;
emu = kern/emu/hostdisk.c;
@@ -1714,7 +1715,6 @@ module = {
arm_uboot = loader/arm/linux.c;
arm64 = loader/arm64/linux.c;
emu = loader/emu/linux.c;
- fdt = lib/fdt.c;
common = loader/linux.c;
common = lib/cmdline.c;
@@ -1725,7 +1725,6 @@ module = {
module = {
name = fdt;
efi = loader/efi/fdt.c;
- common = lib/fdt.c;
enable = fdt;
};
diff --git a/grub-core/lib/fdt.c b/grub-core/lib/fdt.c
index 0d371c5633e..37e04bd69e7 100644
--- a/grub-core/lib/fdt.c
+++ b/grub-core/lib/fdt.c
@@ -21,8 +21,6 @@
#include <grub/mm.h>
#include <grub/dl.h>
-GRUB_MOD_LICENSE ("GPLv3+");
-
#define FDT_SUPPORTED_VERSION 17
#define FDT_BEGIN_NODE 0x00000001
diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
index a4c6e803645..a9dbcfdfeaf 100644
--- a/grub-core/loader/efi/fdt.c
+++ b/grub-core/loader/efi/fdt.c
@@ -26,6 +26,8 @@
#include <grub/efi/fdtload.h>
#include <grub/efi/memory.h>
+GRUB_MOD_LICENSE ("GPLv3+");
+
static void *loaded_fdt;
static void *fdt;
diff --git a/include/grub/fdt.h b/include/grub/fdt.h
index 158b1bc4b3a..6ee57e11ab3 100644
--- a/include/grub/fdt.h
+++ b/include/grub/fdt.h
@@ -19,6 +19,8 @@
#ifndef GRUB_FDT_HEADER
#define GRUB_FDT_HEADER 1
+#if defined(__arm__) || defined(__aarch64__)
+
#include <grub/types.h>
#include <grub/symbol.h>
@@ -141,4 +143,6 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch
grub_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \
})
+#endif /* defined(__arm__) || defined(__aarch64__) */
+
#endif /* ! GRUB_FDT_HEADER */
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index 3781bb9cbb9..4062652506d 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -76,6 +76,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/sb.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/file.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 2 Aug 2018 10:56:38 -0400
Subject: [PATCH] Disable non-wordsize allocations on arm
Signed-off-by: Peter Jones <pjones@redhat.com>
---
configure.ac | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/configure.ac b/configure.ac
index 819212095ff..9323c125469 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1234,6 +1234,26 @@ if test "x$target_cpu" = xarm; then
done
])
+ AC_CACHE_CHECK([for options to disable movt and movw relocations],
+ grub_cv_target_cc_mword_relocations,
+ [grub_cv_target_cc_mword_relocations=no
+ for cand in "-mword-relocations" ; do
+ if test x"$grub_cv_target_cc_mword_relocations" != xno ; then
+ break
+ fi
+ CFLAGS="$TARGET_CFLAGS $cand -Werror"
+ CPPFLAGS="$TARGET_CPPFLAGS"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+ [grub_cv_target_cc_mword_relocations="$cand"],
+ [])
+ done
+ ])
+ if test x"$grub_cv_target_cc_mword_relocations" = xno ; then
+ AC_MSG_ERROR(["your compiler doesn't support disabling movw/movt relocations"])
+ else
+ TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mword_relocations"
+ fi
+
if test x"$grub_cv_target_cc_mno_movt" != xno ; then
# A trick so that clang doesn't see it on link stage
TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_movt"
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 3 Aug 2018 15:07:23 -0400
Subject: [PATCH] strip "-R .note.gnu.property" at more places.
For whatever reason, sometimes I see:
lzma_decompress.image: file format elf32-i386
lzma_decompress.image
architecture: i386, flags 0x00000012:
EXEC_P, HAS_SYMS
start address 0x00008200
Program Header:
LOAD off 0x000000c0 vaddr 0x00008200 paddr 0x00008200 align 2**5
filesz 0x00000b10 memsz 0x00000b10 flags rwx
LOAD off 0x00000bd0 vaddr 0x080480b4 paddr 0x080480b4 align 2**2
filesz 0x0000001c memsz 0x0000001c flags r--
NOTE off 0x00000bd0 vaddr 0x080480b4 paddr 0x080480b4 align 2**2
filesz 0x0000001c memsz 0x0000001c flags r--
STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4
filesz 0x00000000 memsz 0x00000000 flags rw-
Sections:
Idx Name Size VMA LMA File off Algn
0 .note.gnu.property 0000001c 080480b4 080480b4 00000bd0 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .text 00000b10 00008200 00008200 000000c0 2**5
CONTENTS, ALLOC, LOAD, CODE
SYMBOL TABLE:
080480b4 l d .note.gnu.property 00000000 .note.gnu.property
00008200 l d .text 00000000 .text
00000000 l df *ABS* 00000000 startup_raw.S
...
Which just looks wrong no matter what to my eyes (seriously it's at
128M? Why?), and when we fail to strip it, we get:
trillian:~/tmp/f29$ hexdump -C usr/lib/grub/i386-pc/lzma_decompress.img | tail -6
00000b00 ff 45 e8 5a 83 c2 02 89 d1 e9 df fe ff ff 66 90 |.E.Z..........f.|
00000b10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
0803feb0 00 00 00 00 04 00 00 00 0c 00 00 00 05 00 00 00 |................|
0803fec0 47 4e 55 00 02 00 00 c0 04 00 00 00 03 00 00 00 |GNU.............|
0803fed0
Which is very very much not what we want.
Cut it out.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Makefile.am | 2 +-
gentpl.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index c7b0e6a9c46..287fff66b20 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -209,7 +209,7 @@ pc-chainloader.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-
$(TARGET_CC) -o $@ $< -static -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32
pc-chainloader.bin: pc-chainloader.elf
- $(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@;
+ $(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .note.gnu.property $< $@;
ntldr.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
$(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32
diff --git a/gentpl.py b/gentpl.py
index 1e4635f4426..d662c305f66 100644
--- a/gentpl.py
+++ b/gentpl.py
@@ -776,7 +776,7 @@ def image(defn, platform):
if test x$(TARGET_APPLE_LINKER) = x1; then \
$(MACHO2IMG) $< $@; \
else \
- $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx $< $@; \
+ $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx -R .note.gnu.property $< $@; \
fi
""")
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Stephen Benjamin <stephen@redhat.com>
Date: Thu, 16 Aug 2018 16:58:51 -0400
Subject: [PATCH] Prepend prefix when HTTP path is relative
This sets a couple of variables. With the url http://www.example.com/foo/bar :
http_path: /foo/bar
http_url: http://www.example.com/foo/bar
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/kern/main.c | 10 +++++-
grub-core/net/efi/http.c | 82 ++++++++++++++++++++++++++++++++++++------------
2 files changed, 71 insertions(+), 21 deletions(-)
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
index da47b18b50e..dcf48726d54 100644
--- a/grub-core/kern/main.c
+++ b/grub-core/kern/main.c
@@ -130,11 +130,19 @@ grub_set_prefix_and_root (void)
if (fwdevice && fwpath)
{
char *fw_path;
+ char separator[3] = ")";
- fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
+ grub_dprintf ("fw_path", "\n");
+ grub_dprintf ("fw_path", "fwdevice:\"%s\" fwpath:\"%s\"\n", fwdevice, fwpath);
+
+ if (!grub_strncmp(fwdevice, "http", 4) && fwpath[0] != '/')
+ grub_strcpy(separator, ")/");
+
+ fw_path = grub_xasprintf ("(%s%s%s", fwdevice, separator, fwpath);
if (fw_path)
{
grub_env_set ("fw_path", fw_path);
+ grub_dprintf ("fw_path", "fw_path:\"%s\"\n", fw_path);
grub_free (fw_path);
}
}
diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c
index 243acbaa35b..2a9624dacc4 100644
--- a/grub-core/net/efi/http.c
+++ b/grub-core/net/efi/http.c
@@ -9,10 +9,52 @@
static void
http_configure (struct grub_efi_net_device *dev, int prefer_ip6)
{
+ grub_efi_ipv6_address_t address;
grub_efi_http_config_data_t http_config;
grub_efi_httpv4_access_point_t httpv4_node;
grub_efi_httpv6_access_point_t httpv6_node;
grub_efi_status_t status;
+ int https;
+ char *http_url;
+ const char *rest, *http_server, *http_path = NULL;
+
+ http_server = grub_env_get ("root");
+ https = grub_strncmp (http_server, "https", 5) ? 1 : 0;
+
+ /* extract http server + port */
+ if (http_server)
+ {
+ http_server = grub_strchr (http_server, ',');
+ if (http_server)
+ http_server++;
+ }
+
+ /* fw_path is like (http,192.168.1.1:8000)/httpboot, extract path part */
+ http_path = grub_env_get ("fw_path");
+ if (http_path)
+ {
+ http_path = grub_strchr (http_path, ')');
+ if (http_path)
+ {
+ http_path++;
+ grub_env_unset ("http_path");
+ grub_env_set ("http_path", http_path);
+ }
+ }
+
+ if (http_server && http_path)
+ {
+ if (grub_efi_string_to_ip6_address (http_server, &address, &rest) && *rest == 0)
+ http_url = grub_xasprintf ("%s://[%s]%s", https ? "https" : "http", http_server, http_path);
+ else
+ http_url = grub_xasprintf ("%s://%s%s", https ? "https" : "http", http_server, http_path);
+ if (http_url)
+ {
+ grub_env_unset ("http_url");
+ grub_env_set ("http_url", http_url);
+ grub_free (http_url);
+ }
+ }
grub_efi_http_t *http = dev->http;
@@ -352,32 +394,32 @@ grub_efihttp_open (struct grub_efi_net_device *dev,
grub_err_t err;
grub_off_t size;
char *buf;
- char *root_url;
- grub_efi_ipv6_address_t address;
- const char *rest;
+ char *file_name;
+ const char *http_path;
- if (grub_efi_string_to_ip6_address (file->device->net->server, &address, &rest) && *rest == 0)
- root_url = grub_xasprintf ("%s://[%s]", type ? "https" : "http", file->device->net->server);
+ /* If path is relative, prepend http_path */
+ http_path = grub_env_get ("http_path");
+ if (http_path && file->device->net->name[0] != '/')
+ file_name = grub_xasprintf ("%s/%s", http_path, file->device->net->name);
else
- root_url = grub_xasprintf ("%s://%s", type ? "https" : "http", file->device->net->server);
- if (root_url)
- {
- grub_env_unset ("root_url");
- grub_env_set ("root_url", root_url);
- grub_free (root_url);
- }
- else
- {
- return grub_errno;
- }
+ file_name = grub_strdup (file->device->net->name);
- err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 1, 0);
+ if (!file_name)
+ return grub_errno;
+
+ err = efihttp_request (dev->http, file->device->net->server, file_name, type, 1, 0);
if (err != GRUB_ERR_NONE)
- return err;
+ {
+ grub_free (file_name);
+ return err;
+ }
- err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 0, &size);
+ err = efihttp_request (dev->http, file->device->net->server, file_name, type, 0, &size);
+ grub_free (file_name);
if (err != GRUB_ERR_NONE)
- return err;
+ {
+ return err;
+ }
buf = grub_malloc (size);
efihttp_read (dev, buf, size);
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 16 Aug 2018 11:08:11 -0400
Subject: [PATCH] Make linux_arm_kernel_header.hdr_offset be at the right place
The kernel in front of me (slightly edited to make objdump work) looks like:
00000000 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 |MZ..MZ..MZ..MZ..|
00000010 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 00 00 a0 e1 |MZ..MZ..MZ......|
00000020 f6 03 00 ea 18 28 6f 01 00 00 00 00 00 32 74 00 |.....(o......2t.|
00000030 01 02 03 04 45 45 45 45 74 a2 00 00 40 00 00 00 |....EEEEt...@...|
00000040 50 45 00 00 4c 01 04 00 00 00 00 00 00 00 00 00 |PE..L...........|
00000050 00 00 00 00 90 00 06 03 0b 01 02 14 00 20 74 00 |............. t.|
00000060 00 14 00 00 00 00 00 00 b4 19 00 00 00 10 00 00 |................|
00000070 00 30 74 00 00 00 00 00 00 10 00 00 00 02 00 00 |.0t.............|
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000090 00 44 74 00 00 10 00 00 00 00 00 00 0a 00 00 00 |.Dt.............|
000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000000b0 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 |................|
000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
(I don't know why the MZ header is there 7 times, but the offsets work out, so
it's merely a surprising distraction.)
If linux_arm_kernel_header.reserved2 is 16 bytes, that means hdr_offset is
here:
00000030 01 02 03 04 45 45 45 45 74 a2 00 00 40 00 00 00 |....EEEEt...@...|
00000040 50 45 00 00 4c 01 04 00 00 00 00 00 00 00 00 00 |PE..L...........|
^^^^^^^^^^^
But it's supposed to be 4 bytes before that.
This patch makes the reserved field be 3*32 instead of 4*32, and that means we
can find the PE header correcrtly at 0x40 by reading the value at 0x3c.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/loader/efi/linux.c | 3 +++
include/grub/arm/linux.h | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
index 0622dfa48d4..b56ea0bc041 100644
--- a/grub-core/loader/efi/linux.c
+++ b/grub-core/loader/efi/linux.c
@@ -79,7 +79,10 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,
offset = 512;
#endif
+ grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n",
+ kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params);
hf = (handover_func)((char *)kernel_addr + handover_offset + offset);
+ grub_dprintf ("linux", "handover_func() = %p\n", hf);
hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
return GRUB_ERR_BUG;
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
index 5900fc8a40c..bed308f22cb 100644
--- a/include/grub/arm/linux.h
+++ b/include/grub/arm/linux.h
@@ -31,7 +31,7 @@ struct linux_arm_kernel_header {
grub_uint32_t magic;
grub_uint32_t start; /* _start */
grub_uint32_t end; /* _edata */
- grub_uint32_t reserved2[4];
+ grub_uint32_t reserved2[3];
grub_uint32_t hdr_offset;
};
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 27 Aug 2018 13:10:08 -0400
Subject: [PATCH] Mark some unused stuff unused
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/commands/blscfg.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
index bdb1c5a95aa..abd6f00d0de 100644
--- a/grub-core/commands/blscfg.c
+++ b/grub-core/commands/blscfg.c
@@ -434,7 +434,7 @@ finish:
static grub_envblk_t saved_env = NULL;
-static int
+static int UNUSED
save_var (const char *name, const char *value, void *whitelist UNUSED)
{
const char *val = grub_env_get (name);
@@ -446,7 +446,7 @@ save_var (const char *name, const char *value, void *whitelist UNUSED)
return 0;
}
-static int
+static int UNUSED
unset_var (const char *name, const char *value UNUSED, void *whitelist)
{
grub_dprintf("blscfg", "restoring \"%s\"\n", name);
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 27 Aug 2018 13:14:06 -0400
Subject: [PATCH] Make grub_error() more verbose
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/kern/efi/mm.c | 17 ++++++++++++++---
grub-core/kern/err.c | 13 +++++++++++--
include/grub/err.h | 5 ++++-
3 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index 5cdf6c943f2..7692e63ba24 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -157,12 +157,20 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
/* Limit the memory access to less than 4GB for 32-bit platforms. */
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
- return 0;
+ {
+ grub_error (GRUB_ERR_BAD_ARGUMENT,
+ N_("invalid memory address (0x%llx > 0x%llx)"),
+ address, GRUB_EFI_MAX_USABLE_ADDRESS);
+ return NULL;
+ }
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
if (status != GRUB_EFI_SUCCESS)
- return 0;
+ {
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+ return NULL;
+ }
if (address == 0)
{
@@ -172,7 +180,10 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
grub_efi_free_pages (0, pages);
if (status != GRUB_EFI_SUCCESS)
- return 0;
+ {
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+ return NULL;
+ }
}
grub_efi_store_alloc (address, pages);
diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c
index 53c734de70e..aebfe0cf839 100644
--- a/grub-core/kern/err.c
+++ b/grub-core/kern/err.c
@@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];
static int grub_error_stack_pos;
static int grub_error_stack_assert;
+#ifdef grub_error
+#undef grub_error
+#endif
+
grub_err_t
-grub_error (grub_err_t n, const char *fmt, ...)
+grub_error (grub_err_t n, const char *file, const int line, const char *fmt, ...)
{
va_list ap;
+ int m;
grub_errno = n;
+ m = grub_snprintf (grub_errmsg, sizeof (grub_errmsg), "%s:%d:", file, line);
+ if (m < 0)
+ m = 0;
+
va_start (ap, fmt);
- grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), _(fmt), ap);
+ grub_vsnprintf (grub_errmsg + m, sizeof (grub_errmsg) - m, _(fmt), ap);
va_end (ap);
return n;
diff --git a/include/grub/err.h b/include/grub/err.h
index 1590c688e1d..9b830757d35 100644
--- a/include/grub/err.h
+++ b/include/grub/err.h
@@ -84,7 +84,10 @@ struct grub_error_saved
extern grub_err_t EXPORT_VAR(grub_errno);
extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG];
-grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...);
+grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...);
+
+#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
+
void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn));
void EXPORT_FUNC(grub_error_push) (void);
int EXPORT_FUNC(grub_error_pop) (void);
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 14 Aug 2018 14:07:44 -0400
Subject: [PATCH] arm/arm64 loader: Better memory allocation and error
messages.
On mustang, our memory map looks like:
Type Physical start - end #Pages Size Attributes
reserved 0000004000000000-00000040001fffff 00000200 2MiB UC WC WT WB
conv-mem 0000004000200000-0000004393ffffff 00393e00 14654MiB UC WC WT WB
ldr-code 0000004394000000-00000043f7ffffff 00064000 1600MiB UC WC WT WB
BS-data 00000043f8000000-00000043f801ffff 00000020 128KiB UC WC WT WB
conv-mem 00000043f8020000-00000043fa15bfff 0000213c 34032KiB UC WC WT WB
ldr-code 00000043fa15c000-00000043fa2a1fff 00000146 1304KiB UC WC WT WB
ldr-data 00000043fa2a2000-00000043fa3e8fff 00000147 1308KiB UC WC WT WB
conv-mem 00000043fa3e9000-00000043fa3e9fff 00000001 4KiB UC WC WT WB
ldr-data 00000043fa3ea000-00000043fa3eafff 00000001 4KiB UC WC WT WB
ldr-code 00000043fa3eb000-00000043fa4affff 000000c5 788KiB UC WC WT WB
BS-code 00000043fa4b0000-00000043fa59ffff 000000f0 960KiB UC WC WT WB
RT-code 00000043fa5a0000-00000043fa5affff 00000010 64KiB RT UC WC WT WB
RT-data 00000043fa5b0000-00000043fa5bffff 00000010 64KiB RT UC WC WT WB
RT-code 00000043fa5c0000-00000043fa5cffff 00000010 64KiB RT UC WC WT WB
ldr-data 00000043fa5d0000-00000043fa5d0fff 00000001 4KiB UC WC WT WB
BS-code 00000043fa5d1000-00000043fa5ddfff 0000000d 52KiB UC WC WT WB
reserved 00000043fa5de000-00000043fa60ffff 00000032 200KiB UC WC WT WB
ACPI-rec 00000043fa610000-00000043fa6affff 000000a0 640KiB UC WC WT WB
ACPI-nvs 00000043fa6b0000-00000043fa6bffff 00000010 64KiB UC WC WT WB
ACPI-rec 00000043fa6c0000-00000043fa70ffff 00000050 320KiB UC WC WT WB
RT-code 00000043fa710000-00000043fa72ffff 00000020 128KiB RT UC WC WT WB
RT-data 00000043fa730000-00000043fa78ffff 00000060 384KiB RT UC WC WT WB
RT-code 00000043fa790000-00000043fa79ffff 00000010 64KiB RT UC WC WT WB
RT-data 00000043fa7a0000-00000043fa99ffff 00000200 2MiB RT UC WC WT WB
RT-code 00000043fa9a0000-00000043fa9affff 00000010 64KiB RT UC WC WT WB
RT-data 00000043fa9b0000-00000043fa9cffff 00000020 128KiB RT UC WC WT WB
BS-code 00000043fa9d0000-00000043fa9d9fff 0000000a 40KiB UC WC WT WB
reserved 00000043fa9da000-00000043fa9dbfff 00000002 8KiB UC WC WT WB
conv-mem 00000043fa9dc000-00000043fc29dfff 000018c2 25352KiB UC WC WT WB
BS-data 00000043fc29e000-00000043fc78afff 000004ed 5044KiB UC WC WT WB
conv-mem 00000043fc78b000-00000043fca01fff 00000277 2524KiB UC WC WT WB
BS-data 00000043fca02000-00000043fcea3fff 000004a2 4744KiB UC WC WT WB
conv-mem 00000043fcea4000-00000043fcea4fff 00000001 4KiB UC WC WT WB
BS-data 00000043fcea5000-00000043fd192fff 000002ee 3000KiB UC WC WT WB
conv-mem 00000043fd193000-00000043fd2b0fff 0000011e 1144KiB UC WC WT WB
BS-data 00000043fd2b1000-00000043ff80ffff 0000255f 38268KiB UC WC WT WB
BS-code 00000043ff810000-00000043ff99ffff 00000190 1600KiB UC WC WT WB
RT-code 00000043ff9a0000-00000043ff9affff 00000010 64KiB RT UC WC WT WB
conv-mem 00000043ff9b0000-00000043ff9bffff 00000010 64KiB UC WC WT WB
RT-data 00000043ff9c0000-00000043ff9effff 00000030 192KiB RT UC WC WT WB
conv-mem 00000043ff9f0000-00000043ffa05fff 00000016 88KiB UC WC WT WB
BS-data 00000043ffa06000-00000043ffffffff 000005fa 6120KiB UC WC WT WB
MMIO 0000000010510000-0000000010510fff 00000001 4KiB RT
MMIO 0000000010548000-0000000010549fff 00000002 8KiB RT
MMIO 0000000017000000-0000000017001fff 00000002 8KiB RT
MMIO 000000001c025000-000000001c025fff 00000001 4KiB RT
When we're trying to find the base of ram, if we start with GRUB_UINT_MAX
(0xffffffff on all platforms) and always use min(), that means we eventually
decide that the base of ram is GRUB_UINT_MAX, which is lower than our first
memory address, and thus our allocation of the initramfs, which specifies this
value as the maximum possible address it can be at, fails.
This patch changes it to start at GRUB_EFI_MAX_USABLE_ADDRESS, which is always
at least 0xffffffff on 32-bit platforms and at least 0x7ffffffffffffff on
64-bit platforms. Additionally, this adds a requirement that the memory we
choose is actually /allocatable/ conventional memory, not merely
write-combining. On this machine that means we wind up with an allocation
around 0x4392XXXXXX, which is a reasonable address.
This also changes grub_efi_allocate_pages_real() so that if 0 is allocated, it
tries to allocate again starting with the same max address it did the first
time, rather than interposing GRUB_EFI_MAX_USABLE_ADDRESS there, so that any
per-platform constraints on its given address are maintained.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/kern/efi/mm.c | 32 ++++++++++++-----
grub-core/loader/arm64/linux.c | 78 ++++++++++++++++++++++++++++++++----------
2 files changed, 82 insertions(+), 28 deletions(-)
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index 7692e63ba24..306924f73a4 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -154,6 +154,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
{
grub_efi_status_t status;
grub_efi_boot_services_t *b;
+ grub_efi_physical_address_t ret = address;
/* Limit the memory access to less than 4GB for 32-bit platforms. */
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
@@ -165,19 +166,19 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
}
b = grub_efi_system_table->boot_services;
- status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
+ status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &ret);
if (status != GRUB_EFI_SUCCESS)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
return NULL;
}
- if (address == 0)
+ if (ret == 0)
{
/* Uggh, the address 0 was allocated... This is too annoying,
so reallocate another one. */
- address = GRUB_EFI_MAX_USABLE_ADDRESS;
- status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
+ ret = address;
+ status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &ret);
grub_efi_free_pages (0, pages);
if (status != GRUB_EFI_SUCCESS)
{
@@ -186,9 +187,9 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
}
}
- grub_efi_store_alloc (address, pages);
+ grub_efi_store_alloc (ret, pages);
- return (void *) ((grub_addr_t) address);
+ return (void *) ((grub_addr_t) ret);
}
void *
@@ -696,11 +697,24 @@ grub_efi_get_ram_base(grub_addr_t *base_addr)
if (ret < 1)
return GRUB_ERR_BUG;
- for (desc = memory_map, *base_addr = GRUB_UINT_MAX;
+ for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS;
(grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size);
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
- if (desc->attribute & GRUB_EFI_MEMORY_WB)
- *base_addr = grub_min (*base_addr, desc->physical_start);
+ {
+ if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY &&
+ (desc->attribute & GRUB_EFI_MEMORY_WB))
+ {
+ *base_addr = grub_min (*base_addr, desc->physical_start);
+ grub_dprintf ("efi", "setting base_addr=0x%016lx\n", *base_addr);
+ }
+ else
+ {
+ grub_dprintf ("efi", "ignoring address 0x%016lx\n", desc->physical_start);
+ }
+ }
+
+ if (*base_addr == GRUB_EFI_MAX_USABLE_ADDRESS)
+ grub_dprintf ("efi", "base_addr 0x%016lx is probably wrong.\n", *base_addr);
grub_free(memory_map);
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
index 93b5cd306eb..e1110749eb9 100644
--- a/grub-core/loader/arm64/linux.c
+++ b/grub-core/loader/arm64/linux.c
@@ -70,13 +70,15 @@ finalize_params_linux (void)
{
grub_efi_loaded_image_t *loaded_image = NULL;
int node, retval, len;
-
+ grub_err_t err = GRUB_ERR_NONE;
void *fdt;
fdt = grub_fdt_load (0x400);
-
if (!fdt)
- goto failure;
+ {
+ err = grub_error(GRUB_ERR_BAD_OS, "failed to load FDT");
+ goto failure;
+ }
node = grub_fdt_find_subnode (fdt, 0, "chosen");
if (node < 0)
@@ -87,17 +89,26 @@ finalize_params_linux (void)
*/
retval = grub_fdt_set_prop32(fdt, 0, "#address-cells", 2);
if (retval)
- goto failure;
+ {
+ err = grub_error(retval, "Could not find #address-cells");
+ goto failure;
+ }
retval = grub_fdt_set_prop32(fdt, 0, "#size-cells", 2);
if (retval)
- goto failure;
+ {
+ err = grub_error(retval, "Could not find #size-cells");
+ goto failure;
+ }
node = grub_fdt_add_subnode (fdt, 0, "chosen");
}
if (node < 1)
- goto failure;
+ {
+ err = grub_error(grub_errno, "failed to load chosen fdt node.");
+ goto failure;
+ }
/* Set initrd info */
if (initrd_start && initrd_end > initrd_start)
@@ -108,15 +119,26 @@ finalize_params_linux (void)
retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start",
initrd_start);
if (retval)
- goto failure;
+ {
+ err = grub_error(retval, "Failed to set linux,initrd-start property");
+ goto failure;
+ }
+
retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-end",
initrd_end);
if (retval)
- goto failure;
+ {
+ err = grub_error(retval, "Failed to set linux,initrd-end property");
+ goto failure;
+ }
}
- if (grub_fdt_install() != GRUB_ERR_NONE)
- goto failure;
+ retval = grub_fdt_install();
+ if (retval != GRUB_ERR_NONE)
+ {
+ err = grub_error(retval, "Failed to install fdt");
+ goto failure;
+ }
grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n",
fdt);
@@ -124,14 +146,20 @@ finalize_params_linux (void)
/* Convert command line to UCS-2 */
loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
if (!loaded_image)
- goto failure;
+ {
+ err = grub_error(grub_errno, "Failed to install fdt");
+ goto failure;
+ }
loaded_image->load_options_size = len =
(grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t);
loaded_image->load_options =
grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
if (!loaded_image->load_options)
- return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters");
+ {
+ err = grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters");
+ goto failure;
+ }
loaded_image->load_options_size =
2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
@@ -141,7 +169,7 @@ finalize_params_linux (void)
failure:
grub_fdt_unload();
- return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
+ return err;
}
static void
@@ -225,16 +253,28 @@ grub_linux_unload (void)
static void *
allocate_initrd_mem (int initrd_pages)
{
- grub_addr_t max_addr;
+ grub_addr_t max_addr = 0;
+ grub_err_t err;
+ void *ret;
- if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE)
- return NULL;
+ err = grub_efi_get_ram_base (&max_addr);
+ if (err != GRUB_ERR_NONE)
+ {
+ grub_error (err, "grub_efi_get_ram_base() failed");
+ return NULL;
+ }
+
+ grub_dprintf ("linux", "max_addr: 0x%016lx, INITRD_MAX_ADDRESS_OFFSET: 0x%016llx\n",
+ max_addr, INITRD_MAX_ADDRESS_OFFSET);
max_addr += INITRD_MAX_ADDRESS_OFFSET - 1;
+ grub_dprintf ("linux", "calling grub_efi_allocate_pages_real (0x%016lx, 0x%08x, EFI_ALLOCATE_MAX_ADDRESS, EFI_LOADER_DATA)", max_addr, initrd_pages);
- return grub_efi_allocate_pages_real (max_addr, initrd_pages,
- GRUB_EFI_ALLOCATE_MAX_ADDRESS,
- GRUB_EFI_LOADER_DATA);
+ ret = grub_efi_allocate_pages_real (max_addr, initrd_pages,
+ GRUB_EFI_ALLOCATE_MAX_ADDRESS,
+ GRUB_EFI_LOADER_DATA);
+ grub_dprintf ("linux", "got 0x%016llx\n", (unsigned long long)ret);
+ return ret;
}
static grub_err_t
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Fri, 21 Sep 2018 17:51:16 +0200
Subject: [PATCH] drop TPM support for legacy BIOS
Currently there's TPM support for both EFI and legacy BIOS.
A software interrupt call interface is used in legacy BIOS to communicate
with the TPM chips. But with some BIOS firmwares, the machine just hangs
after doing a BIOS interrupt call for the TCG_HashLogExtendEvent command.
It's hard to know what exactly is causing this, but the Trousers project
mentions in their docs that they don't use TCG_HashLogExtendEvent [0] due
the command not working reliable on some BIOS.
The TCG_CompactHashLogExtendEvent is less fragile, since it has a simpler
interface, doesn't require to setup any data structure and doesn't return
anything. So it could be used to do measurements and logs events instead.
But even when using this command can be a workaround on some systems, it
doesn't guarantee that could not fail on others. So since the TPM support
for some legacy BIOS don't work and can lead to machines failing to boot,
let's just drop it and only support TPM for EFI.
[0]: http://trousers.sourceforge.net/grub.html
Resolves: rhbz#1579835
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/Makefile.core.def | 1 -
grub-core/kern/i386/pc/tpm.c | 145 --------------------------------------
grub-core/loader/i386/pc/linux.c | 4 --
include/grub/tpm.h | 2 +-
grub-core/boot/i386/pc/boot.S | 30 +-------
grub-core/boot/i386/pc/diskboot.S | 44 ------------
6 files changed, 2 insertions(+), 224 deletions(-)
delete mode 100644 grub-core/kern/i386/pc/tpm.c
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index cf3d549d212..fb0a1e0babb 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -246,7 +246,6 @@ kernel = {
i386_pc = kern/i386/pc/init.c;
i386_pc = kern/i386/pc/mmap.c;
- i386_pc = kern/i386/pc/tpm.c;
i386_pc = term/i386/pc/console.c;
i386_qemu = bus/pci.c;
diff --git a/grub-core/kern/i386/pc/tpm.c b/grub-core/kern/i386/pc/tpm.c
deleted file mode 100644
index f6f264aff2e..00000000000
--- a/grub-core/kern/i386/pc/tpm.c
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <grub/err.h>
-#include <grub/i18n.h>
-#include <grub/mm.h>
-#include <grub/tpm.h>
-#include <grub/misc.h>
-#include <grub/i386/pc/int.h>
-
-#define TCPA_MAGIC 0x41504354
-
-static int tpm_presence = -1;
-
-int tpm_present(void);
-
-int tpm_present(void)
-{
- struct grub_bios_int_registers regs;
-
- if (tpm_presence != -1)
- return tpm_presence;
-
- regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
- regs.eax = 0xbb00;
- regs.ebx = TCPA_MAGIC;
- grub_bios_interrupt (0x1a, &regs);
-
- if (regs.eax == 0)
- tpm_presence = 1;
- else
- tpm_presence = 0;
-
- return tpm_presence;
-}
-
-grub_err_t
-grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf,
- PassThroughToTPM_OutputParamBlock *outbuf)
-{
- struct grub_bios_int_registers regs;
- grub_addr_t inaddr, outaddr;
-
- if (!tpm_present())
- return 0;
-
- inaddr = (grub_addr_t) inbuf;
- outaddr = (grub_addr_t) outbuf;
- regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
- regs.eax = 0xbb02;
- regs.ebx = TCPA_MAGIC;
- regs.ecx = 0;
- regs.edx = 0;
- regs.es = (inaddr & 0xffff0000) >> 4;
- regs.edi = inaddr & 0xffff;
- regs.ds = outaddr >> 4;
- regs.esi = outaddr & 0xf;
-
- grub_bios_interrupt (0x1a, &regs);
-
- if (regs.eax)
- {
- tpm_presence = 0;
- return grub_error (GRUB_ERR_IO, N_("TPM error %x, disabling TPM"), regs.eax);
- }
-
- return 0;
-}
-
-typedef struct {
- grub_uint32_t pcrindex;
- grub_uint32_t eventtype;
- grub_uint8_t digest[20];
- grub_uint32_t eventdatasize;
- grub_uint8_t event[0];
-} GRUB_PACKED Event;
-
-typedef struct {
- grub_uint16_t ipblength;
- grub_uint16_t reserved;
- grub_uint32_t hashdataptr;
- grub_uint32_t hashdatalen;
- grub_uint32_t pcr;
- grub_uint32_t reserved2;
- grub_uint32_t logdataptr;
- grub_uint32_t logdatalen;
-} GRUB_PACKED EventIncoming;
-
-typedef struct {
- grub_uint16_t opblength;
- grub_uint16_t reserved;
- grub_uint32_t eventnum;
- grub_uint8_t hashvalue[20];
-} GRUB_PACKED EventOutgoing;
-
-grub_err_t
-grub_tpm_log_event(unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
- const char *description)
-{
- struct grub_bios_int_registers regs;
- EventIncoming incoming;
- EventOutgoing outgoing;
- Event *event;
- grub_uint32_t datalength;
-
- if (!tpm_present())
- return 0;
-
- datalength = grub_strlen(description);
- event = grub_zalloc(datalength + sizeof(Event));
- if (!event)
- return grub_error (GRUB_ERR_OUT_OF_MEMORY,
- N_("cannot allocate TPM event buffer"));
-
- event->pcrindex = pcr;
- event->eventtype = 0x0d;
- event->eventdatasize = grub_strlen(description);
- grub_memcpy(event->event, description, datalength);
-
- incoming.ipblength = sizeof(incoming);
- incoming.hashdataptr = (grub_uint32_t)buf;
- incoming.hashdatalen = size;
- incoming.pcr = pcr;
- incoming.logdataptr = (grub_uint32_t)event;
- incoming.logdatalen = datalength + sizeof(Event);
-
- regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
- regs.eax = 0xbb01;
- regs.ebx = TCPA_MAGIC;
- regs.ecx = 0;
- regs.edx = 0;
- regs.es = (((grub_addr_t) &incoming) & 0xffff0000) >> 4;
- regs.edi = ((grub_addr_t) &incoming) & 0xffff;
- regs.ds = (((grub_addr_t) &outgoing) & 0xffff0000) >> 4;
- regs.esi = ((grub_addr_t) &outgoing) & 0xffff;
-
- grub_bios_interrupt (0x1a, &regs);
-
- grub_free(event);
-
- if (regs.eax)
- {
- tpm_presence = 0;
- return grub_error (GRUB_ERR_IO, N_("TPM error %x, disabling TPM"), regs.eax);
- }
-
- return 0;
-}
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
index cfff25c21b5..783a3cd93bc 100644
--- a/grub-core/loader/i386/pc/linux.c
+++ b/grub-core/loader/i386/pc/linux.c
@@ -36,7 +36,6 @@
#include <grub/lib/cmdline.h>
#include <grub/linux.h>
#include <grub/efi/sb.h>
-#include <grub/tpm.h>
GRUB_MOD_LICENSE ("GPLv3+");
@@ -162,9 +161,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
goto fail;
}
- grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux16", "Kernel");
- grub_print_error();
-
grub_memcpy (&lh, kernel, sizeof (lh));
kernel_offset = sizeof (lh);
diff --git a/include/grub/tpm.h b/include/grub/tpm.h
index 972a5edc836..ce52be4ff7f 100644
--- a/include/grub/tpm.h
+++ b/include/grub/tpm.h
@@ -69,7 +69,7 @@ typedef struct {
grub_err_t EXPORT_FUNC(grub_tpm_measure) (unsigned char *buf, grub_size_t size,
grub_uint8_t pcr, const char *kind,
const char *description);
-#if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS)
+#if defined (GRUB_MACHINE_EFI)
grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf,
PassThroughToTPM_OutputParamBlock *outbuf);
grub_err_t grub_tpm_log_event(unsigned char *buf, grub_size_t size,
diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S
index acab37369ae..ea167fe1206 100644
--- a/grub-core/boot/i386/pc/boot.S
+++ b/grub-core/boot/i386/pc/boot.S
@@ -24,14 +24,11 @@
* defines for the code go here
*/
-#define TPM 1
-
/* Print message string */
#define MSG(x) movw $x, %si; call LOCAL(message)
#define ERR(x) movw $x, %si; jmp LOCAL(error_message)
.macro floppy
-#ifndef TPM
part_start:
LOCAL(probe_values):
@@ -88,7 +85,6 @@ fd_probe_error_string: .asciz "Floppy"
movb MACRO_DOLLAR(79), %ch
jmp LOCAL(final_init)
-#endif
.endm
.macro scratch
@@ -256,7 +252,6 @@ real_start:
/* set %si to the disk address packet */
movw $disk_address_packet, %si
-#ifndef TPM
/* check if LBA is supported */
movb $0x41, %ah
movw $0x55aa, %bx
@@ -276,7 +271,6 @@ real_start:
andw $1, %cx
jz LOCAL(chs_mode)
-#endif
LOCAL(lba_mode):
xorw %ax, %ax
@@ -320,9 +314,6 @@ LOCAL(lba_mode):
jmp LOCAL(copy_buffer)
LOCAL(chs_mode):
-#ifdef TPM
- jmp LOCAL(general_error)
-#else
/*
* Determine the hard disk geometry from the BIOS!
* We do this first, so that LS-120 IDE floppies work correctly.
@@ -434,7 +425,7 @@ setup_sectors:
jc LOCAL(read_error)
movw %es, %bx
-#endif /* TPM */
+
LOCAL(copy_buffer):
/*
* We need to save %cx and %si because the startup code in
@@ -457,25 +448,6 @@ LOCAL(copy_buffer):
popw %ds
popa
-#ifdef TPM
- pusha
-
- movw $0xBB00, %ax /* TCG_StatusCheck */
- int $0x1A
- test %eax, %eax
- jnz boot /* No TPM or TPM deactivated */
-
- movw $0xBB07, %ax /* TCG_CompactHashLogExtendEvent */
- movw $GRUB_BOOT_MACHINE_KERNEL_ADDR, %di
- xorl %esi, %esi
- movl $0x41504354, %ebx /* TCPA */
- movl $0x200, %ecx /* Measure 512 bytes */
- movl $0x8, %edx /* PCR 8 */
- int $0x1A
-
-boot:
- popa
-#endif
/* boot kernel */
jmp *(LOCAL(kernel_address))
diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S
index f4744ec6fcb..68d31de0c4c 100644
--- a/grub-core/boot/i386/pc/diskboot.S
+++ b/grub-core/boot/i386/pc/diskboot.S
@@ -19,8 +19,6 @@
#include <grub/symbol.h>
#include <grub/machine/boot.h>
-#define TPM 1
-
/*
* defines for the code go here
*/
@@ -55,21 +53,6 @@ _start:
/* this sets up for the first run through "bootloop" */
movw $LOCAL(firstlist), %di
-#ifdef TPM
- /* clear EAX to remove potential garbage */
- xorl %eax, %eax
- /* 8(%di) = number of sectors to read */
- movw 8(%di), %ax
-
- /* Multiply number of sectors to read with 512 bytes. EAX is 32bit
- * which is large enough to hold values of up to 4GB. I doubt there
- * will ever be a core.img larger than that. ;-) */
- shll $9, %eax
-
- /* write result to bytes_to_measure var */
- movl %eax, bytes_to_measure
-#endif
-
/* save the sector number of the second sector in %ebp */
movl (%di), %ebp
@@ -307,29 +290,6 @@ LOCAL(copy_buffer):
/* END OF MAIN LOOP */
LOCAL(bootit):
-#ifdef TPM
- pusha
- movw $0xBB07, %ax /* TCG_CompactHashLogExtendEvent */
-
- movw $0x0, %bx
- movw %bx, %es
-
- /* We've already measured the first 512 bytes, now measure the rest */
- xorl %edi, %edi
- movw $(GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200), %di
-
- movl $0x41504354, %ebx /* EBX = "TCPA" */
-
- /* %ecx = The length, in bytes, of the buffer to measure */
- movl $bytes_to_measure, %esi
- movl (%esi), %ecx
- xorl %esi, %esi
- movl $0x9, %edx /* PCR 9 */
-
- int $0x1A
-
- popa
-#endif
/* print a newline */
MSG(notification_done)
popw %dx /* this makes sure %dl is our "boot" drive */
@@ -364,10 +324,6 @@ geometry_error_string: .asciz "Geom"
read_error_string: .asciz "Read"
general_error_string: .asciz " Error"
-#ifdef TPM
-bytes_to_measure: .long 0
-#endif
-
/*
* message: write the string pointed to by %si
*
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Thu, 27 Sep 2018 10:49:14 +0200
Subject: [PATCH] Move quicksort function from kernel.exec to the blscfg module
The qsort function is defined in the grub2 kernel and exported for modules
to use. But this prevents the blscfg.mod to be loaded by old grub2 kernels
that don't export this symbol.
Loading the latest blscfg module might be useful on legacy BIOS systems to
avoid updating the first and second stage grub2 images in the boot device.
Since the only caller of the qsort function is the blscfg module, move the
qsort function out of the grub2 kernel and only have it in the blscfg.mod.
While being there, also remove the grub_bsearch() function that is unused.
Related: rhbz#1633646
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/Makefile.core.def | 2 +-
grub-core/commands/blscfg.c | 3 ++-
grub-core/{kern/qsort.c => commands/bls_qsort.h} | 30 +++---------------------
include/grub/misc.h | 15 ------------
4 files changed, 6 insertions(+), 44 deletions(-)
rename grub-core/{kern/qsort.c => commands/bls_qsort.h} (93%)
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index fb0a1e0babb..3346d1be658 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -129,7 +129,6 @@ kernel = {
common = kern/rescue_parser.c;
common = kern/rescue_reader.c;
common = kern/term.c;
- common = kern/qsort.c;
common = kern/backtrace.c;
common = kern/tpm.c;
@@ -781,6 +780,7 @@ module = {
module = {
name = blscfg;
common = commands/blscfg.c;
+ common = commands/bls_qsort.h;
common = commands/loadenv.h;
enable = efi;
enable = i386_pc;
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
index abd6f00d0de..bec5a9ffe3e 100644
--- a/grub-core/commands/blscfg.c
+++ b/grub-core/commands/blscfg.c
@@ -36,6 +36,7 @@
GRUB_MOD_LICENSE ("GPLv3+");
+#include "bls_qsort.h"
#include "loadenv.h"
#define GRUB_BLS_CONFIG_PATH "/loader/entries/"
@@ -717,7 +718,7 @@ read_fallback:
use_version = false;
}
- grub_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, &use_version);
+ bls_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, &use_version);
grub_dprintf ("blscfg", "%s Creating %d entries from bls\n", __func__, nentries);
for (r = nentries - 1; r >= 0; r--)
diff --git a/grub-core/kern/qsort.c b/grub-core/commands/bls_qsort.h
similarity index 93%
rename from grub-core/kern/qsort.c
rename to grub-core/commands/bls_qsort.h
index 7f3fc9ffdae..572765fa3f2 100644
--- a/grub-core/kern/qsort.c
+++ b/grub-core/commands/bls_qsort.h
@@ -64,6 +64,7 @@ typedef struct
#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi)))
#define STACK_NOT_EMPTY (stack < top)
+typedef int (*grub_compar_d_fn_t) (const void *p0, const void *p1, void *state);
/* Order size using quicksort. This implementation incorporates
four optimizations discussed in Sedgewick:
@@ -89,8 +90,8 @@ typedef struct
smaller partition. This *guarantees* no more than log (total_elems)
stack size is needed (actually O(1) in this case)! */
-void
-grub_qsort (void *const pbase, grub_size_t total_elems, grub_size_t size,
+static inline void UNUSED
+bls_qsort (void *const pbase, grub_size_t total_elems, grub_size_t size,
grub_compar_d_fn_t cmp, void *arg)
{
char *base_ptr = (char *) pbase;
@@ -252,28 +253,3 @@ grub_qsort (void *const pbase, grub_size_t total_elems, grub_size_t size,
}
}
-void *
-grub_bsearch (const void *key, const void *base, grub_size_t nmemb, grub_size_t size,
- grub_compar_d_fn_t compar, void *state)
-{
- grub_size_t l, u, idx;
- const void *p;
- int comparison;
-
- l = 0;
- u = nmemb;
- while (l < u)
- {
- idx = (l + u) / 2;
- p = (void *) (((const char *) base) + (idx * size));
- comparison = (*compar) (key, p, state);
- if (comparison < 0)
- u = idx;
- else if (comparison > 0)
- l = idx + 1;
- else
- return (void *) p;
- }
-
- return NULL;
-}
diff --git a/include/grub/misc.h b/include/grub/misc.h
index 5f1c1c1be4e..de9016ab709 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -510,19 +510,4 @@ void EXPORT_FUNC(grub_real_boot_time) (const char *file,
#define grub_max(a, b) (((a) > (b)) ? (a) : (b))
#define grub_min(a, b) (((a) < (b)) ? (a) : (b))
-typedef int (*grub_compar_d_fn_t) (const void *p0, const void *p1, void *state);
-
-void *EXPORT_FUNC(grub_bsearch) (const void *key,
- const void *base,
- grub_size_t nmemb,
- grub_size_t size,
- grub_compar_d_fn_t compar,
- void *state);
-
-void EXPORT_FUNC(grub_qsort) (void *const pbase,
- grub_size_t total_elems,
- grub_size_t size,
- grub_compar_d_fn_t cmp,
- void *state);
-
#endif /* ! GRUB_MISC_HEADER */
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Thu, 27 Sep 2018 19:03:43 +0200
Subject: [PATCH] Include blscfg module for powerpc ieee1275
The blscfg module is currently not built for powerpc ieee1275, but this
is still needed when the machine is not booted in bare metal with OPAL.
Related: rhbz#1633646
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/Makefile.core.def | 1 +
1 file changed, 1 insertion(+)
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 3346d1be658..6864e780fd4 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -782,6 +782,7 @@ module = {
common = commands/blscfg.c;
common = commands/bls_qsort.h;
common = commands/loadenv.h;
+ enable = powerpc_ieee1275;
enable = efi;
enable = i386_pc;
enable = emu;
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Fri, 28 Sep 2018 10:35:38 +0200
Subject: [PATCH] grub-switch-to-blscfg: copy blscfg module for legacy BIOS and
ppc ieee1275
On platforms that load the blscfg module the latest version should be used,
so copy the module to the boot directory to make sure that the grub2 kernel
will load the latest version of the BLS parsing code.
Related: rhbz#1633646
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
util/grub-switch-to-blscfg.in | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in
index 9cf64f8e725..1c6bd1882a7 100644
--- a/util/grub-switch-to-blscfg.in
+++ b/util/grub-switch-to-blscfg.in
@@ -53,6 +53,8 @@ blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'`
backupsuffix=.bak
+arch="$(uname -m)"
+
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR="@localedir@"
@@ -248,7 +250,6 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do
fi
if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
- arch="$(uname -m)"
bls_debug="$(echo ${bls_target} | sed -e "s/\.${arch}/-debug.${arch}/")"
cp -aT "${bls_target}" "${bls_debug}"
title="$(grep '^title[ \t]' "${bls_debug}" | sed -e 's/^title[ \t]*//')"
@@ -282,6 +283,16 @@ elif ! grep -q '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" ; then
fi
if [ "${GENERATE}" -eq 1 ] ; then
+ if [ $arch = "x86_64" ] && [ ! -d /sys/firmware/efi ]; then
+ if ! cp ${prefix}/lib/grub//i386-pc/blscfg.mod ${grubdir}/i386-pc/ ; then
+ exit 1
+ fi
+ elif [ $arch = "ppc64" -o $arch = "ppc64le" ] && [ ! -d /sys/firmware/opal ]; then
+ if ! cp ${prefix}/lib/grub/powerpc-ieee1275/blscfg.mod ${grubdir}/powerpc-ieee1275/ ; then
+ exit 1
+ fi
+ fi
+
cp -af "${GRUB_CONFIG_FILE}" "${GRUB_CONFIG_FILE}${backupsuffix}"
if ! grub2-mkconfig -o "${GRUB_CONFIG_FILE}" ; then
cp -af "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}"
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 28 Sep 2018 15:42:19 -0400
Subject: [PATCH] Fix getroot.c's trampolines.
This makes the stack executable on most of the grub utilities, which is
bad, and rpmdiff complains about it.
Related: rhbz#1633646
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/osdep/linux/getroot.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c
index 4c5a13022dc..388a0f70638 100644
--- a/grub-core/osdep/linux/getroot.c
+++ b/grub-core/osdep/linux/getroot.c
@@ -1264,22 +1264,20 @@ grub_util_get_grub_dev_os (const char *os_dev)
return grub_dev;
}
+static void *mp = NULL;
+static void
+btrfs_mount_path_hook(const char *m)
+{
+ mp = strdup (m);
+}
char *
grub_util_get_btrfs_subvol (const char *path, char **mount_path)
{
- char *mp = NULL;
-
if (mount_path)
*mount_path = NULL;
- auto void
- mount_path_hook (const char *m)
- {
- mp = strdup (m);
- }
-
- grub_find_root_btrfs_mount_path_hook = mount_path_hook;
+ grub_find_root_btrfs_mount_path_hook = btrfs_mount_path_hook;
grub_free (grub_find_root_devices_from_mountinfo (path, NULL));
grub_find_root_btrfs_mount_path_hook = NULL;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment