Commit Graph

34 Commits

Author SHA1 Message Date
Peter Jones f725fa7cb2 calloc: Use calloc() at most places
This modifies most of the places we do some form of:

  X = malloc(Y * Z);

to use calloc(Y, Z) instead.

Among other issues, this fixes:
  - allocation of integer overflow in grub_png_decode_image_header()
    reported by Chris Coulson,
  - allocation of integer overflow in luks_recover_key()
    reported by Chris Coulson,
  - allocation of integer overflow in grub_lvm_detect()
    reported by Chris Coulson.

Fixes: CVE-2020-14308

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-07-29 16:55:47 +02:00
Daniel Kiper eba6db6323 relocator: Fix integer underflow. 2016-02-12 16:07:57 +01:00
Vladimir Serbinenko 8063ce197f Replace few instances of memcmp/memcpy in the code that should be grub_memcmp/grub_memcpy. 2014-04-04 07:58:42 +02:00
Vladimir Serbinenko 46b74dd3cb * grub-core/lib/relocator.c: Fix the case when end of leftover is used. 2014-03-26 08:48:30 +01:00
Vladimir Serbinenko 04f39f6df8 * grub-core/lib/relocator.c (grub_mm_check_real): Accept const char *
as file argument.
2013-11-18 02:45:25 +01:00
Vladimir Serbinenko 9612ebc00e Add new ports: i386-xen and x86_64-xen. This allows running GRUB in
XEN PV environment and load kernels.
2013-11-09 21:29:11 +01:00
Vladimir 'phcoder' Serbinenko fb2666b560 Simplify few strings. 2013-05-07 11:44:15 +02:00
Vladimir 'phcoder' Serbinenko 872dac835c * grub-core/lib/efi/relocator.c (grub_relocator_firmware_alloc_region):
Remove dprintf.
	* grub-core/lib/relocator.c (malloc_in_range): Likewise.
2013-04-20 13:39:04 +02:00
Colin Watson d0d4b8a063 Remove nested functions from memory map iterators.
* grub-core/efiemu/mm.c (grub_efiemu_mmap_iterate): Add hook_data
argument, passed to hook.
* grub-core/kern/i386/coreboot/mmap.c
(grub_linuxbios_table_iterate): Likewise.
(grub_machine_mmap_iterate: iterate_linuxbios_table): Make static
instead of nested.
(grub_machine_mmap_iterate): Add hook_data argument.
* grub-core/kern/i386/multiboot_mmap.c (grub_machine_mmap_iterate):
Add hook_data argument, passed to hook.
* grub-core/kern/i386/pc/mmap.c (grub_machine_mmap_iterate):
Likewise.
* grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_iterate):
Likewise.
* grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate):
Likewise.
* grub-core/kern/mips/arc/init.c (grub_machine_mmap_iterate):
Likewise.
* grub-core/kern/mips/loongson/init.c (grub_machine_mmap_iterate):
Likewise.
* grub-core/kern/mips/qemu_mips/init.c (grub_machine_mmap_iterate):
Likewise.
* grub-core/mmap/efi/mmap.c (grub_efi_mmap_iterate): Likewise.
(grub_machine_mmap_iterate): Likewise.
* grub-core/mmap/mmap.c (grub_mmap_iterate): Likewise.
* include/grub/efiemu/efiemu.h (grub_efiemu_mmap_iterate): Update
prototype.
* include/grub/memory.h (grub_memory_hook_t): Add data argument.
Remove NESTED_FUNC_ATTR from here and from all users.
(grub_mmap_iterate): Update prototype.
(grub_efi_mmap_iterate): Update prototype.  Update all callers to
pass appropriate hook data.
(grub_machine_mmap_iterate): Likewise.

* grub-core/commands/acpi.c (grub_acpi_create_ebda: find_hook): Make
static instead of nested.
* grub-core/commands/lsmmap.c (grub_cmd_lsmmap: hook): Likewise.
Rename to ...
(lsmmap_hook): ... this.
* grub-core/efiemu/mm.c (grub_efiemu_mmap_init: bounds_hook):
Likewise.
(grub_efiemu_mmap_fill: fill_hook): Likewise.
* grub-core/kern/i386/coreboot/init.c (grub_machine_init:
heap_init): Likewise.
* grub-core/kern/i386/pc/init.c (grub_machine_init: hook): Likewise.
Rename to ...
(mmap_iterate_hook): ... this.
* grub-core/kern/ieee1275/init.c (grub_claim_heap: heap_init):
Likewise.
* grub-core/lib/ieee1275/relocator.c
(grub_relocator_firmware_get_max_events: count): Likewise.
(grub_relocator_firmware_fill_events: fill): Likewise.  Rename
to ...
(grub_relocator_firmware_fill_events_iter): ... this.
* grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align:
hook): Likewise.  Rename to ...
(grub_relocator_alloc_chunk_align_iter): ... this.
* grub-core/loader/i386/bsd.c (generate_e820_mmap: hook): Likewise.
Rename to ...
(generate_e820_mmap_iter): ... this.
* grub-core/loader/i386/linux.c (find_mmap_size: hook): Likewise.
Rename to ...
(count_hook): ... this.
(grub_linux_boot: hook): Likewise.  Rename to ...
(grub_linux_boot_mmap_find): ... this.
(grub_linux_boot: hook_fill): Likewise.  Rename to ...
(grub_linux_boot_mmap_fill): ... this.
* grub-core/loader/i386/multiboot_mbi.c (grub_fill_multiboot_mmap:
hook): Likewise.  Rename to ...
(grub_fill_multiboot_mmap_iter): ... this.
* grub-core/loader/multiboot.c (grub_get_multiboot_mmap_count:
hook): Likewise.  Rename to ...
(count_hook): ... this.
* grub-core/loader/multiboot_mbi2.c (grub_fill_multiboot_mmap:
hook): Likewise.  Rename to ...
(grub_fill_multiboot_mmap_iter): ... this.
* grub-core/loader/powerpc/ieee1275/linux.c
(grub_linux_claimmap_iterate: alloc_mem): Likewise.
* grub-core/loader/sparc64/ieee1275/linux.c (alloc_phys: choose):
Likewise.  Rename to ...
(alloc_phys_choose): ... this.
(determine_phys_base: get_physbase): Likewise.
* grub-core/mmap/i386/mmap.c (grub_mmap_malign_and_register:
find_hook): Likewise.
* grub-core/mmap/i386/pc/mmap.c (preboot: fill_hook): Likewise.
(malloc_hook: count_hook): Likewise.
* grub-core/mmap/i386/uppermem.c (grub_mmap_get_lower: hook):
Likewise.  Rename to ...
(lower_hook): ... this.
(grub_mmap_get_upper: hook): Likewise.  Rename to ...
(upper_hook): ... this.
(grub_mmap_get_post64: hook): Likewise.  Rename to ...
(post64_hook): ... this.
* grub-core/mmap/mips/uppermem.c (grub_mmap_get_lower: hook):
Likewise.  Rename to ...
(lower_hook): ... this.
(grub_mmap_get_upper: hook): Likewise.  Rename to ...
(upper_hook): ... this.
* grub-core/mmap/mmap.c (grub_mmap_iterate: count_hook): Likewise.
(grub_mmap_iterate: fill_hook): Likewise.
(fill_mask): Pass addr and mask within a single struct.
(grub_cmd_badram: hook): Make static instead of nested.  Rename
to ...
(badram_iter): ... this.
(grub_cmd_cutmem: hook): Likewise.  Rename to ...
(cutmem_iter): ... this.
2013-01-15 12:02:35 +00:00
Vladimir 'phcoder' Serbinenko ee5207750f * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align): Remove
redundant buggy overlap check.
2012-04-13 16:55:20 +02:00
Vladimir 'phcoder' Serbinenko 123f9c50eb Fix FTBFS on mips and ppc 2012-03-03 20:53:54 +01:00
Vladimir 'phcoder' Serbinenko 9be4c45dbe boot services avoid code based on the patch by Matthew Garrett 2012-03-03 20:06:41 +01:00
Vladimir 'phcoder' Serbinenko 5a6e39c28f * grub-core/lib/relocator.c (malloc_in_range): Fix memory leak.
Change order of allocations to decrease fragmentation.
2012-02-28 01:32:38 +01:00
Vladimir 'phcoder' Serbinenko 9c4b5c13e6 Improve gettext support. Stylistic fixes and error handling fixes while
on it.
2012-02-08 19:26:01 +01:00
Vladimir 'phcoder' Serbinenko c84ba308b5 * grub-core/kern/mm.c: Add missing include of i18n.h
* grub-core/lib/relocator.c: Likewise.
2012-02-03 14:20:31 +01:00
Vladimir 'phcoder' Serbinenko 4a9f8346c9 * grub-core/commands/ls.c: Gettextize.
* grub-core/commands/setpci.c: Likewise.
        * grub-core/commands/videotest.c: Likewise.
        * grub-core/disk/geli.c: Likewise.
        * grub-core/kern/mm.c: Likewise.
        * grub-core/lib/relocator.c: Likewise.
        * grub-core/loader/efi/appleloader.c: Likewise.
        * grub-core/loader/i386/xnu.c: Likewise.
        * grub-core/loader/ia64/efi/linux.c: Likewise.
        * grub-core/loader/xnu.c: Likewise.
        * grub-core/net/dns.c: Likewise.
        * grub-core/net/net.c: Likewise.
        * grub-core/script/lexer.c: Likewise.
        * grub-core/script/parser.y: Likewise.
        * grub-core/script/yylex.l: Likewise.
        * util/getroot.c: Likewise.
        * util/grub-setup.c: Likewise.
2012-02-03 11:56:49 +01:00
Mario Limonciello d779e9bdac * configure.ac: Add back in test for limits.h. 2012-01-22 16:43:14 +01:00
Vladimir 'phcoder' Serbinenko bdea379833 * grub-core/lib/relocator.c (malloc_in_range): Fix a memory corruption
when handling leftovers.
2011-06-27 12:18:44 +02:00
Vladimir 'phcoder' Serbinenko e745cf0ca6 Implement automatic module license checking according to new GNU
guidelines.

	* grub-core/kern/dl.c (grub_dl_check_license): New function.
	(grub_dl_load_core): Use grub_dl_check_license.
	* include/grub/dl.h (GRUB_MOD_SECTION): New macro.
	(GRUB_MOD_LICENSE): Likewise.
	(GRUB_MOD_DUAL_LICENSE): Likewise.
	All modules updated.
2011-04-11 23:01:51 +02:00
Vladimir 'phcoder' Serbinenko 7755f66e64 * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align): Add few
useful grub_dprintf's.
2011-04-06 14:04:52 +02:00
Vladimir 'phcoder' Serbinenko a1dc717c58 * grub-core/lib/relocator.c (allocate_regstart)
[!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Avoid grub_dprintf since not all
	terminals are capabple of malloc-free operation.
	(allocate_inreg) [!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Likewise.
	(malloc_in_range) [!DEBUG_RELOCATOR_NOMEM_DPRINTF]: Likewise.
2011-03-29 08:20:19 +02:00
Vladimir 'phcoder' Serbinenko c7064d9425 * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_addr)
[DEBUG_RELOCATOR]: Reuse grub_mm_check.
	(grub_relocator_alloc_chunk_align) [DEBUG_RELOCATOR]: Likewise.
2011-03-24 12:45:51 +01:00
Vladimir 'phcoder' Serbinenko ef6de21af4 * grub-core/lib/relocator.c (allocate_inreg): Avoid dprintf unless
DEBUG_RELOCATOR is defined since gfxterm can't cope with output when
	malloc is disabled.
2011-03-24 12:39:48 +01:00
Vladimir 'phcoder' Serbinenko 7d4e39d65a * grub-core/bus/usb/usb.c (attach_hooks): Make static.
* grub-core/bus/usb/usbhub.c (hubs): Likewise.
	* grub-core/commands/hashsum.c (aliases): Likewise.
	* grub-core/commands/setpci.c (pci_registers): Likewise.
	* grub-core/disk/usbms.c (attach_hook): Likewise.
	* grub-core/fs/zfs/zfs.c (decomp_table): Likewise.
	(zio_checksum_table): Likewise.
	* grub-core/gettext/gettext.c (grub_gettext_msg_list): Likewise.
	* grub-core/gfxmenu/gfxmenu.c (cached_view): Likewise.
	* grub-core/lib/legacy_parse.c (legacy_commands): Likewise.
	* grub-core/lib/relocator.c (leftovers): Likewise.
	(extra_blocks): Likewise.
	* grub-core/loader/i386/bsd.c (relocator): Likewise.
	* grub-core/loader/i386/multiboot_mbi.c (modules): Likewise.
	(modules_last): Likewise.
	* grub-core/loader/i386/xnu.c (table_aliases): Likewise.
	(devices): Likewise.
	* grub-core/loader/multiboot_mbi2.c (modules): Likewise.
	(modules_last): Likewise.
	* grub-core/normal/auth.c (users): Likewise.
	* grub-core/normal/context.c (initial_menu): Likewise.
	(current_menu): Likewise.
	* grub-core/normal/crypto.c (crypto_specs): Likewise.
	* grub-core/term/serial.c (grub_serial_ports): Likewise.
	(grub_serial_terminfo_input_template): Likewise.
	(grub_serial_terminfo_output_template): Likewise.
	(grub_serial_terminfo_input): Likewise.
	(grub_serial_terminfo_output): Likewise.
	(registered): Likewise.
	* grub-core/term/usb_keyboard.c (attach_hook): Likewise.
2011-03-23 12:05:13 +01:00
Vladimir 'phcoder' Serbinenko f6bbabc373 * grub-core/lib/relocator.c (malloc_in_range): Take into account that
allocate_regbeg may need to create new chunk header.
2010-11-15 09:50:58 +01:00
Vladimir 'phcoder' Serbinenko e138c45836 * grub-core/lib/relocator.c (grub_relocator_subchunk): Remove now
useless field head. All users updated.
	(free_subchunk): Correct handling of IN_REGION subchunk.
2010-10-22 22:49:36 +02:00
Szymon Janc 6bdda8f877 * grub-core/commands/legacycfg.c (grub_cmd_legacy_kernel):
Set-but-not-used variable ifdef'ed.
	* grub-core/lib/legacy_parse.c (grub_legacy_parse): Likewise.
	* grub-core/bus/usb/ohci.c (grub_ohci_pci_iter): Set-but-not-used
	variable removed.
	* grub-core/disk/lvm.c (grub_lvm_scan_device): Likewise.
	* grub-core/fs/jfs.c (grub_jfs_find_file): Likewise.
	* grub-core/fs/minix.c (grub_minix_dir): Likewise.
	* grub-core/fs/sfs.c (grub_sfs_read_extent): Likewise.
	* grub-core/fs/ufs.c (grub_ufs_dir): Likewise.
	* grub-core/gfxmenu/gui_list.c (grub_gui_list_new): Likewise.
	* grub-core/gfxmenu/view.c (redraw_menu_visit): Likewise.
	* grub-core/gfxmenu/widget-box.c (draw): Likewise.
	* grub-core/lib/relocator.c (malloc_in_range): Likewise.
	* grub-core/loader/i386/bsdXX.c (grub_netbsd_load_elf_meta): Likewise.
	* grub-core/loader/i386/bsd_pagetable.c (fill_bsd64_pagetable):
	Likewise.
2010-10-16 22:16:52 +02:00
Vladimir 'phcoder' Serbinenko 2a4066114d * grub-core/lib/relocator.c (malloc_in_range): Trim too verbose
debug messages.
	(grub_relocator_prepare_relocs): Set movers_chunk.srcv.
2010-09-29 23:19:21 +02:00
Vladimir 'phcoder' Serbinenko df3df23d5c Reorganise memory map handling 2010-09-04 17:10:10 +02:00
Vladimir 'phcoder' Serbinenko 5d9bdcf167 Fix x86_64-efi compilation error 2010-08-29 02:28:15 +02:00
Vladimir 'phcoder' Serbinenko 328951ac24 Add safety checks in relocator and add a GRUB_MM_CHECK macro 2010-08-28 21:27:10 +02:00
Vladimir 'phcoder' Serbinenko d1dce5d356 Add DEBUG_RELOCATOR parts 2010-08-28 11:34:33 +02:00
Vladimir 'phcoder' Serbinenko 16bd6cfab2 Merge mainline into newreloc. For now without boot tests 2010-08-25 03:25:18 +02:00
BVK Chaitanya 8c41176882 automake commit without merge history 2010-05-06 11:34:04 +05:30