import grub2-2.02-99.el8
This commit is contained in:
parent
fa384bc6b3
commit
c6f0640526
@ -0,0 +1,121 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
|
||||
Date: Thu, 3 Dec 2020 09:13:24 +0100
|
||||
Subject: [PATCH] at_keyboard: use set 1 when keyboard is in Translate mode
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
When keyboard controller acts in Translate mode (0x40 mask), then use
|
||||
set 1 since translation is done.
|
||||
Otherwise use the mode queried from the controller (usually set 2).
|
||||
|
||||
Added "atkeyb" debugging messages in at_keyboard module as well.
|
||||
|
||||
Resolves: rhbz#1897587
|
||||
|
||||
Tested on:
|
||||
- Asus N53SN (set 1 used)
|
||||
- Dell Precision (set 1 used)
|
||||
- HP Elitebook (set 2 used)
|
||||
- HP G5430 (set 1 used, keyboard in XT mode!)
|
||||
- Lenovo P71 & Lenovo T460s (set 2 used)
|
||||
- QEMU/KVM (set 1 used)
|
||||
|
||||
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
||||
---
|
||||
grub-core/term/at_keyboard.c | 29 ++++++++++++++++++++++++-----
|
||||
include/grub/at_keyboard.h | 4 ++++
|
||||
2 files changed, 28 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c
|
||||
index f0a986eb176..69d99b61df5 100644
|
||||
--- a/grub-core/term/at_keyboard.c
|
||||
+++ b/grub-core/term/at_keyboard.c
|
||||
@@ -135,20 +135,28 @@ query_mode (void)
|
||||
int e;
|
||||
|
||||
e = write_mode (0);
|
||||
- if (!e)
|
||||
+ if (!e) {
|
||||
+ grub_dprintf("atkeyb", "query_mode: write_mode(0) failed\n");
|
||||
return 0;
|
||||
+ }
|
||||
|
||||
do {
|
||||
keyboard_controller_wait_until_ready ();
|
||||
ret = grub_inb (KEYBOARD_REG_DATA);
|
||||
} while (ret == GRUB_AT_ACK);
|
||||
/* QEMU translates the set even in no-translate mode. */
|
||||
- if (ret == 0x43 || ret == 1)
|
||||
+ if (ret == 0x43 || ret == 1) {
|
||||
+ grub_dprintf("atkeyb", "query_mode: returning 1 (ret=0x%x)\n", ret);
|
||||
return 1;
|
||||
- if (ret == 0x41 || ret == 2)
|
||||
+ }
|
||||
+ if (ret == 0x41 || ret == 2) {
|
||||
+ grub_dprintf("atkeyb", "query_mode: returning 2 (ret=0x%x)\n", ret);
|
||||
return 2;
|
||||
- if (ret == 0x3f || ret == 3)
|
||||
+ }
|
||||
+ if (ret == 0x3f || ret == 3) {
|
||||
+ grub_dprintf("atkeyb", "query_mode: returning 3 (ret=0x%x)\n", ret);
|
||||
return 3;
|
||||
+ }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -165,7 +173,13 @@ set_scancodes (void)
|
||||
}
|
||||
|
||||
#if !USE_SCANCODE_SET
|
||||
- ps2_state.current_set = 1;
|
||||
+ if ((grub_keyboard_controller_orig & KEYBOARD_AT_TRANSLATE) == KEYBOARD_AT_TRANSLATE) {
|
||||
+ grub_dprintf ("atkeyb", "queried set is %d but keyboard in Translate mode, so actually in set 1\n", grub_keyboard_orig_set);
|
||||
+ ps2_state.current_set = 1;
|
||||
+ } else {
|
||||
+ grub_dprintf ("atkeyb", "using queried set %d\n", grub_keyboard_orig_set);
|
||||
+ ps2_state.current_set = grub_keyboard_orig_set;
|
||||
+ }
|
||||
return;
|
||||
#else
|
||||
|
||||
@@ -266,6 +280,7 @@ grub_keyboard_controller_init (void)
|
||||
grub_keyboard_orig_set = 2;
|
||||
#else
|
||||
grub_keyboard_controller_orig = grub_keyboard_controller_read ();
|
||||
+ grub_dprintf ("atkeyb", "grub_keyboard_controller_orig = 0x%x\n", grub_keyboard_controller_orig);
|
||||
grub_keyboard_orig_set = query_mode ();
|
||||
#endif
|
||||
set_scancodes ();
|
||||
@@ -275,11 +290,15 @@ grub_keyboard_controller_init (void)
|
||||
static grub_err_t
|
||||
grub_keyboard_controller_fini (struct grub_term_input *term __attribute__ ((unused)))
|
||||
{
|
||||
+/* In !USE_SCANCODE_SET mode, we didn't change anything, so nothing to restore */
|
||||
+#if USE_SCANCODE_SET
|
||||
if (ps2_state.current_set == 0)
|
||||
return GRUB_ERR_NONE;
|
||||
+ grub_dprintf ("atkeyb", "restoring set %d, controller 0x%x\n", grub_keyboard_orig_set, grub_keyboard_controller_orig);
|
||||
if (grub_keyboard_orig_set)
|
||||
write_mode (grub_keyboard_orig_set);
|
||||
grub_keyboard_controller_write (grub_keyboard_controller_orig);
|
||||
+#endif
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
diff --git a/include/grub/at_keyboard.h b/include/grub/at_keyboard.h
|
||||
index bcb4d9ba78f..9414dc1b996 100644
|
||||
--- a/include/grub/at_keyboard.h
|
||||
+++ b/include/grub/at_keyboard.h
|
||||
@@ -19,6 +19,10 @@
|
||||
#ifndef GRUB_AT_KEYBOARD_HEADER
|
||||
#define GRUB_AT_KEYBOARD_HEADER 1
|
||||
|
||||
+/*
|
||||
+ * Refer to https://wiki.osdev.org/%228042%22_PS/2_Controller for details.
|
||||
+ */
|
||||
+
|
||||
/* Used for sending commands to the controller. */
|
||||
#define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02)
|
||||
#define KEYBOARD_COMMAND_READ 0x20
|
@ -0,0 +1,118 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jan Hlavac <jhlavac@redhat.com>
|
||||
Date: Fri, 20 Nov 2020 23:51:47 +0100
|
||||
Subject: [PATCH] grub-install: disable support for EFI platforms
|
||||
|
||||
For each platform, GRUB is shipped as a kernel image and a set of
|
||||
modules. These files are then used by the grub-install utility to
|
||||
install GRUB on a specific device. However, in order to support UEFI
|
||||
Secure Boot, the resulting EFI binary must be signed by a recognized
|
||||
private key. For this reason, for EFI platforms, most distributions also
|
||||
ship prebuilt EFI binaries signed by a distribution-specific private
|
||||
key. In this case, however, the grub-install utility should not be used
|
||||
because it would overwrite the signed EFI binary.
|
||||
|
||||
The current fix is suboptimal because it preserves all EFI-related code.
|
||||
A better solution could be to modularize the code and provide a
|
||||
build-time option.
|
||||
|
||||
Resolves: rhbz#1737444
|
||||
|
||||
Signed-off-by: Jan Hlavac <jhlavac@redhat.com>
|
||||
---
|
||||
util/grub-install.c | 35 ++++++++++++++++-------------------
|
||||
docs/grub.texi | 7 +++++++
|
||||
util/grub-install.8 | 4 +++-
|
||||
3 files changed, 26 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/util/grub-install.c b/util/grub-install.c
|
||||
index 3bf0e063a86..65bb2f99ef1 100644
|
||||
--- a/util/grub-install.c
|
||||
+++ b/util/grub-install.c
|
||||
@@ -888,6 +888,22 @@ main (int argc, char *argv[])
|
||||
|
||||
platform = grub_install_get_target (grub_install_source_directory);
|
||||
|
||||
+ switch (platform)
|
||||
+ {
|
||||
+ case GRUB_INSTALL_PLATFORM_ARM_EFI:
|
||||
+ case GRUB_INSTALL_PLATFORM_ARM64_EFI:
|
||||
+ case GRUB_INSTALL_PLATFORM_I386_EFI:
|
||||
+ case GRUB_INSTALL_PLATFORM_IA64_EFI:
|
||||
+ case GRUB_INSTALL_PLATFORM_X86_64_EFI:
|
||||
+ is_efi = 1;
|
||||
+ grub_util_error (_("this utility cannot be used for EFI platforms"
|
||||
+ " because it does not support UEFI Secure Boot"));
|
||||
+ break;
|
||||
+ default:
|
||||
+ is_efi = 0;
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
{
|
||||
char *platname = grub_install_get_platform_name (platform);
|
||||
fprintf (stderr, _("Installing for %s platform.\n"), platname);
|
||||
@@ -994,26 +1010,7 @@ main (int argc, char *argv[])
|
||||
grub_hostfs_init ();
|
||||
grub_host_init ();
|
||||
|
||||
- switch (platform)
|
||||
- {
|
||||
- case GRUB_INSTALL_PLATFORM_I386_EFI:
|
||||
- case GRUB_INSTALL_PLATFORM_X86_64_EFI:
|
||||
- case GRUB_INSTALL_PLATFORM_ARM_EFI:
|
||||
- case GRUB_INSTALL_PLATFORM_ARM64_EFI:
|
||||
- case GRUB_INSTALL_PLATFORM_IA64_EFI:
|
||||
- is_efi = 1;
|
||||
- break;
|
||||
- default:
|
||||
- is_efi = 0;
|
||||
- break;
|
||||
-
|
||||
- /* pacify warning. */
|
||||
- case GRUB_INSTALL_PLATFORM_MAX:
|
||||
- break;
|
||||
- }
|
||||
-
|
||||
/* Find the EFI System Partition. */
|
||||
-
|
||||
if (is_efi)
|
||||
{
|
||||
grub_fs_t fs;
|
||||
diff --git a/docs/grub.texi b/docs/grub.texi
|
||||
index c54bee31679..fa11cc0aff7 100644
|
||||
--- a/docs/grub.texi
|
||||
+++ b/docs/grub.texi
|
||||
@@ -6185,6 +6185,13 @@ grub2-install @var{install_device}
|
||||
The device name @var{install_device} is an OS device name or a GRUB
|
||||
device name.
|
||||
|
||||
+In order to support UEFI Secure Boot, the resulting GRUB EFI binary must
|
||||
+be signed by a recognized private key. For this reason, for EFI
|
||||
+platforms, most distributions also ship prebuilt GRUB EFI binaries
|
||||
+signed by a distribution-specific private key. In this case, however,
|
||||
+@command{grub2-install} should not be used because it would overwrite
|
||||
+the signed EFI binary.
|
||||
+
|
||||
@command{grub2-install} accepts the following options:
|
||||
|
||||
@table @option
|
||||
diff --git a/util/grub-install.8 b/util/grub-install.8
|
||||
index 76272a39d2e..02371930fa1 100644
|
||||
--- a/util/grub-install.8
|
||||
+++ b/util/grub-install.8
|
||||
@@ -1,4 +1,4 @@
|
||||
-.TH GRUB-INSTALL 1 "Wed Feb 26 2014"
|
||||
+.TH GRUB-INSTALL 1 "Fri Nov 20 2020"
|
||||
.SH NAME
|
||||
\fBgrub-install\fR \(em Install GRUB on a device.
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
.SH DESCRIPTION
|
||||
\fBgrub-install\fR installs GRUB onto a device. This includes copying GRUB images into the target directory (generally \fI/boot/grub\fR), and on some platforms may also include installing GRUB onto a boot sector.
|
||||
|
||||
+In order to support UEFI Secure Boot, the resulting GRUB EFI binary must be signed by a recognized private key. For this reason, for EFI platforms, most distributions also ship prebuilt GRUB EFI binaries signed by a distribution-specific private key. In this case, however, the \fBgrub-install\fR utility should not be used because it would overwrite the signed EFI binary.
|
||||
+
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB--modules\fR=\fIMODULES\fR\!
|
@ -0,0 +1,112 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
|
||||
Date: Sat, 23 Nov 2019 14:57:41 +0100
|
||||
Subject: [PATCH] New --with-debug-timestamps configure flag to prepend debug
|
||||
traces with absolute and relative timestamp
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
||||
---
|
||||
configure.ac | 18 ++++++++++++++++++
|
||||
grub-core/kern/misc.c | 20 ++++++++++++++++++++
|
||||
config.h.in | 1 +
|
||||
3 files changed, 39 insertions(+)
|
||||
|
||||
diff --git a/configure.ac b/configure.ac
|
||||
index 9323c125469..0059b938a3a 100644
|
||||
--- a/configure.ac
|
||||
+++ b/configure.ac
|
||||
@@ -1514,6 +1514,17 @@ else
|
||||
fi
|
||||
AC_SUBST([BOOT_TIME_STATS])
|
||||
|
||||
+AC_ARG_WITH([debug-timestamps],
|
||||
+ AS_HELP_STRING([--with-debug-timestamps],
|
||||
+ [prepend debug traces with absolute and relative timestamps]))
|
||||
+
|
||||
+if test x$with_debug_timestamps = xyes; then
|
||||
+ DEBUG_WITH_TIMESTAMPS=1
|
||||
+else
|
||||
+ DEBUG_WITH_TIMESTAMPS=0
|
||||
+fi
|
||||
+AC_SUBST([DEBUG_WITH_TIMESTAMPS])
|
||||
+
|
||||
AC_ARG_ENABLE([grub-emu-sdl],
|
||||
[AS_HELP_STRING([--enable-grub-emu-sdl],
|
||||
[build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
|
||||
@@ -2092,6 +2103,7 @@ AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
|
||||
AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
|
||||
AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
|
||||
AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
|
||||
+AM_CONDITIONAL([COND_DEBUG_WITH_TIMESTAMPS], [test x$DEBUG_WITH_TIMESTAMPS = x1])
|
||||
|
||||
AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
|
||||
|
||||
@@ -2187,6 +2199,12 @@ else
|
||||
echo With boot time statistics: No
|
||||
fi
|
||||
|
||||
+if [ x"$with_debug_timestamps" = xyes ]; then
|
||||
+echo Debug traces with timestamps: Yes
|
||||
+else
|
||||
+echo Debug traces with timestamps: No
|
||||
+fi
|
||||
+
|
||||
if [ x"$efiemu_excuse" = x ]; then
|
||||
echo efiemu runtime: Yes
|
||||
else
|
||||
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
|
||||
index c034f49f97c..11f2974fce5 100644
|
||||
--- a/grub-core/kern/misc.c
|
||||
+++ b/grub-core/kern/misc.c
|
||||
@@ -25,6 +25,9 @@
|
||||
#include <grub/env.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/backtrace.h>
|
||||
+#if DEBUG_WITH_TIMESTAMPS
|
||||
+#include <grub/time.h>
|
||||
+#endif
|
||||
|
||||
union printf_arg
|
||||
{
|
||||
@@ -179,9 +182,26 @@ grub_real_dprintf (const char *file, const int line, const char *condition,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
+#if DEBUG_WITH_TIMESTAMPS
|
||||
+ static long unsigned int last_time = 0;
|
||||
+ static int last_had_cr = 1;
|
||||
+#endif
|
||||
|
||||
if (grub_debug_enabled (condition))
|
||||
{
|
||||
+#if DEBUG_WITH_TIMESTAMPS
|
||||
+ /* Don't print timestamp if last printed message isn't terminated yet */
|
||||
+ if (last_had_cr) {
|
||||
+ long unsigned int tmabs = (long unsigned int) grub_get_time_ms();
|
||||
+ long unsigned int tmrel = tmabs - last_time;
|
||||
+ last_time = tmabs;
|
||||
+ grub_printf ("%3lu.%03lus +%2lu.%03lus ", tmabs / 1000, tmabs % 1000, tmrel / 1000, tmrel % 1000);
|
||||
+ }
|
||||
+ if (fmt[grub_strlen(fmt)-1] == '\n')
|
||||
+ last_had_cr = 1;
|
||||
+ else
|
||||
+ last_had_cr = 0;
|
||||
+#endif
|
||||
grub_printf ("%s:%d: ", file, line);
|
||||
va_start (args, fmt);
|
||||
grub_vprintf (fmt, args);
|
||||
diff --git a/config.h.in b/config.h.in
|
||||
index 9e8f9911b18..d15480b4163 100644
|
||||
--- a/config.h.in
|
||||
+++ b/config.h.in
|
||||
@@ -12,6 +12,7 @@
|
||||
/* Define to 1 to enable disk cache statistics. */
|
||||
#define DISK_CACHE_STATS @DISK_CACHE_STATS@
|
||||
#define BOOT_TIME_STATS @BOOT_TIME_STATS@
|
||||
+#define DEBUG_WITH_TIMESTAMPS @DEBUG_WITH_TIMESTAMPS@
|
||||
|
||||
/* We don't need those. */
|
||||
#define MINILZO_CFG_SKIP_LZO_PTR 1
|
@ -0,0 +1,47 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
|
||||
Date: Sat, 23 Nov 2019 15:22:16 +0100
|
||||
Subject: [PATCH] Added debug statements to grub_disk_open() and
|
||||
grub_disk_close() on success
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
||||
---
|
||||
grub-core/kern/disk.c | 6 +++++-
|
||||
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c
|
||||
index 789f8c05233..7f58c561472 100644
|
||||
--- a/grub-core/kern/disk.c
|
||||
+++ b/grub-core/kern/disk.c
|
||||
@@ -285,6 +285,8 @@ grub_disk_open (const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+ grub_dprintf ("disk", "Opening `%s' succeeded.\n", name);
|
||||
+
|
||||
return disk;
|
||||
}
|
||||
|
||||
@@ -292,7 +294,7 @@ void
|
||||
grub_disk_close (grub_disk_t disk)
|
||||
{
|
||||
grub_partition_t part;
|
||||
- grub_dprintf ("disk", "Closing `%s'.\n", disk->name);
|
||||
+ grub_dprintf ("disk", "Closing `%s'...\n", disk->name);
|
||||
|
||||
if (disk->dev && disk->dev->close)
|
||||
(disk->dev->close) (disk);
|
||||
@@ -306,8 +308,10 @@ grub_disk_close (grub_disk_t disk)
|
||||
grub_free (disk->partition);
|
||||
disk->partition = part;
|
||||
}
|
||||
+ grub_dprintf ("disk", "Closing `%s' succeeded.\n", disk->name);
|
||||
grub_free ((void *) disk->name);
|
||||
grub_free (disk);
|
||||
+
|
||||
}
|
||||
|
||||
/* Small read (less than cache size and not pass across cache unit boundaries).
|
@ -0,0 +1,51 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
|
||||
Date: Mon, 25 Nov 2019 09:29:53 +0100
|
||||
Subject: [PATCH] Introduce function grub_debug_is_enabled(void) returning 1 if
|
||||
'debug' is in the environment and not empty
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
||||
---
|
||||
grub-core/kern/misc.c | 13 +++++++++++++
|
||||
include/grub/misc.h | 1 +
|
||||
2 files changed, 14 insertions(+)
|
||||
|
||||
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
|
||||
index 11f2974fce5..97378c48b22 100644
|
||||
--- a/grub-core/kern/misc.c
|
||||
+++ b/grub-core/kern/misc.c
|
||||
@@ -162,6 +162,19 @@ int grub_err_printf (const char *fmt, ...)
|
||||
__attribute__ ((alias("grub_printf")));
|
||||
#endif
|
||||
|
||||
+/* Return 1 if 'debug' is set and not empty */
|
||||
+int
|
||||
+grub_debug_is_enabled (void)
|
||||
+{
|
||||
+ const char *debug;
|
||||
+
|
||||
+ debug = grub_env_get ("debug");
|
||||
+ if (!debug || debug[0] == '\0')
|
||||
+ return 0;
|
||||
+
|
||||
+ return 1;
|
||||
+}
|
||||
+
|
||||
int
|
||||
grub_debug_enabled (const char * condition)
|
||||
{
|
||||
diff --git a/include/grub/misc.h b/include/grub/misc.h
|
||||
index 1258ec6bbf3..6ca03c4d692 100644
|
||||
--- a/include/grub/misc.h
|
||||
+++ b/include/grub/misc.h
|
||||
@@ -367,6 +367,7 @@ grub_puts (const char *s)
|
||||
}
|
||||
|
||||
int EXPORT_FUNC(grub_puts_) (const char *s);
|
||||
+int EXPORT_FUNC(grub_debug_is_enabled) (void);
|
||||
int EXPORT_FUNC(grub_debug_enabled) (const char *condition);
|
||||
void EXPORT_FUNC(grub_real_dprintf) (const char *file,
|
||||
const int line,
|
@ -0,0 +1,27 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
|
||||
Date: Sat, 23 Nov 2019 16:23:54 +0100
|
||||
Subject: [PATCH] Don't clear screen when debugging is enabled
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
||||
---
|
||||
grub-core/normal/main.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
|
||||
index 04ae9ed02f6..59fd54eb0f1 100644
|
||||
--- a/grub-core/normal/main.c
|
||||
+++ b/grub-core/normal/main.c
|
||||
@@ -204,7 +204,8 @@ void
|
||||
grub_normal_init_page (struct grub_term_output *term,
|
||||
int y __attribute__((__unused__)))
|
||||
{
|
||||
- grub_term_cls (term);
|
||||
+ if (! grub_debug_is_enabled ())
|
||||
+ grub_term_cls (term);
|
||||
|
||||
#if 0
|
||||
grub_ssize_t msg_len;
|
@ -0,0 +1,71 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
|
||||
Date: Fri, 29 Nov 2019 11:02:00 +0100
|
||||
Subject: [PATCH] grub_file_* instrumentation (new 'file' debug tag)
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
|
||||
---
|
||||
grub-core/kern/file.c | 14 ++++++++++++++
|
||||
1 file changed, 14 insertions(+)
|
||||
|
||||
diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c
|
||||
index 668f8930b19..c2d9a550007 100644
|
||||
--- a/grub-core/kern/file.c
|
||||
+++ b/grub-core/kern/file.c
|
||||
@@ -67,6 +67,8 @@ grub_file_open (const char *name)
|
||||
const char *file_name;
|
||||
grub_file_filter_id_t filter;
|
||||
|
||||
+ grub_dprintf ("file", "Opening `%s' ...\n", name);
|
||||
+
|
||||
device_name = grub_file_get_device_name (name);
|
||||
if (grub_errno)
|
||||
goto fail;
|
||||
@@ -127,6 +129,8 @@ grub_file_open (const char *name)
|
||||
grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
|
||||
+ grub_dprintf ("file", "Opening `%s' succeeded.\n", name);
|
||||
+
|
||||
return file;
|
||||
|
||||
fail:
|
||||
@@ -140,6 +144,8 @@ grub_file_open (const char *name)
|
||||
grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
|
||||
+ grub_dprintf ("file", "Opening `%s' failed.\n", name);
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -171,6 +177,7 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len)
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
+
|
||||
read_hook = file->read_hook;
|
||||
read_hook_data = file->read_hook_data;
|
||||
if (!file->read_hook)
|
||||
@@ -191,11 +198,18 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len)
|
||||
grub_err_t
|
||||
grub_file_close (grub_file_t file)
|
||||
{
|
||||
+ grub_dprintf ("file", "Closing `%s' ...\n", file->name);
|
||||
if (file->fs->close)
|
||||
(file->fs->close) (file);
|
||||
|
||||
if (file->device)
|
||||
grub_device_close (file->device);
|
||||
+
|
||||
+ if (grub_errno == GRUB_ERR_NONE)
|
||||
+ grub_dprintf ("file", "Closing `%s' succeeded.\n", file->name);
|
||||
+ else
|
||||
+ grub_dprintf ("file", "Closing `%s' failed with %d.\n", file->name, grub_errno);
|
||||
+
|
||||
grub_free (file->name);
|
||||
grub_free (file);
|
||||
return grub_errno;
|
136
SOURCES/0325-ieee1275-Avoiding-many-unecessary-open-close.patch
Normal file
136
SOURCES/0325-ieee1275-Avoiding-many-unecessary-open-close.patch
Normal file
@ -0,0 +1,136 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Mon, 14 Dec 2020 17:42:45 +0100
|
||||
Subject: [PATCH] ieee1275: Avoiding many unecessary open/close
|
||||
|
||||
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
|
||||
---
|
||||
grub-core/disk/ieee1275/ofdisk.c | 64 ++++++++++++++++++++++------------------
|
||||
1 file changed, 35 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
|
||||
index d887d4b6eee..f3a6ecd797f 100644
|
||||
--- a/grub-core/disk/ieee1275/ofdisk.c
|
||||
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
||||
@@ -44,7 +44,7 @@ struct ofdisk_hash_ent
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
-grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
|
||||
+grub_ofdisk_get_block_size (grub_uint32_t *block_size,
|
||||
struct ofdisk_hash_ent *op);
|
||||
|
||||
#define OFDISK_HASH_SZ 8
|
||||
@@ -461,6 +461,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
grub_ssize_t actual;
|
||||
grub_uint32_t block_size = 0;
|
||||
grub_err_t err;
|
||||
+ struct ofdisk_hash_ent *op;
|
||||
|
||||
if (grub_strncmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) != 0)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
||||
@@ -471,6 +472,35 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
|
||||
grub_dprintf ("disk", "Opening `%s'.\n", devpath);
|
||||
|
||||
+ op = ofdisk_hash_find (devpath);
|
||||
+ if (!op)
|
||||
+ op = ofdisk_hash_add (devpath, NULL);
|
||||
+ if (!op)
|
||||
+ {
|
||||
+ grub_free (devpath);
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
+
|
||||
+ /* Check if the call to open is the same to the last disk already opened */
|
||||
+ if (last_devpath && !grub_strcmp(op->open_path,last_devpath))
|
||||
+ {
|
||||
+ goto finish;
|
||||
+ }
|
||||
+
|
||||
+ /* If not, we need to close the previous disk and open the new one */
|
||||
+ else {
|
||||
+ if (last_ihandle){
|
||||
+ grub_ieee1275_close (last_ihandle);
|
||||
+ }
|
||||
+ last_ihandle = 0;
|
||||
+ last_devpath = NULL;
|
||||
+
|
||||
+ grub_ieee1275_open (op->open_path, &last_ihandle);
|
||||
+ if (! last_ihandle)
|
||||
+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
|
||||
+ last_devpath = op->open_path;
|
||||
+ }
|
||||
+
|
||||
if (grub_ieee1275_finddevice (devpath, &dev))
|
||||
{
|
||||
grub_free (devpath);
|
||||
@@ -491,25 +521,18 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
|
||||
}
|
||||
|
||||
+
|
||||
+ finish:
|
||||
/* XXX: There is no property to read the number of blocks. There
|
||||
should be a property `#blocks', but it is not there. Perhaps it
|
||||
is possible to use seek for this. */
|
||||
disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
|
||||
|
||||
{
|
||||
- struct ofdisk_hash_ent *op;
|
||||
- op = ofdisk_hash_find (devpath);
|
||||
- if (!op)
|
||||
- op = ofdisk_hash_add (devpath, NULL);
|
||||
- if (!op)
|
||||
- {
|
||||
- grub_free (devpath);
|
||||
- return grub_errno;
|
||||
- }
|
||||
disk->id = (unsigned long) op;
|
||||
disk->data = op->open_path;
|
||||
|
||||
- err = grub_ofdisk_get_block_size (devpath, &block_size, op);
|
||||
+ err = grub_ofdisk_get_block_size (&block_size, op);
|
||||
if (err)
|
||||
{
|
||||
grub_free (devpath);
|
||||
@@ -532,13 +555,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
static void
|
||||
grub_ofdisk_close (grub_disk_t disk)
|
||||
{
|
||||
- if (disk->data == last_devpath)
|
||||
- {
|
||||
- if (last_ihandle)
|
||||
- grub_ieee1275_close (last_ihandle);
|
||||
- last_ihandle = 0;
|
||||
- last_devpath = NULL;
|
||||
- }
|
||||
disk->data = 0;
|
||||
}
|
||||
|
||||
@@ -685,7 +701,7 @@ grub_ofdisk_init (void)
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
-grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
|
||||
+grub_ofdisk_get_block_size (grub_uint32_t *block_size,
|
||||
struct ofdisk_hash_ent *op)
|
||||
{
|
||||
struct size_args_ieee1275
|
||||
@@ -698,16 +714,6 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
|
||||
grub_ieee1275_cell_t size2;
|
||||
} args_ieee1275;
|
||||
|
||||
- if (last_ihandle)
|
||||
- grub_ieee1275_close (last_ihandle);
|
||||
-
|
||||
- last_ihandle = 0;
|
||||
- last_devpath = NULL;
|
||||
-
|
||||
- grub_ieee1275_open (device, &last_ihandle);
|
||||
- if (! last_ihandle)
|
||||
- return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
|
||||
-
|
||||
*block_size = 0;
|
||||
|
||||
if (op->block_size_fails >= 2)
|
@ -0,0 +1,90 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Mon, 14 Dec 2020 17:45:28 +0100
|
||||
Subject: [PATCH] ieee1275/powerpc: implements fibre channel discovery for
|
||||
ofpathname
|
||||
|
||||
grub-ofpathname doesn't work with fibre channel because there is no
|
||||
function currently implemented for it.
|
||||
This patch enables it by prividing a function that looks for the port
|
||||
name, building the entire path for OF devices.
|
||||
|
||||
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
|
||||
---
|
||||
grub-core/osdep/linux/ofpath.c | 49 ++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 49 insertions(+)
|
||||
|
||||
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
|
||||
index a6153d35954..0f5d54e9f2d 100644
|
||||
--- a/grub-core/osdep/linux/ofpath.c
|
||||
+++ b/grub-core/osdep/linux/ofpath.c
|
||||
@@ -350,6 +350,38 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
|
||||
return ret;
|
||||
}
|
||||
|
||||
+
|
||||
+static void
|
||||
+of_fc_port_name(const char *path, const char *subpath, char *port_name)
|
||||
+{
|
||||
+ char *bname, *basepath, *p;
|
||||
+ int fd;
|
||||
+
|
||||
+ bname = xmalloc(sizeof(char)*150);
|
||||
+ basepath = xmalloc(strlen(path));
|
||||
+
|
||||
+ /* Generate the path to get port name information from the drive */
|
||||
+ strncpy(basepath,path,subpath-path);
|
||||
+ basepath[subpath-path-1] = '\0';
|
||||
+ p = get_basename(basepath);
|
||||
+ snprintf(bname,sizeof(char)*150,"%s/fc_transport/%s/port_name",basepath,p);
|
||||
+
|
||||
+ /* Read the information from the port name */
|
||||
+ fd = open (bname, O_RDONLY);
|
||||
+ if (fd < 0)
|
||||
+ grub_util_error (_("cannot open `%s': %s"), bname, strerror (errno));
|
||||
+
|
||||
+ if (read(fd,port_name,sizeof(char)*19) < 0)
|
||||
+ grub_util_error (_("cannot read `%s': %s"), bname, strerror (errno));
|
||||
+
|
||||
+ sscanf(port_name,"0x%s",port_name);
|
||||
+
|
||||
+ close(fd);
|
||||
+
|
||||
+ free(bname);
|
||||
+ free(basepath);
|
||||
+}
|
||||
+
|
||||
#ifdef __sparc__
|
||||
static char *
|
||||
of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
@@ -577,6 +609,16 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
|
||||
digit_string = trailing_digits (device);
|
||||
if (strncmp (of_path, "/vdevice/", sizeof ("/vdevice/") - 1) == 0)
|
||||
{
|
||||
+ if(strstr(of_path,"vfc-client"))
|
||||
+ {
|
||||
+ char * port_name = xmalloc(sizeof(char)*17);
|
||||
+ of_fc_port_name(sysfs_path, p, port_name);
|
||||
+
|
||||
+ snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
|
||||
+ free(port_name);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
unsigned long id = 0x8000 | (tgt << 8) | (bus << 5) | lun;
|
||||
if (*digit_string == '\0')
|
||||
{
|
||||
@@ -590,6 +632,13 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
|
||||
snprintf(disk, sizeof (disk),
|
||||
"/%s@%04lx000000000000:%c", disk_name, id, 'a' + (part - 1));
|
||||
}
|
||||
+ }
|
||||
+ } else if (strstr(of_path,"fibre-channel")||(strstr(of_path,"vfc-client"))){
|
||||
+ char * port_name = xmalloc(sizeof(char)*17);
|
||||
+ of_fc_port_name(sysfs_path, p, port_name);
|
||||
+
|
||||
+ snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
|
||||
+ free(port_name);
|
||||
}
|
||||
else
|
||||
{
|
@ -0,0 +1,106 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Mon, 14 Dec 2020 17:47:16 +0100
|
||||
Subject: [PATCH] ieee1275/powerpc: enables device mapper discovery
|
||||
|
||||
this patch enables the device mapper discovery on ofpath.c. Currently,
|
||||
when we are dealing with a device like /dev/dm-* the ofpath returns null
|
||||
since there is no function implemented to handle this case.
|
||||
|
||||
This patch implements a function that will look into /sys/block/dm-*
|
||||
devices and search recursively inside slaves directory to find the root
|
||||
disk.
|
||||
|
||||
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
|
||||
---
|
||||
grub-core/osdep/linux/ofpath.c | 64 +++++++++++++++++++++++++++++++++++++++++-
|
||||
1 file changed, 63 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
|
||||
index 0f5d54e9f2d..cc849d9c94c 100644
|
||||
--- a/grub-core/osdep/linux/ofpath.c
|
||||
+++ b/grub-core/osdep/linux/ofpath.c
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
+#include <dirent.h>
|
||||
|
||||
#ifdef __sparc__
|
||||
typedef enum
|
||||
@@ -755,13 +756,74 @@ strip_trailing_digits (const char *p)
|
||||
return new;
|
||||
}
|
||||
|
||||
+static char *
|
||||
+get_slave_from_dm(const char * device){
|
||||
+ char *curr_device, *tmp;
|
||||
+ char *directory;
|
||||
+ char *ret = NULL;
|
||||
+
|
||||
+ directory = grub_strdup (device);
|
||||
+ tmp = get_basename(directory);
|
||||
+ curr_device = grub_strdup (tmp);
|
||||
+ *tmp = '\0';
|
||||
+
|
||||
+ /* Recursively check for slaves devices so we can find the root device */
|
||||
+ while ((curr_device[0] == 'd') && (curr_device[1] == 'm') && (curr_device[2] == '-')){
|
||||
+ DIR *dp;
|
||||
+ struct dirent *ep;
|
||||
+ char* device_path;
|
||||
+
|
||||
+ device_path = grub_xasprintf ("/sys/block/%s/slaves", curr_device);
|
||||
+ dp = opendir(device_path);
|
||||
+ free(device_path);
|
||||
+
|
||||
+ if (dp != NULL)
|
||||
+ {
|
||||
+ ep = readdir (dp);
|
||||
+ while (ep != NULL){
|
||||
+
|
||||
+ /* avoid some system directories */
|
||||
+ if (!strcmp(ep->d_name,"."))
|
||||
+ goto next_dir;
|
||||
+ if (!strcmp(ep->d_name,".."))
|
||||
+ goto next_dir;
|
||||
+
|
||||
+ free (curr_device);
|
||||
+ free (ret);
|
||||
+ curr_device = grub_strdup (ep->d_name);
|
||||
+ ret = grub_xasprintf ("%s%s", directory, curr_device);
|
||||
+ break;
|
||||
+
|
||||
+ next_dir:
|
||||
+ ep = readdir (dp);
|
||||
+ continue;
|
||||
+ }
|
||||
+ closedir (dp);
|
||||
+ }
|
||||
+ else
|
||||
+ grub_util_warn (_("cannot open directory `%s'"), device_path);
|
||||
+ }
|
||||
+
|
||||
+ free (directory);
|
||||
+ free (curr_device);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
char *
|
||||
grub_util_devname_to_ofpath (const char *sys_devname)
|
||||
{
|
||||
- char *name_buf, *device, *devnode, *devicenode, *ofpath;
|
||||
+ char *name_buf, *device, *devnode, *devicenode, *ofpath, *realname;
|
||||
|
||||
name_buf = xrealpath (sys_devname);
|
||||
|
||||
+ realname = get_slave_from_dm (name_buf);
|
||||
+ if (realname)
|
||||
+ {
|
||||
+ free (name_buf);
|
||||
+ name_buf = realname;
|
||||
+ }
|
||||
+
|
||||
device = get_basename (name_buf);
|
||||
devnode = strip_trailing_digits (name_buf);
|
||||
devicenode = strip_trailing_digits (device);
|
@ -0,0 +1,239 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
|
||||
Date: Fri, 18 Dec 2020 15:39:26 +0100
|
||||
Subject: [PATCH] Add 'at_keyboard_fallback_set' var to force the set manually
|
||||
|
||||
This seems required with HP DL380p Gen 8 systems.
|
||||
Indeed, with this system, we can see the following sequence:
|
||||
|
||||
1. controller is queried to get current configuration (returns 0x30 which is quite standard)
|
||||
2. controller is queried to get the current keyboard set in used, using code 0xf0 (first part)
|
||||
3. controller answers with 0xfa which means "ACK" (== ok)
|
||||
4. then we send "0" to tell "we want to know which set your are supporting"
|
||||
5. controller answers with 0xfa ("ACK")
|
||||
6. controller should then give us 1, 2, 3 or 0x43, 0x41, 0x3f, but here it gives us 0xfe which means "NACK"
|
||||
|
||||
Since there seems no way to determine the current set, and in fact the
|
||||
controller expects set2 to be used, we need to rely on an environment
|
||||
variable.
|
||||
Everything has been tested on this system: using 0xFE (resend command),
|
||||
making sure we wait for ACK in the 2 steps "write_mode", etc.
|
||||
|
||||
Below is litterature I used to come up with "there is no other
|
||||
solution":
|
||||
- https://wiki.osdev.org/%228042%22_PS/2_Controller
|
||||
- http://www-ug.eecg.toronto.edu/msl/nios_devices/datasheets/PS2%20Keyboard%20Protocol.htm
|
||||
- http://www.s100computers.com/My%20System%20Pages/MSDOS%20Board/PC%20Keyboard.pdf
|
||||
---
|
||||
grub-core/term/at_keyboard.c | 121 ++++++++++++++++++++++++++++++++++---------
|
||||
1 file changed, 96 insertions(+), 25 deletions(-)
|
||||
|
||||
diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c
|
||||
index 69d99b61df5..c805cccbdde 100644
|
||||
--- a/grub-core/term/at_keyboard.c
|
||||
+++ b/grub-core/term/at_keyboard.c
|
||||
@@ -31,6 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
static grub_uint8_t grub_keyboard_controller_orig;
|
||||
static grub_uint8_t grub_keyboard_orig_set;
|
||||
struct grub_ps2_state ps2_state;
|
||||
+static int fallback_set;
|
||||
|
||||
static int ping_sent;
|
||||
|
||||
@@ -76,6 +77,8 @@ at_command (grub_uint8_t data)
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
+ if (i == GRUB_AT_TRIES)
|
||||
+ grub_dprintf ("atkeyb", "at_command() timed out! (stopped after %d tries)\n", i);
|
||||
return (i != GRUB_AT_TRIES);
|
||||
}
|
||||
|
||||
@@ -105,6 +108,21 @@ grub_keyboard_controller_read (void)
|
||||
|
||||
#endif
|
||||
|
||||
+static int
|
||||
+resend_last_result (void)
|
||||
+{
|
||||
+ grub_uint8_t ret;
|
||||
+ keyboard_controller_wait_until_ready ();
|
||||
+ grub_dprintf ("atkeyb", "resend_last_result: sending 0xfe\n");
|
||||
+ grub_outb (0xfe, KEYBOARD_REG_DATA);
|
||||
+ ret = wait_ack ();
|
||||
+ grub_dprintf ("atkeyb", "resend_last_result: wait_ack() returned 0x%x\n", ret);
|
||||
+ keyboard_controller_wait_until_ready ();
|
||||
+ ret = grub_inb (KEYBOARD_REG_DATA);
|
||||
+ grub_dprintf ("atkeyb", "resend_last_result: read 0x%x from controller\n", ret);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
static int
|
||||
write_mode (int mode)
|
||||
{
|
||||
@@ -113,11 +131,14 @@ write_mode (int mode)
|
||||
{
|
||||
grub_uint8_t ack;
|
||||
keyboard_controller_wait_until_ready ();
|
||||
+ grub_dprintf ("atkeyb", "write_mode: sending 0xf0\n");
|
||||
grub_outb (0xf0, KEYBOARD_REG_DATA);
|
||||
keyboard_controller_wait_until_ready ();
|
||||
+ grub_dprintf ("atkeyb", "write_mode: sending mode %d\n", mode);
|
||||
grub_outb (mode, KEYBOARD_REG_DATA);
|
||||
keyboard_controller_wait_until_ready ();
|
||||
ack = wait_ack ();
|
||||
+ grub_dprintf ("atkeyb", "write_mode: wait_ack() returned 0x%x\n", ack);
|
||||
if (ack == GRUB_AT_NACK)
|
||||
continue;
|
||||
if (ack == GRUB_AT_ACK)
|
||||
@@ -125,6 +146,9 @@ write_mode (int mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+ if (i == GRUB_AT_TRIES)
|
||||
+ grub_dprintf ("atkeyb", "write_mode() timed out! (stopped after %d tries)\n", i);
|
||||
+
|
||||
return (i != GRUB_AT_TRIES);
|
||||
}
|
||||
|
||||
@@ -132,31 +156,66 @@ static int
|
||||
query_mode (void)
|
||||
{
|
||||
grub_uint8_t ret;
|
||||
+ grub_uint64_t endtime;
|
||||
+ unsigned i;
|
||||
int e;
|
||||
+ char *envvar;
|
||||
|
||||
- e = write_mode (0);
|
||||
- if (!e) {
|
||||
- grub_dprintf("atkeyb", "query_mode: write_mode(0) failed\n");
|
||||
- return 0;
|
||||
- }
|
||||
+ for (i = 0; i < GRUB_AT_TRIES; i++) {
|
||||
+ grub_dprintf ("atkeyb", "query_mode: sending command to controller\n");
|
||||
+ e = write_mode (0);
|
||||
+ if (!e) {
|
||||
+ grub_dprintf ("atkeyb", "query_mode: write_mode(0) failed\n");
|
||||
+ return 0;
|
||||
+ }
|
||||
|
||||
- do {
|
||||
- keyboard_controller_wait_until_ready ();
|
||||
- ret = grub_inb (KEYBOARD_REG_DATA);
|
||||
- } while (ret == GRUB_AT_ACK);
|
||||
- /* QEMU translates the set even in no-translate mode. */
|
||||
- if (ret == 0x43 || ret == 1) {
|
||||
- grub_dprintf("atkeyb", "query_mode: returning 1 (ret=0x%x)\n", ret);
|
||||
- return 1;
|
||||
- }
|
||||
- if (ret == 0x41 || ret == 2) {
|
||||
- grub_dprintf("atkeyb", "query_mode: returning 2 (ret=0x%x)\n", ret);
|
||||
- return 2;
|
||||
+ endtime = grub_get_time_ms () + 20;
|
||||
+ do {
|
||||
+ keyboard_controller_wait_until_ready ();
|
||||
+ ret = grub_inb (KEYBOARD_REG_DATA);
|
||||
+ grub_dprintf ("atkeyb", "query_mode/loop: read 0x%x from controller\n", ret);
|
||||
+ } while ((ret == GRUB_AT_ACK || ret == GRUB_AT_NACK) && grub_get_time_ms () < endtime);
|
||||
+ if (ret == 0xfe) {
|
||||
+ grub_dprintf ("atkeyb", "query_mode: asking controller to resend last result\n");
|
||||
+ ret = resend_last_result();
|
||||
+ grub_dprintf ("atkeyb", "query_mode: read 0x%x from controller\n", ret);
|
||||
+ }
|
||||
+ /* QEMU translates the set even in no-translate mode. */
|
||||
+ if (ret == 0x43 || ret == 1) {
|
||||
+ grub_dprintf ("atkeyb", "query_mode: controller returned 0x%x, returning 1\n", ret);
|
||||
+ return 1;
|
||||
+ }
|
||||
+ if (ret == 0x41 || ret == 2) {
|
||||
+ grub_dprintf ("atkeyb", "query_mode: controller returned 0x%x, returning 2\n", ret);
|
||||
+ return 2;
|
||||
+ }
|
||||
+ if (ret == 0x3f || ret == 3) {
|
||||
+ grub_dprintf ("atkeyb", "query_mode: controller returned 0x%x, returning 3\n", ret);
|
||||
+ return 3;
|
||||
+ }
|
||||
+ grub_dprintf ("atkeyb", "query_mode: controller returned unexpected value 0x%x, retrying\n", ret);
|
||||
}
|
||||
- if (ret == 0x3f || ret == 3) {
|
||||
- grub_dprintf("atkeyb", "query_mode: returning 3 (ret=0x%x)\n", ret);
|
||||
- return 3;
|
||||
+
|
||||
+ /*
|
||||
+ * Falling here means we tried querying and the controller returned something
|
||||
+ * we don't understand, try to use 'at_keyboard_fallback_set' if it exists,
|
||||
+ * otherwise return 0.
|
||||
+ */
|
||||
+ envvar = grub_env_get ("at_keyboard_fallback_set");
|
||||
+ if (envvar) {
|
||||
+ fallback_set = grub_strtoul (envvar, 0, 10);
|
||||
+ if ((grub_errno) || (fallback_set < 1) || (fallback_set > 3)) {
|
||||
+ grub_dprintf ("atkeyb", "WARNING: ignoring unexpected value '%s' for '%s' variable\n",
|
||||
+ envvar, "at_keyboard_fallback_set");
|
||||
+ fallback_set = 0;
|
||||
+ } else {
|
||||
+ grub_dprintf ("atkeyb", "query_mode: '%s' specified in environment, returning %d\n",
|
||||
+ "at_keyboard_fallback_set", fallback_set);
|
||||
+ }
|
||||
+ return fallback_set;
|
||||
}
|
||||
+ grub_dprintf ("atkeyb", "WARNING: no '%s' specified in environment, returning 0\n",
|
||||
+ "at_keyboard_fallback_set");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -165,14 +224,25 @@ set_scancodes (void)
|
||||
{
|
||||
/* You must have visited computer museum. Keyboard without scancode set
|
||||
knowledge. Assume XT. */
|
||||
- if (!grub_keyboard_orig_set)
|
||||
- {
|
||||
- grub_dprintf ("atkeyb", "No sets support assumed\n");
|
||||
- ps2_state.current_set = 1;
|
||||
+ if (!grub_keyboard_orig_set) {
|
||||
+ if (fallback_set) {
|
||||
+ grub_dprintf ("atkeyb", "No sets support assumed but set forced to %d\n", fallback_set);
|
||||
+ ps2_state.current_set = fallback_set;
|
||||
return;
|
||||
}
|
||||
+ grub_dprintf ("atkeyb", "No sets support assumed, forcing to set 1\n");
|
||||
+ ps2_state.current_set = 1;
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
#if !USE_SCANCODE_SET
|
||||
+ if (fallback_set) {
|
||||
+ grub_dprintf ("atkeyb", "queried set is %d but set forced to %d\n",
|
||||
+ grub_keyboard_orig_set, fallback_set);
|
||||
+ ps2_state.current_set = fallback_set;
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
if ((grub_keyboard_controller_orig & KEYBOARD_AT_TRANSLATE) == KEYBOARD_AT_TRANSLATE) {
|
||||
grub_dprintf ("atkeyb", "queried set is %d but keyboard in Translate mode, so actually in set 1\n", grub_keyboard_orig_set);
|
||||
ps2_state.current_set = 1;
|
||||
@@ -261,6 +331,7 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
|
||||
static void
|
||||
grub_keyboard_controller_init (void)
|
||||
{
|
||||
+ grub_dprintf ("atkeyb", "initializing the controller\n");
|
||||
ps2_state.at_keyboard_status = 0;
|
||||
/* Drain input buffer. */
|
||||
while (1)
|
||||
@@ -282,6 +353,7 @@ grub_keyboard_controller_init (void)
|
||||
grub_keyboard_controller_orig = grub_keyboard_controller_read ();
|
||||
grub_dprintf ("atkeyb", "grub_keyboard_controller_orig = 0x%x\n", grub_keyboard_controller_orig);
|
||||
grub_keyboard_orig_set = query_mode ();
|
||||
+ grub_dprintf ("atkeyb", "grub_keyboard_orig_set = %d\n", grub_keyboard_orig_set);
|
||||
#endif
|
||||
set_scancodes ();
|
||||
keyboard_controller_led (ps2_state.led_status);
|
||||
@@ -329,7 +401,6 @@ grub_at_restore_hw (void)
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
-
|
||||
static struct grub_term_input grub_at_keyboard_term =
|
||||
{
|
||||
.name = "at_keyboard",
|
@ -0,0 +1,60 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Kiper <daniel.kiper@oracle.com>
|
||||
Date: Mon, 29 Oct 2018 13:25:25 +0100
|
||||
Subject: [PATCH] bufio: Use grub_size_t instead of plain int for size
|
||||
|
||||
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>
|
||||
(cherry picked from commit f3f8347569383e7f483f37ca70d41eb1af9f990f)
|
||||
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||
---
|
||||
grub-core/io/bufio.c | 6 +++---
|
||||
include/grub/bufio.h | 4 ++--
|
||||
2 files changed, 5 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c
|
||||
index 6118bade50d..2781afe0515 100644
|
||||
--- a/grub-core/io/bufio.c
|
||||
+++ b/grub-core/io/bufio.c
|
||||
@@ -43,7 +43,7 @@ typedef struct grub_bufio *grub_bufio_t;
|
||||
static struct grub_fs grub_bufio_fs;
|
||||
|
||||
grub_file_t
|
||||
-grub_bufio_open (grub_file_t io, int size)
|
||||
+grub_bufio_open (grub_file_t io, grub_size_t size)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_bufio_t bufio = 0;
|
||||
@@ -57,7 +57,7 @@ grub_bufio_open (grub_file_t io, int size)
|
||||
else if (size > GRUB_BUFIO_MAX_SIZE)
|
||||
size = GRUB_BUFIO_MAX_SIZE;
|
||||
|
||||
- if ((size < 0) || ((unsigned) size > io->size))
|
||||
+ if (size > io->size)
|
||||
size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
|
||||
io->size);
|
||||
|
||||
@@ -88,7 +88,7 @@ grub_bufio_open (grub_file_t io, int size)
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
-grub_buffile_open (const char *name, int size)
|
||||
+grub_buffile_open (const char *name, grub_size_t size)
|
||||
{
|
||||
grub_file_t io, file;
|
||||
|
||||
diff --git a/include/grub/bufio.h b/include/grub/bufio.h
|
||||
index acdd0c882c6..77eb8ee5672 100644
|
||||
--- a/include/grub/bufio.h
|
||||
+++ b/include/grub/bufio.h
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <grub/file.h>
|
||||
|
||||
-grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, int size);
|
||||
-grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name, int size);
|
||||
+grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, grub_size_t size);
|
||||
+grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name, grub_size_t size);
|
||||
|
||||
#endif /* ! GRUB_BUFIO_H */
|
File diff suppressed because it is too large
Load Diff
1026
SOURCES/0331-verifiers-Framework-core.patch
Normal file
1026
SOURCES/0331-verifiers-Framework-core.patch
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,520 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Vladimir Serbinenko <phcoder@gmail.com>
|
||||
Date: Tue, 7 Feb 2017 02:10:14 +0100
|
||||
Subject: [PATCH] verifiers: Add possibility to verify kernel and modules
|
||||
command lines
|
||||
|
||||
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>
|
||||
(backported from 4d4a8c96e3593d76fe7b025665ccdecc70a53c1f)
|
||||
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||
---
|
||||
grub-core/commands/verifiers.c | 14 ++++++++++++++
|
||||
grub-core/lib/cmdline.c | 7 ++++---
|
||||
grub-core/loader/arm/linux.c | 8 ++++++--
|
||||
grub-core/loader/arm64/linux.c | 10 +++++++---
|
||||
grub-core/loader/i386/bsd.c | 6 ++++++
|
||||
grub-core/loader/i386/linux.c | 16 +++++++++++-----
|
||||
grub-core/loader/i386/multiboot_mbi.c | 16 ++++++++++------
|
||||
grub-core/loader/i386/pc/linux.c | 13 ++++++++-----
|
||||
grub-core/loader/i386/pc/plan9.c | 11 +++++++++++
|
||||
grub-core/loader/i386/xen.c | 7 +++++++
|
||||
grub-core/loader/ia64/efi/linux.c | 7 +++++++
|
||||
grub-core/loader/mips/linux.c | 8 ++++++++
|
||||
grub-core/loader/multiboot_mbi2.c | 8 +++-----
|
||||
grub-core/loader/powerpc/ieee1275/linux.c | 5 +++--
|
||||
grub-core/loader/sparc64/ieee1275/linux.c | 5 +++--
|
||||
grub-core/loader/xnu.c | 9 +++++++++
|
||||
include/grub/lib/cmdline.h | 5 +++--
|
||||
include/grub/verify.h | 11 +++++++++++
|
||||
18 files changed, 131 insertions(+), 35 deletions(-)
|
||||
|
||||
diff --git a/grub-core/commands/verifiers.c b/grub-core/commands/verifiers.c
|
||||
index fde88318d4c..59ea418a2d9 100644
|
||||
--- a/grub-core/commands/verifiers.c
|
||||
+++ b/grub-core/commands/verifiers.c
|
||||
@@ -186,6 +186,20 @@ grub_verifiers_open (grub_file_t io, enum grub_file_type type)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+grub_err_t
|
||||
+grub_verify_string (char *str, enum grub_verify_string_type type)
|
||||
+{
|
||||
+ struct grub_file_verifier *ver;
|
||||
+ FOR_LIST_ELEMENTS(ver, grub_file_verifiers)
|
||||
+ {
|
||||
+ grub_err_t err;
|
||||
+ err = ver->verify_string ? ver->verify_string (str, type) : GRUB_ERR_NONE;
|
||||
+ if (err)
|
||||
+ return err;
|
||||
+ }
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
GRUB_MOD_INIT(verifiers)
|
||||
{
|
||||
grub_file_filter_register (GRUB_FILE_FILTER_VERIFY, grub_verifiers_open);
|
||||
diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
|
||||
index d5c12957cad..463c3c65c79 100644
|
||||
--- a/grub-core/lib/cmdline.c
|
||||
+++ b/grub-core/lib/cmdline.c
|
||||
@@ -75,8 +75,9 @@ unsigned int grub_loader_cmdline_size (int argc, char *argv[])
|
||||
return size;
|
||||
}
|
||||
|
||||
-int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
- grub_size_t size)
|
||||
+grub_err_t
|
||||
+grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
+ grub_size_t size, enum grub_verify_string_type type)
|
||||
{
|
||||
int i, space;
|
||||
unsigned int arg_size;
|
||||
@@ -130,5 +131,5 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
"grub_kernel_cmdline", orig);
|
||||
grub_print_error();
|
||||
|
||||
- return i;
|
||||
+ return grub_verify_string (orig, type);
|
||||
}
|
||||
diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
|
||||
index ea29d7a724a..beceda52030 100644
|
||||
--- a/grub-core/loader/arm/linux.c
|
||||
+++ b/grub-core/loader/arm/linux.c
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <grub/cpu/linux.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/linux.h>
|
||||
+#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -383,8 +384,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
- grub_create_loader_cmdline (argc, argv,
|
||||
- linux_args + sizeof (LINUX_IMAGE) - 1, size);
|
||||
+ err = grub_create_loader_cmdline (argc, argv,
|
||||
+ linux_args + sizeof (LINUX_IMAGE) - 1, size,
|
||||
+ GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ goto fail;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
|
||||
index 7a076c13171..48ea66596ad 100644
|
||||
--- a/grub-core/loader/arm64/linux.c
|
||||
+++ b/grub-core/loader/arm64/linux.c
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <grub/efi/pe32.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
+#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -403,9 +404,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
- grub_create_loader_cmdline (argc, argv,
|
||||
- linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
- cmdline_size);
|
||||
+ err = grub_create_loader_cmdline (argc, argv,
|
||||
+ linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
+ cmdline_size,
|
||||
+ GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ goto fail;
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
{
|
||||
diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
|
||||
index 8306b415abd..45a71509956 100644
|
||||
--- a/grub-core/loader/i386/bsd.c
|
||||
+++ b/grub-core/loader/i386/bsd.c
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <grub/bsdlabel.h>
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/verify.h>
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
#include <grub/machine/int.h>
|
||||
#endif
|
||||
@@ -418,6 +419,8 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
|
||||
grub_addr_t addr, grub_uint32_t size)
|
||||
{
|
||||
const char *name;
|
||||
+ grub_err_t err;
|
||||
+
|
||||
name = grub_strrchr (filename, '/');
|
||||
if (name)
|
||||
name++;
|
||||
@@ -471,6 +474,9 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
|
||||
*(p++) = ' ';
|
||||
}
|
||||
*p = 0;
|
||||
+ err = grub_verify_string (cmdline, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
+ if (err)
|
||||
+ return err;
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
|
||||
index aa2cbc4e7eb..ef8fcb9e1b6 100644
|
||||
--- a/grub-core/loader/i386/linux.c
|
||||
+++ b/grub-core/loader/i386/linux.c
|
||||
@@ -1039,11 +1039,17 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!linux_cmdline)
|
||||
goto fail;
|
||||
grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
- grub_create_loader_cmdline (argc, argv,
|
||||
- linux_cmdline
|
||||
- + sizeof (LINUX_IMAGE) - 1,
|
||||
- maximal_cmdline_size
|
||||
- - (sizeof (LINUX_IMAGE) - 1));
|
||||
+ {
|
||||
+ grub_err_t err;
|
||||
+ err = grub_create_loader_cmdline (argc, argv,
|
||||
+ linux_cmdline
|
||||
+ + sizeof (LINUX_IMAGE) - 1,
|
||||
+ maximal_cmdline_size
|
||||
+ - (sizeof (LINUX_IMAGE) - 1),
|
||||
+ GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ goto fail;
|
||||
+ }
|
||||
|
||||
len = prot_file_size;
|
||||
grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
|
||||
diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
|
||||
index 9d3466d6ace..525446b5687 100644
|
||||
--- a/grub-core/loader/i386/multiboot_mbi.c
|
||||
+++ b/grub-core/loader/i386/multiboot_mbi.c
|
||||
@@ -676,10 +676,8 @@ grub_multiboot_init_mbi (int argc, char *argv[])
|
||||
return grub_errno;
|
||||
cmdline_size = len;
|
||||
|
||||
- grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
- cmdline_size);
|
||||
-
|
||||
- return GRUB_ERR_NONE;
|
||||
+ return grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
+ cmdline_size, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
@@ -688,6 +686,7 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
{
|
||||
struct module *newmod;
|
||||
grub_size_t len = 0;
|
||||
+ grub_err_t err;
|
||||
|
||||
newmod = grub_malloc (sizeof (*newmod));
|
||||
if (!newmod)
|
||||
@@ -707,8 +706,13 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
newmod->cmdline_size = len;
|
||||
total_modcmd += ALIGN_UP (len, 4);
|
||||
|
||||
- grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
- newmod->cmdline_size);
|
||||
+ err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
+ newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_free (newmod);
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
|
||||
if (modules_last)
|
||||
modules_last->next = newmod;
|
||||
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
|
||||
index b5c28c6580e..f631225f59b 100644
|
||||
--- a/grub-core/loader/i386/pc/linux.c
|
||||
+++ b/grub-core/loader/i386/pc/linux.c
|
||||
@@ -348,11 +348,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy ((char *)grub_linux_real_chunk + GRUB_LINUX_CL_OFFSET,
|
||||
LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
- grub_create_loader_cmdline (argc, argv,
|
||||
- (char *)grub_linux_real_chunk
|
||||
- + GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1,
|
||||
- maximal_cmdline_size
|
||||
- - (sizeof (LINUX_IMAGE) - 1));
|
||||
+ err = grub_create_loader_cmdline (argc, argv,
|
||||
+ (char *)grub_linux_real_chunk
|
||||
+ + GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1,
|
||||
+ maximal_cmdline_size
|
||||
+ - (sizeof (LINUX_IMAGE) - 1),
|
||||
+ GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ goto fail;
|
||||
|
||||
if (grub_linux_is_bzimage)
|
||||
grub_linux_prot_target = GRUB_LINUX_BZIMAGE_ADDR;
|
||||
diff --git a/grub-core/loader/i386/pc/plan9.c b/grub-core/loader/i386/pc/plan9.c
|
||||
index 0351090daf8..37550155df7 100644
|
||||
--- a/grub-core/loader/i386/pc/plan9.c
|
||||
+++ b/grub-core/loader/i386/pc/plan9.c
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <grub/mm.h>
|
||||
#include <grub/cpu/relocator.h>
|
||||
#include <grub/extcmd.h>
|
||||
+#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -505,6 +506,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
configptr = grub_stpcpy (configptr, "bootfile=");
|
||||
configptr = grub_stpcpy (configptr, bootpath);
|
||||
*configptr++ = '\n';
|
||||
+ char *cmdline = configptr;
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; i++)
|
||||
@@ -513,6 +515,15 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
*configptr++ = '\n';
|
||||
}
|
||||
}
|
||||
+
|
||||
+ {
|
||||
+ grub_err_t err;
|
||||
+ *configptr = '\0';
|
||||
+ err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
configptr = grub_stpcpy (configptr, fill_ctx.pmap);
|
||||
|
||||
{
|
||||
diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c
|
||||
index 82350d3a178..07a4837c532 100644
|
||||
--- a/grub-core/loader/i386/xen.c
|
||||
+++ b/grub-core/loader/i386/xen.c
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <grub/linux.h>
|
||||
#include <grub/i386/memory.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -649,6 +650,9 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_create_loader_cmdline (argc - 1, argv + 1,
|
||||
(char *) xen_state.next_start.cmd_line,
|
||||
sizeof (xen_state.next_start.cmd_line) - 1);
|
||||
+ err = grub_verify_string (xen_state.next_start.cmd_line, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
+ if (err)
|
||||
+ return err;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
if (!file)
|
||||
@@ -916,6 +920,9 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_create_loader_cmdline (argc - 1, argv + 1,
|
||||
get_virtual_current_address (ch), cmdline_len);
|
||||
+ err = grub_verify_string (get_virtual_current_address (ch), GRUB_VERIFY_MODULE_CMDLINE);
|
||||
+ if (err)
|
||||
+ goto fail;
|
||||
|
||||
xen_state.module_info_page[xen_state.n_modules].cmdline =
|
||||
xen_state.max_addr - xen_state.modules_target_start;
|
||||
diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c
|
||||
index 750330d4572..e325fe0ee83 100644
|
||||
--- a/grub-core/loader/ia64/efi/linux.c
|
||||
+++ b/grub-core/loader/ia64/efi/linux.c
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/linux.h>
|
||||
+#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -543,6 +544,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
p = grub_stpcpy (p, argv[i]);
|
||||
}
|
||||
cmdline[10] = '=';
|
||||
+
|
||||
+ *p = '\0';
|
||||
+
|
||||
+ err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ goto fail;
|
||||
|
||||
boot_param->command_line = (grub_uint64_t) cmdline;
|
||||
boot_param->efi_systab = (grub_uint64_t) grub_efi_system_table;
|
||||
diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c
|
||||
index 10358854458..20135ce253d 100644
|
||||
--- a/grub-core/loader/mips/linux.c
|
||||
+++ b/grub-core/loader/mips/linux.c
|
||||
@@ -327,6 +327,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
linux_argv++;
|
||||
linux_args += ALIGN_UP (sizeof ("a0"), 4);
|
||||
|
||||
+ char *params = linux_args;
|
||||
+
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
{
|
||||
unsigned mtype = grub_arch_machine;
|
||||
@@ -352,6 +354,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
linux_args += ALIGN_UP (grub_strlen (argv[i]) + 1, 4);
|
||||
}
|
||||
|
||||
+ *linux_args = '\0';
|
||||
+
|
||||
+ err = grub_verify_string (params, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ return err;
|
||||
+
|
||||
/* Reserve space for rd arguments. */
|
||||
rd_addr_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground;
|
||||
linux_args += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4);
|
||||
diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
|
||||
index 3cfb47650a0..f64a857e394 100644
|
||||
--- a/grub-core/loader/multiboot_mbi2.c
|
||||
+++ b/grub-core/loader/multiboot_mbi2.c
|
||||
@@ -1077,10 +1077,8 @@ grub_multiboot2_init_mbi (int argc, char *argv[])
|
||||
return grub_errno;
|
||||
cmdline_size = len;
|
||||
|
||||
- grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
- cmdline_size);
|
||||
-
|
||||
- return GRUB_ERR_NONE;
|
||||
+ return grub_create_loader_cmdline (argc, argv, cmdline, cmdline_size,
|
||||
+ GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
@@ -1109,7 +1107,7 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size,
|
||||
total_modcmd += ALIGN_UP (len, MULTIBOOT_TAG_ALIGN);
|
||||
|
||||
err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
- newmod->cmdline_size);
|
||||
+ newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
{
|
||||
grub_free (newmod->cmdline);
|
||||
diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c
|
||||
index 6e814649f31..c114e7df4fb 100644
|
||||
--- a/grub-core/loader/powerpc/ieee1275/linux.c
|
||||
+++ b/grub-core/loader/powerpc/ieee1275/linux.c
|
||||
@@ -302,8 +302,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
- grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
- size);
|
||||
+ if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
+ size))
|
||||
+ goto out;
|
||||
|
||||
out:
|
||||
|
||||
diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c
|
||||
index 67ef0488324..abe46faa012 100644
|
||||
--- a/grub-core/loader/sparc64/ieee1275/linux.c
|
||||
+++ b/grub-core/loader/sparc64/ieee1275/linux.c
|
||||
@@ -340,8 +340,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
- grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
- size);
|
||||
+ if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
+ size, GRUB_VERIFY_KERNEL_CMDLINE))
|
||||
+ goto out;
|
||||
|
||||
out:
|
||||
if (elf)
|
||||
diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c
|
||||
index 9f78abb05f9..5944dc5eafc 100644
|
||||
--- a/grub-core/loader/xnu.c
|
||||
+++ b/grub-core/loader/xnu.c
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/efi/sb.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -429,6 +430,10 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (ptr != grub_xnu_cmdline)
|
||||
*(ptr - 1) = 0;
|
||||
|
||||
+ err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ return err;
|
||||
+
|
||||
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
|
||||
err = grub_efiemu_autocore ();
|
||||
if (err)
|
||||
@@ -538,6 +543,10 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (ptr != grub_xnu_cmdline)
|
||||
*(ptr - 1) = 0;
|
||||
|
||||
+ err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ return err;
|
||||
+
|
||||
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
|
||||
err = grub_efiemu_autocore ();
|
||||
if (err)
|
||||
diff --git a/include/grub/lib/cmdline.h b/include/grub/lib/cmdline.h
|
||||
index 1fe8d017971..cdca09b7a16 100644
|
||||
--- a/include/grub/lib/cmdline.h
|
||||
+++ b/include/grub/lib/cmdline.h
|
||||
@@ -21,11 +21,12 @@
|
||||
#define GRUB_CMDLINE_HEADER 1
|
||||
|
||||
#include <grub/types.h>
|
||||
+#include <grub/verify.h>
|
||||
|
||||
#define LINUX_IMAGE "BOOT_IMAGE="
|
||||
|
||||
unsigned int grub_loader_cmdline_size (int argc, char *argv[]);
|
||||
-int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
- grub_size_t size);
|
||||
+grub_err_t grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
+ grub_size_t size, enum grub_verify_string_type type);
|
||||
|
||||
#endif /* ! GRUB_CMDLINE_HEADER */
|
||||
diff --git a/include/grub/verify.h b/include/grub/verify.h
|
||||
index 298120f5776..9f892d8fedb 100644
|
||||
--- a/include/grub/verify.h
|
||||
+++ b/include/grub/verify.h
|
||||
@@ -25,6 +25,12 @@ enum grub_verify_flags
|
||||
GRUB_VERIFY_FLAGS_SINGLE_CHUNK = 2
|
||||
};
|
||||
|
||||
+enum grub_verify_string_type
|
||||
+ {
|
||||
+ GRUB_VERIFY_KERNEL_CMDLINE,
|
||||
+ GRUB_VERIFY_MODULE_CMDLINE,
|
||||
+ };
|
||||
+
|
||||
struct grub_file_verifier
|
||||
{
|
||||
struct grub_file_verifier *next;
|
||||
@@ -48,6 +54,8 @@ struct grub_file_verifier
|
||||
|
||||
grub_err_t (*fini) (void *context);
|
||||
void (*close) (void *context);
|
||||
+
|
||||
+ grub_err_t (*verify_string) (char *str, enum grub_verify_string_type type);
|
||||
};
|
||||
|
||||
extern struct grub_file_verifier *grub_file_verifiers;
|
||||
@@ -63,3 +71,6 @@ grub_verifier_unregister (struct grub_file_verifier *ver)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST (ver));
|
||||
}
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_verify_string (char *str, enum grub_verify_string_type type);
|
@ -0,0 +1,91 @@
|
||||