Compare commits

..
Author SHA1 Message Date
Javier Martinez Canillas c0e647eb0e util/mkimage: Fix wrong PE32+ section sizes for some arches
The commit f60ba9e594 (util/mkimage: Refactor section setup to use a helper)
added a helper function to setup PE sections. But it also changed how the
raw data offsets were calculated since all the section sizes are aligned.
However, for some platforms, i.e ia64-efi and arm64-efi, the kernel image
size is not aligned using the section alignment. This leads to the situation
in which the mods section offset in its PE section header does not match its
real placement in the PE file. So, finally the GRUB is not able to locate
and load built-in modules.

The problem surfaces on ia64-efi and arm64-efi because both platforms
require additional relocation data which is added behind .bss section.
So, we have to add some padding behind this extra data to make the
beginning of mods section properly aligned in the PE file. Fix it by
aligning the kernel_size to the section alignment. That makes the sizes
and offsets in the PE section headers to match relevant sections in the
PE32+ binary file.

Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-05-10 15:18:34 +02:00
Daniel Kiper 88e856a5b3 term/terminfo: Fix the terminfo command help and documentation
Additionally, fix the terminfo spelling mistake in
the GRUB development documentation.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
2021-05-10 15:08:39 +02:00
Daniel Kiper 3a1afa19ca i18n: Align N_() formatting with the rest of GRUB code
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
2021-05-10 15:07:58 +02:00
Daniel Kiper 66be067e61 i18n: Format large integers before the translation message - take 2
This is an additional fix which has been missing from the commit 837fe48de
(i18n: Format large integers before the translation message).

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
2021-05-10 15:06:33 +02:00
Miguel Ángel Arruga Vivas 837fe48deb i18n: Format large integers before the translation message
The GNU gettext only supports the ISO C99 macros for integral
types. If there is a need to use unsupported formatting macros,
e.g. PRIuGRUB_UINT64_T, according to [1] the number to a string
conversion should be separated from the code printing message
requiring the internationalization. So, the function grub_snprintf()
is used to print the numeric values to an intermediate buffer and
the internationalized message contains a string format directive.

[1] https://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html#No-string-concatenation

Signed-off-by: Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-04-13 17:16:04 +02:00
Daniel Axtens e48fc8880d video/fb/fbfill: Use unsigned integers for width/height
Since commit 7ce3259f67 (video/fb/fbfill: Fix potential integer
overflow), clang builds of grub-emu have failed with messages like:

  /usr/bin/ld: libgrubmods.a(libgrubmods_a-fbfill.o): in function `grub_video_fbfill_direct24':
  fbfill.c:(.text+0x28e): undefined reference to `__muloti4'

This appears to be due to a weird quirk in how clang compiles

  grub_mul(dst->mode_info->bytes_per_pixel, width, &rowskip)

which is grub_mul(unsigned int, int, &grub_size_t).

It looks like clang somewhere promotes everything to 128-bit maths
before ultimately reducing down to 64 bit for grub_size_t. I think
this is because width is signed, and indeed converting width to an
unsigned int makes the problem go away.

This conversion also makes more sense generally:
  - the caller of all the fbfill_directN functions is
    grub_video_fb_fill_dispatch() and it takes width and height as
    unsigned ints already,
  - it doesn't make sense to fill a negative width or height.

Convert the width and height arguments and associated loop counters
to unsigned ints.

Fixes: 7ce3259f67 (video/fb/fbfill: Fix potential integer overflow)

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-04-12 16:56:45 +02:00
Glenn Washburn 406dde6f27 docs: Conform badmem and cutmem description indentations with other commands
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-04-12 16:49:40 +02:00
Glenn Washburn cb715be37d docs: Add note to cryptomount that UUIDs should be specified without dashes
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-04-12 16:46:27 +02:00
Aru Sahni 7227376308 templates: Fix user-facing typo with an incorrect use of "it's"
Since the possessive form of "it" is being used, the apostrophe must be omitted.

Signed-off-by: Aru Sahni <aru@arusahni.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-04-12 16:40:34 +02:00
Colin Watson edbe7076cb buffer: Sync up out-of-range error message
The messages associated with other similar GRUB_ERR_OUT_OF_RANGE errors
were lacking the trailing full stop. Syncing up the strings saves a small
amount of precious core image space on i386-pc.

  DOWN: obj/i386-pc/grub-core/kernel.img (31740 > 31708) - change: -32
  DOWN: i386-pc core image (biosdisk ext2 part_msdos) (27453 > 27452) - change: -1
  DOWN: i386-pc core image (biosdisk ext2 part_msdos diskfilter mdraid09) (32367 > 32359) - change: -8

Signed-off-by: Colin Watson <cjwatson@debian.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-04-12 16:31:18 +02:00
Glenn Washburn c9c22dc803 usb/usbhub: Use GRUB_USB_MAX_CONF macro instead of literal in hub for maximum configs
Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-04-12 16:26:49 +02:00
Daniel Drake 25d64bb273 fs/minix: Avoid mistakenly probing ext2 filesystems
The ext2 (and ext3, ext4) filesystems write the number of free inodes to
location 0x410.

On a MINIX filesystem, that same location is used for the MINIX superblock
magic number.

If the number of free inodes on an ext2 filesystem is equal to any
of the four MINIX superblock magic values plus any multiple of 65536,
GRUB's MINIX filesystem code will probe it as a MINIX filesystem.

In the case of an OS using ext2 as the root filesystem, since there will
ordinarily be some amount of file creation and deletion on every bootup,
it effectively means that this situation has a 1:16384 chance of being hit
on every reboot.

This will cause GRUB's filesystem probing code to mistakenly identify an
ext2 filesystem as MINIX. This can be seen by e.g. "search --label"
incorrectly indicating that no such ext2 partition with matching label
exists, whereas in fact it does.

After spotting the rough cause of the issue I was facing here, I borrowed
much of the diagnosis/explanation from meierfra who found and investigated
the same issue in util-linux in 2010:

  https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/518582

This was fixed in util-linux by having the MINIX code check for the
ext2 magic. Do the same here.

Signed-off-by: Daniel Drake <drake@endlessm.com>
Reviewed-by: Derek Foreman <derek@endlessos.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2021-04-12 16:22:44 +02:00
17 changed files with 97 additions and 47 deletions

No files matched your search

+1 -1
View File
@@ -820,7 +820,7 @@ Of video is loongson (kern/mips/loongson/init.c). Note that terminfo has
to be inited in 2 stages: one before (to get at least rudimentary console
as early as possible) and another after the heap (to get full-featured console).
For the input there are string of keys, terminfo and direct hardware. For string
of keys look at i386-pc (same files), for termino ieee1275 (same files) and for
of keys look at i386-pc (same files), for terminfo ieee1275 (same files) and for
hardware loongson (kern/mips/loongson/init.c and term/at_keyboard.c).
For the timer you'll need to call grub_install_get_time_ms (...) with as sole
+8 -3
View File
@@ -3934,7 +3934,7 @@ names active.
@node terminfo
@subsection terminfo
@deffn Command terminfo [-a|-u|-v] [term]
@deffn Command terminfo [@option{-a}|@option{-u}|@option{-v}] [@option{-g WxH}] [term] [type]
Define the capabilities of your terminal by giving the name of an entry in
the terminfo database, which should correspond roughly to a @samp{TERM}
environment variable in Unix.
@@ -3951,6 +3951,8 @@ specifies logically-ordered UTF-8; and @option{-v} specifies
emulator without bidirectional text support will display right-to-left text
in the proper order; this is not really proper UTF-8, but a workaround).
The @option{-g} (@option{--geometry}) can be used to specify terminal geometry.
If no option or terminal type is specified, the current terminal type is
printed.
@end deffn
@@ -4125,7 +4127,6 @@ can be changed only when using @samp{gfxterm} for terminal output.
@deffn Command badram addr,mask[,addr,mask...]
Filter out bad RAM.
@end deffn
This command notifies the memory manager that specified regions of
RAM ought to be filtered out (usually, because they're damaged). This
@@ -4147,6 +4148,7 @@ The command is similar to @command{cutmem} command.
Note: The command is not allowed when lockdown is enforced (@pxref{Lockdown}).
This prevents removing EFI memory regions to potentially subvert the
security mechanisms provided by the UEFI secure boot.
@end deffn
@node blocklist
@subsection blocklist
@@ -4307,6 +4309,9 @@ GRUB suports devices encrypted using LUKS, LUKS2 and geli. Note that necessary
modules (@var{luks}, @var{luks2} and @var{geli}) have to be loaded manually
before this command can be used. For LUKS2 only the PBKDF2 key derivation
function is supported, as Argon2 is not yet supported.
Also, note that, unlike filesystem UUIDs, UUIDs for encrypted devices must be
specified without dash separators.
@end deffn
@node cutmem
@@ -4314,7 +4319,6 @@ function is supported, as Argon2 is not yet supported.
@deffn Command cutmem from[K|M|G] to[K|M|G]
Remove any memory regions in specified range.
@end deffn
This command notifies the memory manager that specified regions of RAM ought to
be filtered out. This remains in effect after a payload kernel has been loaded
@@ -4327,6 +4331,7 @@ The command is similar to @command{badram} command.
Note: The command is not allowed when lockdown is enforced (@pxref{Lockdown}).
This prevents removing EFI memory regions to potentially subvert the
security mechanisms provided by the UEFI secure boot.
@end deffn
@node date
@subsection date
+2 -2
View File
@@ -82,7 +82,7 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
if (i == GRUB_USBHUB_MAX_DEVICES)
{
grub_error (GRUB_ERR_IO, "can't assign address to USB device");
for (i = 0; i < 8; i++)
for (i = 0; i < GRUB_USB_MAX_CONF; i++)
grub_free (dev->config[i].descconf);
grub_free (dev);
return NULL;
@@ -96,7 +96,7 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
i, 0, 0, NULL);
if (err)
{
for (i = 0; i < 8; i++)
for (i = 0; i < GRUB_USB_MAX_CONF; i++)
grub_free (dev->config[i].descconf);
grub_free (dev);
return NULL;
+3 -1
View File
@@ -612,6 +612,7 @@ luks2_recover_key (grub_disk_t source,
/* Try all keyslot */
for (json_idx = 0; json_idx < size; json_idx++)
{
char indexstr[21]; /* log10(2^64) ~ 20, plus NUL character. */
typeof (source->total_sectors) max_crypt_sectors = 0;
grub_errno = GRUB_ERR_NONE;
@@ -732,11 +733,12 @@ luks2_recover_key (grub_disk_t source,
continue;
}
grub_snprintf (indexstr, sizeof (indexstr) - 1, "%" PRIuGRUB_UINT64_T, keyslot.idx);
/*
* TRANSLATORS: It's a cryptographic key slot: one element of an array
* where each element is either empty or holds a key.
*/
grub_printf_ (N_("Slot \"%" PRIuGRUB_UINT64_T "\" opened\n"), keyslot.idx);
grub_printf_ (N_("Slot \"%s\" opened\n"), indexstr);
candidate_key_len = keyslot.key_size;
break;
+7 -3
View File
@@ -121,10 +121,14 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
return err;
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}
}
+17 -1
View File
@@ -38,6 +38,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_MINIX_MAGIC_30 0x138F
#endif
#define EXT2_MAGIC 0xEF53
#define GRUB_MINIX_INODE_DIR_BLOCKS 7
#define GRUB_MINIX_LOG2_BSIZE 1
#define GRUB_MINIX_ROOT_INODE 1
@@ -466,7 +468,21 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
static struct grub_minix_data *
grub_minix_mount (grub_disk_t disk)
{
struct grub_minix_data *data;
struct grub_minix_data *data = NULL;
grub_uint16_t ext2_marker;
grub_disk_read (disk, 2, 56, sizeof (ext2_marker), &ext2_marker);
if (grub_errno != GRUB_ERR_NONE)
goto fail;
/*
* The ext2 filesystems can sometimes be mistakenly identified as MINIX, e.g.
* due to the number of free ext2 inodes being written to the same location
* where the MINIX superblock magic is found. Avoid such situations by
* skipping any filesystems that have the ext2 superblock magic.
*/
if (ext2_marker == grub_cpu_to_le16_compile_time (EXT2_MAGIC))
goto fail;
data = grub_malloc (sizeof (struct grub_minix_data));
if (!data)
+7 -3
View File
@@ -183,10 +183,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}
+7 -3
View File
@@ -126,10 +126,14 @@ 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)
{
char inv_addr[17], max_addr[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (inv_addr, sizeof (inv_addr) - 1, "%" PRIxGRUB_UINT64_T,
address);
grub_snprintf (max_addr, sizeof (max_addr) - 1, "%" PRIxGRUB_UINT64_T,
(grub_efi_uint64_t) GRUB_EFI_MAX_USABLE_ADDRESS);
grub_error (GRUB_ERR_BAD_ARGUMENT,
N_("invalid memory address (0x%" PRIxGRUB_UINT64_T
" > 0x%" PRIxGRUB_UINT64_T ")"),
address, (grub_efi_uint64_t) GRUB_EFI_MAX_USABLE_ADDRESS);
N_("invalid memory address (0x%s > 0x%s)"), inv_addr, max_addr);
return NULL;
}
+7 -3
View File
@@ -136,10 +136,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
case R_IA64_LDXMOV:
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}
return GRUB_ERR_NONE;
+7 -3
View File
@@ -330,10 +330,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
case R_RISCV_RELAX:
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
(grub_uint64_t) ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}
+7 -3
View File
@@ -176,10 +176,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
& 0x1fff);
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}
+7 -3
View File
@@ -106,10 +106,14 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%" PRIxGRUB_UINT64_T
" is not implemented yet"),
{
char rel_info[17]; /* log16(2^64) = 16, plus NUL. */
grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
ELF_R_TYPE (rel->r_info));
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("relocation 0x%s is not implemented yet"), rel_info);
}
}
}
+1 -1
View File
@@ -785,7 +785,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(terminfo)
{
cmd = grub_register_extcmd ("terminfo", grub_cmd_terminfo, 0,
N_("[[-a|-u|-v] [-g WxH] TERM [TYPE]]"),
N_("[[-a|-u|-v] [-g WxH] [TERM] [TYPE]]"),
N_("Set terminfo type of TERM to TYPE.\n"),
options);
}
+10 -15
View File
@@ -38,10 +38,9 @@
static void
grub_video_fbfill (struct grub_video_fbblit_info *dst,
grub_video_color_t color, int x, int y,
int width, int height)
unsigned int width, unsigned int height)
{
int i;
int j;
unsigned int i, j;
for (j = 0; j < height; j++)
for (i = 0; i < width; i++)
@@ -53,10 +52,9 @@ grub_video_fbfill (struct grub_video_fbblit_info *dst,
static void
grub_video_fbfill_direct32 (struct grub_video_fbblit_info *dst,
grub_video_color_t color, int x, int y,
int width, int height)
unsigned int width, unsigned int height)
{
int i;
int j;
unsigned int i, j;
grub_uint32_t *dstptr;
grub_size_t rowskip;
@@ -84,10 +82,9 @@ grub_video_fbfill_direct32 (struct grub_video_fbblit_info *dst,
static void
grub_video_fbfill_direct24 (struct grub_video_fbblit_info *dst,
grub_video_color_t color, int x, int y,
int width, int height)
unsigned int width, unsigned int height)
{
int i;
int j;
unsigned int i, j;
grub_size_t rowskip;
grub_uint8_t *dstptr;
#ifndef GRUB_CPU_WORDS_BIGENDIAN
@@ -127,10 +124,9 @@ grub_video_fbfill_direct24 (struct grub_video_fbblit_info *dst,
static void
grub_video_fbfill_direct16 (struct grub_video_fbblit_info *dst,
grub_video_color_t color, int x, int y,
int width, int height)
unsigned int width, unsigned int height)
{
int i;
int j;
unsigned int i, j;
grub_size_t rowskip;
grub_uint16_t *dstptr;
@@ -158,10 +154,9 @@ grub_video_fbfill_direct16 (struct grub_video_fbblit_info *dst,
static void
grub_video_fbfill_direct8 (struct grub_video_fbblit_info *dst,
grub_video_color_t color, int x, int y,
int width, int height)
unsigned int width, unsigned int height)
{
int i;
int j;
unsigned int i, j;
grub_size_t rowskip;
grub_uint8_t *dstptr;
grub_uint8_t fill = (grub_uint8_t)color & 0xFF;
+1 -1
View File
@@ -114,7 +114,7 @@ grub_buffer_peek_data_at (grub_buffer_t buf, grub_size_t off)
{
if (grub_add (buf->pos, off, &off))
{
grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected."));
grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
return NULL;
}
+4
View File
@@ -2388,6 +2388,10 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path,
layout->kernel_size += ALIGN_UP (layout->got_size, 16);
}
#endif
if (image_target->id == IMAGE_EFI)
layout->kernel_size = ALIGN_UP (layout->kernel_size,
GRUB_PE32_FILE_ALIGNMENT);
}
else
{
+1 -1
View File
@@ -36,7 +36,7 @@ if ! command -v os-prober > /dev/null || ! command -v linux-boot-prober > /dev/n
exit 0
fi
grub_warn "$(gettext_printf "os-prober will be executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")"
grub_warn "$(gettext_printf "os-prober will be executed to detect other bootable partitions.\nIts output will be used to detect bootable binaries on them and create new boot entries.")"
OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
if [ -z "${OSPROBED}" ] ; then