Merge ~juliank/grub/+git/ubuntu:boot-complete into ~ubuntu-core-dev/grub/+git/ubuntu:master

Proposed by Julian Andres Klode
Status: Superseded
Proposed branch: ~juliank/grub/+git/ubuntu:boot-complete
Merge into: ~ubuntu-core-dev/grub/+git/ubuntu:master
Diff against target: 33477 lines (+26270/-719) (has conflicts)
219 files modified
ChangeLog (+5278/-0)
INSTALL (+31/-21)
Makefile.am (+1/-1)
Makefile.in (+270/-54)
Makefile.util.am (+16/-7)
Makefile.util.def (+15/-40)
NEWS (+14/-0)
README (+6/-0)
acinclude.m4 (+36/-2)
aclocal.m4 (+1/-0)
autogen.sh (+1/-1)
conf/Makefile.common (+2/-0)
conf/Makefile.extra-dist (+21/-0)
config-util.h.in (+6/-0)
config.h.in (+0/-2)
configure (+192/-39)
configure.ac (+99/-104)
debian/.git-dpm (+3/-0)
debian/NEWS (+8/-0)
debian/README.source (+3/-0)
debian/apport/source_grub2.py (+14/-5)
debian/build-efi-images (+27/-11)
debian/changelog (+1421/-1)
debian/control (+92/-26)
debian/dirs.in (+1/-0)
debian/grub-check-signatures (+21/-0)
debian/grub-common.service (+13/-0)
debian/grub-efi-amd64-bin.maintscript.in (+1/-0)
debian/grub-efi-arm64-bin.maintscript.in (+1/-0)
debian/grub-extras/915resolution/.gitignore (+3/-0)
debian/grub-extras/915resolution/915resolution.c (+29/-8)
debian/grub-extras/disabled/gpxe/.gitignore (+3/-0)
debian/grub-extras/disabled/zfs/.gitignore (+5/-0)
debian/grub-extras/lua/.gitignore (+3/-0)
debian/grub-extras/ntldr-img/.gitignore (+3/-0)
debian/grub.d/05_debian_theme (+2/-2)
debian/legacy/upgrade-from-grub-legacy (+3/-1)
debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch (+37/-0)
debian/patches/0077-ubuntu-Update-the-linux-boot-protocol-version-check.patch (+7/-0)
debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch (+52/-0)
debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch (+7/-0)
debian/patches/0105-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch (+7/-0)
debian/patches/0129-loader-efi-chainloader-grub_load_and_start_image-doe.patch (+68/-0)
debian/patches/0130-loader-efi-chainloader-simplify-the-loader-state.patch (+334/-0)
debian/patches/0131-commands-boot-Add-API-to-pass-context-to-loader.patch (+157/-0)
debian/patches/0132-loader-efi-chainloader-Use-grub_loader_set_ex.patch (+144/-0)
debian/patches/0133-loader-i386-efi-linux-Use-grub_loader_set_ex.patch (+306/-0)
debian/patches/0134-loader-i386-efi-linux-Fix-a-memory-leak-in-the-initr.patch (+72/-0)
debian/patches/0135-kern-efi-sb-Reject-non-kernel-files-in-the-shim_lock.patch (+98/-0)
debian/patches/0136-kern-file-Do-not-leak-device_name-on-error-in-grub_f.patch (+36/-0)
debian/patches/0137-video-readers-png-Abort-sooner-if-a-read-operation-f.patch (+196/-0)
debian/patches/0138-video-readers-png-Refuse-to-handle-multiple-image-he.patch (+26/-0)
debian/patches/0139-video-readers-png-Drop-greyscale-support-to-fix-heap.patch (+167/-0)
debian/patches/0140-video-readers-png-Avoid-heap-OOB-R-W-inserting-huff-.patch (+37/-0)
debian/patches/0141-video-readers-png-Sanity-check-some-huffman-codes.patch (+38/-0)
debian/patches/0142-video-readers-jpeg-Abort-sooner-if-a-read-operation-.patch (+253/-0)
debian/patches/0143-video-readers-jpeg-Do-not-reallocate-a-given-huff-ta.patch (+27/-0)
debian/patches/0144-video-readers-jpeg-Refuse-to-handle-multiple-start-o.patch (+41/-0)
debian/patches/0145-video-readers-jpeg-Block-int-underflow-wild-pointer-.patch (+72/-0)
debian/patches/0146-normal-charset-Fix-array-out-of-bounds-formatting-un.patch (+32/-0)
debian/patches/0147-net-netbuff-Block-overly-large-netbuff-allocs.patch (+44/-0)
debian/patches/0148-net-ip-Do-IP-fragment-maths-safely.patch (+42/-0)
debian/patches/0149-net-dns-Fix-double-free-addresses-on-corrupt-DNS-res.patch (+54/-0)
debian/patches/0150-net-dns-Don-t-read-past-the-end-of-the-string-we-re-.patch (+69/-0)
debian/patches/0151-net-tftp-Prevent-a-UAF-and-double-free-from-a-failed.patch (+110/-0)
debian/patches/0152-net-tftp-Avoid-a-trivial-UAF.patch (+33/-0)
debian/patches/0153-net-http-Do-not-tear-down-socket-if-it-s-already-bee.patch (+39/-0)
debian/patches/0154-net-http-Fix-OOB-write-for-split-http-headers.patch (+44/-0)
debian/patches/0155-net-http-Error-out-on-headers-with-LF-without-CR.patch (+46/-0)
debian/patches/0156-fs-f2fs-Do-not-read-past-the-end-of-nat-journal-entr.patch (+70/-0)
debian/patches/0157-fs-f2fs-Do-not-read-past-the-end-of-nat-bitmap.patch (+130/-0)
debian/patches/0158-fs-f2fs-Do-not-copy-file-names-that-are-too-long.patch (+36/-0)
debian/patches/0159-fs-btrfs-Fix-several-fuzz-issues-with-invalid-dir-it.patch (+74/-0)
debian/patches/0160-fs-btrfs-Fix-more-ASAN-and-SEGV-issues-found-with-fu.patch (+132/-0)
debian/patches/0161-fs-btrfs-Fix-more-fuzz-issues-related-to-chunks.patch (+74/-0)
debian/patches/0241-Call-hwmatch-only-on-the-grub-pc-platform.patch (+47/-0)
debian/patches/RISC-V-Update-image-header.patch (+84/-0)
debian/patches/RISC-V-Use-common-linux-loader.patch (+120/-0)
debian/patches/at_keyboard-module-init.patch (+4/-1)
debian/patches/bash-completion-drop-have-checks.patch (+5/-2)
debian/patches/blacklist-1440x900x32.patch (+4/-1)
debian/patches/bootp-new-net_bootp6-command.patch (+22/-17)
debian/patches/bootp-process-dhcpack-http-boot.patch (+20/-15)
debian/patches/cherrypick-efi-grub_efi_close_protocol.patch (+79/-0)
debian/patches/cherrypick-efinet-correct-closing-snp-protocol.patch (+106/-0)
debian/patches/core-in-fs.patch (+3/-4)
debian/patches/debug_verifiers.patch (+27/-0)
debian/patches/default-grub-d.patch (+34/-17)
debian/patches/dejavu-font-path.patch (+22/-0)
debian/patches/disable-floppies.patch (+1/-2)
debian/patches/dpkg-version-comparison.patch (+3/-4)
debian/patches/efi-EFI-Device-Tree-Fixup-Protocol.patch (+140/-0)
debian/patches/efi-add-definition-of-LoadFile2-protocol.patch (+61/-0)
debian/patches/efi-correct-struct-grub_efi_boot_services.patch (+28/-0)
debian/patches/efi-implement-grub_efi_run_image.patch (+900/-0)
debian/patches/efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch (+183/-0)
debian/patches/efi-variable-storage-minimise-writes.patch (+60/-11)
debian/patches/efinet-set-dns-from-uefi-proto.patch (+13/-8)
debian/patches/efinet-set-network-from-uefi-devpath.patch (+8/-5)
debian/patches/efinet-uefi-ipv6-pxe-support.patch (+8/-5)
debian/patches/efivar-check-that-efivarfs-is-writeable.patch (+74/-0)
debian/patches/fat-fix-listing-the-root-directory.patch (+46/-0)
debian/patches/fdt-add-debug-output-to-devicetree-command.patch (+31/-0)
debian/patches/gettext-quiet.patch (+4/-1)
debian/patches/gfxpayload-dynamic.patch (+23/-7)
debian/patches/gfxpayload-keep-default.patch (+9/-0)
debian/patches/grub-install-pvxen-paths.patch (+14/-3)
debian/patches/grub-legacy-0-based-partitions.patch (+1/-2)
debian/patches/grub.cfg-400.patch (+2/-3)
debian/patches/ieee1275-clear-reset.patch (+4/-1)
debian/patches/ignore-grub_func_test-failures.patch (+4/-1)
debian/patches/insmod-xzio-and-lzopio-on-xen.patch (+7/-0)
debian/patches/install-efi-adjust-distributor.patch (+33/-0)
debian/patches/install-efi-fallback.patch (+5/-2)
debian/patches/install-efi-ubuntu-flavours.patch (+3/-0)
debian/patches/install-locale-langpack.patch (+10/-7)
debian/patches/install-powerpc-machtypes.patch (+18/-11)
debian/patches/install-stage2-confusion.patch (+9/-6)
debian/patches/linux-ignore-FDT-unless-we-need-to-modify-it.patch (+80/-0)
debian/patches/linux_xen-Properly-load-multiple-initrd-files.patch (+123/-0)
debian/patches/linux_xen-Properly-order-multiple-initrd-files.patch (+79/-0)
debian/patches/linuxefi-Invalidate-i-cache-before-starting-the-kern.patch (+111/-0)
debian/patches/linuxefi-do-not-validate-kernels-twice.patch (+227/-0)
debian/patches/loader-Move-arm64-linux-loader-to-common-code.patch (+1091/-0)
debian/patches/loader-drop-argv-argument-in-grub_initrd_load.patch (+178/-0)
debian/patches/maybe-quiet.patch (+30/-21)
debian/patches/minilzo-2.10.patch (+2538/-0)
debian/patches/mkconfig-loopback.patch (+11/-4)
debian/patches/mkconfig-mid-upgrade.patch (+3/-0)
debian/patches/mkconfig-nonexistent-loopback.patch (+11/-8)
debian/patches/mkconfig-other-inits.patch (+14/-3)
debian/patches/mkconfig-recovery-title.patch (+17/-10)
debian/patches/mkconfig-signed-kernel.patch (+9/-0)
debian/patches/mkconfig-ubuntu-distributor.patch (+7/-0)
debian/patches/mkconfig-ubuntu-recovery.patch (+18/-5)
debian/patches/mkimage-fix-section-sizes.patch (+108/-0)
debian/patches/mkrescue-efi-modules.patch (+6/-3)
debian/patches/net-read-bracketed-ipv6-addr.patch (+20/-16)
debian/patches/no-devicetree-if-secure-boot.patch (+8/-5)
debian/patches/no-insmod-on-sb.patch (+8/-58)
debian/patches/olpc-prefix-hack.patch (+1/-2)
debian/patches/pc-verifiers-module.patch (+166/-0)
debian/patches/ppc64el-disable-vsx.patch (+4/-1)
debian/patches/probe-fusionio.patch (+8/-5)
debian/patches/quick-boot-lvm.patch (+6/-3)
debian/patches/quick-boot.patch (+34/-20)
debian/patches/restore-mkdevicemap.patch (+26/-13)
debian/patches/rhboot-f34-dont-use-int-for-efi-status.patch (+7/-0)
debian/patches/rhboot-f34-efinet-also-use-the-firmware-acceleration-for-http.patch (+26/-0)
debian/patches/rhboot-f34-make-exit-take-a-return-code.patch (+68/-0)
debian/patches/rhboot-f34-make-pmtimer-tsc-calibration-fast.patch (+11/-0)
debian/patches/rhboot-try-to-pick-better-locations-for-kernel-and-initrd.patch (+215/-0)
debian/patches/riscv-adjust-march-flags-for-binutils-2.38.patch (+43/-0)
debian/patches/series (+122/-4)
debian/patches/skip-grub_cmd_set_date.patch (+4/-1)
debian/patches/sleep-shift.patch (+3/-0)
debian/patches/suse-AUDIT-0-http-boot-tracker-bug.patch (+68/-0)
debian/patches/suse-add-support-for-UEFI-network-protocols.patch (+4941/-0)
debian/patches/suse-grub.texi-add-net_bootp6-document.patch (+49/-0)
debian/patches/tests-ahci-update-qemu-device-name.patch (+33/-0)
debian/patches/tpm-unknown-error-non-fatal.patch (+30/-0)
debian/patches/ubuntu-add-devicetree-command-support.patch (+7/-0)
debian/patches/ubuntu-add-initrd-less-boot-fallback.patch (+44/-0)
debian/patches/ubuntu-add-initrd-less-boot-messages.patch (+24/-0)
debian/patches/ubuntu-boot-from-multipath-dependent-symlink.patch (+7/-0)
debian/patches/ubuntu-disable-LOAD-FILE2-protocol-for-initrd-on-ARM.patch (+63/-0)
debian/patches/ubuntu-dont-verify-loopback-images.patch (+11/-0)
debian/patches/ubuntu-efi-allow-loopmount-chainload.patch (+27/-0)
debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch (+10/-0)
debian/patches/ubuntu-fix-reproducible-squashfs-test.patch (+7/-0)
debian/patches/ubuntu-flavour-order.patch (+17/-0)
debian/patches/ubuntu-fuse3.patch (+108/-0)
debian/patches/ubuntu-grub-install-extra-removable.patch (+37/-0)
debian/patches/ubuntu-install-signed.patch (+41/-0)
debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch (+22/-0)
debian/patches/ubuntu-linuxefi-arm64.patch (+90/-0)
debian/patches/ubuntu-linuxefi.patch (+510/-0)
debian/patches/ubuntu-mkconfig-leave-breadcrumbs.patch (+10/-0)
debian/patches/ubuntu-os-prober-auto.patch (+51/-0)
debian/patches/ubuntu-recovery-dis_ucode_ldr.patch (+15/-0)
debian/patches/ubuntu-resilient-boot-boot-order.patch (+45/-0)
debian/patches/ubuntu-resilient-boot-ignore-alternative-esps.patch (+11/-0)
debian/patches/ubuntu-shorter-version-info.patch (+18/-0)
debian/patches/ubuntu-skip-disk-by-id-lvm-pvm-uuid-entries.patch (+10/-0)
debian/patches/ubuntu-speed-zsys-history.patch (+34/-0)
debian/patches/ubuntu-support-initrd-less-boot.patch (+27/-0)
debian/patches/ubuntu-temp-keep-auto-nvram.patch (+7/-0)
debian/patches/ubuntu-verifiers-last.patch (+59/-0)
debian/patches/ubuntu-zfs-enhance-support.patch (+46/-0)
debian/patches/ubuntu-zfs-gfxpayload-dynamic.patch (+95/-0)
debian/patches/ubuntu-zfs-gfxpayload-keep-default.patch (+38/-0)
debian/patches/ubuntu-zfs-insmod-xzio-and-lzopio-on-xen.patch (+32/-0)
debian/patches/ubuntu-zfs-maybe-quiet.patch (+72/-0)
debian/patches/ubuntu-zfs-mkconfig-recovery-title.patch (+49/-0)
debian/patches/ubuntu-zfs-mkconfig-signed-kernel.patch (+51/-0)
debian/patches/ubuntu-zfs-mkconfig-ubuntu-distributor.patch (+36/-0)
debian/patches/ubuntu-zfs-mkconfig-ubuntu-recovery.patch (+66/-0)
debian/patches/ubuntu-zfs-quick-boot.patch (+50/-0)
debian/patches/ubuntu-zfs-vt-handoff.patch (+77/-0)
debian/patches/uefi-firmware-setup.patch (+3/-0)
debian/patches/uefi-secure-boot-cryptomount.patch (+11/-0)
debian/patches/vsnprintf-upper-case-hex.patch (+3/-0)
debian/patches/vt-handoff.patch (+9/-2)
debian/patches/wubi-no-windows.patch (+6/-3)
debian/patches/xen-no-xsm-policy-in-non-xsm-options.patch (+34/-0)
debian/patches/xfs-fix-v4-superblock.patch (+121/-0)
debian/patches/zpool-full-device-name.patch (+4/-1)
debian/patches/zstd-require-8-byte-buffer.patch (+63/-0)
debian/postinst.in (+91/-7)
debian/postrm.in (+2/-2)
debian/rules (+113/-10)
debian/sbat.debian.csv.in (+3/-0)
debian/sbat.ubuntu.csv.in (+3/-0)
debian/signing-template/control.in (+1/-1)
dev/null (+0/-1)
docs/Makefile.in (+2/-2)
docs/grub-dev.info (+113/-45)
docs/grub-dev.texi (+65/-1)
docs/grub.info (+2/-1)
Conflict in configure.ac
Conflict in debian/.git-dpm
Conflict in debian/build-efi-images
Conflict in debian/changelog
Conflict in debian/control
Conflict in debian/grub-check-signatures
Conflict in debian/grub-common.service
Conflict in debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch
Conflict in debian/patches/0077-ubuntu-Update-the-linux-boot-protocol-version-check.patch
Conflict in debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch
Conflict in debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch
Conflict in debian/patches/0105-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch
Conflict in debian/patches/at_keyboard-module-init.patch
Conflict in debian/patches/bash-completion-drop-have-checks.patch
Conflict in debian/patches/blacklist-1440x900x32.patch
Conflict in debian/patches/bootp-new-net_bootp6-command.patch
Conflict in debian/patches/bootp-process-dhcpack-http-boot.patch
Conflict in debian/patches/default-grub-d.patch
Conflict in debian/patches/efi-variable-storage-minimise-writes.patch
Conflict in debian/patches/efinet-set-dns-from-uefi-proto.patch
Conflict in debian/patches/efinet-set-network-from-uefi-devpath.patch
Conflict in debian/patches/efinet-uefi-ipv6-pxe-support.patch
Conflict in debian/patches/gettext-quiet.patch
Conflict in debian/patches/gfxpayload-dynamic.patch
Conflict in debian/patches/gfxpayload-keep-default.patch
Conflict in debian/patches/grub-install-extra-removable.patch
Conflict in debian/patches/grub-install-pvxen-paths.patch
Conflict in debian/patches/ieee1275-clear-reset.patch
Conflict in debian/patches/ignore-grub_func_test-failures.patch
Conflict in debian/patches/insmod-xzio-and-lzopio-on-xen.patch
Conflict in debian/patches/install-efi-adjust-distributor.patch
Conflict in debian/patches/install-efi-fallback.patch
Conflict in debian/patches/install-efi-ubuntu-flavours.patch
Conflict in debian/patches/install-locale-langpack.patch
Conflict in debian/patches/install-powerpc-machtypes.patch
Conflict in debian/patches/install-signed.patch
Conflict in debian/patches/install-stage2-confusion.patch
Conflict in debian/patches/maybe-quiet.patch
Conflict in debian/patches/mkconfig-loopback.patch
Conflict in debian/patches/mkconfig-mid-upgrade.patch
Conflict in debian/patches/mkconfig-nonexistent-loopback.patch
Conflict in debian/patches/mkconfig-other-inits.patch
Conflict in debian/patches/mkconfig-recovery-title.patch
Conflict in debian/patches/mkconfig-signed-kernel.patch
Conflict in debian/patches/mkconfig-ubuntu-distributor.patch
Conflict in debian/patches/mkconfig-ubuntu-recovery.patch
Conflict in debian/patches/mkrescue-efi-modules.patch
Conflict in debian/patches/net-read-bracketed-ipv6-addr.patch
Conflict in debian/patches/no-devicetree-if-secure-boot.patch
Conflict in debian/patches/no-insmod-on-sb.patch
Conflict in debian/patches/ppc64el-disable-vsx.patch
Conflict in debian/patches/probe-fusionio.patch
Conflict in debian/patches/quick-boot-lvm.patch
Conflict in debian/patches/quick-boot.patch
Conflict in debian/patches/restore-mkdevicemap.patch
Conflict in debian/patches/rhboot-f34-dont-use-int-for-efi-status.patch
Conflict in debian/patches/rhboot-f34-make-exit-take-a-return-code.patch
Conflict in debian/patches/rhboot-f34-make-pmtimer-tsc-calibration-fast.patch
Conflict in debian/patches/series
Conflict in debian/patches/skip-grub_cmd_set_date.patch
Conflict in debian/patches/sleep-shift.patch
Conflict in debian/patches/ubuntu-add-devicetree-command-support.patch
Conflict in debian/patches/ubuntu-add-initrd-less-boot-fallback.patch
Conflict in debian/patches/ubuntu-add-initrd-less-boot-messages.patch
Conflict in debian/patches/ubuntu-boot-from-multipath-dependent-symlink.patch
Conflict in debian/patches/ubuntu-dont-verify-loopback-images.patch
Conflict in debian/patches/ubuntu-efi-allow-loopmount-chainload.patch
Conflict in debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch
Conflict in debian/patches/ubuntu-fix-reproducible-squashfs-test.patch
Conflict in debian/patches/ubuntu-flavour-order.patch
Conflict in debian/patches/ubuntu-grub-install-extra-removable.patch
Conflict in debian/patches/ubuntu-install-signed.patch
Conflict in debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch
Conflict in debian/patches/ubuntu-linuxefi-arm64.patch
Conflict in debian/patches/ubuntu-linuxefi.patch
Conflict in debian/patches/ubuntu-mkconfig-leave-breadcrumbs.patch
Conflict in debian/patches/ubuntu-recovery-dis_ucode_ldr.patch
Conflict in debian/patches/ubuntu-resilient-boot-boot-order.patch
Conflict in debian/patches/ubuntu-resilient-boot-ignore-alternative-esps.patch
Conflict in debian/patches/ubuntu-shorter-version-info.patch
Conflict in debian/patches/ubuntu-skip-disk-by-id-lvm-pvm-uuid-entries.patch
Conflict in debian/patches/ubuntu-speed-zsys-history.patch
Conflict in debian/patches/ubuntu-support-initrd-less-boot.patch
Conflict in debian/patches/ubuntu-temp-keep-auto-nvram.patch
Conflict in debian/patches/ubuntu-zfs-enhance-support.patch
Conflict in debian/patches/uefi-firmware-setup.patch
Conflict in debian/patches/uefi-secure-boot-cryptomount.patch
Conflict in debian/patches/vsnprintf-upper-case-hex.patch
Conflict in debian/patches/vt-handoff.patch
Conflict in debian/patches/wubi-no-windows.patch
Conflict in debian/patches/zpool-full-device-name.patch
Conflict in debian/postinst.in
Conflict in debian/rules
Conflict in docs/grub.info
Conflict in docs/grub.texi
Conflict in grub-core/Makefile.core.def
Conflict in grub-core/commands/efi/tpm.c
Conflict in grub-core/commands/iorw.c
Conflict in grub-core/commands/memrw.c
Conflict in grub-core/disk/ldm.c
Conflict in grub-core/disk/lvm.c
Conflict in grub-core/fs/hfsplus.c
Conflict in grub-core/fs/xfs.c
Conflict in grub-core/kern/efi/efi.c
Conflict in grub-core/kern/efi/sb.c
Conflict in grub-core/kern/mm.c
Conflict in grub-core/kern/parser.c
Conflict in grub-core/loader/efi/chainloader.c
Conflict in grub-core/loader/efi/fdt.c
Conflict in grub-core/loader/i386/efi/linux.c
Conflict in grub-core/loader/i386/linux.c
Conflict in grub-core/loader/i386/pc/linux.c
Conflict in grub-core/loader/linux.c
Conflict in grub-core/loader/multiboot_mbi2.c
Conflict in grub-core/loader/xnu.c
Conflict in grub-core/net/tftp.c
Conflict in grub-core/osdep/unix/config.c
Conflict in grub-core/osdep/unix/efivar.c
Conflict in grub-core/osdep/unix/platform.c
Conflict in grub-core/term/efi/console.c
Conflict in include/grub/efi/sb.h
Conflict in include/grub/util/install.h
Conflict in util/deviceiter.c
Conflict in util/grub-install-common.c
Conflict in util/grub-install.c
Conflict in util/grub-mkconfig.in
Conflict in util/grub.d/00_header.in
Conflict in util/grub.d/10_linux.in
Conflict in util/grub.d/30_uefi-firmware.in
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+431421@code.launchpad.net

This proposal has been superseded by a proposal from 2022-10-12.

To post a comment you must log in.

Unmerged commits

ab03c1e... by Julian Andres Klode

grub-common.service: Add After=boot-complete.target

LP: #1992643

a093515... by Julian Andres Klode

Try to pick better locations for kernel and initrd

LP: #1989446

5e9731a... by Julian Andres Klode

releasing package grub2 version 2.06-2ubuntu12

1c0c8a3... by Julian Andres Klode

ubuntu-zfs-enhance-support.patch: Fix missing lines

The line count of the file was too short for unknown reasons,
fix this manually and then reimport and export the patch series
to clean up all the hunk locations.

LP: #1990143

2fa139e... by dann frazier

releasing package grub2 version 2.06-2ubuntu11

64478a9... by Julian Andres Klode

Cleanup patch series

d5f693b... by dann frazier

linuxefi: Invalidate i-cache before starting the kernel (LP: #1987924)

- d/p/linuxefi-Invalidate-i-cache-before-starting-the-kern.patch

Gbp-Dch: Full

196b45a... by Mauricio Faria de Oliveira

Fix for ZFS snapshots without etc directory

In the situation where ZFS snapshots do not contain a .../etc directory,
the generation of /b/g/grub.cfg silently fails, providing no "linux"
kernel lines in the /b/g/grub.cfg file.

This patch prevents this type of failure from occurring.

This issue is especially apparent on systems running in FIPS mode
with ZFS boot+root pools.

Source: https://code.launchpad.net/~arbell/grub/+git/grub/+merge/417575

LP: #1965983
Thanks: Adam R Bell <email address hidden>

Signed-off-by: Mauricio Faria de Oliveira <email address hidden>

83bcaf1... by Heinrich Schuchardt

efi/peimage: fix typos in code comments

Signed-off-by: Heinrich Schuchardt <email address hidden>

47a3d1d... by Mauricio Faria de Oliveira

linux_xen: Properly handle multiple initrd files (LP: #1987567)

- d/p/linux_xen-Properly-load-multiple-initrd-files.patch
- d/p/linux_xen-Properly-order-multiple-initrd-files.patch

Gbp-Dch: Full

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/ChangeLog b/ChangeLog
index ba90478..434754f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5281 @@
12021-06-08 Daniel Kiper <daniel.kiper@oracle.com>
2
3 Release 2.06
4
52021-06-08 Daniel Kiper <daniel.kiper@oracle.com>
6
7 SECURITY: Add SECURITY file
8 The SECURITY file describes the GRUB project security policy.
9
10 It is based on https://github.com/wireapp/wire/blob/master/SECURITY.md
11
122021-06-08 Daniel Kiper <daniel.kiper@oracle.com>
13
14 MAINTAINERS: Add MAINTAINERS file
15 The MAINTAINERS file provides basic information about the GRUB project
16 and its maintainers.
17
182021-06-01 Dimitri John Ledkov <xnox@ubuntu.com>
19
20 grub-install: Add backup and restore
21 Refactor clean_grub_dir() to create a backup of all the files, instead
22 of just irrevocably removing them as the first action. If available,
23 register atexit() handler to restore the backup if errors occur before
24 point of no return, or remove the backup if everything was successful.
25 If atexit() is not available, the backup remains on disk for manual
26 recovery.
27
28 Some platforms defined a point of no return, i.e. after modules & core
29 images were updated. Failures from any commands after that stage are
30 ignored, and backup is cleaned up. For example, on EFI platforms update
31 is not reverted when efibootmgr fails.
32
33 Extra care is taken to ensure atexit() handler is only invoked by the
34 parent process and not any children forks. Some older GRUB codebases
35 can invoke parent atexit() hooks from forks, which can mess up the
36 backup.
37
38 This allows safer upgrades of MBR & modules, such that
39 modules/images/fonts/translations are consistent with MBR in case of
40 errors. For example accidental grub-install /dev/non-existent-disk
41 currently clobbers and upgrades modules in /boot/grub, despite not
42 actually updating any MBR.
43
44 This patch only handles backup and restore of files copied to /boot/grub.
45 This patch does not perform backup (or restoration) of MBR itself or
46 blocklists. Thus when installing i386-pc platform, corruption may still
47 occur with MBR and blocklists which will not be attempted to be
48 automatically recovered.
49
50 Also add modinfo.sh and *.efi to the cleanup/backup/restore code path,
51 to ensure it is also cleaned, backed up and restored.
52
53 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
54
552021-06-01 Dimitri John Ledkov <xnox@ubuntu.com>
56
57 osdep/unix/exec: Avoid atexit() handlers when child execvp() fails
58 The functions grub_util_exec_pipe() and grub_util_exec_pipe_stderr()
59 currently call execvp(). If the call fails for any reason, the child
60 currently calls exit(127). This in turn executes the parents
61 atexit() handlers from the forked child, and then the same handlers
62 are called again from parent. This is usually not desired, and can
63 lead to deadlocks, and undesired behavior. So, change the exit() calls
64 to _exit() calls to avoid calling atexit() handlers from child.
65
66 Fixes: e75cf4a58 (unix exec: avoid atexit handlers when child exits)
67
68 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
69
702021-06-01 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
71
72 lib/i386/relocator64: Build fixes for i386
73 This fixes cross-compiling to x86 (e.g., the Hurd) from x86-linux of
74
75 grub-core/lib/i386/relocator64.S
76
77 This file has six sections that only build with a 64-bit assembler,
78 yet only the first two sections had support for a 32-bit assembler.
79 This patch completes this for the remaining sections.
80
81 To reproduce, update the GRUB source description in your local Guix
82 archive and run
83
84 ./pre-inst-env guix build --system=i686-linux --target=i586-pc-gnu grub
85
86 or install an x86 cross-build environment on x86-linux (32-bit!) and
87 configure to cross build and make, e.g., do something like
88
89 ./configure \
90 CC_FOR_BUILD=gcc \
91 --build=i686-unknown-linux-gnu \
92 --host=i586-pc-gnu
93 make
94
95 Additionally, remove a line with redundant spaces.
96
97 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
98
992021-06-01 Javier Martinez Canillas <javierm@redhat.com>
100
101 fs/xfs: Add needsrepair incompat feature support
102 The XFS now has an incompat feature flag to indicate that a filesystem
103 needs to be repaired. The Linux kernel refuses to mount the filesystem
104 that has it set and only the xfs_repair tool is able to clear that flag.
105
106 The GRUB doesn't have the concept of mounting filesystems and just
107 attempts to read the files. But it does some sanity checking before
108 attempting to read from the filesystem. Among the things which are tested,
109 is if the super block only has set of incompatible features flags that
110 are supported by GRUB. If it contains any flags that are not listed as
111 supported, reading the XFS filesystem fails.
112
113 Since the GRUB doesn't attempt to detect if the filesystem is inconsistent
114 nor replays the journal, the filesystem access is a best effort. For this
115 reason, ignore if the filesystem needs to be repaired and just print a debug
116 message. That way, if reading or booting fails later, the user is able to
117 figure out that the failures can be related to broken XFS filesystem.
118
119 Suggested-by: Eric Sandeen <esandeen@redhat.com>
120 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
121
1222021-06-01 Carlos Maiolino <cmaiolino@redhat.com>
123
124 fs/xfs: Add bigtime incompat feature support
125 The XFS filesystem supports a bigtime feature to overcome y2038 problem.
126 This patch makes the GRUB able to support the XFS filesystems with this
127 feature enabled.
128
129 The XFS counter for the bigtime enabled timestamps starts at 0, which
130 translates to GRUB_INT32_MIN (Dec 31 20:45:52 UTC 1901) in the legacy
131 timestamps. The conversion to Unix timestamps is made before passing the
132 value to other GRUB functions.
133
134 For this to work properly, GRUB requires an access to flags2 field in the
135 XFS ondisk inode. So, the grub_xfs_inode structure has been updated to
136 cover full ondisk inode.
137
138 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
139
1402021-06-01 Carlos Maiolino <cmaiolino@redhat.com>
141
142 fs: Use 64-bit type for filesystem timestamp
143 Some filesystems nowadays use 64-bit types for timestamps. So, update
144 grub_dirhook_info struct to use an grub_int64_t type to store mtime.
145 This also updates the grub_unixtime2datetime() function to receive
146 a 64-bit timestamp argument and do 64-bit-safe divisions.
147
148 All the remaining conversion from 32-bit to 64-bit should be safe, as
149 32-bit to 64-bit attributions will be implicitly casted. The most
150 critical part in the 32-bit to 64-bit conversion is in the function
151 grub_unixtime2datetime() where it needs to deal with the 64-bit type.
152 So, for that, the grub_divmod64() helper has been used.
153
154 These changes enables the GRUB to support dates beyond y2038.
155
156 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
157
1582021-05-28 Javier Martinez Canillas <javierm@redhat.com>
159
160 types: Define PRI{x,d}GRUB_INT{32,64}_T format specifiers
161 There are already PRI*_T constants defined for unsigned integers but not
162 for signed integers. Add format specifiers for the latter.
163
164 Suggested-by: Daniel Kiper <daniel.kiper@oracle.com>
165 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
166
1672021-05-28 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
168
169 kern/efi/sb: Remove duplicate efi_shim_lock_guid variable
170 The efi_shim_lock_guid local variable and shim_lock_guid global variable
171 have the same GUID value. Only the latter is retained.
172
173 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
174
1752021-05-10 Javier Martinez Canillas <javierm@redhat.com>
176
177 util/mkimage: Fix wrong PE32+ section sizes for some arches
178 The commit f60ba9e5945 (util/mkimage: Refactor section setup to use a helper)
179 added a helper function to setup PE sections. But it also changed how the
180 raw data offsets were calculated since all the section sizes are aligned.
181 However, for some platforms, i.e ia64-efi and arm64-efi, the kernel image
182 size is not aligned using the section alignment. This leads to the situation
183 in which the mods section offset in its PE section header does not match its
184 real placement in the PE file. So, finally the GRUB is not able to locate
185 and load built-in modules.
186
187 The problem surfaces on ia64-efi and arm64-efi because both platforms
188 require additional relocation data which is added behind .bss section.
189 So, we have to add some padding behind this extra data to make the
190 beginning of mods section properly aligned in the PE file. Fix it by
191 aligning the kernel_size to the section alignment. That makes the sizes
192 and offsets in the PE section headers to match relevant sections in the
193 PE32+ binary file.
194
195 Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
196 Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
197 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
198
1992021-05-10 Daniel Kiper <daniel.kiper@oracle.com>
200
201 term/terminfo: Fix the terminfo command help and documentation
202 Additionally, fix the terminfo spelling mistake in
203 the GRUB development documentation.
204
205 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
206
2072021-05-10 Daniel Kiper <daniel.kiper@oracle.com>
208
209 i18n: Align N_() formatting with the rest of GRUB code
210 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
211
2122021-05-10 Daniel Kiper <daniel.kiper@oracle.com>
213
214 i18n: Format large integers before the translation message - take 2
215 This is an additional fix which has been missing from the commit 837fe48de
216 (i18n: Format large integers before the translation message).
217
218 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
219
2202021-04-13 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
221
222 i18n: Format large integers before the translation message
223 The GNU gettext only supports the ISO C99 macros for integral
224 types. If there is a need to use unsupported formatting macros,
225 e.g. PRIuGRUB_UINT64_T, according to [1] the number to a string
226 conversion should be separated from the code printing message
227 requiring the internationalization. So, the function grub_snprintf()
228 is used to print the numeric values to an intermediate buffer and
229 the internationalized message contains a string format directive.
230
231 [1] https://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html#No-string-concatenation
232
233 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
234
2352021-04-12 Daniel Axtens <dja@axtens.net>
236
237 video/fb/fbfill: Use unsigned integers for width/height
238 Since commit 7ce3259f67ac (video/fb/fbfill: Fix potential integer
239 overflow), clang builds of grub-emu have failed with messages like:
240
241 /usr/bin/ld: libgrubmods.a(libgrubmods_a-fbfill.o): in function `grub_video_fbfill_direct24':
242 fbfill.c:(.text+0x28e): undefined reference to `__muloti4'
243
244 This appears to be due to a weird quirk in how clang compiles
245
246 grub_mul(dst->mode_info->bytes_per_pixel, width, &rowskip)
247
248 which is grub_mul(unsigned int, int, &grub_size_t).
249
250 It looks like clang somewhere promotes everything to 128-bit maths
251 before ultimately reducing down to 64 bit for grub_size_t. I think
252 this is because width is signed, and indeed converting width to an
253 unsigned int makes the problem go away.
254
255 This conversion also makes more sense generally:
256 - the caller of all the fbfill_directN functions is
257 grub_video_fb_fill_dispatch() and it takes width and height as
258 unsigned ints already,
259 - it doesn't make sense to fill a negative width or height.
260
261 Convert the width and height arguments and associated loop counters
262 to unsigned ints.
263
264 Fixes: 7ce3259f67ac (video/fb/fbfill: Fix potential integer overflow)
265
266 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
267
2682021-04-12 Glenn Washburn <development@efficientek.com>
269
270 docs: Conform badmem and cutmem description indentations with other commands
271 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
272
273 docs: Add note to cryptomount that UUIDs should be specified without dashes
274 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
275
2762021-04-12 Aru Sahni <aru@arusahni.net>
277
278 templates: Fix user-facing typo with an incorrect use of "it's"
279 Since the possessive form of "it" is being used, the apostrophe must be omitted.
280
281 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
282
2832021-04-12 Colin Watson <cjwatson@debian.org>
284
285 buffer: Sync up out-of-range error message
286 The messages associated with other similar GRUB_ERR_OUT_OF_RANGE errors
287 were lacking the trailing full stop. Syncing up the strings saves a small
288 amount of precious core image space on i386-pc.
289
290 DOWN: obj/i386-pc/grub-core/kernel.img (31740 > 31708) - change: -32
291 DOWN: i386-pc core image (biosdisk ext2 part_msdos) (27453 > 27452) - change: -1
292 DOWN: i386-pc core image (biosdisk ext2 part_msdos diskfilter mdraid09) (32367 > 32359) - change: -8
293
294 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
295
2962021-04-12 Glenn Washburn <development@efficientek.com>
297
298 usb/usbhub: Use GRUB_USB_MAX_CONF macro instead of literal in hub for maximum configs
299 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
300
3012021-04-12 Daniel Drake <drake@endlessm.com>
302
303 fs/minix: Avoid mistakenly probing ext2 filesystems
304 The ext2 (and ext3, ext4) filesystems write the number of free inodes to
305 location 0x410.
306
307 On a MINIX filesystem, that same location is used for the MINIX superblock
308 magic number.
309
310 If the number of free inodes on an ext2 filesystem is equal to any
311 of the four MINIX superblock magic values plus any multiple of 65536,
312 GRUB's MINIX filesystem code will probe it as a MINIX filesystem.
313
314 In the case of an OS using ext2 as the root filesystem, since there will
315 ordinarily be some amount of file creation and deletion on every bootup,
316 it effectively means that this situation has a 1:16384 chance of being hit
317 on every reboot.
318
319 This will cause GRUB's filesystem probing code to mistakenly identify an
320 ext2 filesystem as MINIX. This can be seen by e.g. "search --label"
321 incorrectly indicating that no such ext2 partition with matching label
322 exists, whereas in fact it does.
323
324 After spotting the rough cause of the issue I was facing here, I borrowed
325 much of the diagnosis/explanation from meierfra who found and investigated
326 the same issue in util-linux in 2010:
327
328 https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/518582
329
330 This was fixed in util-linux by having the MINIX code check for the
331 ext2 magic. Do the same here.
332
333 Reviewed-by: Derek Foreman <derek@endlessos.org>
334 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
335
3362021-03-12 Daniel Kiper <daniel.kiper@oracle.com>
337
338 Release 2.06~rc1
339
3402021-03-11 Ard Biesheuvel <ard.biesheuvel@arm.com>
341
342 arm/linux: Fix ARM Linux header layout
343 The hdr_offset member of the ARM Linux image header appears at
344 offset 0x3c, matching the PE/COFF spec's placement of the COFF
345 header offset in the MS-DOS header. We're currently off by four,
346 so fix that.
347
348 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
349
3502021-03-10 Glenn Washburn <development@efficientek.com>
351
352 style: Format string macro should have a space between quotes
353 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
354
3552021-03-10 Glenn Washburn <development@efficientek.com>
356
357 grub/err: Do compile-time format string checking on grub_error()
358 This should help prevent format string errors and thus improve the quality
359 of error reporting.
360
361 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
362
3632021-03-10 Glenn Washburn <development@efficientek.com>
364
365 fs/zfs/zfs: Use format code "%llu" for 64-bit uint bp->blk_prop in grub_error()
366 This is a temporary, less-intrusive change to get the build to success with
367 compiler format string checking turned on. There is a better fix which
368 addresses this issue, but it needs more testing. Use this change so that
369 format string checking on grub_error() can be turned on until the better
370 change is fully tested.
371
372 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
373
3742021-03-10 Glenn Washburn <development@efficientek.com>
375
376 fs/hfsplus: Use format code PRIuGRUB_UINT64_T for 64-bit typed fileblock in grub_error()
377 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
378
3792021-03-10 Glenn Washburn <development@efficientek.com>
380
381 dl/elf: Use format code PRIxGRUB_UINT64_T for 64-bit arg in grub_error()
382 The macro ELF_R_TYPE does not change the underlying type. Here its argument
383 is a 64-bit Elf64_Xword. Make sure the format code matches.
384
385 For the RISC-V architecture, rel->r_info could be either Elf32_Xword or
386 Elf64_Xword depending on if 32 or 64-bit RISC-V is being built. So cast
387 to 64-bit value regardless.
388
389 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
390
3912021-03-10 Glenn Washburn <development@efficientek.com>
392
393 disk/ata: Use format code PRIxGRUB_UINT64_T for 64-bit uint argument in grub_error()
394 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
395
3962021-03-10 Glenn Washburn <development@efficientek.com>
397
398 loader/i386/pc/linux: Use PRI* macros to get correct format string code across architectures
399 Also remove casting of format string args so that the architecture dependent
400 type is preserved.
401
402 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
403
4042021-03-10 Glenn Washburn <development@efficientek.com>
405
406 kern/efi/mm: Format string error in grub_error()
407 The second format string argument, GRUB_EFI_MAX_USABLE_ADDRESS, is a macro
408 to a number literal. However, depending on what the target architecture, the
409 type can be 32 or 64 bits. Cast to a 64-bit integer. Also, change the
410 format string literals "%llx" to use PRIxGRUB_UINT64_T.
411
412 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
413
4142021-03-10 Glenn Washburn <development@efficientek.com>
415
416 commands/pgp: Format code for grub_error() is incorrect
417 The format code is for a 32-bit int, but the argument, keyid, is declared as
418 a 64 bit int. The comment above says keyid is 32-bit. I'm not sure if the
419 comment or declaration is wrong, so force the display of a 64-bit int for now.
420
421 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
422
4232021-03-10 Glenn Washburn <development@efficientek.com>
424
425 grub_error: Use format code PRIuGRUB_SIZE for variables of type grub_size_t
426 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
427
4282021-03-10 Glenn Washburn <development@efficientek.com>
429
430 disk/dmraid_nvidia: Format string error in grub_error()
431 The grub_error() has a format string expecting two arguments, but only one
432 provided. According to the comments in the struct grub_nv_super definition,
433 the version field looks like a version number where major.minor is encoded
434 as each a byte in the two-byte short.
435
436 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
437
4382021-03-10 Glenn Washburn <development@efficientek.com>
439
440 video/bochs: grub_error() format string add missing format code
441 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
442
4432021-03-10 Glenn Washburn <development@efficientek.com>
444
445 parttool/msdospart: grub_error() missing format string argument
446 Its obvious from the error message that the variable named "type" was
447 accidentally omitted.
448
449 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
450
4512021-03-10 Glenn Washburn <development@efficientek.com>
452
453 misc: Format string for grub_error() should be a literal
454 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
455
4562021-03-10 Philip Müller <philm@manjaro.org>
457
458 templates: Properly disable the os-prober by default
459 This patch does the following:
460 - really disables os-prober by default in the util/grub-mkconfig.in
461 by setting GRUB_DISABLE_OS_PROBER to true,
462 - fixes the logic in the util/grub.d/30_os-prober.in,
463 - updates the grub_warn() lines.
464
465 Reason for the code shuffling in the util/grub-mkconfig.in:
466
467 The default was GRUB_DISABLE_OS_PROBER=false if you don't set
468 GRUB_DISABLE_OS_PROBER at all. To prevent os-prober from starting we
469 have to set it by default to true and shuffle GRUB_DISABLE_OS_PROBER to
470 code section, which is executed by the script. However we still give an
471 option to the user to overwrite it with false, if he wants to execute
472 os-prober after all.
473
474 Fixes: e3464147 (templates: Disable the os-prober by default)
475
476 Reported-by: Didier Spaier <didier@slint.fr>
477 Reported-by: Lennart Sorensen <lsorense@csclub.uwaterloo.ca>
478 Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
479 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
480
4812021-03-10 Michael Chang <mchang@suse.com>
482
483 kern/efi/sb: Add chainloaded image as shim's verifiable object
484 While attempting to dual boot Microsoft Windows with UEFI chainloader,
485 it failed with below error when UEFI Secure Boot was enabled:
486
487 error ../../grub-core/kern/verifiers.c:119:verification requested but
488 nobody cares: /EFI/Microsoft/Boot/bootmgfw.efi.
489
490 It is a regression, as previously it worked without any problem.
491
492 It turns out chainloading PE image has been locked down by commit
493 578c95298 (kern: Add lockdown support). However, we should consider it
494 as verifiable object by shim to allow booting in UEFI Secure Boot mode.
495 The chainloaded PE image could also have trusted signature created by
496 vendor with their pubkey cert in db. For that matters it's usage should
497 not be locked down under UEFI Secure Boot, and instead shim should be
498 allowed to validate a PE binary signature before running it.
499
500 Fixes: 578c95298 (kern: Add lockdown support)
501
502 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
503
5042021-03-10 Glenn Washburn <development@efficientek.com>
505
506 disk/pata: Suppress error message "no device connected"
507 This error message comes from the grub_print_error() in
508 grub_pata_device_initialize(), which does not pass on the error, and is
509 raised in check_device(). The function check_device() needs to return this
510 as an error because check_device() is also used in grub_pata_open(), which
511 does pass on this error to indicate that the device can not be used.
512
513 This is actually not an error when displayed by grub_pata_device_initialize()
514 because it just indicates that there are no pata devices seen. This may be
515 confusing to end users who do not have pata devices yet are loading the
516 pata module (perhaps implicitly via nativedisk). This also causes unnecessary
517 output which may need to be accounted for in functional testing.
518
519 Instead print to the debug log when check_device() raises this "error" and
520 pop the error from the error stack. If there is another error on the stack
521 then print the error stack as those should be real errors.
522
523 Acked-by: Paul Menzel <pmenzel@molgen.mpg.de>
524 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
525
5262021-03-10 Yi Zhao <yi.zhao@windriver.com>
527
528 fs/ext2: Fix a file not found error when a symlink filesize is equal to 60
529 We encountered a file not found error when the symlink filesize is
530 equal to 60:
531
532 $ ls -l initrd
533 lrwxrwxrwx 1 root root 60 Jan 6 16:37 initrd -> secure-core-image-initramfs-5.10.2-yoctodev-standard.cpio.gz
534
535 When booting, we got the following error in the GRUB:
536
537 error: file `/initrd' not found
538
539 The root cause is that the size of diro->inode.symlink is equal to 60
540 and a symlink name has to be terminated with NUL there. So, if the
541 symlink filesize is exactly 60 then it is also stored in a separate
542 block rather than in the inode itself.
543
544 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
545
5462021-03-02 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
547
548 loader/i386/linux: Do not use grub_le_to_cpu32() for relocatable variable
549 The relocatable variable is defined as grub_uint8_t. Relevant
550 member in setup_header structure is also defined as one byte
551 in Linux boot protocol. By semantic definition it is a bool type.
552 It is not appropriate to treat it as a four bytes. This patch
553 fixes the issue.
554
555 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
556
5572021-03-02 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
558
559 loader/i386/linux: Remove redundant code from in grub_cmd_linux()
560 The preferred_address has been assigned to GRUB_LINUX_BZIMAGE_ADDR
561 during initialization in grub_cmd_linux(). The assignment here
562 is redundant and should be removed.
563
564 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
565
5662021-03-02 Heinrich Schuchardt <xypron.glpk@gmx.de>
567
568 efi: The device-tree must be in EfiACPIReclaimMemory
569 According to the Embedded Base Boot Requirements (EBBR) specification the
570 device-tree passed to Linux as a configuration table must reside in
571 EfiACPIReclaimMemory.
572
573 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
574
5752021-03-02 Heinrich Schuchardt <xypron.glpk@gmx.de>
576
577 commands/efi/lsefisystab: Add short text for EFI_RT_PROPERTIES_TABLE_GUID
578 UEFI specification 2.8 errata B introduced the EFI_RT_PROPERTIES_TABLE
579 describing the services available at runtime.
580
581 The lsefisystab command is used to display installed EFI configuration
582 tables. Currently it only shows the GUID but not a short text for the
583 new table.
584
585 Provide a short text for the EFI_RT_PROPERTIES_TABLE_GUID.
586
587 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
588
5892021-03-02 Petr Vorel <pvorel@suse.cz>
590
591 docs/luks2: Mention key derivation function support
592 To give users hint why Argon2, the default in cryptsetup for LUKS2, does
593 not work.
594
595 Acked-by: Paul Menzel <pmenzel@molgen.mpg.de>
596 Reviewed-by: Patrick Steinhardt <ps@pks.im>
597 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
598
5992021-03-02 Derek Foreman <derek@endlessos.org>
600
601 commands/file: Fix array/enum desync
602 The commit f1957dc8a (RISC-V: Add to build system) added two entries to
603 the options array, but only 1 entry to the enum. This resulted in
604 everything after the insertion point being off by one.
605
606 This broke at least the "file --is-hibernated-hiberfil" command.
607
608 Bring the two back in sync by splitting the IS_RISCV_EFI enum entry into
609 two, as is done for other architectures.
610
611 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
612
6132021-03-02 Marco A Benatto <mbenatto@redhat.com>
614
615 kern/mm: Fix grub_debug_calloc() compilation error
616 Fix compilation error due to missing parameter to
617 grub_printf() when MM_DEBUG is defined.
618
619 Fixes: 64e26162e (calloc: Make sure we always have an overflow-checking calloc() available)
620
621 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
622
6232021-03-02 Alex Burmashev <alexander.burmashev@oracle.com>
624
625 templates: Disable the os-prober by default
626 The os-prober is enabled by default what may lead to potentially
627 dangerous use cases and borderline opening attack vectors. This
628 patch disables the os-prober, adds warning messages and updates
629 GRUB_DISABLE_OS_PROBER configuration option documentation. This
630 way we make it clear that the os-prober usage is not recommended.
631
632 Simplistic nature of this change allows downstream vendors, who
633 really want os-prober to be enabled out of the box in their
634 relevant products, easily revert to it's old behavior.
635
636 Reported-by: NyankoSec (<nyanko@10x.moe>, https://twitter.com/NyankoSec),
637 working with SSD Secure Disclosure
638 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
639
6402021-03-02 Thomas Frauendorfer | Miray Software <tf@miray.de>
641
642 gfxmenu/gui: Check printf() format in the gui_progress_bar and gui_label
643 The gui_progress_bar and gui_label components can display the timeout
644 value. The format string can be set through a theme file. This patch
645 adds a validation step to the format string.
646
647 If a user loads a theme file into the GRUB without this patch then
648 a GUI label with the following settings
649
650 + label {
651 ...
652 id = "__timeout__"
653 text = "%s"
654 }
655
656 will interpret the current timeout value as string pointer and print the
657 memory at that position on the screen. It is not desired behavior.
658
659 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
660
6612021-03-02 Thomas Frauendorfer | Miray Software <tf@miray.de>
662
663 kern/misc: Add function to check printf() format against expected format
664 The grub_printf_fmt_check() function parses the arguments of an untrusted
665 printf() format and an expected printf() format and then compares the
666 arguments counts and arguments types. The arguments count in the untrusted
667 format string must be less or equal to the arguments count in the expected
668 format string and both arguments types must match.
669
670 To do this the parse_printf_arg_fmt() helper function is extended in the
671 following way:
672
673 1. Add a return value to report errors to the grub_printf_fmt_check().
674
675 2. Add the fmt_check argument to enable stricter format verification:
676 - the function expects that arguments definitions are always
677 terminated by a supported conversion specifier.
678 - positional parameters, "$", are not allowed, as they cannot be
679 validated correctly with the current implementation. For example
680 "%s%1$d" would assign the first args entry twice while leaving the
681 second one unchanged.
682 - Return an error if preallocated space in args is too small and
683 allocation fails for the needed size. The grub_printf_fmt_check()
684 should verify all arguments. So, if validation is not possible for
685 any reason it should return an error.
686 This also adds a case entry to handle "%%", which is the escape
687 sequence to print "%" character.
688
689 3. Add the max_args argument to check for the maximum allowed arguments
690 count in a printf() string. This should be set to the arguments count
691 of the expected format. Then the parse_printf_arg_fmt() function will
692 return an error if the arguments count is exceeded.
693
694 The two additional arguments allow us to use parse_printf_arg_fmt() in
695 printf() and grub_printf_fmt_check() calls.
696
697 When parse_printf_arg_fmt() is used by grub_printf_fmt_check() the
698 function parse user provided untrusted format string too. So, in
699 that case it is better to be too strict than too lenient.
700
701 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
702
7032021-03-02 Thomas Frauendorfer | Miray Software <tf@miray.de>
704
705 kern/misc: Add STRING type for internal printf() format handling
706 Set printf() argument type for "%s" to new type STRING. This is in
707 preparation for a follow up patch to compare a printf() format string
708 against an expected printf() format string.
709
710 For "%s" the corresponding printf() argument is dereferenced as pointer
711 while all other argument types are defined as integer value. However,
712 when validating a printf() format it is necessary to differentiate "%s"
713 from "%p" and other integers. So, let's do that.
714
715 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
716
7172021-03-02 Thomas Frauendorfer | Miray Software <tf@miray.de>
718
719 kern/misc: Split parse_printf_args() into format parsing and va_list handling
720 This patch is preparing for a follow up patch which will use
721 the format parsing part to compare the arguments in a printf()
722 format from an external source against a printf() format with
723 expected arguments.
724
725 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
726
7272021-03-02 Dimitri John Ledkov <xnox@ubuntu.com>
728
729 shim_lock: Only skip loading shim_lock verifier with explicit consent
730 Commit 32ddc42c (efi: Only register shim_lock verifier if shim_lock
731 protocol is found and SB enabled) reintroduced CVE-2020-15705 which
732 previously only existed in the out-of-tree linuxefi patches and was
733 fixed as part of the BootHole patch series.
734
735 Under Secure Boot enforce loading shim_lock verifier. Allow skipping
736 shim_lock verifier if SecureBoot/MokSBState EFI variables indicate
737 skipping validations, or if GRUB image is built with --disable-shim-lock.
738
739 Fixes: 132ddc42c (efi: Only register shim_lock verifier if shim_lock
740 protocol is found and SB enabled)
741 Fixes: CVE-2020-15705
742 Fixes: CVE-2021-3418
743
744 Reported-by: Dimitri John Ledkov <xnox@ubuntu.com>
745 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
746
7472021-03-02 Dimitri John Ledkov <xnox@ubuntu.com>
748
749 grub-install-common: Add --sbat option
750 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
751
7522021-03-02 Peter Jones <pjones@redhat.com>
753
754 util/mkimage: Add an option to import SBAT metadata into a .sbat section
755 Add a --sbat option to the grub-mkimage tool which allows us to import
756 an SBAT metadata formatted as a CSV file into a .sbat section of the
757 EFI binary.
758
759 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
760
7612021-03-02 Peter Jones <pjones@redhat.com>
762
763 util/mkimage: Refactor section setup to use a helper
764 Add a init_pe_section() helper function to setup PE sections. This makes
765 the code simpler and easier to read.
766
767 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
768
7692021-03-02 Peter Jones <pjones@redhat.com>
770
771 util/mkimage: Improve data_size value calculation
772 According to "Microsoft Portable Executable and Common Object File Format
773 Specification", the Optional Header SizeOfInitializedData field contains:
774
775 Size of the initialized data section, or the sum of all such sections if
776 there are multiple data sections.
777
778 Make this explicit by adding the GRUB kernel data size to the sum of all
779 the modules sizes. The ALIGN_UP() is not required by the PE spec but do
780 it to avoid alignment issues.
781
782 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
783
7842021-03-02 Peter Jones <pjones@redhat.com>
785
786 util/mkimage: Reorder PE optional header fields set-up
787 This makes the PE32 and PE32+ header fields set-up easier to follow by
788 setting them closer to the initialization of their related sections.
789
790 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
791
7922021-03-02 Peter Jones <pjones@redhat.com>
793
794 util/mkimage: Unify more of the PE32 and PE32+ header set-up
795 There's quite a bit of code duplication in the code that sets the optional
796 header for PE32 and PE32+. The two are very similar with the exception of
797 a few fields that have type grub_uint64_t instead of grub_uint32_t.
798
799 Factor out the common code and add a PE_OHDR() macro that simplifies the
800 set-up and make the code more readable.
801
802 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
803
8042021-03-02 Peter Jones <pjones@redhat.com>
805
806 util/mkimage: Always use grub_host_to_target32() to initialize PE stack and heap stuff
807 This change does not impact final result of initialization itself.
808 However, it eases PE code unification in subsequent patches.
809
810 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
811
8122021-03-02 Peter Jones <pjones@redhat.com>
813
814 util/mkimage: Use grub_host_to_target32() instead of grub_cpu_to_le32()
815 The latter doesn't take into account the target image endianness. There is
816 a grub_cpu_to_le32_compile_time() but no compile time variant for function
817 grub_host_to_target32(). So, let's keep using the other one for this case.
818
819 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
820
8212021-03-02 Javier Martinez Canillas <javierm@redhat.com>
822
823 util/mkimage: Remove unused code to add BSS section
824 The code is compiled out so there is no reason to keep it.
825
826 Additionally, don't set bss_size field since we do not add a BSS section.
827
828 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
829
8302021-03-02 Chris Coulson <chris.coulson@canonical.com>
831
832 kern/efi: Add initial stack protector implementation
833 It works only on UEFI platforms but can be quite easily extended to
834 others architectures and platforms if needed.
835
836 Reviewed-by: Marco A Benatto <mbenatto@redhat.com>
837 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
838
8392021-03-02 Chris Coulson <chris.coulson@canonical.com>
840
841 kern/parser: Fix a stack buffer overflow
842 grub_parser_split_cmdline() expands variable names present in the supplied
843 command line in to their corresponding variable contents and uses a 1 kiB
844 stack buffer for temporary storage without sufficient bounds checking. If
845 the function is called with a command line that references a variable with
846 a sufficiently large payload, it is possible to overflow the stack
847 buffer via tab completion, corrupt the stack frame and potentially
848 control execution.
849
850 Fixes: CVE-2020-27749
851
852 Reported-by: Chris Coulson <chris.coulson@canonical.com>
853 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
854
8552021-03-02 Chris Coulson <chris.coulson@canonical.com>
856
857 kern/buffer: Add variable sized heap buffer
858 Add a new variable sized heap buffer type (grub_buffer_t) with simple
859 operations for appending data, accessing the data and maintaining
860 a read cursor.
861
862 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
863
8642021-03-02 Chris Coulson <chris.coulson@canonical.com>
865
866 kern/parser: Refactor grub_parser_split_cmdline() cleanup
867 Introduce a common function epilogue used for cleaning up on all
868 return paths, which will simplify additional error handling to be
869 introduced in a subsequent commit.
870
871 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
872
8732021-03-02 Chris Coulson <chris.coulson@canonical.com>
874
875 kern/parser: Introduce terminate_arg() helper
876 process_char() and grub_parser_split_cmdline() use similar code for
877 terminating the most recent argument. Add a helper function for this.
878
879 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
880
8812021-03-02 Chris Coulson <chris.coulson@canonical.com>
882
883 kern/parser: Introduce process_char() helper
884 grub_parser_split_cmdline() iterates over each command line character.
885 In order to add error checking and to simplify the subsequent error
886 handling, split the character processing in to a separate function.
887
888 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
889
8902021-03-02 Chris Coulson <chris.coulson@canonical.com>
891
892 kern/parser: Fix a memory leak
893 The getline() function supplied to grub_parser_split_cmdline() returns
894 a newly allocated buffer and can be called multiple times, but the
895 returned buffer is never freed.
896
897 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
898
8992021-03-02 Daniel Axtens <dja@axtens.net>
900
901 fs/btrfs: Squash some uninitialized reads
902 We need to check errors before calling into a function that uses the result.
903
904 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
905
9062021-03-02 Daniel Axtens <dja@axtens.net>
907
908 fs/btrfs: Validate the number of stripes/parities in RAID5/6
909 This prevents a divide by zero if nstripes == nparities, and
910 also prevents propagation of invalid values if nstripes ends up
911 less than nparities.
912
913 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
914
9152021-03-02 Daniel Axtens <dja@axtens.net>
916
917 disk/lvm: Do not allow a LV to be it's own segment's node's LV
918 This prevents infinite recursion in the diskfilter verification code.
919
920 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
921
9222021-03-02 Daniel Axtens <dja@axtens.net>
923
924 disk/lvm: Sanitize rlocn->offset to prevent wild read
925 rlocn->offset is read directly from disk and added to the metadatabuf
926 pointer to create a pointer to a block of metadata. It's a 64-bit
927 quantity so as long as you don't overflow you can set subsequent
928 pointers to point anywhere in memory.
929
930 Require that rlocn->offset fits within the metadata buffer size.
931
932 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
933
9342021-03-02 Daniel Axtens <dja@axtens.net>
935
936 disk/lvm: Do not overread metadata
937 We could reach the end of valid metadata and not realize, leading to
938 some buffer overreads. Check if we have reached the end and bail.
939
940 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
941
9422021-03-02 Daniel Axtens <dja@axtens.net>
943
944 disk/lvm: Do not crash if an expected string is not found
945 Clean up a bunch of cases where we could have strstr() fail and lead to
946 us dereferencing NULL.
947
948 We'll still leak memory in some cases (loops don't clean up allocations
949 from earlier iterations if a later iteration fails) but at least we're
950 not crashing.
951
952 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
953
9542021-03-02 Daniel Axtens <dja@axtens.net>
955
956 disk/lvm: Bail on missing PV list
957 There's an if block for the presence of "physical_volumes {", but if
958 that block is absent, then p remains NULL and a NULL-deref will result
959 when looking for logical volumes.
960
961 It doesn't seem like LVM makes sense without physical volumes, so error
962 out rather than crashing.
963
964 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
965
9662021-03-02 Daniel Axtens <dja@axtens.net>
967
968 disk/lvm: Don't blast past the end of the circular metadata buffer
969 This catches at least some OOB reads, and it's possible I suppose that
970 if 2 * mda_size is less than GRUB_LVM_MDA_HEADER_SIZE it might catch some
971 OOB writes too (although that hasn't showed up as a crash in fuzzing yet).
972
973 It's a bit ugly and I'd appreciate better suggestions.
974
975 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
976
9772021-03-02 Daniel Axtens <dja@axtens.net>
978
979 disk/lvm: Don't go beyond the end of the data we read from disk
980 We unconditionally trusted offset_xl from the LVM label header, even if
981 it told us that the PV header/disk locations were way off past the end
982 of the data we read from disk.
983
984 Require that the offset be sane, fixing an OOB read and crash.
985
986 Fixes: CID 314367, CID 314371
987
988 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
989
9902021-03-02 Daniel Axtens <dja@axtens.net>
991
992 io/gzio: Zero gzio->tl/td in init_dynamic_block() if huft_build() fails
993 If huft_build() fails, gzio->tl or gzio->td could contain pointers that
994 are no longer valid. Zero them out.
995
996 This prevents a double free when grub_gzio_close() comes through and
997 attempts to free them again.
998
999 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1000
10012021-03-02 Daniel Axtens <dja@axtens.net>
1002
1003 io/gzio: Catch missing values in huft_build() and bail
1004 In huft_build(), "v" is a table of values in order of bit length.
1005 The code later (when setting up table entries in "r") assumes that all
1006 elements of this array corresponding to a code are initialized and less
1007 than N_MAX. However, it doesn't enforce this.
1008
1009 With sufficiently manipulated inputs (e.g. from fuzzing), there can be
1010 elements of "v" that are not filled. Therefore a lookup into "e" or "d"
1011 will use an uninitialized value. This can lead to an invalid/OOB read on
1012 those values, often leading to a crash.
1013
1014 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1015
10162021-03-02 Daniel Axtens <dja@axtens.net>
1017
1018 io/gzio: Add init_dynamic_block() clean up if unpacking codes fails
1019 init_dynamic_block() didn't clean up gzio->tl and td in some error
1020 paths. This left td pointing to part of tl. Then in grub_gzio_close(),
1021 when tl was freed the storage for td would also be freed. The code then
1022 attempts to free td explicitly, performing a UAF and then a double free.
1023
1024 Explicitly clean up tl and td in the error paths.
1025
1026 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1027
10282021-03-02 Daniel Axtens <dja@axtens.net>
1029
1030 io/gzio: Bail if gzio->tl/td is NULL
1031 This is an ugly fix that doesn't address why gzio->tl comes to be NULL.
1032 However, it seems to be sufficient to patch up a bunch of NULL derefs.
1033
1034 It would be good to revisit this in future and see if we can have
1035 a cleaner solution that addresses some of the causes of the unexpected
1036 NULL pointers.
1037
1038 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1039
10402021-03-02 Daniel Axtens <dja@axtens.net>
1041
1042 fs/nilfs2: Properly bail on errors in grub_nilfs2_btree_node_lookup()
1043 We just introduced an error return in grub_nilfs2_btree_node_lookup().
1044 Make sure the callers catch it.
1045
1046 At the same time, make sure that grub_nilfs2_btree_node_lookup() always
1047 inits the index pointer passed to it.
1048
1049 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1050
10512021-03-02 Daniel Axtens <dja@axtens.net>
1052
1053 fs/nilfs2: Don't search children if provided number is too large
1054 NILFS2 reads the number of children a node has from the node. Unfortunately,
1055 that's not trustworthy. Check if it's beyond what the filesystem permits and
1056 reject it if so.
1057
1058 This blocks some OOB reads. I'm not sure how controllable the read is and what
1059 could be done with invalidly read data later on.
1060
1061 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1062
10632021-03-02 Daniel Axtens <dja@axtens.net>
1064
1065 fs/nilfs2: Reject too-large keys
1066 NILFS2 has up to 7 keys, per the data structure. Do not permit array
1067 indices in excess of that.
1068
1069 This catches some OOB reads. I don't know how controllable the invalidly
1070 read data is or if that could be used later in the program.
1071
1072 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1073
10742021-03-02 Daniel Axtens <dja@axtens.net>
1075
1076 fs/jfs: Catch infinite recursion
1077 It's possible with a fuzzed filesystem for JFS to keep getblk()-ing
1078 the same data over and over again, leading to stack exhaustion.
1079
1080 Check if we'd be calling the function with exactly the same data as
1081 was passed in, and if so abort.
1082
1083 I'm not sure what the performance impact of this is and am open to
1084 better ideas.
1085
1086 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1087
10882021-03-02 Daniel Axtens <dja@axtens.net>
1089
1090 fs/jfs: Limit the extents that getblk() can consider
1091 getblk() implicitly trusts that treehead->count is an accurate count of
1092 the number of extents. However, that value is read from disk and is not
1093 trustworthy, leading to OOB reads and crashes. I am not sure to what
1094 extent the data read from OOB can influence subsequent program execution.
1095
1096 Require callers to pass in the maximum number of extents for which
1097 they have storage.
1098
1099 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1100
11012021-03-02 Daniel Axtens <dja@axtens.net>
1102
1103 fs/jfs: Do not move to leaf level if name length is negative
1104 Fuzzing JFS revealed crashes where a negative number would be passed
1105 to le_to_cpu16_copy(). There it would be cast to a large positive number
1106 and the copy would read and write off the end of the respective buffers.
1107
1108 Catch this at the top as well as the bottom of the loop.
1109
1110 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1111
11122021-03-02 Daniel Axtens <dja@axtens.net>
1113
1114 fs/sfs: Fix over-read of root object name
1115 There's a read of the name of the root object that assumes that the name
1116 is nul-terminated within the root block. This isn't guaranteed - it seems
1117 SFS would require you to read multiple blocks to get a full name in general,
1118 but maybe that doesn't apply to the root object.
1119
1120 Either way, figure out how much space is left in the root block and don't
1121 over-read it. This fixes some OOB reads.
1122
1123 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1124
11252021-03-02 Daniel Axtens <dja@axtens.net>
1126
1127 fs/hfs: Disable under lockdown
1128 HFS has issues such as infinite mutual recursion that are simply too
1129 complex to fix for such a legacy format. So simply do not permit
1130 it to be loaded under lockdown.
1131
1132 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1133
11342021-03-02 Daniel Axtens <dja@axtens.net>
1135
1136 fs/hfsplus: Don't use uninitialized data on corrupt filesystems
1137 Valgrind identified the following use of uninitialized data:
1138
1139 ==2782220== Conditional jump or move depends on uninitialised value(s)
1140 ==2782220== at 0x42B364: grub_hfsplus_btree_search (hfsplus.c:566)
1141 ==2782220== by 0x42B21D: grub_hfsplus_read_block (hfsplus.c:185)
1142 ==2782220== by 0x42A693: grub_fshelp_read_file (fshelp.c:386)
1143 ==2782220== by 0x42C598: grub_hfsplus_read_file (hfsplus.c:219)
1144 ==2782220== by 0x42C598: grub_hfsplus_mount (hfsplus.c:330)
1145 ==2782220== by 0x42B8C5: grub_hfsplus_dir (hfsplus.c:958)
1146 ==2782220== by 0x4C1AE6: grub_fs_probe (fs.c:73)
1147 ==2782220== by 0x407C94: grub_ls_list_files (ls.c:186)
1148 ==2782220== by 0x407C94: grub_cmd_ls (ls.c:284)
1149 ==2782220== by 0x4D7130: grub_extcmd_dispatcher (extcmd.c:55)
1150 ==2782220== by 0x4045A6: execute_command (grub-fstest.c:59)
1151 ==2782220== by 0x4045A6: fstest (grub-fstest.c:433)
1152 ==2782220== by 0x4045A6: main (grub-fstest.c:772)
1153 ==2782220== Uninitialised value was created by a heap allocation
1154 ==2782220== at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
1155 ==2782220== by 0x4C0305: grub_malloc (mm.c:42)
1156 ==2782220== by 0x42C21D: grub_hfsplus_mount (hfsplus.c:239)
1157 ==2782220== by 0x42B8C5: grub_hfsplus_dir (hfsplus.c:958)
1158 ==2782220== by 0x4C1AE6: grub_fs_probe (fs.c:73)
1159 ==2782220== by 0x407C94: grub_ls_list_files (ls.c:186)
1160 ==2782220== by 0x407C94: grub_cmd_ls (ls.c:284)
1161 ==2782220== by 0x4D7130: grub_extcmd_dispatcher (extcmd.c:55)
1162 ==2782220== by 0x4045A6: execute_command (grub-fstest.c:59)
1163 ==2782220== by 0x4045A6: fstest (grub-fstest.c:433)
1164 ==2782220== by 0x4045A6: main (grub-fstest.c:772)
1165
1166 This happens when the process of reading the catalog file goes sufficiently
1167 wrong that there's an attempt to read the extent overflow file, which has
1168 not yet been loaded. Keep track of when the extent overflow file is
1169 fully loaded and refuse to use it before then.
1170
1171 The load valgrind doesn't like is btree->nodesize, and that's then used
1172 to allocate a data structure. It looks like there are subsequently a lot
1173 of reads based on that pointer so OOB reads are likely, and indeed crashes
1174 (albeit difficult-to-replicate ones) have been observed in fuzzing.
1175
1176 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1177
11782021-03-02 Daniel Axtens <dja@axtens.net>
1179
1180 fs/hfsplus: Don't fetch a key beyond the end of the node
1181 Otherwise you get a wild pointer, leading to a bunch of invalid reads.
1182 Check it falls inside the given node.
1183
1184 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1185
11862021-03-02 Daniel Axtens <dja@axtens.net>
1187
1188 fs/fshelp: Catch impermissibly large block sizes in read helper
1189 A fuzzed HFS+ filesystem had log2blocksize = 22. This gave
1190 log2blocksize + GRUB_DISK_SECTOR_BITS = 31. 1 << 31 = 0x80000000,
1191 which is -1 as an int. This caused some wacky behavior later on in
1192 the function, leading to out-of-bounds writes on the destination buffer.
1193
1194 Catch log2blocksize + GRUB_DISK_SECTOR_BITS >= 31. We could be stricter,
1195 but this is the minimum that will prevent integer size weirdness.
1196
1197 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1198
11992021-03-02 Daniel Axtens <dja@axtens.net>
1200
1201 term/gfxterm: Don't set up a font with glyphs that are too big
1202 Catch the case where we have a font so big that it causes the number of
1203 rows or columns to be 0. Currently we continue and allocate a
1204 virtual_screen.text_buffer of size 0. We then try to use that for glpyhs
1205 and things go badly.
1206
1207 On the emu platform, malloc() may give us a valid pointer, in which case
1208 we'll access heap memory which we shouldn't. Alternatively, it may give us
1209 NULL, in which case we'll crash. For other platforms, if I understand
1210 grub_memalign() correctly, we will receive a valid but small allocation
1211 that we will very likely later overrun.
1212
1213 Prevent the creation of a virtual screen that isn't at least 40 cols
1214 by 12 rows. This is arbitrary, but it seems that if your width or height
1215 is half a standard 80x24 terminal, you're probably going to struggle to
1216 read anything anyway.
1217
1218 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1219
12202021-03-02 Daniel Axtens <dja@axtens.net>
1221
1222 video/readers/jpeg: Don't decode data before start of stream
1223 When a start of stream marker is encountered, we call grub_jpeg_decode_sos()
1224 which allocates space for a bitmap.
1225
1226 When a restart marker is encountered, we call grub_jpeg_decode_data() which
1227 then fills in that bitmap.
1228
1229 If we get a restart marker before the start of stream marker, we will
1230 attempt to write to a bitmap_ptr that hasn't been allocated. Catch this
1231 and bail out. This fixes an attempt to write to NULL.
1232
1233 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1234
12352021-03-02 Daniel Axtens <dja@axtens.net>
1236
1237 video/readers/jpeg: Catch OOB reads/writes in grub_jpeg_decode_du()
1238 The key line is:
1239
1240 du[jpeg_zigzag_order[pos]] = val * (int) data->quan_table[qt][pos];
1241
1242 jpeg_zigzag_order is grub_uint8_t[64].
1243
1244 I don't understand JPEG decoders quite well enough to explain what's
1245 going on here. However, I observe sometimes pos=64, which leads to an
1246 OOB read of the jpeg_zigzag_order global then an OOB write to du.
1247 That leads to various unpleasant memory corruption conditions.
1248
1249 Catch where pos >= ARRAY_SIZE(jpeg_zigzag_order) and bail.
1250
1251 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1252
12532021-03-02 Daniel Axtens <dja@axtens.net>
1254
1255 video/readers/jpeg: Catch files with unsupported quantization or Huffman tables
1256 Our decoder only supports 2 quantization tables. If a file asks for
1257 a quantization table with index > 1, reject it.
1258
1259 Similarly, our decoder only supports 4 Huffman tables. If a file asks
1260 for a Huffman table with index > 3, reject it.
1261
1262 This fixes some out of bounds reads. It's not clear what degree of control
1263 over subsequent execution could be gained by someone who can carefully
1264 set up the contents of memory before loading an invalid JPEG file.
1265
1266 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1267
12682021-03-02 Daniel Axtens <dja@axtens.net>
1269
1270 kern/misc: Always set *end in grub_strtoull()
1271 Currently, if there is an error in grub_strtoull(), *end is not set.
1272 This differs from the usual behavior of strtoull(), and also means that
1273 some callers may use an uninitialized value for *end.
1274
1275 Set *end unconditionally.
1276
1277 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1278
12792021-03-02 Daniel Axtens <dja@axtens.net>
1280
1281 commands/menuentry: Fix quoting in setparams_prefix()
1282 Commit 9acdcbf32542 (use single quotes in menuentry setparams command)
1283 says that expressing a quoted single quote will require 3 characters. It
1284 actually requires (and always did require!) 4 characters:
1285
1286 str: a'b => a'\''b
1287 len: 3 => 6 (2 for the letters + 4 for the quote)
1288
1289 This leads to not allocating enough memory and thus out of bounds writes
1290 that have been observed to cause heap corruption.
1291
1292 Allocate 4 bytes for each single quote.
1293
1294 Commit 22e7dbb2bb81 (Fix quoting in legacy parser.) does the same
1295 quoting, but it adds 3 as extra overhead on top of the single byte that
1296 the quote already needs. So it's correct.
1297
1298 Fixes: 9acdcbf32542 (use single quotes in menuentry setparams command)
1299 Fixes: CVE-2021-20233
1300
1301 Reported-by: Daniel Axtens <dja@axtens.net>
1302 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1303
13042021-03-02 Daniel Axtens <dja@axtens.net>
1305
1306 script/execute: Don't crash on a "for" loop with no items
1307 The following crashes the parser:
1308
1309 for x in; do
1310 0
1311 done
1312
1313 This is because grub_script_arglist_to_argv() doesn't consider the
1314 possibility that arglist is NULL. Catch that explicitly.
1315
1316 This avoids a NULL pointer dereference.
1317
1318 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1319
13202021-03-02 Daniel Axtens <dja@axtens.net>
1321
1322 lib/arg: Block repeated short options that require an argument
1323 Fuzzing found the following crash:
1324
1325 search -hhhhhhhhhhhhhf
1326
1327 We didn't allocate enough option space for 13 hints because the
1328 allocation code counts the number of discrete arguments (i.e. argc).
1329 However, the shortopt parsing code will happily keep processing
1330 a combination of short options without checking if those short
1331 options require an argument. This means you can easily end writing
1332 past the allocated option space.
1333
1334 This fixes a OOB write which can cause heap corruption.
1335
1336 Fixes: CVE-2021-20225
1337
1338 Reported-by: Daniel Axtens <dja@axtens.net>
1339 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1340
13412021-03-02 Daniel Axtens <dja@axtens.net>
1342
1343 script/execute: Avoid crash when using "$#" outside a function scope
1344 "$#" represents the number of arguments to a function. It is only
1345 defined in a function scope, where "scope" is non-NULL. Currently,
1346 if we attempt to evaluate "$#" outside a function scope, "scope" will
1347 be NULL and we will crash with a NULL pointer dereference.
1348
1349 Do not attempt to count arguments for "$#" if "scope" is NULL. This
1350 will result in "$#" being interpreted as an empty string if evaluated
1351 outside a function scope.
1352
1353 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1354
13552021-03-02 Daniel Axtens <dja@axtens.net>
1356
1357 commands/ls: Require device_name is not NULL before printing
1358 This can be triggered with:
1359 ls -l (0 0*)
1360 and causes a NULL deref in grub_normal_print_device_info().
1361
1362 I'm not sure if there's any implication with the IEEE 1275 platform.
1363
1364 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1365
13662021-03-02 Daniel Axtens <dja@axtens.net>
1367
1368 script/execute: Fix NULL dereference in grub_script_execute_cmdline()
1369 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1370
13712021-03-02 Darren Kenny <darren.kenny@oracle.com>
1372
1373 util/glue-efi: Fix incorrect use of a possibly negative value
1374 It is possible for the ftell() function to return a negative value,
1375 although it is fairly unlikely here, we should be checking for
1376 a negative value before we assign it to an unsigned value.
1377
1378 Fixes: CID 73744
1379
1380 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1381
13822021-03-02 Darren Kenny <darren.kenny@oracle.com>
1383
1384 util/grub-editenv: Fix incorrect casting of a signed value
1385 The return value of ftell() may be negative (-1) on error. While it is
1386 probably unlikely to occur, we should not blindly cast to an unsigned
1387 value without first testing that it is not negative.
1388
1389 Fixes: CID 73856
1390
1391 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1392
13932021-03-02 Daniel Kiper <daniel.kiper@oracle.com>
1394
1395 util/grub-install: Fix NULL pointer dereferences
1396 Two grub_device_open() calls does not have associated NULL checks
1397 for returned values. Fix that and appease the Coverity.
1398
1399 Fixes: CID 314583
1400
1401 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
1402
14032021-03-02 Paulo Flabiano Smorigo <pfsmorigo@canonical.com>
1404
1405 loader/xnu: Check if pointer is NULL before using it
1406 Fixes: CID 73654
1407
1408 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1409
14102021-03-02 Marco A Benatto <mbenatto@redhat.com>
1411
1412 loader/xnu: Free driverkey data when an error is detected in grub_xnu_writetree_toheap()
1413 ... to avoid memory leaks.
1414
1415 Fixes: CID 96640
1416
1417 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1418
14192021-03-02 Darren Kenny <darren.kenny@oracle.com>
1420
1421 loader/xnu: Fix memory leak
1422 The code here is finished with the memory stored in name, but it only
1423 frees it if there curvalue is valid, while it could actually free it
1424 regardless.
1425
1426 The fix is a simple relocation of the grub_free() to before the test
1427 of curvalue.
1428
1429 Fixes: CID 96646
1430
1431 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1432
14332021-03-02 Darren Kenny <darren.kenny@oracle.com>
1434
1435 loader/bsd: Check for NULL arg up-front
1436 The code in the next block suggests that it is possible for .set to be
1437 true but .arg may still be NULL.
1438
1439 This code assumes that it is never NULL, yet later is testing if it is
1440 NULL - that is inconsistent.
1441
1442 So we should check first if .arg is not NULL, and remove this check that
1443 is being flagged by Coverity since it is no longer required.
1444
1445 Fixes: CID 292471
1446
1447 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1448
14492021-03-02 Darren Kenny <darren.kenny@oracle.com>
1450
1451 gfxmenu/gui_list: Remove code that coverity is flagging as dead
1452 The test of value for NULL before calling grub_strdup() is not required,
1453 since the if condition prior to this has already tested for value being
1454 NULL and cannot reach this code if it is.
1455
1456 Fixes: CID 73659
1457
1458 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1459
14602021-03-02 Darren Kenny <darren.kenny@oracle.com>
1461
1462 video/readers/jpeg: Test for an invalid next marker reference from a jpeg file
1463 While it may never happen, and potentially could be caught at the end of
1464 the function, it is worth checking up front for a bad reference to the
1465 next marker just in case of a maliciously crafted file being provided.
1466
1467 Fixes: CID 73694
1468
1469 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1470
14712021-03-02 Darren Kenny <darren.kenny@oracle.com>
1472
1473 video/fb/video_fb: Fix possible integer overflow
1474 It is minimal possibility that the values being used here will overflow.
1475 So, change the code to use the safemath function grub_mul() to ensure
1476 that doesn't happen.
1477
1478 Fixes: CID 73761
1479
1480 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1481
14822021-03-02 Darren Kenny <darren.kenny@oracle.com>
1483
1484 video/fb/video_fb: Fix multiple integer overflows
1485 The calculation of the unsigned 64-bit value is being generated by
1486 multiplying 2, signed or unsigned, 32-bit integers which may overflow
1487 before promotion to unsigned 64-bit. Fix all of them.
1488
1489 Fixes: CID 73703, CID 73767, CID 73833
1490
1491 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1492
14932021-03-02 Darren Kenny <darren.kenny@oracle.com>
1494
1495 video/fb/fbfill: Fix potential integer overflow
1496 The multiplication of 2 unsigned 32-bit integers may overflow before
1497 promotion to unsigned 64-bit. We should ensure that the multiplication
1498 is done with overflow detection. Additionally, use grub_sub() for
1499 subtraction.
1500
1501 Fixes: CID 73640, CID 73697, CID 73702, CID 73823
1502
1503 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1504
15052021-03-02 Darren Kenny <darren.kenny@oracle.com>
1506
1507 video/efi_gop: Remove unnecessary return value of grub_video_gop_fill_mode_info()
1508 The return value of grub_video_gop_fill_mode_info() is never able to be
1509 anything other than GRUB_ERR_NONE. So, rather than continue to return
1510 a value and checking it each time, it is more correct to redefine the
1511 function to not return anything and remove checks of its return value
1512 altogether.
1513
1514 Fixes: CID 96701
1515
1516 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1517
15182021-03-02 Darren Kenny <darren.kenny@oracle.com>
1519
1520 commands/probe: Fix a resource leak when probing disks
1521 Every other return statement in this code is calling grub_device_close()
1522 to clean up dev before returning. This one should do that too.
1523
1524 Fixes: CID 292443
1525
1526 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1527
15282021-03-02 Chris Coulson <chris.coulson@canonical.com>
1529
1530 commands/hashsum: Fix a memory leak
1531 check_list() uses grub_file_getline(), which allocates a buffer.
1532 If the hash list file contains invalid lines, the function leaks
1533 this buffer when it returns an error.
1534
1535 Fixes: CID 176635
1536
1537 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1538
15392021-03-02 Darren Kenny <darren.kenny@oracle.com>
1540
1541 normal/completion: Fix leaking of memory when processing a completion
1542 It is possible for the code to reach the end of the function without
1543 freeing the memory allocated to argv and argc still to be 0.
1544
1545 We should always call grub_free(argv). The grub_free() will handle
1546 a NULL argument correctly if it reaches that code without the memory
1547 being allocated.
1548
1549 Fixes: CID 96672
1550
1551 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1552
15532021-03-02 Darren Kenny <darren.kenny@oracle.com>
1554
1555 syslinux: Fix memory leak while parsing
1556 In syslinux_parse_real() the 2 points where return is being called
1557 didn't release the memory stored in buf which is no longer required.
1558
1559 Fixes: CID 176634
1560
1561 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1562
15632021-03-02 Darren Kenny <darren.kenny@oracle.com>
1564
1565 libgcrypt/mpi: Fix possible NULL dereference
1566 The code in gcry_mpi_scan() assumes that buffer is not NULL, but there
1567 is no explicit check for that, so we add one.
1568
1569 Fixes: CID 73757
1570
1571 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1572
15732021-03-02 Darren Kenny <darren.kenny@oracle.com>
1574
1575 libgcrypt/mpi: Fix possible unintended sign extension
1576 The array of unsigned char gets promoted to a signed 32-bit int before
1577 it is finally promoted to a size_t. There is the possibility that this
1578 may result in the signed-bit being set for the intermediate signed
1579 32-bit int. We should ensure that the promotion is to the correct type
1580 before we bitwise-OR the values.
1581
1582 Fixes: CID 96697
1583
1584 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1585
15862021-03-02 Darren Kenny <darren.kenny@oracle.com>
1587
1588 affs: Fix memory leaks
1589 The node structure reference is being allocated but not freed if it
1590 reaches the end of the function. If any of the hooks had returned
1591 a non-zero value, then node would have been copied in to the context
1592 reference, but otherwise node is not stored and should be freed.
1593
1594 Similarly, the call to grub_affs_create_node() replaces the allocated
1595 memory in node with a newly allocated structure, leaking the existing
1596 memory pointed by node.
1597
1598 Finally, when dir->parent is set, then we again replace node with newly
1599 allocated memory, which seems unnecessary when we copy in the values
1600 from dir->parent immediately after.
1601
1602 Fixes: CID 73759
1603
1604 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1605
16062021-03-02 Darren Kenny <darren.kenny@oracle.com>
1607
1608 zfsinfo: Correct a check for error allocating memory
1609 While arguably the check for grub_errno is correct, we should really be
1610 checking the return value from the function since it is always possible
1611 that grub_errno was set elsewhere, making this code behave incorrectly.
1612
1613 Fixes: CID 73668
1614
1615 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1616
16172021-03-02 Darren Kenny <darren.kenny@oracle.com>
1618
1619 zfs: Fix possible integer overflows
1620 In all cases the problem is that the value being acted upon by
1621 a left-shift is a 32-bit number which is then being used in the
1622 context of a 64-bit number.
1623
1624 To avoid overflow we ensure that the number being shifted is 64-bit
1625 before the shift is done.
1626
1627 Fixes: CID 73684, CID 73695, CID 73764
1628
1629 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1630
16312021-03-02 Paulo Flabiano Smorigo <pfsmorigo@canonical.com>
1632
1633 zfs: Fix resource leaks while constructing path
1634 There are several exit points in dnode_get_path() that are causing possible
1635 memory leaks.
1636
1637 In the while(1) the correct exit mechanism should not be to do a direct return,
1638 but to instead break out of the loop, setting err first if it is not already set.
1639
1640 The reason behind this is that the dnode_path is a linked list, and while doing
1641 through this loop, it is being allocated and built up - the only way to
1642 correctly unravel it is to traverse it, which is what is being done at the end
1643 of the function outside of the loop.
1644
1645 Several of the existing exit points correctly did a break, but not all so this
1646 change makes that more consistent and should resolve the leaking of memory as
1647 found by Coverity.
1648
1649 Fixes: CID 73741
1650
1651 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1652
16532021-03-02 Darren Kenny <darren.kenny@oracle.com>
1654
1655 zfs: Fix possible negative shift operation
1656 While it is possible for the return value from zfs_log2() to be zero
1657 (0), it is quite unlikely, given that the previous assignment to blksz
1658 is shifted up by SPA_MINBLOCKSHIFT (9) before 9 is subtracted at the
1659 assignment to epbs.
1660
1661 But, while unlikely during a normal operation, it may be that a carefully
1662 crafted ZFS filesystem could result in a zero (0) value to the
1663 dn_datalbkszsec field, which means that the shift left does nothing
1664 and assigns zero (0) to blksz, resulting in a negative epbs value.
1665
1666 Fixes: CID 73608
1667
1668 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1669
16702021-03-02 Darren Kenny <darren.kenny@oracle.com>
1671
1672 hfsplus: Check that the volume name length is valid
1673 HFS+ documentation suggests that the maximum filename and volume name is
1674 255 Unicode characters in length.
1675
1676 So, when converting from big-endian to little-endian, we should ensure
1677 that the name of the volume has a length that is between 0 and 255,
1678 inclusive.
1679
1680 Fixes: CID 73641
1681
1682 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1683
16842021-03-02 Darren Kenny <darren.kenny@oracle.com>
1685
1686 disk/cryptodisk: Fix potential integer overflow
1687 The encrypt and decrypt functions expect a grub_size_t. So, we need to
1688 ensure that the constant bit shift is using grub_size_t rather than
1689 unsigned int when it is performing the shift.
1690
1691 Fixes: CID 307788
1692
1693 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1694
16952021-03-02 Darren Kenny <darren.kenny@oracle.com>
1696
1697 disk/ldm: Fix memory leak on uninserted lv references
1698 The problem here is that the memory allocated to the variable lv is not
1699 yet inserted into the list that is being processed at the label fail2.
1700
1701 As we can already see at line 342, which correctly frees lv before going
1702 to fail2, we should also be doing that at these earlier jumps to fail2.
1703
1704 Fixes: CID 73824
1705
1706 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1707
17082021-03-02 Paulo Flabiano Smorigo <pfsmorigo@canonical.com>
1709
1710 disk/ldm: If failed then free vg variable too
1711 Fixes: CID 73809
1712
1713 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1714
17152021-03-02 Marco A Benatto <mbenatto@redhat.com>
1716
1717 disk/ldm: Make sure comp data is freed before exiting from make_vg()
1718 Several error handling paths in make_vg() do not free comp data before
1719 jumping to fail2 label and returning from the function. This will leak
1720 memory. So, let's fix all issues of that kind.
1721
1722 Fixes: CID 73804
1723
1724 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1725
17262021-03-02 Darren Kenny <darren.kenny@oracle.com>
1727
1728 kern/partition: Check for NULL before dereferencing input string
1729 There is the possibility that the value of str comes from an external
1730 source and continuing to use it before ever checking its validity is
1731 wrong. So, needs fixing.
1732
1733 Additionally, drop unneeded part initialization.
1734
1735 Fixes: CID 292444
1736
1737 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1738
17392021-03-02 Darren Kenny <darren.kenny@oracle.com>
1740
1741 zstd: Initialize seq_t structure fully
1742 While many compilers will initialize this to zero, not all will, so it
1743 is better to be sure that fields not being explicitly set are at known
1744 values, and there is code that checks this fields value elsewhere in the
1745 code.
1746
1747 Fixes: CID 292440
1748
1749 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1750
17512021-03-02 Darren Kenny <darren.kenny@oracle.com>
1752
1753 io/lzopio: Resolve unnecessary self-assignment errors
1754 These 2 assignments are unnecessary since they are just assigning
1755 to themselves.
1756
1757 Fixes: CID 73643
1758
1759 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1760
17612021-03-02 Darren Kenny <darren.kenny@oracle.com>
1762
1763 gnulib/regcomp: Fix uninitialized re_token
1764 This issue has been fixed in the latest version of gnulib, so to
1765 maintain consistency, I've backported that change rather than doing
1766 something different.
1767
1768 Fixes: CID 73828
1769
1770 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1771
17722021-03-02 Darren Kenny <darren.kenny@oracle.com>
1773
1774 gnulib/regexec: Fix possible null-dereference
1775 It appears to be possible that the mctx->state_log field may be NULL,
1776 and the name of this function, clean_state_log_if_needed(), suggests
1777 that it should be checking that it is valid to be cleaned before
1778 assuming that it does.
1779
1780 Fixes: CID 86720
1781
1782 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1783
17842021-03-02 Darren Kenny <darren.kenny@oracle.com>
1785
1786 gnulib/argp-help: Fix dereference of a possibly NULL state
1787 All other instances of call to __argp_failure() where there is
1788 a dgettext() call is first checking whether state is NULL before
1789 attempting to dereference it to get the root_argp->argp_domain.
1790
1791 Fixes: CID 292436
1792
1793 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1794
17952021-03-02 Darren Kenny <darren.kenny@oracle.com>
1796
1797 gnulib/regcomp: Fix uninitialized token structure
1798 The code is assuming that the value of br_token.constraint was
1799 initialized to zero when it wasn't.
1800
1801 While some compilers will ensure that, not all do, so it is better to
1802 fix this explicitly than leave it to chance.
1803
1804 Fixes: CID 73749
1805
1806 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1807
18082021-03-02 Darren Kenny <darren.kenny@oracle.com>
1809
1810 gnulib/regexec: Resolve unused variable
1811 This is a really minor issue where a variable is being assigned to but
1812 not checked before it is overwritten again.
1813
1814 The reason for this issue is that we are not building with DEBUG set and
1815 this in turn means that the assert() that reads the value of the
1816 variable match_last is being processed out.
1817
1818 The solution, move the assignment to match_last in to an ifdef DEBUG too.
1819
1820 Fixes: CID 292459
1821
1822 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1823
18242021-03-02 Darren Kenny <darren.kenny@oracle.com>
1825
1826 kern/efi/mm: Fix possible NULL pointer dereference
1827 The model of grub_efi_get_memory_map() is that if memory_map is NULL,
1828 then the purpose is to discover how much memory should be allocated to
1829 it for the subsequent call.
1830
1831 The problem here is that with grub_efi_is_finished set to 1, there is no
1832 check at all that the function is being called with a non-NULL memory_map.
1833
1834 While this MAY be true, we shouldn't assume it.
1835
1836 The solution to this is to behave as expected, and if memory_map is NULL,
1837 then don't try to use it and allow memory_map_size to be filled in, and
1838 return 0 as is done later in the code if the buffer is too small (or NULL).
1839
1840 Additionally, drop unneeded ret = 1.
1841
1842 Fixes: CID 96632
1843
1844 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1845
18462021-03-02 Darren Kenny <darren.kenny@oracle.com>
1847
1848 kern/efi: Fix memory leak on failure
1849 Free the memory allocated to name before returning on failure.
1850
1851 Fixes: CID 296222
1852
1853 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1854
18552021-03-02 Darren Kenny <darren.kenny@oracle.com>
1856
1857 kern/parser: Fix resource leak if argc == 0
1858 After processing the command-line yet arriving at the point where we are
1859 setting argv, we are allocating memory, even if argc == 0, which makes
1860 no sense since we never put anything into the allocated argv.
1861
1862 The solution is to simply return that we've successfully processed the
1863 arguments but that argc == 0, and also ensure that argv is NULL when
1864 we're not allocating anything in it.
1865
1866 There are only 2 callers of this function, and both are handling a zero
1867 value in argc assuming nothing is allocated in argv.
1868
1869 Fixes: CID 96680
1870
1871 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1872
18732021-03-02 Darren Kenny <darren.kenny@oracle.com>
1874
1875 net/tftp: Fix dangling memory pointer
1876 The static code analysis tool, Parfait, reported that the valid of
1877 file->data was left referencing memory that was freed by the call to
1878 grub_free(data) where data was initialized from file->data.
1879
1880 To ensure that there is no unintentional access to this memory
1881 referenced by file->data we should set the pointer to NULL.
1882
1883 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1884
18852021-03-02 Darren Kenny <darren.kenny@oracle.com>
1886
1887 net/net: Fix possible dereference to of a NULL pointer
1888 It is always possible that grub_zalloc() could fail, so we should check for
1889 a NULL return. Otherwise we run the risk of dereferencing a NULL pointer.
1890
1891 Fixes: CID 296221
1892
1893 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1894
18952021-03-02 Darren Kenny <darren.kenny@oracle.com>
1896
1897 mmap: Fix memory leak when iterating over mapped memory
1898 When returning from grub_mmap_iterate() the memory allocated to present
1899 is not being released causing it to leak.
1900
1901 Fixes: CID 96655
1902
1903 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1904
19052021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1906
1907 usb: Avoid possible out-of-bound accesses caused by malicious devices
1908 The maximum number of configurations and interfaces are fixed but there is
1909 no out-of-bound checking to prevent a malicious USB device to report large
1910 values for these and cause accesses outside the arrays' memory.
1911
1912 Fixes: CVE-2020-25647
1913
1914 Reported-by: Joseph Tartaro <joseph.tartaro@ioactive.com>
1915 Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
1916 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1917
19182021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1919
1920 dl: Only allow unloading modules that are not dependencies
1921 When a module is attempted to be removed its reference counter is always
1922 decremented. This means that repeated rmmod invocations will cause the
1923 module to be unloaded even if another module depends on it.
1924
1925 This may lead to a use-after-free scenario allowing an attacker to execute
1926 arbitrary code and by-pass the UEFI Secure Boot protection.
1927
1928 While being there, add the extern keyword to some function declarations in
1929 that header file.
1930
1931 Fixes: CVE-2020-25632
1932
1933 Reported-by: Chris Coulson <chris.coulson@canonical.com>
1934 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1935
19362021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1937
1938 docs: Document the cutmem command
1939 The command is not present in the docs/grub.texi user documentation.
1940
1941 Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
1942 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
1943
19442021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1945
1946 loader/xnu: Don't allow loading extension and packages when locked down
1947 The shim_lock verifier validates the XNU kernels but no its extensions
1948 and packages. Prevent these to be loaded when the GRUB is locked down.
1949
1950 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1951
19522021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1953
1954 gdb: Restrict GDB access when locked down
1955 The gdbstub* commands allow to start and control a GDB stub running on
1956 local host that can be used to connect from a remote debugger. Restrict
1957 this functionality when the GRUB is locked down.
1958
1959 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1960
19612021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1962
1963 commands/hdparm: Restrict hdparm command when locked down
1964 The command can be used to get/set ATA disk parameters. Some of these can
1965 be dangerous since change the disk behavior. Restrict it when locked down.
1966
1967 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1968
19692021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1970
1971 commands/setpci: Restrict setpci command when locked down
1972 This command can set PCI devices register values, which makes it dangerous
1973 in a locked down configuration. Restrict it so can't be used on this setup.
1974
1975 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1976
19772021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1978
1979 commands: Restrict commands that can load BIOS or DT blobs when locked down
1980 There are some more commands that should be restricted when the GRUB is
1981 locked down. Following is the list of commands and reasons to restrict:
1982
1983 * fakebios: creates BIOS-like structures for backward compatibility with
1984 existing OSes. This should not be allowed when locked down.
1985
1986 * loadbios: reads a BIOS dump from storage and loads it. This action
1987 should not be allowed when locked down.
1988
1989 * devicetree: loads a Device Tree blob and passes it to the OS. It replaces
1990 any Device Tree provided by the firmware. This also should
1991 not be allowed when locked down.
1992
1993 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1994
19952021-03-02 Javier Martinez Canillas <javierm@redhat.com>
1996
1997 mmap: Don't register cutmem and badram commands when lockdown is enforced
1998 The cutmem and badram commands can be used to remove EFI memory regions
1999 and potentially disable the UEFI Secure Boot. Prevent the commands to be
2000 registered if the GRUB is locked down.
2001
2002 Fixes: CVE-2020-27779
2003
2004 Reported-by: Teddy Reed <teddy.reed@gmail.com>
2005 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2006
20072021-03-02 Javier Martinez Canillas <javierm@redhat.com>
2008
2009 acpi: Don't register the acpi command when locked down
2010 The command is not allowed when lockdown is enforced. Otherwise an
2011 attacker can instruct the GRUB to load an SSDT table to overwrite
2012 the kernel lockdown configuration and later load and execute
2013 unsigned code.
2014
2015 Fixes: CVE-2020-14372
2016
2017 Reported-by: Máté Kukri <km@mkukri.xyz>
2018 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019
20202021-03-02 Javier Martinez Canillas <javierm@redhat.com>
2021
2022 efi: Use grub_is_lockdown() instead of hardcoding a disabled modules list
2023 Now the GRUB can check if it has been locked down and this can be used to
2024 prevent executing commands that can be utilized to circumvent the UEFI
2025 Secure Boot mechanisms. So, instead of hardcoding a list of modules that
2026 have to be disabled, prevent the usage of commands that can be dangerous.
2027
2028 This not only allows the commands to be disabled on other platforms, but
2029 also properly separate the concerns. Since the shim_lock verifier logic
2030 should be only about preventing to run untrusted binaries and not about
2031 defining these kind of policies.
2032
2033 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2034
20352021-03-02 Javier Martinez Canillas <javierm@redhat.com>
2036
2037 efi: Lockdown the GRUB when the UEFI Secure Boot is enabled
2038 If the UEFI Secure Boot is enabled then the GRUB must be locked down
2039 to prevent executing code that can potentially be used to subvert its
2040 verification mechanisms.
2041
2042 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2043
20442021-03-02 Javier Martinez Canillas <javierm@redhat.com>
2045
2046 kern/lockdown: Set a variable if the GRUB is locked down
2047 It may be useful for scripts to determine whether the GRUB is locked
2048 down or not. Add the lockdown variable which is set to "y" when the GRUB
2049 is locked down.
2050
2051 Suggested-by: Dimitri John Ledkov <xnox@ubuntu.com>
2052 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2053
20542021-03-02 Javier Martinez Canillas <javierm@redhat.com>
2055
2056 kern: Add lockdown support
2057 When the GRUB starts on a secure boot platform, some commands can be
2058 used to subvert the protections provided by the verification mechanism and
2059 could lead to booting untrusted system.
2060
2061 To prevent that situation, allow GRUB to be locked down. That way the code
2062 may check if GRUB has been locked down and further restrict the commands
2063 that are registered or what subset of their functionality could be used.
2064
2065 The lockdown support adds the following components:
2066
2067 * The grub_lockdown() function which can be used to lockdown GRUB if,
2068 e.g., UEFI Secure Boot is enabled.
2069
2070 * The grub_is_lockdown() function which can be used to check if the GRUB
2071 was locked down.
2072
2073 * A verifier that flags OS kernels, the GRUB modules, Device Trees and ACPI
2074 tables as GRUB_VERIFY_FLAGS_DEFER_AUTH to defer verification to other
2075 verifiers. These files are only successfully verified if another registered
2076 verifier returns success. Otherwise, the whole verification process fails.
2077
2078 For example, PE/COFF binaries verification can be done by the shim_lock
2079 verifier which validates the signatures using the shim_lock protocol.
2080 However, the verification is not deferred directly to the shim_lock verifier.
2081 The shim_lock verifier is hooked into the verification process instead.
2082
2083 * A set of grub_{command,extcmd}_lockdown functions that can be used by
2084 code registering command handlers, to only register unsafe commands if
2085 the GRUB has not been locked down.
2086
2087 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2088
20892021-03-02 Marco A Benatto <mbenatto@redhat.com>
2090
2091 efi: Move the shim_lock verifier to the GRUB core
2092 Move the shim_lock verifier from its own module into the core image. The
2093 Secure Boot lockdown mechanism has the intent to prevent the load of any
2094 unsigned code or binary when Secure Boot is enabled.
2095
2096 The reason is that GRUB must be able to prevent executing untrusted code
2097 if UEFI Secure Boot is enabled, without depending on external modules.
2098
2099 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2100
21012021-03-02 Marco A Benatto <mbenatto@redhat.com>
2102
2103 verifiers: Move verifiers API to kernel image
2104 Move verifiers API from a module to the kernel image, so it can be
2105 used there as well. There are no functional changes in this patch.
2106
2107 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2108
21092020-12-18 Glenn Washburn <development@efficientek.com>
2110
2111 docs: Add documentation of disk size limitations
2112 Document the artificially imposed 1 EiB disk size limit and size limitations
2113 with LUKS volumes.
2114
2115 Fix a few punctuation issues.
2116
2117 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2118
21192020-12-18 Glenn Washburn <development@efficientek.com>
2120
2121 luks2: Use grub_log2ull() to calculate log_sector_size and improve readability
2122 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2123
2124 misc: Add grub_log2ull() macro for calculating log base 2 of 64-bit integers
2125 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2126
21272020-12-18 Glenn Washburn <development@efficientek.com>
2128
2129 mips: Enable __clzdi2()
2130 This patch is similar to commit 9dab2f51e (sparc: Enable __clzsi2() and
2131 __clzdi2()) but for MIPS target and __clzdi2() only, __clzsi2() was
2132 already enabled.
2133
2134 Suggested-by: Daniel Kiper <dkiper@net-space.pl>
2135 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2136
21372020-12-18 Glenn Washburn <development@efficientek.com>
2138
2139 luks2: Better error handling when setting up the cryptodisk
2140 Do some sanity checking on data coming from the LUKS2 header. If segment.size
2141 is "dynamic", verify that the offset is not past the end of disk. Otherwise,
2142 check for errors from grub_strtoull() when converting segment size from
2143 string. If a GRUB_ERR_BAD_NUMBER error was returned, then the string was
2144 not a valid parsable number, so skip the key. If GRUB_ERR_OUT_OF_RANGE was
2145 returned, then there was an overflow in converting to a 64-bit unsigned
2146 integer. So this could be a very large disk (perhaps large RAID array).
2147 In this case skip the key too. Additionally, enforce some other limits
2148 and fail if needed.
2149
2150 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2151
21522020-12-18 Glenn Washburn <development@efficientek.com>
2153
2154 luks2: Do not handle disks of size GRUB_DISK_SIZE_UNKNOWN for now
2155 Check to make sure that source disk has a known size. If not, print
2156 a message and return error. There are 4 cases where GRUB_DISK_SIZE_UNKNOWN
2157 is set (biosdisk, obdisk, ofdisk, and uboot), and in all those cases
2158 processing continues. So this is probably a bit conservative. However,
2159 3 of the cases seem pathological, and the other, biosdisk, happens when
2160 booting from a CD-ROM. Since I doubt booting from a LUKS2 volume on
2161 a CD-ROM is a big use case, we'll error until someone complains.
2162
2163 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2164
21652020-12-18 Glenn Washburn <development@efficientek.com>
2166
2167 luks2: Convert to crypt sectors from GRUB native sectors
2168 The function grub_disk_native_sectors(source) returns the number of sectors
2169 of source in GRUB native (512-byte) sectors, not source sized sectors. So
2170 the conversion needs to use GRUB_DISK_SECTOR_BITS, the GRUB native sector
2171 size.
2172
2173 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2174
21752020-12-12 Glenn Washburn <development@efficientek.com>
2176
2177 luks2: Error check segment.sector_size
2178 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2179
21802020-12-12 Glenn Washburn <development@efficientek.com>
2181
2182 cryptodisk: Properly handle non-512 byte sized sectors
2183 By default, dm-crypt internally uses an IV that corresponds to 512-byte
2184 sectors, even when a larger sector size is specified. What this means is
2185 that when using a larger sector size, the IV is incremented every sector.
2186 However, the amount the IV is incremented is the number of 512 byte blocks
2187 in a sector (i.e. 8 for 4K sectors). Confusingly the IV does not correspond
2188 to the number of, for example, 4K sectors. So each 512 byte cipher block in
2189 a sector will be encrypted with the same IV and the IV will be incremented
2190 afterwards by the number of 512 byte cipher blocks in the sector.
2191
2192 There are some encryption utilities which do it the intuitive way and have
2193 the IV equal to the sector number regardless of sector size (ie. the fifth
2194 sector would have an IV of 4 for each cipher block). And this is supported
2195 by dm-crypt with the iv_large_sectors option and also cryptsetup as of 2.3.3
2196 with the --iv-large-sectors, though not with LUKS headers (only with --type
2197 plain). However, support for this has not been included as grub does not
2198 support plain devices right now.
2199
2200 One gotcha here is that the encrypted split keys are encrypted with a hard-
2201 coded 512-byte sector size. So even if your data is encrypted with 4K sector
2202 sizes, the split key encrypted area must be decrypted with a block size of
2203 512 (ie the IV increments every 512 bytes). This made these changes less
2204 aesthetically pleasing than desired.
2205
2206 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2207
22082020-12-12 Glenn Washburn <development@efficientek.com>
2209
2210 luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors
2211 We need to convert the sectors from the size of the underlying device to the
2212 cryptodisk sector size; segment.size is in bytes which need to be converted
2213 to cryptodisk sectors as well.
2214
2215 Also, removed an empty statement.
2216
2217 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2218
22192020-12-12 Glenn Washburn <development@efficientek.com>
2220
2221 cryptodisk: Add macros GRUB_TYPE_U_MAX/MIN(type) to replace literals
2222 Add GRUB_TYPE_U_MAX/MIN(type) macros to get the max/min values for an
2223 unsigned number with size of type.
2224
2225 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2226
22272020-12-12 Glenn Washburn <development@efficientek.com>
2228
2229 cryptodisk: Add macro GRUB_TYPE_BITS() to replace some literals
2230 The new macro GRUB_TYPE_BITS(type) returns the number of bits
2231 allocated for type.
2232
2233 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2234
22352020-12-12 Glenn Washburn <development@efficientek.com>
2236
2237 luks2: Add string "index" to user strings using a json index
2238 This allows error messages to be more easily distinguishable between indexes
2239 and slot keys. The former include the string "index" in the error/debug
2240 string, and the later are surrounded in quotes.
2241
2242 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2243
22442020-12-12 Glenn Washburn <development@efficientek.com>
2245
2246 luks2: Rename json index variables to names that they are obviously json indexes
2247 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2248
22492020-12-12 Glenn Washburn <development@efficientek.com>
2250
2251 luks2: Use more intuitive object name instead of json index in user messages
2252 Use the object name in the json array rather than the 0 based index in the
2253 json array for keyslots, segments, and digests. This is less confusing for
2254 the end user. For example, say you have a LUKS2 device with a key in slot 1
2255 and slot 4. When using the password for slot 4 to unlock the device, the
2256 messages using the index of the keyslot will mention keyslot 1 (its a
2257 zero-based index). Furthermore, with this change the keyslot number will
2258 align with the number used to reference the keyslot when using the
2259 --key-slot argument to cryptsetup.
2260
2261 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2262
22632020-12-12 Glenn Washburn <development@efficientek.com>
2264
2265 luks2: Add idx member to struct grub_luks2_keyslot/segment/digest
2266 This allows code using these structs to know the named key associated with
2267 these json data structures. In the future we can use these to provide better
2268 error messages to the user.
2269
2270 Get rid of idx local variable in luks2_get_keyslot() which was overloaded to
2271 be used for both keyslot and segment slot keys.
2272
2273 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2274
22752020-12-12 Glenn Washburn <development@efficientek.com>
2276
2277 luks2: Make sure all fields of output argument in luks2_parse_digest() are written to
2278 We should assume that the output argument "out" is uninitialized and could
2279 have random data. So, make sure to initialize the segments and keyslots bit
2280 fields because potentially not all bits of those fields are written to.
2281 Otherwise, the digest could say it belongs to keyslots and segments that it
2282 does not.
2283
2284 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2285 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2286
22872020-12-12 Glenn Washburn <development@efficientek.com>
2288
2289 luks2: Remove unused argument in grub_error() call
2290 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2291 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2292
2293 luks2: Convert 8 spaces to tabs
2294 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2295 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2296
22972020-12-12 Glenn Washburn <development@efficientek.com>
2298
2299 misc: Add parentheses around ALIGN_UP() and ALIGN_DOWN() arguments
2300 This ensures that expected order of operations is preserved when arguments
2301 are expressions.
2302
2303 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2304 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2305
23062020-12-12 Glenn Washburn <development@efficientek.com>
2307
2308 disk: Rename grub_disk_get_size() to grub_disk_native_sectors()
2309 The function grub_disk_get_size() is confusingly named because it actually
2310 returns a sector count where the sectors are sized in the GRUB native sector
2311 size. Rename to something more appropriate.
2312
2313 Suggested-by: Daniel Kiper <daniel.kiper@oracle.com>
2314 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2315 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2316
23172020-12-12 Glenn Washburn <development@efficientek.com>
2318
2319 loopback: Do not automaticaly replace existing loopback dev, error instead
2320 If there is a loopback device with the same name as the one to be created,
2321 instead of closing the old one and replacing it with the new one, return an
2322 error instead. If the loopback device was created, its probably being used
2323 by something and just replacing it may cause GRUB to crash unexpectedly.
2324 This fixes obvious problems like "loopback d (d)/somefile". Its not too
2325 onerous to force the user to delete the loopback first with the "-d" switch.
2326
2327 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2328
23292020-12-12 Glenn Washburn <development@efficientek.com>
2330
2331 disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h
2332 There is a hardcoded maximum disk size that can be read or written from,
2333 currently set at 1 EiB in grub_disk_adjust_range(). Move the literal into a
2334 macro in disk.h, so our assumptions are more visible. This hard coded limit
2335 does not prevent using larger disks, just GRUB won't read/write past the
2336 limit. The comment accompanying this restriction didn't quite make sense to
2337 me, so its been modified too.
2338
2339 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2340
23412020-12-12 Glenn Washburn <development@efficientek.com>
2342
2343 fs: Fix block lists not being able to address to end of disk sometimes
2344 When checking if a block list goes past the end of the disk, make sure
2345 the total size of the disk is in GRUB native sector sizes, otherwise there
2346 will be blocks at the end of the disk inaccessible by block lists.
2347
2348 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2349
23502020-12-12 Vladimir Serbinenko <phcoder@gmail.com>
2351
2352 mbr: Document new limitations on MBR gap support
2353 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2354
23552020-12-12 Vladimir Serbinenko <phcoder@google.com>
2356
2357 mbr: Warn if MBR gap is small and user uses advanced modules
2358 We don't want to support small MBR gap in pair with anything but the
2359 simplest config of biosdisk + part_msdos + simple filesystem. In this
2360 path "simple filesystems" are all current filesystems except ZFS and
2361 Btrfs.
2362
2363 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2364
23652020-12-12 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
2366
2367 efi/tpm: Extract duplicate code into independent functions
2368 Part of the code logic for processing the return value of efi
2369 log_extend_event is repetitive and complicated. Extract the
2370 repetitive code into an independent function.
2371
2372 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2373
23742020-12-12 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
2375
2376 efi/tpm: Add debug information for device protocol and eventlog
2377 Add a number of debug logs to the tpm module. The condition tag
2378 for opening debugging is "tpm". On TPM machines, this will bring
2379 great convenience to diagnosis and debugging.
2380
2381 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2382
23832020-12-12 Daniel Kiper <daniel.kiper@oracle.com>
2384
2385 loader/linux: Report the UEFI Secure Boot status to the Linux kernel
2386 Now that the GRUB has a grub_efi_get_secureboot() function to check the
2387 UEFI Secure Boot status, use it to report that to the Linux kernel.
2388
2389 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2390
23912020-12-12 Javier Martinez Canillas <javierm@redhat.com>
2392
2393 efi: Only register shim_lock verifier if shim_lock protocol is found and SB enabled
2394 The shim_lock module registers a verifier to call shim's verify, but the
2395 handler is registered even when the shim_lock protocol was not installed.
2396
2397 This doesn't cause a NULL pointer dereference in shim_lock_write() because
2398 the shim_lock_init() function just returns GRUB_ERR_NONE if sl isn't set.
2399
2400 But in that case there's no point to even register the shim_lock verifier
2401 since won't do anything. Additionally, it is only useful when Secure Boot
2402 is enabled.
2403
2404 Finally, don't assume that the shim_lock protocol will always be present
2405 when the shim_lock_write() function is called, and check for it on every
2406 call to this function.
2407
2408 Reported-by: Michael Chang <mchang@suse.com>
2409 Reported-by: Peter Jones <pjones@redhat.com>
2410 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2411
24122020-12-11 Daniel Kiper <daniel.kiper@oracle.com>
2413
2414 efi: Add secure boot detection
2415 Introduce grub_efi_get_secureboot() function which returns whether
2416 UEFI Secure Boot is enabled or not on UEFI systems.
2417
2418 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2419
24202020-12-11 Daniel Kiper <daniel.kiper@oracle.com>
2421
2422 efi: Add a function to read EFI variables with attributes
2423 It will be used to properly detect and report UEFI Secure Boot status to
2424 the x86 Linux kernel. The functionality will be added by subsequent patches.
2425
2426 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2427
24282020-12-11 Daniel Kiper <daniel.kiper@oracle.com>
2429
2430 efi: Return grub_efi_status_t from grub_efi_get_variable()
2431 This is needed to properly detect and report UEFI Secure Boot status
2432 to the x86 Linux kernel. The functionality will be added by subsequent
2433 patches.
2434
2435 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2436
24372020-12-11 Daniel Kiper <daniel.kiper@oracle.com>
2438
2439 efi: Make shim_lock GUID and protocol type public
2440 The GUID will be used to properly detect and report UEFI Secure Boot
2441 status to the x86 Linux kernel. The functionality will be added by
2442 subsequent patches. The shim_lock protocol type is made public for
2443 completeness.
2444
2445 Additionally, fix formatting of four preceding GUIDs.
2446
2447 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2448
24492020-12-11 Javier Martinez Canillas <javierm@redhat.com>
2450
2451 arm/term: Fix linking error due multiple ps2_state definitions
2452 When building with --target=arm-linux-gnu --with-platform=coreboot
2453 a linking error occurs caused by multiple definitions of the
2454 ps2_state variable.
2455
2456 Mark them as static since they aren't used outside their compilation unit.
2457
2458 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2459
24602020-12-11 Javier Martinez Canillas <javierm@redhat.com>
2461
2462 include/grub/i386/linux.h: Include missing <grub/types.h> header
2463 This header uses types defined in <grub/types.h> but does not include it,
2464 which leads to compile errors like the following:
2465
2466 In file included from ../include/grub/cpu/linux.h:19,
2467 from kern/efi/sb.c:21:
2468 ../include/grub/i386/linux.h:80:3: error: unknown type name ‘grub_uint64_t’
2469 80 | grub_uint64_t addr;
2470
2471 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2472
24732020-12-11 Javier Martinez Canillas <javierm@redhat.com>
2474
2475 i386: Don't include <grub/cpu/linux.h> in coreboot and ieee1275 startup.S
2476 Nothing defined in the header file is used in the assembly code but it
2477 may lead to build errors if some headers are included through this and
2478 contains definitions that are not recognized by the assembler, e.g.:
2479
2480 ../include/grub/types.h: Assembler messages:
2481 ../include/grub/types.h:76: Error: no such instruction: `typedef signed char grub_int8_t'
2482 ../include/grub/types.h:77: Error: no such instruction: `typedef short grub_int16_t'
2483 ../include/grub/types.h:78: Error: no such instruction: `typedef int grub_int32_t'
2484
2485 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2486
24872020-11-20 Glenn Washburn <development@efficientek.com>
2488
2489 luks2: Rename index variable "j" to "i" in luks2_get_keyslot()
2490 Looping variable "j" was named such because the variable name "i" was taken.
2491 Since "i" has been renamed in the previous patch, we can rename "j" to "i".
2492
2493 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2494 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2495
24962020-11-20 Glenn Washburn <development@efficientek.com>
2497
2498 luks2: Rename variable "i" to "keyslot_idx" in luks2_get_keyslot()
2499 Variables named "i" are usually looping variables. So, rename it to
2500 "keyslot_idx" to ease luks2_get_keyslot() reading.
2501
2502 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2503 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2504
25052020-11-20 Glenn Washburn <development@efficientek.com>
2506
2507 luks2: Use correct index variable when looping in luks2_get_keyslot()
2508 The loop variable "j" should be used to index the digests and segments json
2509 array, instead of the variable "i", which is the keyslot index.
2510
2511 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2512 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2513
25142020-11-20 Glenn Washburn <development@efficientek.com>
2515
2516 luks2: Rename source disk variable named "disk" to "source" as in luks.c
2517 This makes it more obvious to the reader that the disk referred to is the
2518 source disk, as opposed to say the disk holding the cryptodisk.
2519
2520 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2521 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2522
25232020-11-20 Glenn Washburn <development@efficientek.com>
2524
2525 cryptodisk: Rename "offset" in grub_cryptodisk_t to "offset_sectors"
2526 This makes it clear that the offset represents sectors, not bytes, in
2527 order to improve readability.
2528
2529 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2530 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2531
25322020-11-20 Glenn Washburn <development@efficientek.com>
2533
2534 cryptodisk: Rename "total_length" field in grub_cryptodisk_t to "total_sectors"
2535 This creates an alignment with grub_disk_t naming of the same field and is
2536 more intuitive as to how it should be used.
2537
2538 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2539 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2540
25412020-11-20 Glenn Washburn <development@efficientek.com>
2542
2543 types: Define GRUB_CHAR_BIT based on compiler macro instead of using literal
2544 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2545
25462020-11-20 Javier Martinez Canillas <javierm@redhat.com>
2547
2548 include/grub/arm64/linux.h: Include missing <grub/types.h> header
2549 This header uses types defined in <grub/types.h> but does not include it,
2550 which leads to compile errors like the following:
2551
2552 ../include/grub/cpu/linux.h:27:3: error: unknown type name ‘grub_uint32_t’
2553 27 | grub_uint32_t code0; /* Executable code */
2554 | ^~~~~~~~~~~~~
2555
2556 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2557
25582020-11-20 Javier Martinez Canillas <javierm@redhat.com>
2559
2560 include/grub/arm/system.h: Include missing <grub/symbol.h> header
2561 The header uses the EXPORT_FUNC() macro defined in <grub/types.h> but
2562 doesn't include it, which leads to the following compile error on arm:
2563
2564 ../include/grub/cpu/system.h:12:13: error: ‘EXPORT_FUNC’ declared as function returning a function
2565 12 | extern void EXPORT_FUNC(grub_arm_disable_caches_mmu) (void);
2566 | ^~~~~~~~~~~
2567 ../include/grub/cpu/system.h:12:1: warning: parameter names (without types) in function declaration
2568 12 | extern void EXPORT_FUNC(grub_arm_disable_caches_mmu) (void);
2569 | ^~~~~~
2570 make[3]: *** [Makefile:36581: kern/efi/kernel_exec-sb.o] Error 1
2571
2572 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2573
25742020-11-20 Daniel Axtens <dja@axtens.net>
2575
2576 docs: grub-install --pubkey has been supported for some time
2577 grub-install --pubkey is supported, so we can now document it.
2578
2579 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2580
25812020-11-20 Daniel Axtens <dja@axtens.net>
2582
2583 docs: grub-install is no longer a shell script
2584 Since commit cd46aa6cefab in 2013, grub-install hasn't been a shell
2585 script. The para doesn't really add that much, especially since it's
2586 the user manual, so just drop it.
2587
2588 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2589
25902020-10-30 Jacob Kroon <jacob.kroon@gmail.com>
2591
2592 Makefile: Remove unused GRUB_PKGLIBDIR definition
2593 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2594
25952020-10-30 Daniel Axtens <dja@axtens.net>
2596
2597 lzma: Fix compilation error under clang 10
2598 Compiling under clang 10 gives:
2599
2600 grub-core/lib/LzmaEnc.c:1362:9: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]
2601 {
2602 ^
2603 grub-core/lib/LzmaEnc.c:1358:7: note: previous statement is here
2604 if (repIndex == 0)
2605 ^
2606 1 error generated.
2607
2608 It's not really that unclear in context: there's a commented-out
2609 if-statement. But tweak the alignment anyway so that clang is happy.
2610
2611 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2612
26132020-10-30 Cao jin <caoj.fnst@cn.fujitsu.com>
2614
2615 kern/i386/realmode: Update comment
2616 Commit b81d609e4c did not update it.
2617
2618 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2619
26202020-10-30 Glenn Washburn <development@efficientek.com>
2621
2622 cryptodisk: Fix cipher IV mode "plain64" always being set as "plain"
2623 When setting cipher IV mode, detection is done by prefix matching the
2624 cipher IV mode part of the cipher mode string. Since "plain" matches
2625 "plain64", we must check for "plain64" first. Otherwise, "plain64" will
2626 be detected as "plain".
2627
2628 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2629 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2630
26312020-09-18 Glenn Washburn <development@efficientek.com>
2632
2633 crypto: Remove GPG_ERROR_CFLAGS from gpg_err_code_t enum
2634 This was probably added by accident when originally creating the file.
2635
2636 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2637
26382020-09-18 Glenn Washburn <development@efficientek.com>
2639
2640 script: Do not allow a delimiter between function name and block start
2641 Currently the following is valid syntax but should be a syntax error:
2642
2643 grub> function f; { echo HERE; }
2644 grub> f
2645 HERE
2646
2647 This fix is not backward compatible, but current syntax is not documented
2648 either and has no functional value. So any scripts with this unintended
2649 syntax are technically syntactically incorrect and should not be relying
2650 on this behavior.
2651
2652 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2653
26542020-09-18 Glenn Washburn <development@efficientek.com>
2655
2656 docs: Support for loading and concatenating multiple initrds
2657 This has been available since January of 2012 but has not been documented.
2658
2659 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2660
26612020-09-18 Glenn Washburn <development@efficientek.com>
2662
2663 lexer: char const * should be const char *
2664 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2665
2666 cryptodisk: Use cipher name instead of object in error message
2667 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2668
26692020-09-18 Glenn Washburn <development@efficientek.com>
2670
2671 tests: F2FS test should use MOUNTDEVICE like other tests
2672 LODEVICES is not an array variable and should not be accessed as such.
2673 This allows the f2fs test to pass as it was failing because a device
2674 name had a space prepended to the path.
2675
2676 Acked-by: Jaegeuk Kim <jaegeuk@kernel.org>
2677 Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>
2678 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2679
26802020-09-18 Florian La Roche <Florian.LaRoche@gmail.com>
2681
2682 grub-mkconfig: If $hints is not set reduce the output into grub.cfg to just 1 line
2683 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2684
26852020-09-18 Petr Vorel <pvorel@suse.cz>
2686
2687 travis: Run bootstrap to fix build
2688 autogen.sh isn't enough:
2689
2690 $ ./autogen.sh
2691 Gnulib not yet bootstrapped; run ./bootstrap instead.
2692 The command "./autogen.sh" exited with 1.
2693
2694 Additionally, using bootstrap requires to install autopoint package.
2695
2696 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2697
26982020-09-18 Patrick Steinhardt <ps@pks.im>
2699
2700 luks2: Strip dashes off of the UUID
2701 The UUID header for LUKS2 uses a format with dashes, same as for
2702 LUKS(1). But while we strip these dashes for the latter, we don't for
2703 the former. This isn't wrong per se, but it's definitely inconsistent
2704 for users as they need to use the dashed format for LUKS2 and the
2705 non-dashed format for LUKS when e.g. calling "cryptomount -u $UUID".
2706
2707 Fix this inconsistency by stripping dashes off of the LUKS2 UUID.
2708
2709 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2710
27112020-09-18 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
2712
2713 efi/tpm: Remove unused functions and structures
2714 Although the tpm_execute() series of functions are defined they are not
2715 used anywhere. Several structures in the include/grub/efi/tpm.h header
2716 file are not used too. There is even nonexistent grub_tpm_init()
2717 declaration in this header. Delete all that unneeded stuff.
2718
2719 If somebody needs the functionality implemented in the dropped code then
2720 he/she can re-add it later. Now it needlessly increases the GRUB
2721 code/image size.
2722
2723 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2724
27252020-09-18 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
2726
2727 shim_lock: Enable module for all EFI architectures
2728 Like the tpm the shim_lock module is only enabled for x86_64 target.
2729 However, there's nothing specific to x86_64 in the implementation and
2730 it can be enabled for all EFI architectures.
2731
2732 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2733
27342020-09-18 Daniel Kiper <daniel.kiper@oracle.com>
2735
2736 efi/tpm: Fix typo in grub_efi_tpm2_protocol struct
2737 Rename get_active_pcr_blanks() to get_active_pcr_banks().
2738
2739 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
2740
27412020-09-18 Daniel Kiper <daniel.kiper@oracle.com>
2742
2743 i386/efi/init: Drop bogus include
2744 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
2745
27462020-09-18 Daniel Kiper <daniel.kiper@oracle.com>
2747
2748 docs: Fix devicetree command description
2749 Specifically fix the subsection and drop bogus reference to the GNU/Linux.
2750
2751 Reported-by: Patrick Higgins <higgi1pt@gmail.com>
2752 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
2753
27542020-09-18 Martin Whitaker <fsf@martin-whitaker.me.uk>
2755
2756 grub-install: Fix inverted test for NLS enabled when copying locales
2757 Commit 3d8439da8 (grub-install: Locale depends on nls) attempted to avoid
2758 copying locale files to the target directory when NLS was disabled.
2759 However the test is inverted, and it does the opposite.
2760
2761 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
2762
27632020-09-11 Javier Martinez Canillas <javierm@redhat.com>
2764
2765 tftp: Roll-over block counter to prevent data packets timeouts
2766 Commit 781b3e5efc3 (tftp: Do not use priority queue) caused a regression
2767 when fetching files over TFTP whose size is bigger than 65535 * block size.
2768
2769 grub> linux /images/pxeboot/vmlinuz
2770 grub> echo $?
2771 0
2772 grub> initrd /images/pxeboot/initrd.img
2773 error: timeout reading '/images/pxeboot/initrd.img'.
2774 grub> echo $?
2775 28
2776
2777 It is caused by the block number counter being a 16-bit field, which leads
2778 to a maximum file size of ((1 << 16) - 1) * block size. Because GRUB sets
2779 the block size to 1024 octets (by using the TFTP Blocksize Option from RFC
2780 2348 [0]), the maximum file size that can be transferred is 67107840 bytes.
2781
2782 The TFTP PROTOCOL (REVISION 2) RFC 1350 [1] does not mention what a client
2783 should do when a file size is bigger than the maximum, but most TFTP hosts
2784 support the block number counter to be rolled over. That is, acking a data
2785 packet with a block number of 0 is taken as if the 65356th block was acked.
2786
2787 It was working before because the block counter roll-over was happening due
2788 an overflow. But that got fixed by the mentioned commit, which led to the
2789 regression when attempting to fetch files larger than the maximum size.
2790
2791 To allow TFTP file transfers of unlimited size again, re-introduce a block
2792 counter roll-over so the data packets are acked preventing the timeouts.
2793
2794 [0]: https://tools.ietf.org/html/rfc2348
2795 [1]: https://tools.ietf.org/html/rfc1350
2796
2797 Fixes: 781b3e5efc3 (tftp: Do not use priority queue)
2798
2799 Suggested-by: Peter Jones <pjones@redhat.com>
2800 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2801
28022020-09-11 Florian La Roche <Florian.LaRoche@gmail.com>
2803
2804 templates: Remove unnecessary trailing semicolon
2805 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2806
28072020-09-11 Glenn Washburn <development@efficientek.com>
2808
2809 cryptodisk: Fix incorrect calculation of start sector
2810 Here dev is a grub_cryptodisk_t and dev->offset is offset in sectors of size
2811 native to the cryptodisk device. The sector is correctly transformed into
2812 native grub sector size, but then added to dev->offset which is not
2813 transformed. It would be nice if the type system would help us with this.
2814
2815 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2816 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2817
28182020-09-11 Glenn Washburn <development@efficientek.com>
2819
2820 cryptodisk: Unregister cryptomount command when removing module
2821 Reviewed-by: Patrick Steinhardt <ps@pks.im>
2822 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2823
28242020-09-11 Patrick Steinhardt <ps@pks.im>
2825
2826 luks2: Improve error reporting when decrypting/verifying key
2827 While we already set up error messages in both luks2_verify_key() and
2828 luks2_decrypt_key(), we do not ever print them. This makes it really
2829 hard to discover why a given key actually failed to decrypt a disk.
2830
2831 Improve this by including the error message in the user-visible output.
2832
2833 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2834
28352020-09-11 Patrick Steinhardt <ps@pks.im>
2836
2837 luks: Fix out-of-bounds copy of UUID
2838 When configuring a LUKS disk, we copy over the UUID from the LUKS header
2839 into the new grub_cryptodisk_t structure via grub_memcpy(). As size
2840 we mistakenly use the size of the grub_cryptodisk_t UUID field, which
2841 is guaranteed to be strictly bigger than the LUKS UUID field we're
2842 copying. As a result, the copy always goes out-of-bounds and copies some
2843 garbage from other surrounding fields. During runtime, this isn't
2844 noticed due to the fact that we always NUL-terminate the UUID and thus
2845 never hit the trailing garbage.
2846
2847 Fix the issue by using the size of the local stripped UUID field.
2848
2849 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2850
28512020-09-11 Patrick Steinhardt <ps@pks.im>
2852
2853 json: Remove invalid typedef redefinition
2854 The C standard does not allow for typedef redefinitions, even if they
2855 map to the same underlying type. In order to avoid including the
2856 jsmn.h in json.h and thus exposing jsmn's internals, we have exactly
2857 such a forward-declaring typedef in json.h. If enforcing the GNU99 C
2858 standard, clang may generate a warning about this non-standard
2859 construct.
2860
2861 Fix the issue by using a simple "struct jsmntok" forward declaration
2862 instead of using a typedef.
2863
2864 Tested-by: Chuck Tuffli <chuck@freebsd.org>
2865 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2866
28672020-09-11 Cao jin <caoj.fnst@cn.fujitsu.com>
2868
2869 i386/relocator_common: Drop empty #ifdef
2870 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2871
28722020-09-11 Ave Milia <avemilia@protonmail.com>
2873
2874 video/bochs: Fix typo
2875 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2876
28772020-07-29 Colin Watson <cjwatson@debian.org>
2878
2879 linux: Fix integer overflows in initrd size handling
2880 These could be triggered by a crafted filesystem with very large files.
2881
2882 Fixes: CVE-2020-15707
2883
2884 Reviewed-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
2885 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2886
28872020-07-29 Peter Jones <pjones@redhat.com>
2888
2889 loader/linux: Avoid overflow on initrd size calculation
2890 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2891
28922020-07-29 Alexey Makhalov <amakhalov@vmware.com>
2893
2894 efi: Fix use-after-free in halt/reboot path
2895 commit 92bfc33db984 ("efi: Free malloc regions on exit")
2896 introduced memory freeing in grub_efi_fini(), which is
2897 used not only by exit path but by halt/reboot one as well.
2898 As result of memory freeing, code and data regions used by
2899 modules, such as halt, reboot, acpi (used by halt) also got
2900 freed. After return to module code, CPU executes, filled
2901 by UEFI firmware (tested with edk2), 0xAFAFAFAF pattern as
2902 a code. Which leads to #UD exception later.
2903
2904 grub> halt
2905 !!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!!
2906 RIP - 0000000003F4EC28, CS - 0000000000000038, RFLAGS - 0000000000200246
2907 RAX - 0000000000000000, RCX - 00000000061DA188, RDX - 0A74C0854DC35D41
2908 RBX - 0000000003E10E08, RSP - 0000000007F0F860, RBP - 0000000000000000
2909 RSI - 00000000064DB768, RDI - 000000000832C5C3
2910 R8 - 0000000000000002, R9 - 0000000000000000, R10 - 00000000061E2E52
2911 R11 - 0000000000000020, R12 - 0000000003EE5C1F, R13 - 00000000061E0FF4
2912 R14 - 0000000003E10D80, R15 - 00000000061E2F60
2913 DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030
2914 GS - 0000000000000030, SS - 0000000000000030
2915 CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 0000000007C01000
2916 CR4 - 0000000000000668, CR8 - 0000000000000000
2917 DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
2918 DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
2919 GDTR - 00000000079EEA98 0000000000000047, LDTR - 0000000000000000
2920 IDTR - 0000000007598018 0000000000000FFF, TR - 0000000000000000
2921 FXSAVE_STATE - 0000000007F0F4C0
2922
2923 Proposal here is to continue to free allocated memory for
2924 exit boot services path but keep it for halt/reboot path
2925 as it won't be much security concern here.
2926 Introduced GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY
2927 loader flag to be used by efi halt/reboot path.
2928
2929 Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
2930 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2931
29322020-07-29 Daniel Kiper <daniel.kiper@oracle.com>
2933
2934 efi/chainloader: Propagate errors from copy_file_path()
2935 Without any error propagated to the caller, make_file_path()
2936 would then try to advance the invalid device path node with
2937 GRUB_EFI_NEXT_DEVICE_PATH(), which would fail, returning a NULL
2938 pointer that would subsequently be dereferenced. Hence, propagate
2939 errors from copy_file_path().
2940
2941 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2942
29432020-07-29 Peter Jones <pjones@redhat.com>
2944
2945 efi: Fix some malformed device path arithmetic errors
2946 Several places we take the length of a device path and subtract 4 from
2947 it, without ever checking that it's >= 4. There are also cases where
2948 this kind of malformation will result in unpredictable iteration,
2949 including treating the length from one dp node as the type in the next
2950 node. These are all errors, no matter where the data comes from.
2951
2952 This patch adds a checking macro, GRUB_EFI_DEVICE_PATH_VALID(), which
2953 can be used in several places, and makes GRUB_EFI_NEXT_DEVICE_PATH()
2954 return NULL and GRUB_EFI_END_ENTIRE_DEVICE_PATH() evaluate as true when
2955 the length is too small. Additionally, it makes several places in the
2956 code check for and return errors in these cases.
2957
2958 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2959
29602020-07-29 Peter Jones <pjones@redhat.com>
2961
2962 emu: Make grub_free(NULL) safe
2963 The grub_free() implementation in grub-core/kern/mm.c safely handles
2964 NULL pointers, and code at many places depends on this. We don't know
2965 that the same is true on all host OSes, so we need to handle the same
2966 behavior in grub-emu's implementation.
2967
2968 Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
2969 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2970
29712020-07-29 Peter Jones <pjones@redhat.com>
2972
2973 lvm: Fix two more potential data-dependent alloc overflows
2974 It appears to be possible to make a (possibly invalid) lvm PV with
2975 a metadata size field that overflows our type when adding it to the
2976 address we've allocated. Even if it doesn't, it may be possible to do so
2977 with the math using the outcome of that as an operand. Check them both.
2978
2979 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2980
29812020-07-29 Peter Jones <pjones@redhat.com>
2982
2983 hfsplus: Fix two more overflows
2984 Both node->size and node->namelen come from the supplied filesystem,
2985 which may be user-supplied. We can't trust them for the math unless we
2986 know they don't overflow. Making sure they go through grub_add() or
2987 grub_calloc() first will give us that.
2988
2989 Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
2990 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2991
29922020-07-29 Alexey Makhalov <amakhalov@vmware.com>
2993
2994 relocator: Fix grub_relocator_alloc_chunk_align() top memory allocation
2995 Current implementation of grub_relocator_alloc_chunk_align()
2996 does not allow allocation of the top byte.
2997
2998 Assuming input args are:
2999 max_addr = 0xfffff000;
3000 size = 0x1000;
3001
3002 And this is valid. But following overflow protection will
3003 unnecessarily move max_addr one byte down (to 0xffffefff):
3004 if (max_addr > ~size)
3005 max_addr = ~size;
3006
3007 ~size + 1 will fix the situation. In addition, check size
3008 for non zero to do not zero max_addr.
3009
3010 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3011
30122020-07-29 Chris Coulson <chris.coulson@canonical.com>
3013
3014 script: Avoid a use-after-free when redefining a function during execution
3015 Defining a new function with the same name as a previously defined
3016 function causes the grub_script and associated resources for the
3017 previous function to be freed. If the previous function is currently
3018 executing when a function with the same name is defined, this results
3019 in use-after-frees when processing subsequent commands in the original
3020 function.
3021
3022 Instead, reject a new function definition if it has the same name as
3023 a previously defined function, and that function is currently being
3024 executed. Although a behavioural change, this should be backwards
3025 compatible with existing configurations because they can't be
3026 dependent on the current behaviour without being broken.
3027
3028 Fixes: CVE-2020-15706
3029
3030 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3031
30322020-07-29 Chris Coulson <chris.coulson@canonical.com>
3033
3034 script: Remove unused fields from grub_script_function struct
3035 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3036
30372020-07-29 Alexey Makhalov <amakhalov@vmware.com>
3038
3039 relocator: Protect grub_relocator_alloc_chunk_align() max_addr against integer underflow
3040 This commit introduces integer underflow mitigation in max_addr calculation
3041 in grub_relocator_alloc_chunk_align() invocation.
3042
3043 It consists of 2 fixes:
3044 1. Introduced grub_relocator_alloc_chunk_align_safe() wrapper function to perform
3045 sanity check for min/max and size values, and to make safe invocation of
3046 grub_relocator_alloc_chunk_align() with validated max_addr value. Replace all
3047 invocations such as grub_relocator_alloc_chunk_align(..., min_addr, max_addr - size, size, ...)
3048 by grub_relocator_alloc_chunk_align_safe(..., min_addr, max_addr, size, ...).
3049 2. Introduced UP_TO_TOP32(s) macro for the cases where max_addr is 32-bit top
3050 address (0xffffffff - size + 1) or similar.
3051
3052 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3053
30542020-07-29 Alexey Makhalov <amakhalov@vmware.com>
3055
3056 relocator: Protect grub_relocator_alloc_chunk_addr() input args against integer underflow/overflow
3057 Use arithmetic macros from safemath.h to accomplish it. In this commit,
3058 I didn't want to be too paranoid to check every possible math equation
3059 for overflow/underflow. Only obvious places (with non zero chance of
3060 overflow/underflow) were refactored.
3061
3062 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3063
30642020-07-29 Alexey Makhalov <amakhalov@vmware.com>
3065
3066 tftp: Do not use priority queue
3067 There is not need to reassemble the order of blocks. Per RFC 1350,
3068 server must wait for the ACK, before sending next block. Data packets
3069 can be served immediately without putting them to priority queue.
3070
3071 Logic to handle incoming packet is this:
3072 - if packet block id equal to expected block id, then
3073 process the packet,
3074 - if packet block id is less than expected - this is retransmit
3075 of old packet, then ACK it and drop the packet,
3076 - if packet block id is more than expected - that shouldn't
3077 happen, just drop the packet.
3078
3079 It makes the tftp receive path code simpler, smaller and faster.
3080 As a benefit, this change fixes CID# 73624 and CID# 96690, caused
3081 by following while loop:
3082
3083 while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0)
3084
3085 where tftph pointer is not moving from one iteration to another, causing
3086 to serve same packet again. Luckily, double serving didn't happen due to
3087 data->block++ during the first iteration.
3088
3089 Fixes: CID 73624, CID 96690
3090
3091 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3092
30932020-07-29 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
3094
3095 multiboot2: Fix memory leak if grub_create_loader_cmdline() fails
3096 Fixes: CID 292468
3097
3098 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3099
31002020-07-29 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
3101
3102 udf: Fix memory leak
3103 Fixes: CID 73796
3104
3105 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3106 Reviewed-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
3107
31082020-07-29 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
3109
3110 term: Fix overflow on user inputs
3111 This requires a very weird input from the serial interface but can cause
3112 an overflow in input_buf (keys) overwriting the next variable (npending)
3113 with the user choice:
3114
3115 (pahole output)
3116
3117 struct grub_terminfo_input_state {
3118 int input_buf[6]; /* 0 24 */
3119 int npending; /* 24 4 */ <- CORRUPT
3120 ...snip...
3121
3122 The magic string requires causing this is "ESC,O,],0,1,2,q" and we overflow
3123 npending with "q" (aka increase npending to 161). The simplest fix is to
3124 just to disallow overwrites input_buf, which exactly what this patch does.
3125
3126 Fixes: CID 292449
3127
3128 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3129
31302020-07-29 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
3131
3132 lzma: Make sure we don't dereference past array
3133 The two dimensional array p->posSlotEncoder[4][64] is being dereferenced
3134 using the GetLenToPosState() macro which checks if len is less than 5,
3135 and if so subtracts 2 from it. If len = 0, that is 0 - 2 = 4294967294.
3136 Obviously we don't want to dereference that far out so we check if the
3137 position found is greater or equal kNumLenToPosStates (4) and bail out.
3138
3139 N.B.: Upstream LZMA 18.05 and later has this function completely rewritten
3140 without any history.
3141
3142 Fixes: CID 51526
3143
3144 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3145
31462020-07-29 Chris Coulson <chris.coulson@canonical.com>
3147
3148 json: Avoid a double-free when parsing fails.
3149 When grub_json_parse() succeeds, it returns the root object which
3150 contains a pointer to the provided JSON string. Callers are
3151 responsible for ensuring that this string outlives the root
3152 object and for freeing its memory when it's no longer needed.
3153
3154 If grub_json_parse() fails to parse the provided JSON string,
3155 it frees the string before returning an error. This results
3156 in a double free in luks2_recover_key(), which also frees the
3157 same string after grub_json_parse() returns an error.
3158
3159 This changes grub_json_parse() to never free the JSON string
3160 passed to it, and updates the documentation for it to make it
3161 clear that callers are responsible for ensuring that the string
3162 outlives the root JSON object.
3163
3164 Fixes: CID 292465
3165
3166 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3167
31682020-07-29 Alexey Makhalov <amakhalov@vmware.com>
3169
3170 xnu: Fix double free in grub_xnu_devprop_add_property()
3171 grub_xnu_devprop_add_property() should not free utf8 and utf16 as it get
3172 allocated and freed in the caller.
3173
3174 Minor improvement: do prop fields initialization after memory allocations.
3175
3176 Fixes: CID 292442, CID 292457, CID 292460, CID 292466
3177
3178 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3179
31802020-07-29 Alexey Makhalov <amakhalov@vmware.com>
3181
3182 gfxmenu: Fix double free in load_image()
3183 self->bitmap should be zeroed after free. Otherwise, there is a chance
3184 to double free (USE_AFTER_FREE) it later in rescale_image().
3185
3186 Fixes: CID 292472
3187
3188 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3189
31902020-07-29 Daniel Kiper <daniel.kiper@oracle.com>
3191
3192 font: Do not load more than one NAME section
3193 The GRUB font file can have one NAME section only. Though if somebody
3194 crafts a broken font file with many NAME sections and loads it then the
3195 GRUB leaks memory. So, prevent against that by loading first NAME
3196 section and failing in controlled way on following one.
3197
3198 Reported-by: Chris Coulson <chris.coulson@canonical.com>
3199 Reviewed-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
3200
32012020-07-29 Peter Jones <pjones@redhat.com>
3202
3203 iso9660: Don't leak memory on realloc() failures
3204 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3205
32062020-07-29 Peter Jones <pjones@redhat.com>
3207
3208 malloc: Use overflow checking primitives where we do complex allocations
3209 This attempts to fix the places where we do the following where
3210 arithmetic_expr may include unvalidated data:
3211
3212 X = grub_malloc(arithmetic_expr);
3213
3214 It accomplishes this by doing the arithmetic ahead of time using grub_add(),
3215 grub_sub(), grub_mul() and testing for overflow before proceeding.
3216
3217 Among other issues, this fixes:
3218 - allocation of integer overflow in grub_video_bitmap_create()
3219 reported by Chris Coulson,
3220 - allocation of integer overflow in grub_png_decode_image_header()
3221 reported by Chris Coulson,
3222 - allocation of integer overflow in grub_squash_read_symlink()
3223 reported by Chris Coulson,
3224 - allocation of integer overflow in grub_ext2_read_symlink()
3225 reported by Chris Coulson,
3226 - allocation of integer overflow in read_section_as_string()
3227 reported by Chris Coulson.
3228
3229 Fixes: CVE-2020-14309, CVE-2020-14310, CVE-2020-14311
3230
3231 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3232
32332020-07-29 Peter Jones <pjones@redhat.com>
3234
3235 calloc: Use calloc() at most places
3236 This modifies most of the places we do some form of:
3237
3238 X = malloc(Y * Z);
3239
3240 to use calloc(Y, Z) instead.
3241
3242 Among other issues, this fixes:
3243 - allocation of integer overflow in grub_png_decode_image_header()
3244 reported by Chris Coulson,
3245 - allocation of integer overflow in luks_recover_key()
3246 reported by Chris Coulson,
3247 - allocation of integer overflow in grub_lvm_detect()
3248 reported by Chris Coulson.
3249
3250 Fixes: CVE-2020-14308
3251
3252 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3253
32542020-07-29 Peter Jones <pjones@redhat.com>
3255
3256 calloc: Make sure we always have an overflow-checking calloc() available
3257 This tries to make sure that everywhere in this source tree, we always have
3258 an appropriate version of calloc() (i.e. grub_calloc(), xcalloc(), etc.)
3259 available, and that they all safely check for overflow and return NULL when
3260 it would occur.
3261
3262 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3263
32642020-07-29 Peter Jones <pjones@redhat.com>
3265
3266 safemath: Add some arithmetic primitives that check for overflow
3267 This adds a new header, include/grub/safemath.h, that includes easy to
3268 use wrappers for __builtin_{add,sub,mul}_overflow() declared like:
3269
3270 bool OP(a, b, res)
3271
3272 where OP is grub_add, grub_sub or grub_mul. OP() returns true in the
3273 case where the operation would overflow and res is not modified.
3274 Otherwise, false is returned and the operation is executed.
3275
3276 These arithmetic primitives require newer compiler versions. So, bump
3277 these requirements in the INSTALL file too.
3278
3279 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3280
32812020-07-29 Peter Jones <pjones@redhat.com>
3282
3283 yylex: Make lexer fatal errors actually be fatal
3284 When presented with a command that can't be tokenized to anything
3285 smaller than YYLMAX characters, the parser calls YY_FATAL_ERROR(errmsg),
3286 expecting that will stop further processing, as such:
3287
3288 #define YY_DO_BEFORE_ACTION \
3289 yyg->yytext_ptr = yy_bp; \
3290 yyleng = (int) (yy_cp - yy_bp); \
3291 yyg->yy_hold_char = *yy_cp; \
3292 *yy_cp = '\0'; \
3293 if ( yyleng >= YYLMAX ) \
3294 YY_FATAL_ERROR( "token too large, exceeds YYLMAX" ); \
3295 yy_flex_strncpy( yytext, yyg->yytext_ptr, yyleng + 1 , yyscanner); \
3296 yyg->yy_c_buf_p = yy_cp;
3297
3298 The code flex generates expects that YY_FATAL_ERROR() will either return
3299 for it or do some form of longjmp(), or handle the error in some way at
3300 least, and so the strncpy() call isn't in an "else" clause, and thus if
3301 YY_FATAL_ERROR() is *not* actually fatal, it does the call with the
3302 questionable limit, and predictable results ensue.
3303
3304 Unfortunately, our implementation of YY_FATAL_ERROR() is:
3305
3306 #define YY_FATAL_ERROR(msg) \
3307 do { \
3308 grub_printf (_("fatal error: %s\n"), _(msg)); \
3309 } while (0)
3310
3311 The same pattern exists in yyless(), and similar problems exist in users
3312 of YY_INPUT(), several places in the main parsing loop,
3313 yy_get_next_buffer(), yy_load_buffer_state(), yyensure_buffer_stack,
3314 yy_scan_buffer(), etc.
3315
3316 All of these callers expect YY_FATAL_ERROR() to actually be fatal, and
3317 the things they do if it returns after calling it are wildly unsafe.
3318
3319 Fixes: CVE-2020-10713
3320
3321 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3322
33232020-05-25 Marc Zyngier <maz@kernel.org>
3324
3325 arm: Fix 32-bit ARM handling of the CTR register
3326 When booting on an ARMv8 core that implements either CTR.IDC or CTR.DIC
3327 (indicating that some of the cache maintenance operations can be
3328 removed when dealing with I/D-cache coherency, GRUB dies with a
3329 "Unsupported cache type 0x........" message.
3330
3331 This is pretty likely to happen when running in a virtual machine
3332 hosted on an arm64 machine (I've triggered it on a system built around
3333 a bunch of Cortex-A55 cores, which implements CTR.IDC).
3334
3335 It turns out that the way GRUB deals with the CTR register is a bit
3336 harsh for anything from ARMv7 onwards. The layout of the register is
3337 backward compatible, meaning that nothing that gets added is allowed to
3338 break earlier behaviour. In this case, ignoring IDC is completely fine,
3339 and only results in unnecessary cache maintenance.
3340
3341 We can thus avoid being paranoid, and align the 32bit behaviour with
3342 its 64bit equivalent.
3343
3344 This patch has the added benefit that it gets rid of a (gnu-specific)
3345 case range too.
3346
3347 Reviewed-by: Leif Lindholm <leif@nuviainc.com>
3348 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3349
33502020-05-25 Ian Jackson <ian.jackson@eu.citrix.com>
3351
3352 templates/20_linux_xen: Support Xen Security Modules (XSM/FLASK)
3353 XSM is enabled by adding "flask=enforcing" as a Xen command line
3354 argument, and providing the policy file as a grub module.
3355
3356 We make entries for both with and without XSM. If XSM is not compiled
3357 into Xen, then there are no policy files, so no change to the boot
3358 options.
3359
3360 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3361
33622020-05-25 Ian Jackson <ian.jackson@eu.citrix.com>
3363
3364 templates/20_linux_xen: Ignore xenpolicy and config files too
3365 file_is_not_sym() currently only checks for xen-syms. Extend it to
3366 disregard xenpolicy (XSM policy files) and files ending .config (which
3367 are built by the Xen upstream build system in some configurations and
3368 can therefore end up in /boot).
3369
3370 Rename the function accordingly, to file_is_not_xen_garbage().
3371
3372 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3373
33742020-05-25 Javier Martinez Canillas <javierm@redhat.com>
3375
3376 net: Break out nested function
3377 Nested functions are not supported in C, but are permitted as an extension
3378 in the GNU C dialect. Commit cb2f15c5448 ("normal/main: Search for specific
3379 config files for netboot") added a nested function which caused the build
3380 to break when compiling with clang.
3381
3382 Break that out into a static helper function to make the code portable again.
3383
3384 Reported-by: Daniel Axtens <dja@axtens.net>
3385 Tested-by: Daniel Axtens <dja@axtens.net>
3386 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3387
33882020-05-25 Javier Martinez Canillas <javierm@redhat.com>
3389
3390 tpm: Enable module for all EFI platforms
3391 The module is only enabled for x86_64, but there's nothing specific to
3392 x86_64 in the implementation and can be enabled for all EFI platforms.
3393
3394 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3395
33962020-05-25 Daniel Kiper <daniel.kiper@oracle.com>
3397
3398 INSTALL/configure: Update install doc and configure comment
3399 ..to reflect the GRUB build reality in them.
3400
3401 Additionally, fix text formatting a bit.
3402
3403 Reviewed-by: Leif Lindholm <leif@nuviainc.com>
3404
34052020-05-25 Daniel Kiper <daniel.kiper@oracle.com>
3406
3407 configure: Set gnu99 C language standard by default
3408 Commit d5a32255d (misc: Make grub_strtol() "end" pointers have safer
3409 const qualifiers) introduced "restrict" keyword into some functions
3410 definitions. This keyword was introduced in C99 standard. However, some
3411 compilers by default may use C89 or something different. This behavior
3412 leads to the breakage during builds when c89 or gnu89 is in force. So,
3413 let's set gnu99 C language standard for all compilers by default. This
3414 way a bit random build issue will be fixed and the GRUB source will be
3415 build consistently regardless of type and version of the compiler.
3416
3417 It was decided to use gnu99 C language standard because it fixes the
3418 issue mentioned above and also provides some useful extensions which are
3419 used here and there in the GRUB source. Potentially we can use gnu11
3420 too. However, this may reduce pool of older compilers which can be used
3421 to build the GRUB. So, let's live with gnu99 until we discover that we
3422 strongly require a feature from newer C standard.
3423
3424 The user is still able to override C language standard using relevant
3425 *_CFLAGS variables.
3426
3427 Reviewed-by: Leif Lindholm <leif@nuviainc.com>
3428
34292020-05-15 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
3430
3431 tpm: Rename function grub_tpm_log_event() to grub_tpm_measure()
3432 grub_tpm_log_event() and grub_tpm_measure() are two functions that
3433 have the same effect. So, keep grub_tpm_log_event() and rename it
3434 to grub_tpm_measure(). This way we get also a more clear semantics.
3435
3436 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3437
34382020-05-15 Daniel Kiper <daniel.kiper@oracle.com>
3439
3440 autogen: Replace -iname with -ipath in find command
3441 ..because -iname cannot be used to match paths.
3442
3443 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
3444 Reviewed-by: Leif Lindholm <leif@nuviainc.com>
3445 Reviewed-by: Daniel Axtens <dja@axtens.net>
3446
34472020-05-15 Daniel Kiper <daniel.kiper@oracle.com>
3448
3449 INSTALL: Update configure example
3450 ..to make it more relevant.
3451
3452 Reviewed-by: Leif Lindholm <leif@nuviainc.com>
3453
34542020-05-15 Daniel Kiper <daniel.kiper@oracle.com>
3455
3456 configure: Drop unneeded TARGET_CFLAGS expansion
3457 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
3458 Reviewed-by: Leif Lindholm <leif@nuviainc.com>
3459
34602020-05-15 Jacob Kroon <jacob.kroon@gmail.com>
3461
3462 docs/grub: Support for probing partition UUID on MSDOS disks
3463 Support was implemented in commit c7cb11b21 (probe: Support probing for
3464 msdos PARTUUID).
3465
3466 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3467
34682020-05-15 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
3469
3470 verifiers: Add verify string debug message
3471 Like grub_verifiers_open(), the grub_verify_string() should also
3472 display this debug message, which is very helpful for debugging.
3473
3474 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3475
34762020-05-15 Javier Martinez Canillas <javierm@redhat.com>
3477
3478 envblk: Fix buffer overrun when attempting to shrink a variable value
3479 If an existing variable is set with a value whose length is smaller than
3480 the current value, a memory corruption can happen due copying padding '#'
3481 characters outside of the environment block buffer.
3482
3483 This is caused by a wrong calculation of the previous free space position
3484 after moving backward the characters that followed the old variable value.
3485
3486 That position is calculated to fill the remaining of the buffer with the
3487 padding '#' characters. But since isn't calculated correctly, it can lead
3488 to copies outside of the buffer.
3489
3490 The issue can be reproduced by creating a variable with a large value and
3491 then try to set a new value that is much smaller:
3492
3493 $ grub2-editenv --version
3494 grub2-editenv (GRUB) 2.04
3495
3496 $ grub2-editenv env create
3497
3498 $ grub2-editenv env set a="$(for i in {1..500}; do var="b$var"; done; echo $var)"
3499
3500 $ wc -c env
3501 1024 grubenv
3502
3503 $ grub2-editenv env set a="$(for i in {1..50}; do var="b$var"; done; echo $var)"
3504 malloc(): corrupted top size
3505 Aborted (core dumped)
3506
3507 $ wc -c env
3508 0 grubenv
3509
3510 Reported-by: Renaud Métrich <rmetrich@redhat.com>
3511 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3512
35132020-05-15 Hans Ulrich Niedermann <hun@n-dimensional.de>
3514
3515 docs: Remove docs for non-existing uppermem command
3516 Remove all documentation of and mentions of the uppermem
3517 command from the docs/grub.texi file.
3518
3519 The uppermem command is not implemented in the GRUB source
3520 at all and appears to never have been implemented despite
3521 former plans to add an uppermem command.
3522
3523 To reduce user confusion, this even removes the paragraph
3524 describing how GRUB's uppermem command was supposed to
3525 complement the Linux kernel's mem= parameter.
3526
3527 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3528
35292020-05-15 Hans Ulrich Niedermann <hun@n-dimensional.de>
3530
3531 docs: Remove docs for non-existing pxe_unload command
3532 Remove the documentation of the pxe_unload command from the
3533 docs/grub.texi file.
3534
3535 The pxe_unload command is not implemented in the grub source
3536 at this time at all. It appears to have been removed in commit
3537 671a78acb (cleanup pxe and efi network release).
3538
3539 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3540
35412020-05-15 Hans Ulrich Niedermann <hun@n-dimensional.de>
3542
3543 gitignore: Add a few forgotten file patterns
3544 Add a few patterns to .gitignore to cover files which are generated
3545 by building grub ("make", "make check", "make dist") but which have
3546 been forgotten to add to .gitignore in the past.
3547
3548 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3549
35502020-05-15 Hans Ulrich Niedermann <hun@n-dimensional.de>
3551
3552 gitignore: Add leading slashes where appropriate
3553 Going through the list of gitignore patterns without a leading slash,
3554 this adds a leading slash where it appears to have been forgotten.
3555
3556 Some gitignore patterns like ".deps/" or "Makefile" clearly should
3557 match everywhere, so those definitively need no leading slash.
3558
3559 For some patterns like "ascii.bitmaps", it is unclear where in the
3560 source tree they should match. Those patterns are kept as they are,
3561 matching the patterns in the whole tree of subdirectories.
3562
3563 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3564
35652020-05-15 Hans Ulrich Niedermann <hun@n-dimensional.de>
3566
3567 gitignore: Add trailing slashes for directories
3568 Add trailing slashes for all patterns matching directories.
3569
3570 Note that we do *not* add trailing slashes for *symlinks*
3571 to directories.
3572
3573 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3574
35752020-05-15 Hans Ulrich Niedermann <hun@n-dimensional.de>
3576
3577 gitignore: Sort both pattern groups alphabetically
3578 Alphabetically sort the two groups of gitignore patterns:
3579
3580 * The group of patterns without slashes, matching anywhere
3581 in the directory subtree.
3582
3583 * The group of patterns with slashes, matching relative to the
3584 .gitignore file's directory
3585
3586 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3587
35882020-05-15 Hans Ulrich Niedermann <hun@n-dimensional.de>
3589
3590 gitignore: Group patterns with and without slash
3591 Group the .gitignore patterns into two groups:
3592
3593 * Pattern not including a slash, i.e. matching files anywhere in
3594 the .gitignore file's directory and all of its subdirectories.
3595
3596 * Patterns including a slash, i.e. matching only relative to the
3597 .gitignore file's directory.
3598
3599 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3600
36012020-05-15 Hans Ulrich Niedermann <hun@n-dimensional.de>
3602
3603 gitignore: Consistent leading slash is easier to read
3604 As all gitignore patterns containing a left or middle slash match
3605 only relative to the .gitignore file's directory, we write them
3606 all in the same manner with a leading slash.
3607
3608 This makes the file significantly easier to read.
3609
3610 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3611
36122020-05-15 Daniel Kiper <daniel.kiper@oracle.com>
3613
3614 mips/cache: Add missing nop's in delay slots
3615 Lack of them causes random instructions to be executed before the
3616 jump really happens.
3617
3618 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3619
36202020-04-21 Patrick Steinhardt <ps@pks.im>
3621
3622 luks2: Propagate error when reading area key fails
3623 When decrypting a given keyslot, all error cases except for one set up
3624 an error and return the error code. The only exception is when we try to
3625 read the area key: instead of setting up an error message, we directly
3626 print it via grub_dprintf().
3627
3628 Convert the outlier to use grub_error() to allow more uniform handling
3629 of errors.
3630
3631 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3632
36332020-04-21 Patrick Steinhardt <ps@pks.im>
3634
3635 json: Get rid of casts for "jsmntok_t"
3636 With the upstream change having landed that adds a name to the
3637 previously anonymous "jsmntok" typedef, we can now add a forward
3638 declaration for that struct in our code. As a result, we no longer have
3639 to store the "tokens" member of "struct grub_json" as a void pointer but
3640 can instead use the forward declaration, allowing us to get rid of casts
3641 of that field.
3642
3643 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3644
36452020-04-21 Patrick Steinhardt <ps@pks.im>
3646
3647 json: Update jsmn library to upstream commit 053d3cd
3648 Update our embedded version of the jsmn library to upstream commit
3649 053d3cd (Merge pull request #175 from pks-t/pks/struct-type,
3650 2020-04-02).
3651
3652 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3653
36542020-04-21 Steve Langasek <steve.langasek@ubuntu.com>
3655
3656 templates: Output a menu entry for firmware setup on UEFI FastBoot systems
3657 The fwsetup command allows to reboot into the EFI firmware setup menu, add
3658 a template to include a menu entry on EFI systems that makes use of that
3659 command to reboot into the EFI firmware settings.
3660
3661 This is useful for users since the hotkey to enter into the EFI setup menu
3662 may not be the same on all systems so users can use the menu entry without
3663 needing to figure out what key needs to be pressed.
3664
3665 Also, if fastboot is enabled in the BIOS then often it is not possible to
3666 enter the firmware setup menu. So the entry is again useful for this case.
3667
3668 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3669
36702020-04-21 Hans de Goede <hdegoede@redhat.com>
3671
3672 kern/term: Accept ESC, F4 and holding SHIFT as user interrupt keys
3673 On some devices the ESC key is the hotkey to enter the BIOS/EFI setup
3674 screen, making it really hard to time pressing it right. Besides that
3675 ESC is also pretty hard to discover for a user who does not know it
3676 will unhide the menu.
3677
3678 This commit makes F4, which was chosen because is not used as a hotkey
3679 to enter the BIOS setup by any vendor, also interrupt sleeps / stop the
3680 menu countdown.
3681
3682 This solves the ESC gets into the BIOS setup and also somewhat solves
3683 the discoverability issue, but leaves the timing issue unresolved.
3684
3685 This commit fixes the timing issue by also adding support for keeping
3686 SHIFT pressed during boot to stop the menu countdown. This matches
3687 what Ubuntu is doing, which should also help with discoverability.
3688
3689 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3690
36912020-04-21 Hans de Goede <hdegoede@redhat.com>
3692
3693 efi/console: Do not set text-mode until we actually need it
3694 If we're running with a hidden menu we may never need text mode, so do not
3695 change the video-mode to text until we actually need it.
3696
3697 This allows to boot a machine without unnecessary graphical transitions and
3698 provide a seamless boot experience to users.
3699
3700 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3701
37022020-04-21 Hans de Goede <hdegoede@redhat.com>
3703
3704 efi/console: Implement getkeystatus() support
3705 Implement getkeystatus() support in the EFI console driver.
3706
3707 This is needed because the logic to determine if a key was pressed to make
3708 the menu countdown stop will be changed by a later patch to also take into
3709 account the SHIFT key being held down.
3710
3711 For this reason the EFI console driver has to support getkeystatus() to
3712 allow detecting that event.
3713
3714 Note that if a non-modifier key gets pressed and repeated calls to
3715 getkeystatus() are made then it will return the modifier status at the
3716 time of the non-modifier key, until that key-press gets consumed by a
3717 getkey() call.
3718
3719 This is a side-effect of how the EFI simple-text-input protocol works
3720 and cannot be avoided.
3721
3722 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3723
37242020-04-21 Hans de Goede <hdegoede@redhat.com>
3725
3726 efi/console: Add grub_console_read_key_stroke() helper function
3727 This is a preparatory patch for adding getkeystatus() support to the
3728 EFI console driver.
3729
3730 We can get modifier status through the simple_text_input read_key_stroke()
3731 method, but if a non-modifier key is (also) pressed the read_key_stroke()
3732 call will consume that key from the firmware's queue.
3733
3734 The new grub_console_read_key_stroke() helper buffers upto 1 key-stroke.
3735 If it has a non-modifier key buffered, it will return that one, if its
3736 buffer is empty, it will fills its buffer by getting a new key-stroke.
3737
3738 If called with consume=1 it will empty its buffer after copying the
3739 key-data to the callers buffer, this is how getkey() will use it.
3740
3741 If called with consume=0 it will keep the last key-stroke buffered, this
3742 is how getkeystatus() will call it. This means that if a non-modifier
3743 key gets pressed, repeated getkeystatus() calls will return the modifiers
3744 of that key-press until it is consumed by a getkey() call.
3745
3746 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3747
37482020-04-21 Hans de Goede <hdegoede@redhat.com>
3749
3750 kern/term: Make grub_getkeystatus() helper function available everywhere
3751 Move grub_getkeystatushelper() function from grub-core/commands/keystatus.c
3752 to grub-core/kern/term.c and export it so that it can be used outside of
3753 the keystatus command code too.
3754
3755 There's no logic change in this patch. The function definition is moved so
3756 it can be called from grub-core/kern/term.c in a subsequent patch. It will
3757 be used to determine if a SHIFT key has was held down and use that also to
3758 interrupt the countdown, without the need to press a key at the right time.
3759
3760 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3761
37622020-04-21 Javier Martinez Canillas <javierm@redhat.com>
3763
3764 efi/console: Move grub_console_set{colorstate,cursor} higher in the file
3765 This is just a preparatory patch to move the functions higher in the file,
3766 since these will be called by the grub_prepare_for_text_output() function
3767 that will be introduced in a later patch.
3768
3769 The logic is unchanged by this patch. Functions definitions are just moved
3770 to avoid a forward declaration in a later patch, keeping the code clean.
3771
3772 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3773
37742020-04-21 Paul Menzel <pmenzel@molgen.mpg.de>
3775
3776 docs/grub: Fix typo in *preferred*
3777 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3778
37792020-04-21 Daniel Axtens <dja@axtens.net>
3780
3781 powerpc/mkimage: Fix CHRP note descsz
3782 Currently, an image generated with 'grub-mkimage -n' causes an error when
3783 read with 'readelf -a':
3784
3785 Displaying notes found at file offset 0x000106f0 with length 0x0000002c:
3786 Owner Data size Description
3787 readelf: Warning: note with invalid namesz and/or descsz found at offset 0x0
3788 readelf: Warning: type: 0x1275, namesize: 0x00000008, descsize: 0x0000002c, alignment: 4
3789
3790 This is because the descsz of the CHRP note is set to
3791 sizeof (struct grub_ieee1275_note)
3792 which is the size of the entire note, including name and elf header. The
3793 desczs should contain only the contents, not the name and header sizes.
3794
3795 Set the descsz instead to 'sizeof (struct grub_ieee1275_note_desc)'
3796
3797 Resultant readelf output:
3798
3799 Displaying notes found at file offset 0x00010710 with length 0x0000002c:
3800 Owner Data size Description
3801 PowerPC 0x00000018 Unknown note type: (0x00001275)
3802 description data: ff ff ff ff 00 c0 00 00 ff ff ff ff ff ff ff ff ff ff ff ff 00 00 40 00
3803
3804 So far as I can tell this issue has existed for as long as the note
3805 generation code has existed, but I guess nothing really checks descsz.
3806
3807 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3808
38092020-03-31 Flavio Suligoi <f.suligoi@asem.it>
3810
3811 efi: Add missed space in GRUB_EFI_GLOBAL_VARIABLE_GUID
3812 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3813
38142020-03-31 Michael Chang <mchang@suse.com>
3815
3816 zfs: Fix gcc10 error -Werror=zero-length-bounds
3817 We bumped into the build error while testing gcc-10 pre-release.
3818
3819 In file included from ../../include/grub/file.h:22,
3820 from ../../grub-core/fs/zfs/zfs.c:34:
3821 ../../grub-core/fs/zfs/zfs.c: In function 'zap_leaf_lookup':
3822 ../../grub-core/fs/zfs/zfs.c:2263:44: error: array subscript '<unknown>' is outside the bounds of an interior zero-length array 'grub_uint16_t[0]' {aka 'short unsigned int[0]'} [-Werror=zero-length-bounds]
3823 2263 | for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian);
3824 ../../include/grub/types.h:241:48: note: in definition of macro 'grub_le_to_cpu16'
3825 241 | # define grub_le_to_cpu16(x) ((grub_uint16_t) (x))
3826 | ^
3827 ../../grub-core/fs/zfs/zfs.c:2263:16: note: in expansion of macro 'grub_zfs_to_cpu16'
3828 2263 | for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian);
3829 | ^~~~~~~~~~~~~~~~~
3830 In file included from ../../grub-core/fs/zfs/zfs.c:48:
3831 ../../include/grub/zfs/zap_leaf.h:72:16: note: while referencing 'l_hash'
3832 72 | grub_uint16_t l_hash[0];
3833 | ^~~~~~
3834
3835 Here I'd like to quote from the gcc document [1] which seems best to
3836 explain what is going on here.
3837
3838 "Although the size of a zero-length array is zero, an array member of
3839 this kind may increase the size of the enclosing type as a result of
3840 tail padding. The offset of a zero-length array member from the
3841 beginning of the enclosing structure is the same as the offset of an
3842 array with one or more elements of the same type. The alignment of a
3843 zero-length array is the same as the alignment of its elements.
3844
3845 Declaring zero-length arrays in other contexts, including as interior
3846 members of structure objects or as non-member objects, is discouraged.
3847 Accessing elements of zero-length arrays declared in such contexts is
3848 undefined and may be diagnosed."
3849
3850 The l_hash[0] is apparnetly an interior member to the enclosed structure
3851 while l_entries[0] is the trailing member. And the offending code tries
3852 to access members in l_hash[0] array that triggers the diagnose.
3853
3854 Given that the l_entries[0] is used to get proper alignment to access
3855 leaf chunks, we can accomplish the same thing through the ALIGN_UP macro
3856 thus eliminating l_entries[0] from the structure. In this way we can
3857 pacify the warning as l_hash[0] now becomes the last member to the
3858 enclosed structure.
3859
3860 [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
3861
3862 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3863
38642020-03-31 Michael Chang <mchang@suse.com>
3865
3866 mdraid1x_linux: Fix gcc10 error -Werror=array-bounds
3867 We bumped into the build error while testing gcc-10 pre-release.
3868
3869 ../../grub-core/disk/mdraid1x_linux.c: In function 'grub_mdraid_detect':
3870 ../../grub-core/disk/mdraid1x_linux.c:181:15: error: array subscript <unknown> is outside array bounds of 'grub_uint16_t[0]' {aka 'short unsigned int[0]'} [-Werror=array-bounds]
3871 181 | (char *) &sb.dev_roles[grub_le_to_cpu32 (sb.dev_number)]
3872 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3873 ../../grub-core/disk/mdraid1x_linux.c:98:17: note: while referencing 'dev_roles'
3874 98 | grub_uint16_t dev_roles[0]; /* Role in array, or 0xffff for a spare, or 0xfffe for faulty. */
3875 | ^~~~~~~~~
3876 ../../grub-core/disk/mdraid1x_linux.c:127:33: note: defined here 'sb'
3877 127 | struct grub_raid_super_1x sb;
3878 | ^~
3879 cc1: all warnings being treated as errors
3880
3881 Apparently gcc issues the warning when trying to access sb.dev_roles
3882 array's member, since it is a zero length array as the last element of
3883 struct grub_raid_super_1x that is allocated sparsely without extra
3884 chunks for the trailing bits, so the warning looks legitimate in this
3885 regard.
3886
3887 As the whole thing here is doing offset computation, it is undue to use
3888 syntax that would imply array member access then take address from it
3889 later. Instead we could accomplish the same thing through basic array
3890 pointer arithmetic to pacify the warning.
3891
3892 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3893
38942020-03-31 Simon Hardy <simon.hardy@itdev.co.uk>
3895
3896 build: Fix GRUB i386-pc build with Ubuntu gcc
3897 With recent versions of gcc on Ubuntu a very large lzma_decompress.img file is
3898 output. (e.g. 134479600 bytes instead of 2864.) This causes grub-mkimage to
3899 fail with: "error: Decompressor is too big."
3900
3901 This seems to be caused by a section .note.gnu.property that is placed at an
3902 offset such that objcopy needs to pad the img file with zeros.
3903
3904 This issue is present on:
3905 Ubuntu 19.10 with gcc (Ubuntu 8.3.0-26ubuntu1~19.10) 8.3.0
3906 Ubuntu 19.10 with gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008
3907
3908 This issue is not present on:
3909 Ubuntu 19.10 with gcc (Ubuntu 7.5.0-3ubuntu1~19.10) 7.5.0
3910 RHEL 8.0 with gcc 8.3.1 20190507 (Red Hat 8.3.1-4)
3911
3912 The issue can be fixed by removing the section using objcopy as shown in
3913 this patch.
3914
3915 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3916
39172020-03-31 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
3918
3919 efi/tpm: Fix memory leak in grub_tpm1/2_log_event()
3920 The memory requested for the event is not released here,
3921 causing memory leaks. This patch fixes this problem.
3922
3923 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
3924 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3925
39262020-03-31 Michael Chang <mchang@suse.com>
3927
3928 docs: Document notes on LVM cache booting
3929 Add notes on LVM cache booting to the GRUB manual to help user understanding
3930 the outstanding issue and status.
3931
3932 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3933
39342020-03-31 Michael Chang <mchang@suse.com>
3935
3936 lvm: Add LVM cache logical volume handling
3937 The LVM cache logical volume is the logical volume consisting of the original
3938 and the cache pool logical volume. The original is usually on a larger and
3939 slower storage device while the cache pool is on a smaller and faster one. The
3940 performance of the original volume can be improved by storing the frequently
3941 used data on the cache pool to utilize the greater performance of faster
3942 device.
3943
3944 The default cache mode "writethrough" ensures that any data written will be
3945 stored both in the cache and on the origin LV, therefore grub can be straight
3946 to read the original lv as no data loss is guarenteed.
3947
3948 The second cache mode is "writeback", which delays writing from the cache pool
3949 back to the origin LV to have increased performance. The drawback is potential
3950 data loss if losing the associated cache device.
3951
3952 During the boot time grub reads the LVM offline i.e. LVM volumes are not
3953 activated and mounted, hence it should be fine to read directly from original
3954 lv since all cached data should have been flushed back in the process of taking
3955 it offline.
3956
3957 It is also not much helpful to the situation by adding fsync calls to the
3958 install code. The fsync did not force to write back dirty cache to the original
3959 device and rather it would update associated cache metadata to complete the
3960 write transaction with the cache device. IOW the writes to cached blocks still
3961 go only to the cache device.
3962
3963 To write back dirty cache, as LVM cache did not support dirty cache flush per
3964 block range, there'no way to do it for file. On the other hand the "cleaner"
3965 policy is implemented and can be used to write back "all" dirty blocks in a
3966 cache, which effectively drain all dirty cache gradually to attain and last in
3967 the "clean" state, which can be useful for shrinking or decommissioning a
3968 cache. The result and effect is not what we are looking for here.
3969
3970 In conclusion, as it seems no way to enforce file writes to the original
3971 device, grub may suffer from power failure as it cannot assemble the cache
3972 device and read the dirty data from it. However since the case is only
3973 applicable to writeback mode which is sensitive to data lost in nature, I'd
3974 still like to propose my (relatively simple) patch and treat reading dirty
3975 cache as improvement.
3976
3977 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3978
39792020-03-10 Patrick Steinhardt <ps@pks.im>
3980
3981 gnulib: Fix build of base64 when compiling with memory debugging
3982 When building GRUB with memory management debugging enabled, then the
3983 build fails because of `grub_debug_malloc()` and `grub_debug_free()`
3984 being undefined in the luks2 module. The cause is that we patch
3985 "base64.h" to unconditionaly include "config-util.h", which shouldn't be
3986 included for modules at all. As a result, `MM_DEBUG` is defined when
3987 building the module, causing it to use the debug memory allocation
3988 functions. As these are not built into modules, we end up with a linker
3989 error.
3990
3991 Fix the issue by removing the <config-util.h> include altogether. The
3992 sole reason it was included was for the `_GL_ATTRIBUTE_CONST` macro,
3993 which we can simply define as empty in case it's not set.
3994
3995 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
3996
39972020-03-10 Patrick Steinhardt <ps@pks.im>
3998
3999 build: Fix option to explicitly disable memory debugging
4000 The memory management system supports a debug mode that can be enabled
4001 at build time by passing "--enable-mm-debug" to the configure script.
4002 Passing the option will cause us define MM_DEBUG as expected, but in
4003 fact the reverse option "--disable-mm-debug" will do the exact same
4004 thing and also set up the define. This currently causes the build of
4005 "lib/gnulib/base64.c" to fail as it tries to use `grub_debug_malloc()`
4006 and `grub_debug_free()` even though both symbols aren't defined.
4007
4008 Seemingly, `AC_ARG_ENABLE()` will always execute the third argument if
4009 either the positive or negative option was passed. Let's thus fix the
4010 issue by moving the call to`AC_DEFINE()` into an explicit `if test
4011 $xenable_mm_debug` block, similar to how other defines work.
4012
4013 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4014 Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
4015
40162020-03-10 David Michael <fedora.dm0@gmail.com>
4017
4018 fat: Support file modification times
4019 This allows comparing file ages on EFI system partitions.
4020
4021 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4022
40232020-03-10 David Michael <fedora.dm0@gmail.com>
4024
4025 exfat: Save the matching directory entry struct when searching
4026 This provides the node's attributes outside the iterator function
4027 so the file modification time can be accessed and reported.
4028
4029 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4030
40312020-03-10 Mike Gilbert <floppym@gentoo.org>
4032
4033 datetime: Enable the datetime module for the emu platform
4034 Fixes a build failure:
4035
4036 grub-core/commands/date.c:49: undefined reference to `grub_get_weekday_name'
4037 grub-core/commands/ls.c:155: undefined reference to `grub_unixtime2datetime'
4038
4039 Bug: https://bugs.gentoo.org/711512
4040
4041 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
4042 Tested-by: Javier Martinez Canillas <javierm@redhat.com>
4043 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4044
40452020-03-10 John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
4046
4047 build: Add soft-float handling for SuperH (sh4)
4048 While GRUB has no platform support for SuperH (sh4) yet, this change
4049 adds the target-specific handling of soft-floats such that the GRUB
4050 utilities can be built on this target.
4051
4052 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4053
40542020-03-10 Peter Jones <pjones@redhat.com>
4055
4056 efi: Fix the type of grub_efi_status_t
4057 Currently, in some builds with some checkers, we see:
4058
4059 1. grub-core/disk/efi/efidisk.c:601: error[shiftTooManyBitsSigned]: Shifting signed 64-bit value by 63 bits is undefined behaviour
4060
4061 This is because grub_efi_status_t is defined as grub_efi_intn_t, which is
4062 signed, and shifting into the sign bit is not defined behavior. UEFI fixed
4063 this in the spec in 2.3:
4064
4065 2.3 | Change the defined type of EFI_STATUS from INTN to UINTN | May 7, 2009
4066
4067 And the current EDK2 code has:
4068 MdePkg/Include/Base.h-//
4069 MdePkg/Include/Base.h-// Status codes common to all execution phases
4070 MdePkg/Include/Base.h-//
4071 MdePkg/Include/Base.h:typedef UINTN RETURN_STATUS;
4072 MdePkg/Include/Base.h-
4073 MdePkg/Include/Base.h-/**
4074 MdePkg/Include/Base.h- Produces a RETURN_STATUS code with the highest bit set.
4075 MdePkg/Include/Base.h-
4076 MdePkg/Include/Base.h- @param StatusCode The status code value to convert into a warning code.
4077 MdePkg/Include/Base.h- StatusCode must be in the range 0x00000000..0x7FFFFFFF.
4078 MdePkg/Include/Base.h-
4079 MdePkg/Include/Base.h- @return The value specified by StatusCode with the highest bit set.
4080 MdePkg/Include/Base.h-
4081 MdePkg/Include/Base.h-**/
4082 MdePkg/Include/Base.h-#define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode)))
4083 MdePkg/Include/Base.h-
4084 MdePkg/Include/Base.h-/**
4085 MdePkg/Include/Base.h- Produces a RETURN_STATUS code with the highest bit clear.
4086 MdePkg/Include/Base.h-
4087 MdePkg/Include/Base.h- @param StatusCode The status code value to convert into a warning code.
4088 MdePkg/Include/Base.h- StatusCode must be in the range 0x00000000..0x7FFFFFFF.
4089 MdePkg/Include/Base.h-
4090 MdePkg/Include/Base.h- @return The value specified by StatusCode with the highest bit clear.
4091 MdePkg/Include/Base.h-
4092 MdePkg/Include/Base.h-**/
4093 MdePkg/Include/Base.h-#define ENCODE_WARNING(StatusCode) ((RETURN_STATUS)(StatusCode))
4094 MdePkg/Include/Base.h-
4095 MdePkg/Include/Base.h-/**
4096 MdePkg/Include/Base.h- Returns TRUE if a specified RETURN_STATUS code is an error code.
4097 MdePkg/Include/Base.h-
4098 MdePkg/Include/Base.h- This function returns TRUE if StatusCode has the high bit set. Otherwise, FALSE is returned.
4099 MdePkg/Include/Base.h-
4100 MdePkg/Include/Base.h- @param StatusCode The status code value to evaluate.
4101 MdePkg/Include/Base.h-
4102 MdePkg/Include/Base.h- @retval TRUE The high bit of StatusCode is set.
4103 MdePkg/Include/Base.h- @retval FALSE The high bit of StatusCode is clear.
4104 MdePkg/Include/Base.h-
4105 MdePkg/Include/Base.h-**/
4106 MdePkg/Include/Base.h-#define RETURN_ERROR(StatusCode) (((INTN)(RETURN_STATUS)(StatusCode)) < 0)
4107 ...
4108 Uefi/UefiBaseType.h:typedef RETURN_STATUS EFI_STATUS;
4109
4110 This patch makes grub's implementation match the Edk2 declaration with regards
4111 to the signedness of the type.
4112
4113 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4114
41152020-03-10 Peter Jones <pjones@redhat.com>
4116
4117 efi/gop: Add debug output on GOP probing
4118 Add debug information to EFI GOP video driver probing function.
4119
4120 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4121
41222020-03-10 Peter Jones <pjones@redhat.com>
4123
4124 efi/uga: Use video instead of fb as debug condition
4125 All other video drivers use "video" as the debug condition instead of "fb"
4126 so change this in the efi/uga driver to make it consistent with the others.
4127
4128 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4129
41302020-03-10 Peter Jones <pjones@redhat.com>
4131
4132 efi: Print error messages to grub_efi_allocate_pages_real()
4133 No messages were printed in this function, add some to ease debugging.
4134
4135 Also, the function returns a void * pointer so return NULL instead of
4136 0 to make the code more readable.
4137
4138 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4139
41402020-03-10 Andrei Borzenkov <arvidjaar@gmail.com>
4141
4142 efi/uga: Use 64 bit for fb_base
4143 We get 64 bit from PCI BAR but then truncate by assigning to 32 bit.
4144 Make sure to check that pointer does not overflow on 32 bit platform.
4145
4146 Closes: 50931
4147
4148 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4149
41502020-03-10 Alexander Graf <agraf@suse.de>
4151
4152 efi/gop: Add support for BLT_ONLY adapters
4153 EFI GOP has support for multiple different bitness types of frame buffers
4154 and for a special "BLT only" type which is always defined to be RGBx.
4155
4156 Because grub2 doesn't ever directly access the frame buffer but instead
4157 only renders graphics via the BLT interface anyway, we can easily support
4158 these adapters.
4159
4160 The reason this has come up now is the emerging support for virtio-gpu
4161 in OVMF. That adapter does not have the notion of a memory mapped frame
4162 buffer and thus is BLT only.
4163
4164 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4165
41662020-03-10 Peter Jones <pjones@redhat.com>
4167
4168 normal/completion: Fix possible NULL pointer dereference
4169 Coverity Scan reports that the grub_strrchr() function can return NULL if
4170 the character is not found. Check if that's the case for dirfile pointer.
4171
4172 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4173
41742020-03-10 Peter Jones <pjones@redhat.com>
4175
4176 kern: Add grub_debug_enabled()
4177 Add a grub_debug_enabled() helper function instead of open coding it.
4178
4179 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4180
41812020-03-10 Peter Jones <pjones@redhat.com>
4182
4183 Makefile: Make libgrub.pp depend on config-util.h
4184 If you build with "make -j48" a lot, sometimes you see:
4185
4186 gcc -E -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub_script.tab.h\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I../grub-core/lib/minilzo -I../grub-core/lib/xzembed -DMINILZO_HAVE_CONFIG_H -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub_script.tab.h\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I./grub-core/gnulib -I../grub-core/gnulib -I/builddir/build/BUILD/grub-2.02/grub-aarch64-efi-2.02 -D_FILE_OFFSET_BITS=64 \
4187 -D'GRUB_MOD_INIT(x)=@MARKER@x@' grub_script.tab.h grub_script.yy.h ../grub-core/commands/blocklist.c ../grub-core/commands/macbless.c ../grub-core/commands/xnu_uuid.c ../grub-core/commands/testload.c ../grub-core/commands/ls.c ../grub-core/disk/dmraid_nvidia.c ../grub-core/disk/loopback.c ../grub-core/disk/lvm.c ../grub-core/disk/mdraid_linux.c ../grub-core/disk/mdraid_linux_be.c ../grub-core/disk/mdraid1x_linux.c ../grub-core/disk/raid5_recover.c ../grub-core/disk/raid6_recover.c ../grub-core/font/font.c ../grub-core/gfxmenu/font.c ../grub-core/normal/charset.c ../grub-core/video/fb/fbblit.c ../grub-core/video/fb/fbutil.c ../grub-core/video/fb/fbfill.c ../grub-core/video/fb/video_fb.c ../grub-core/video/video.c ../grub-core/video/capture.c ../grub-core/video/colors.c ../grub-core/unidata.c ../grub-core/io/bufio.c ../grub-core/fs/affs.c ../grub-core/fs/afs.c ../grub-core/fs/bfs.c ../grub-core/fs/btrfs.c ../grub-core/fs/cbfs.c ../grub-core/fs/cpio.c ../grub-core/fs/cpio_be.c ../grub-core/fs/odc.c ../grub-core/fs/newc.c ../grub-core/fs/ext2.c ../grub-core/fs/fat.c ../grub-core/fs/exfat.c ../grub-core/fs/fshelp.c ../grub-core/fs/hfs.c ../grub-core/fs/hfsplus.c ../grub-core/fs/hfspluscomp.c ../grub-core/fs/iso9660.c ../grub-core/fs/jfs.c ../grub-core/fs/minix.c ../grub-core/fs/minix2.c ../grub-core/fs/minix3.c ../grub-core/fs/minix_be.c ../grub-core/fs/minix2_be.c ../grub-core/fs/minix3_be.c ../grub-core/fs/nilfs2.c ../grub-core/fs/ntfs.c ../grub-core/fs/ntfscomp.c ../grub-core/fs/reiserfs.c ../grub-core/fs/romfs.c ../grub-core/fs/sfs.c ../grub-core/fs/squash4.c ../grub-core/fs/tar.c ../grub-core/fs/udf.c ../grub-core/fs/ufs2.c ../grub-core/fs/ufs.c ../grub-core/fs/ufs_be.c ../grub-core/fs/xfs.c ../grub-core/fs/zfs/zfscrypt.c ../grub-core/fs/zfs/zfs.c ../grub-core/fs/zfs/zfsinfo.c ../grub-core/fs/zfs/zfs_lzjb.c ../grub-core/fs/zfs/zfs_lz4.c ../grub-core/fs/zfs/zfs_sha256.c ../grub-core/fs/zfs/zfs_fletcher.c ../grub-core/lib/envblk.c ../grub-core/lib/hexdump.c ../grub-core/lib/LzFind.c ../grub-core/lib/LzmaEnc.c ../grub-core/lib/crc.c ../grub-core/lib/adler32.c ../grub-core/lib/crc64.c ../grub-core/normal/datetime.c ../grub-core/normal/misc.c ../grub-core/partmap/acorn.c ../grub-core/partmap/amiga.c ../grub-core/partmap/apple.c ../grub-core/partmap/sun.c ../grub-core/partmap/plan.c ../grub-core/partmap/dvh.c ../grub-core/partmap/sunpc.c ../grub-core/partmap/bsdlabel.c ../grub-core/partmap/dfly.c ../grub-core/script/function.c ../grub-core/script/lexer.c ../grub-core/script/main.c ../grub-core/script/script.c ../grub-core/script/argv.c ../grub-core/io/gzio.c ../grub-core/io/xzio.c ../grub-core/io/lzopio.c ../grub-core/kern/ia64/dl_helper.c ../grub-core/kern/arm/dl_helper.c ../grub-core/kern/arm64/dl_helper.c ../grub-core/lib/minilzo/minilzo.c ../grub-core/lib/xzembed/xz_dec_bcj.c ../grub-core/lib/xzembed/xz_dec_lzma2.c ../grub-core/lib/xzembed/xz_dec_stream.c ../util/misc.c ../grub-core/kern/command.c ../grub-core/kern/device.c ../grub-core/kern/disk.c ../grub-core/lib/disk.c ../util/getroot.c ../grub-core/osdep/unix/getroot.c ../grub-core/osdep/getroot.c ../grub-core/osdep/devmapper/getroot.c ../grub-core/osdep/relpath.c ../grub-core/kern/emu/hostdisk.c ../grub-core/osdep/devmapper/hostdisk.c ../grub-core/osdep/hostdisk.c ../grub-core/osdep/unix/hostdisk.c ../grub-core/osdep/exec.c ../grub-core/osdep/sleep.c ../grub-core/osdep/password.c ../grub-core/kern/emu/misc.c ../grub-core/kern/emu/mm.c ../grub-core/kern/env.c ../grub-core/kern/err.c ../grub-core/kern/file.c ../grub-core/kern/fs.c ../grub-core/kern/list.c ../grub-core/kern/misc.c ../grub-core/kern/partition.c ../grub-core/lib/crypto.c ../grub-core/disk/luks.c ../grub-core/disk/geli.c ../grub-core/disk/cryptodisk.c ../grub-core/disk/AFSplitter.c ../grub-core/lib/pbkdf2.c ../grub-core/commands/extcmd.c ../grub-core/lib/arg.c ../grub-core/disk/ldm.c ../grub-core/disk/diskfilter.c ../grub-core/partmap/gpt.c ../grub-core/partmap/msdos.c ../grub-core/fs/proc.c ../grub-core/fs/archelp.c > libgrub.pp || (rm -f libgrub.pp; exit 1)
4188 rm -f stamp-h1
4189 touch ../config-util.h.in
4190 cd . && /bin/sh ./config.status config-util.h
4191 config.status: creating config-util.h
4192 In file included from ../include/grub/mm.h:25:0,
4193 from ../include/grub/disk.h:29,
4194 from ../include/grub/file.h:26,
4195 from ../grub-core/fs/btrfs.c:21:
4196 ./config.h:38:10: fatal error: ./config-util.h: No such file or directory
4197 #include <config-util.h>
4198 ^~~~~~~~~~~~~~~
4199 compilation terminated.
4200 make: *** [Makefile:13098: libgrub.pp] Error 1
4201
4202 This is because libgrub.pp is built with -DGRUB_UTIL=1, which means
4203 it'll try to include config-util.h, but a parallel make is actually
4204 building that file. I think.
4205
4206 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4207
42082020-03-10 Peter Jones <pjones@redhat.com>
4209
4210 efi: Print more debug info in our module loader
4211 The function that searches the mods section base address does not have
4212 any debug information. Add some debugging outputs that could be useful.
4213
4214 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4215
42162020-03-10 Peter Jones <pjones@redhat.com>
4217
4218 linux/getroot: Handle rssd storage device names
4219 The Micron PCIe SSDs Linux driver (mtip32xx) exposes block devices
4220 as /dev/rssd[a-z]+[0-9]*. Add support for these rssd device names.
4221
4222 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4223
42242020-03-10 Julian Andres Klode <julian.klode@canonical.com>
4225
4226 smbios: Add a --linux argument to apply linux modalias-like filtering
4227 Linux creates modalias strings by filtering out non-ASCII, space,
4228 and colon characters. Provide an option that does the same filtering
4229 so people can create a modalias string in GRUB, and then match their
4230 modalias patterns against it.
4231
4232 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4233
42342020-03-10 Mike Gilbert <floppym@gentoo.org>
4235
4236 po: Fix replacement of %m in sed programs
4237 When running make dist, I hit this error:
4238
4239 rm -f en@arabic.gmo && /usr/bin/gmsgfmt -c --statistics --verbose -o en@arabic.gmo en@arabic.po
4240 en@arabic.po:5312: 'msgstr' is not a valid C format string, unlike 'msgid'.
4241 Reason: The character that terminates the directive number 3 is not a valid conversion specifier.
4242 /usr/bin/gmsgfmt: found 1 fatal error
4243
4244 This was caused by "%m" being replaced with foreign Unicode characters.
4245 For example:
4246
4247 msgid "cannot rename the file %s to %s: %m"
4248 msgstr "ﺹﺎﻨﻧﻮﺗ ﺮﻌﻧﺎﻤﻋ ﺖﻬﻋ ﻒִﻴﻠﻋ %s ﺕﻭ %s: %ﻡ"
4249
4250 Mimic the workaround used for "%s" by reversing the replacement of "%m" at
4251 the end of the sed programs.
4252
4253 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4254
42552020-03-10 Colin Watson <cjwatson@ubuntu.com>
4256
4257 gettext: Restore patches to po/Makefile.in.in
4258 These were inadvertently lost during the conversion to Gnulib (gnulib:
4259 Upgrade Gnulib and switch to bootstrap tool; commit 35b909062). The
4260 files in po/gettext-patches/ can be imported using "git am" on top of
4261 the gettext tag corresponding to AM_GNU_GETTEXT_VERSION in configure.ac
4262 (currently 0.18.3). They handle translation of messages in shell files,
4263 make msgfmt output in little-endian format, and arrange to use @SHELL@
4264 rather than /bin/sh.
4265
4266 There were some changes solely for the purpose of distributing extra
4267 files; for ease of maintenance, I've added these to
4268 conf/Makefile.extra-dist instead.
4269
4270 Fixes: https://savannah.gnu.org/bugs/?57298
4271
4272 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4273
42742020-02-28 Peter Jones <pjones@redhat.com>
4275
4276 misc: Make grub_strtol() "end" pointers have safer const qualifiers
4277 Currently the string functions grub_strtol(), grub_strtoul(), and
4278 grub_strtoull() don't declare the "end" pointer in such a way as to
4279 require the pointer itself or the character array to be immutable to the
4280 implementation, nor does the C standard do so in its similar functions,
4281 though it does require us not to change any of it.
4282
4283 The typical declarations of these functions follow this pattern:
4284
4285 long
4286 strtol(const char * restrict nptr, char ** restrict endptr, int base);
4287
4288 Much of the reason for this is historic, and a discussion of that
4289 follows below, after the explanation of this change. (GRUB currently
4290 does not include the "restrict" qualifiers, and we name the arguments a
4291 bit differently.)
4292
4293 The implementation is semantically required to treat the character array
4294 as immutable, but such accidental modifications aren't stopped by the
4295 compiler, and the semantics for both the callers and the implementation
4296 of these functions are sometimes also helped by adding that requirement.
4297
4298 This patch changes these declarations to follow this pattern instead:
4299
4300 long
4301 strtol(const char * restrict nptr,
4302 const char ** const restrict endptr,
4303 int base);
4304
4305 This means that if any modification to these functions accidentally
4306 introduces either an errant modification to the underlying character
4307 array, or an accidental assignment to endptr rather than *endptr, the
4308 compiler should generate an error. (The two uses of "restrict" in this
4309 case basically mean strtol() isn't allowed to modify the character array
4310 by going through *endptr, and endptr isn't allowed to point inside the
4311 array.)
4312
4313 It also means the typical use case changes to:
4314
4315 char *s = ...;
4316 const char *end;
4317 long l;
4318
4319 l = strtol(s, &end, 10);
4320
4321 Or even:
4322
4323 const char *p = str;
4324 while (p && *p) {
4325 long l = strtol(p, &p, 10);
4326 ...
4327 }
4328
4329 This fixes 26 places where we discard our attempts at treating the data
4330 safely by doing:
4331
4332 const char *p = str;
4333 long l;
4334
4335 l = strtol(p, (char **)&ptr, 10);
4336
4337 It also adds 5 places where we do:
4338
4339 char *p = str;
4340 while (p && *p) {
4341 long l = strtol(p, (const char ** const)&p, 10);
4342 ...
4343 /* more calls that need p not to be pointer-to-const */
4344 }
4345
4346 While moderately distasteful, this is a better problem to have.
4347
4348 With one minor exception, I have tested that all of this compiles
4349 without relevant warnings or errors, and that /much/ of it behaves
4350 correctly, with gcc 9 using 'gcc -W -Wall -Wextra'. The one exception
4351 is the changes in grub-core/osdep/aros/hostdisk.c , which I have no idea
4352 how to build.
4353
4354 Because the C standard defined type-qualifiers in a way that can be
4355 confusing, in the past there's been a slow but fairly regular stream of
4356 churn within our patches, which add and remove the const qualifier in many
4357 of the users of these functions. This change should help avoid that in
4358 the future, and in order to help ensure this, I've added an explanation
4359 in misc.h so that when someone does get a compiler warning about a type
4360 error, they have the fix at hand.
4361
4362 The reason we don't have "const" in these calls in the standard is
4363 purely anachronistic: C78 (de facto) did not have type qualifiers in the
4364 syntax, and the "const" type qualifier was added for C89 (I think; it
4365 may have been later). strtol() appears to date from 4.3BSD in 1986,
4366 which means it could not be added to those functions in the standard
4367 without breaking compatibility, which is usually avoided.
4368
4369 The syntax chosen for type qualifiers is what has led to the churn
4370 regarding usage of const, and is especially confusing on string
4371 functions due to the lack of a string type. Quoting from C99, the
4372 syntax is:
4373
4374 declarator:
4375 pointer[opt] direct-declarator
4376 direct-declarator:
4377 identifier
4378 ( declarator )
4379 direct-declarator [ type-qualifier-list[opt] assignment-expression[opt] ]
4380 ...
4381 direct-declarator [ type-qualifier-list[opt] * ]
4382 ...
4383 pointer:
4384 * type-qualifier-list[opt]
4385 * type-qualifier-list[opt] pointer
4386 type-qualifier-list:
4387 type-qualifier
4388 type-qualifier-list type-qualifier
4389 ...
4390 type-qualifier:
4391 const
4392 restrict
4393 volatile
4394
4395 So the examples go like:
4396
4397 const char foo; // immutable object
4398 const char *foo; // mutable pointer to object
4399 char * const foo; // immutable pointer to mutable object
4400 const char * const foo; // immutable pointer to immutable object
4401 const char const * const foo; // XXX extra const keyword in the middle
4402 const char * const * const foo; // immutable pointer to immutable
4403 // pointer to immutable object
4404 const char ** const foo; // immutable pointer to mutable pointer
4405 // to immutable object
4406
4407 Making const left-associative for * and right-associative for everything
4408 else may not have been the best choice ever, but here we are, and the
4409 inevitable result is people using trying to use const (as they should!),
4410 putting it at the wrong place, fighting with the compiler for a bit, and
4411 then either removing it or typecasting something in a bad way. I won't
4412 go into describing restrict, but its syntax has exactly the same issue
4413 as with const.
4414
4415 Anyway, the last example above actually represents the *behavior* that's
4416 required of strtol()-like functions, so that's our choice for the "end"
4417 pointer.
4418
4419 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4420
44212020-02-28 Mike Gilbert <floppym@gentoo.org>
4422
4423 build: Disable PIE in TARGET_CCASFLAGS if needed
4424 PIE should be disabled in assembly sources as well, or else GRUB will
4425 fail to boot.
4426
4427 Bug: https://bugs.gentoo.org/667852
4428
4429 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4430 Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
4431
44322020-02-28 Mike Gilbert <floppym@gentoo.org>
4433
4434 build: Move TARGET_* assignments earlier
4435 On a 32-bit SPARC userland, configure fails to compile assembly and the
4436 build fails:
4437
4438 checking for options to compile assembly... configure: error: could not compile assembly
4439
4440 config.log shows:
4441
4442 asm-tests/sparc64.S: Assembler messages:
4443 asm-tests/sparc64.S:5: Error: Architecture mismatch on "lduw [%o4+4],%o4".
4444 asm-tests/sparc64.S:5: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
4445 asm-tests/sparc64.S:7: Error: Architecture mismatch on "stw %o5,[%o3]".
4446 asm-tests/sparc64.S:7: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
4447 asm-tests/sparc64.S:8: Error: Architecture mismatch on "bne,pt %icc,1b ,pt %icc,1b".
4448 asm-tests/sparc64.S:8: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
4449
4450 Simply moving these blocks earlier in configure.ac is sufficient to
4451 ensure that the tests are executed with the appropriate flags
4452 (specifically -m64 in this case).
4453
4454 Bug: https://bugs.gentoo.org/667850
4455
4456 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4457 Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
4458
44592020-02-28 Patrick Steinhardt <ps@pks.im>
4460
4461 luks2: Add missing newline to debug message
4462 The debug message printed when decryption with a keyslot fails is
4463 missing its trailing newline. Add it to avoid mangling it with
4464 subsequent output.
4465
4466 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4467
44682020-02-18 Michael Chang <mchang@suse.com>
4469
4470 verifiers: Fix calling uninitialized function pointer
4471 The necessary check for NULL before use of function ver->close is not
4472 taking place in the failure path. This patch simply adds the missing
4473 check and fixes the problem that GRUB hangs indefinitely after booting
4474 rogue image without valid signature if secure boot is turned on.
4475
4476 Now it displays like this for booting rogue UEFI image:
4477
4478 error: bad shim signature
4479 error: you need to load the kernel first
4480
4481 Press any key to continue...
4482
4483 and then you can go back to boot menu by pressing any key or after a few
4484 seconds expired.
4485
4486 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
4487 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4488
44892020-02-18 Peter Jones <pjones@redhat.com>
4490
4491 grub-editenv: Make grub-editenv chase symlinks including those across devices
4492 The grub-editenv create command will wrongly overwrite /boot/grub2/grubenv
4493 with a regular file if grubenv is a symbolic link. But instead, it should
4494 create a new file in the path the symlink points to.
4495
4496 This lets /boot/grub2/grubenv be a symlink to /boot/efi/EFI/fedora/grubenv
4497 even when they're different mount points, which allows grub2-editenv to be
4498 the same across platforms (i.e. UEFI vs BIOS).
4499
4500 For example, in Fedora the GRUB EFI builds have prefix set to /EFI/fedora
4501 (on the EFI System Partition), but for BIOS machine it'll be /boot/grub2
4502 (which may or may not be its own mountpoint).
4503
4504 With this patch, on EFI machines we can make /boot/grub2/grubenv a symlink
4505 to /boot/efi/EFI/fedora/grubenv, and the same copy of grub-set-default will
4506 work on both kinds of systems.
4507
4508 Windows doesn't implement a readlink primitive, so the current behaviour is
4509 maintained for this operating system.
4510
4511 Reviewed-by: Adam Jackson <ajax@redhat.com>
4512 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4513
45142020-02-18 Peter Jones <pjones@redhat.com>
4515
4516 grub-editenv: Add grub_util_readlink()
4517 Currently grub-editenv and related tools are not able to follow symbolic
4518 links when finding their config file. For example the grub-editenv create
4519 command will wrongly overwrite a symlink in /boot/grub2/grubenv with a new
4520 regular file, instead of creating a file in the path the symlink points to.
4521
4522 A following patch will change that and add support in grub-editenv to
4523 follow symbolic links when finding the grub environment variables file.
4524
4525 Add a grub_util_readlink() helper function that is just a wrapper around
4526 the platform specific function to read the value of a symbolic link. This
4527 helper function will be used by the following patch for grub-editenv.
4528
4529 The helper function is not added for Windows, since this operating system
4530 doesn't have a primitive to read the contents of a symbolic link.
4531
4532 Reviewed-by: Adam Jackson <ajax@redhat.com>
4533 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4534
45352020-02-18 Robert Marshall <rmarshall@redhat.com>
4536
4537 docs: Update info with grub.cfg netboot selection order
4538 Add documentation to the GRUB manual that specifies the order netboot
4539 clients use to select a GRUB configuration file.
4540
4541 Also explain that the feature is enabled by default but can be disabled
4542 by setting the "feature_net_search_cfg" environment variable to "n" in
4543 an embedded configuration file.
4544
4545 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4546
45472020-02-18 Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
4548
4549 normal/main: Search for specific config files for netboot
4550 This patch implements a search for a specific configuration when the config
4551 file is on a remoteserver. It uses the following order:
4552 1) DHCP client UUID option.
4553 2) MAC address (in lower case hexadecimal with dash separators);
4554 3) IP (in upper case hexadecimal) or IPv6;
4555 4) The original grub.cfg file.
4556
4557 This procedure is similar to what is used by pxelinux and yaboot:
4558 http://www.syslinux.org/wiki/index.php/PXELINUX#config
4559
4560 It is enabled by default but can be disabled by setting the environment
4561 variable "feature_net_search_cfg" to "n" in an embedded configuration.
4562
4563 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=873406
4564
4565 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4566
45672020-02-18 Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
4568
4569 net/dhcp: Set net_<interface>_client{id, uuid} variables from DHCP options
4570 This patch sets a net_<interface>_clientid and net_<interface>_clientuuid
4571 GRUB environment variables, using the DHCP client ID and UUID options if
4572 these are found.
4573
4574 In the same way than net_<interface>_<option> variables are set for other
4575 options such domain name, boot file, next server, etc.
4576
4577 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4578
45792020-02-18 Javier Martinez Canillas <javierm@redhat.com>
4580
4581 net/dhcp: Consistently use decimal numbers for DHCP/BOOTP options enum
4582 The DHCP Options and BOOTP Vendor Extensions enum values are a mixture of
4583 decimal and hexadecimal numbers. Change this to consistently use decimal
4584 numbers for all since that is how these values are defined by RFC 2132.
4585
4586 Suggested-by: Daniel Kiper <daniel.kiper@oracle.com>
4587 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4588
45892020-02-18 Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
4590
4591 kern: Add %X option to printf functions
4592 The printf(3) function has support for the %X format specifier, to output
4593 an unsigned hexadecimal integer in uppercase.
4594
4595 This can be achived in GRUB using the %x format specifier in grub_printf()
4596 and calling grub_toupper(), but it is more convenient if there is support
4597 for %X in grub_printf().
4598
4599 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4600
46012020-02-18 Javier Martinez Canillas <javierm@redhat.com>
4602
4603 normal: Move common datetime functions out of the normal module
4604 The common datetime helper functions are currently included in the normal
4605 module, but this makes any other module that calls these functions to have
4606 a dependency with the normal module only for this reason.
4607
4608 Since the normal module does a lot of stuff, it calls functions from other
4609 modules. But since other modules may depend on it for calling the datetime
4610 helpers, this could lead to circular dependencies between modules.
4611
4612 As an example, when platform == xen the grub_get_datetime() function from
4613 the datetime module calls to the grub_unixtime2datetime() helper function
4614 from the normal module. Which leads to the following module dependency:
4615
4616 datetime -> normal
4617
4618 and send_dhcp_packet() from the net module calls the grub_get_datetime()
4619 function, which leads to the following module dependency:
4620
4621 net -> datetime -> normal
4622
4623 but that means that the normal module is not allowed to depend on net or
4624 any other module that depends on it due the transitive dependency caused
4625 by datetime. A recent patch attempted to add support to fetch the config
4626 file over the network, which leads to the following circular dependency:
4627
4628 normal -> net -> datetime -> normal
4629
4630 So having the datetime helpers in the normal module makes it quite fragile
4631 and easy to add circular dependencies like these, that break the build due
4632 the genmoddep.awk script catching the issues.
4633
4634 Fix this by taking the datetime helper functions out of the normal module
4635 and instead add them to the datetime module itself. Besides fixing these
4636 issues, it makes more sense to have these helper functions there anyways.
4637
4638 Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
4639 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4640
46412020-02-11 Peter Jones <pjones@redhat.com>
4642
4643 minilzo: Update to minilzo-2.08
4644 This patch updates the miniLZO library to a newer version, which among other
4645 things fixes "CVE-2014-4607 - lzo: lzo1x_decompress_safe() integer overflow"
4646 that is present in the current used in GRUB.
4647
4648 It also updates the "GRUB Developers Manual", to mention that the library is
4649 used and describes the process to update it to a newer release when needed.
4650
4651 Resolves: http://savannah.gnu.org/bugs/?42635
4652
4653 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4654
46552020-01-28 Peter Jones <pjones@redhat.com>
4656
4657 squash4: Fix an uninitialized variable
4658 gcc says:
4659
4660 grub-core/fs/squash4.c: In function ‘direct_read’:
4661 grub-core/fs/squash4.c:868:10: error: ‘err’ may be used uninitialized in
4662 this function [-Werror=maybe-uninitialized]
4663 868 | if (err)
4664 | ^
4665 cc1: all warnings being treated as errors
4666
4667 This patch initializes it to GRUB_ERR_NONE.
4668
4669 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4670
46712020-01-28 C. Masloch <pushbx@ulukai.org>
4672
4673 freedos: Fix FreeDOS command booting large files (near or above 64 KiB)
4674 While testing the 86-DOS lDebug [1] booting from GRUB2, newer versions of the
4675 debugger would fail to load when booted using GRUB's freedos command. The
4676 behaviour observed in a qemu i386 machine was that the ROM-BIOS's boot load
4677 would start anew, instead of loading the selected debugger as kernel.
4678
4679 It came to light that there was a size limit: Kernel files that were 58880
4680 bytes (E600h) long or shorter succeeded to boot, while files that were 64000
4681 bytes or longer failed in the manner described.
4682
4683 Eventually it turned out that the relocator16 stub succeeded whenever it was
4684 placed completely within the first 64 KiB of the Low Memory Area. The chunk
4685 for the relocator is allocated with a minimum address of 0x8010 and a maximum
4686 address just below 0xA0000 [2]. That means if the kernel is, for instance,
4687 E600h bytes long, then the kernel will be allocated memory starting at 00600h
4688 (the fixed FreeDOS kernel load address) up to E600h + 00600h = 0EC00h, which
4689 leaves 1400h (5120) bytes for the relocator to stay in the first 64 KiB.
4690 If the kernel is 64000 bytes (FA00h) long, then the relocator must go to
4691 FA00h + 00600h = 10000h at least which is outside the first 64 KiB.
4692
4693 The problem is that the relocator16 initialises the DS register with a
4694 "pseudo real mode" descriptor, which is defined with a segment limit of
4695 64 KiB and a segment base of zero. After that, the relocator addressed
4696 parts of itself (implicitly) using the DS register, with an offset from
4697 ESI, which holds the linear address of the relocator's base [3]. With the
4698 larger kernel files this would lead to accessing data beyond the 64 KiB
4699 segment limit, presumably leading to a fault and perhaps a subsequent
4700 triple-fault or such.
4701
4702 This patch fixes the relocator to set the segment base of the descriptors
4703 to the base address of the relocator; then, the subsequent accesses to
4704 the relocator's variables are done without the ESI register as an index.
4705 This does not interfere with the relocator's or its target's normal
4706 operation; the segment limits are still loaded with 64 KiB and all the
4707 segment bases are subsequently reset by the relocator anyway.
4708
4709 Current versions of the debugger to test are uploaded to [4]. The file
4710 ldebugnh.com (LZ4-compressed and built with -D_EXTHELP=0) at 58368 bytes
4711 loads successfully, whereas ldebug.com at 64000 bytes fails. Loading one
4712 of these files requires setting root to a FAT FS partition and using the
4713 freedos command to specify the file as kernel:
4714
4715 set root='(hd0,msdos1)'
4716 freedos /ldebug.com
4717 boot
4718
4719 Booting the file using the multiboot command (which uses a WIP entrypoint
4720 of the debugger) works, as it does not use GRUB's relocator16 but instead
4721 includes a loader in the kernel itself, which drops it back to 86 Mode.
4722
4723 [1]: https://hg.ulukai.org/ecm/ldebug
4724 [2]: http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/lib/i386/relocator.c?id=495781f5ed1b48bf27f16c53940d6700c181c74c#n127
4725 [3]: http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/lib/i386/relocator16.S?id=495781f5ed1b48bf27f16c53940d6700c181c74c#n97
4726 [4]: https://ulukai.org/ecm/lDebug-5479a7988d21-nohelp.zip
4727
4728 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4729
47302020-01-10 Patrick Steinhardt <ps@pks.im>
4731
4732 disk: Implement support for LUKS2
4733 With cryptsetup 2.0, a new version of LUKS was introduced that breaks
4734 compatibility with the previous version due to various reasons. GRUB
4735 currently lacks any support for LUKS2, making it impossible to decrypt
4736 disks encrypted with that version. This commit implements support for
4737 this new format.
4738
4739 Note that LUKS1 and LUKS2 are quite different data formats. While they
4740 do share the same disk signature in the first few bytes, representation
4741 of encryption parameters is completely different between both versions.
4742 While the former version one relied on a single binary header, only,
4743 LUKS2 uses the binary header only in order to locate the actual metadata
4744 which is encoded in JSON. Furthermore, the new data format is a lot more
4745 complex to allow for more flexible setups, like e.g. having multiple
4746 encrypted segments and other features that weren't previously possible.
4747 Because of this, it was decided that it doesn't make sense to keep both
4748 LUKS1 and LUKS2 support in the same module and instead to implement it
4749 in two different modules luks and luks2.
4750
4751 The proposed support for LUKS2 is able to make use of the metadata to
4752 decrypt such disks. Note though that in the current version, only the
4753 PBKDF2 key derival function is supported. This can mostly attributed to
4754 the fact that the libgcrypt library currently has no support for either
4755 Argon2i or Argon2id, which are the remaining KDFs supported by LUKS2. It
4756 wouldn't have been much of a problem to bundle those algorithms with
4757 GRUB itself, but it was decided against that in order to keep down the
4758 number of patches required for initial LUKS2 support. Adding it in the
4759 future would be trivial, given that the code structure is already in
4760 place.
4761
4762 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4763
47642020-01-10 Patrick Steinhardt <ps@pks.im>
4765
4766 luks: Move configuration of ciphers into cryptodisk
4767 The luks module contains quite a lot of logic to parse cipher and
4768 cipher-mode strings like aes-xts-plain64 into constants to apply them
4769 to the grub_cryptodisk_t structure. This code will be required by the
4770 upcoming luks2 module, as well, which is why this commit moves it into
4771 its own function grub_cryptodisk_setcipher in the cryptodisk module.
4772 While the strings are probably rather specific to the LUKS modules, it
4773 certainly does make sense that the cryptodisk module houses code to set
4774 up its own internal ciphers instead of hosting that code in the luks
4775 module.
4776
4777 Except for necessary adjustments around error handling, this commit does
4778 an exact move of the cipher configuration logic from luks.c to
4779 cryptodisk.c. Any behavior changes are unintentional.
4780
4781 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4782
47832020-01-10 Patrick Steinhardt <ps@pks.im>
4784
4785 afsplitter: Move into its own module
4786 While the AFSplitter code is currently used only by the luks module,
4787 upcoming support for luks2 will add a second module that depends on it.
4788 To avoid any linker errors when adding the code to both modules because
4789 of duplicated symbols, this commit moves it into its own standalone
4790 module afsplitter as a preparatory step.
4791
4792 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4793
47942020-01-10 Patrick Steinhardt <ps@pks.im>
4795
4796 bootstrap: Add gnulib's base64 module
4797 The upcoming support for LUKS2 disc encryption requires us to include a
4798 parser for base64-encoded data, as it is used to represent salts and
4799 digests. As gnulib already has code to decode such data, we can just
4800 add it to the boostrapping configuration in order to make it available
4801 in GRUB.
4802
4803 The gnulib module makes use of booleans via the <stdbool.h> header. As
4804 GRUB does not provide any POSIX wrapper header for this, but instead
4805 implements support for bool in <sys/types.h>, we need to patch
4806 base64.h to not use <stdbool.h> anymore. We unfortunately cannot include
4807 <sys/types.h> instead, as it would then use gnulib's internal header
4808 while compiling the gnulib object but our own <sys/types.h> when
4809 including it in a GRUB module. Because of this, the patch replaces the
4810 include with a direct typedef.
4811
4812 A second fix is required to make available _GL_ATTRIBUTE_CONST, which
4813 is provided by the configure script. As base64.h does not include
4814 <config.h>, it is thus not available and results in a compile error.
4815 This is fixed by adding an include of <config-util.h>.
4816
4817 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4818
48192020-01-10 Patrick Steinhardt <ps@pks.im>
4820
4821 json: Implement wrapping interface
4822 While the newly added jsmn library provides the parsing interface, it
4823 does not provide any kind of interface to act on parsed tokens. Instead,
4824 the caller is expected to handle pointer arithmetics inside of the token
4825 array in order to extract required information. While simple, this
4826 requires users to know some of the inner workings of the library and is
4827 thus quite an unintuitive interface.
4828
4829 This commit adds a new interface on top of the jsmn parser that provides
4830 convenience functions to retrieve values from the parsed json type, grub_json_t.
4831
4832 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4833
48342020-01-10 Patrick Steinhardt <ps@pks.im>
4835
4836 json: Import upstream jsmn-1.1.0
4837 The upcoming support for LUKS2 encryption will require a JSON parser to
4838 decode all parameters required for decryption of a drive. As there is
4839 currently no other tool that requires JSON, and as gnulib does not
4840 provide a parser, we need to introduce a new one into the code base. The
4841 backend for the JSON implementation is going to be the jsmn library [1].
4842 It has several benefits that make it a very good fit for inclusion in
4843 GRUB:
4844
4845 - It is licensed under MIT.
4846 - It is written in C89.
4847 - It has no dependencies, not even libc.
4848 - It is small with only about 500 lines of code.
4849 - It doesn't do any dynamic memory allocation.
4850 - It is testen on x86, amd64, ARM and AVR.
4851
4852 The library itself comes as a single header, only, that contains both
4853 declarations and definitions. The exposed interface is kind of
4854 simplistic, though, and does not provide any convenience features
4855 whatsoever. Thus there will be a separate interface provided by GRUB
4856 around this parser that is going to be implemented in the following
4857 commit. This change only imports jsmn.h from tag v1.1.0 and adds it
4858 unmodified to a new json module with the following command:
4859
4860 curl -L https://raw.githubusercontent.com/zserge/jsmn/v1.1.0/jsmn.h \
4861 -o grub-core/lib/json/jsmn.h
4862
4863 Upstream jsmn commit hash: fdcef3ebf886fa210d14956d3c068a653e76a24e
4864 Upstream jsmn commit name: Modernize (#149), 2019-04-20
4865
4866 [1]: https://github.com/zserge/jsmn
4867
4868 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4869
48702019-12-20 Lukasz Hawrylko <lukasz.hawrylko@linux.intel.com>
4871
4872 multiboot2: Set min address for mbi allocation to 0x1000
4873 In some cases GRUB2 allocates multiboot2 structure at 0 address, that is
4874 a confusing behavior. Consumers of that structure can have internal NULL-checks
4875 that will throw an error when get a pointer to data allocated at address 0.
4876 To prevent that, define min address for mbi allocation on x86 and x86_64
4877 platforms.
4878
4879 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4880
48812019-12-20 Paul Menzel <pmenzel@molgen.mpg.de>
4882
4883 docs: Export "superusers" variable to apply to submenus
4884 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4885
48862019-12-20 Daniel Kiper <daniel.kiper@oracle.com>
4887
4888 loader/i386/linux: Fix an underflow in the setup_header length calculation
4889 Recent work around x86 Linux kernel loader revealed an underflow in the
4890 setup_header length calculation and another related issue. Both lead to
4891 the memory overwrite and later machine crash.
4892
4893 Currently when the GRUB copies the setup_header into the linux_params
4894 (struct boot_params, traditionally known as "zero page") it assumes the
4895 setup_header size as sizeof(linux_i386_kernel_header/lh). This is
4896 incorrect. It should use the value calculated accordingly to the Linux
4897 kernel boot protocol. Otherwise in case of pretty old kernel, to be
4898 exact Linux kernel boot protocol, the GRUB may write more into
4899 linux_params than it was expected to. Fortunately this is not very big
4900 issue. Though it has to be fixed. However, there is also an underflow
4901 which is grave. It happens when
4902
4903 sizeof(linux_i386_kernel_header/lh) > "real size of the setup_header".
4904
4905 Then len value wraps around and grub_file_read() reads whole kernel into
4906 the linux_params overwriting memory past it. This leads to the GRUB
4907 memory allocator breakage and finally to its crash during boot.
4908
4909 The patch fixes both issues. Additionally, it moves the code not related to
4910 grub_memset(linux_params)/grub_memcpy(linux_params)/grub_file_read(linux_params)
4911 section outside of it to not confuse the reader.
4912
4913 Fixes: e683cfb0cf5 (loader/i386/linux: Calculate the setup_header length)
4914
4915 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
4916 Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
4917 Reviewed-by: Krystian Hebel <krystian.hebel@3mdeb.com>
4918
49192019-12-06 David Sterba <dave@jikos.cz>
4920
4921 btrfs: Add support for new RAID1C34 profiles
4922 New 3- and 4-copy variants of RAID1 were merged into Linux kernel 5.5.
4923 Add the two new profiles to the list of recognized ones. As this builds
4924 on the same code as RAID1, only the redundancy level needs to be
4925 adjusted, the rest is done by the existing code.
4926
4927 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4928
49292019-12-06 Lenny Szubowicz <lszubowi@redhat.com>
4930
4931 tftp: Normalize slashes in TFTP paths
4932 Some TFTP servers do not handle multiple consecutive slashes correctly.
4933 This patch avoids sending TFTP requests with non-normalized paths.
4934
4935 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4936
49372019-11-18 Michael Chang <MChang@suse.com>
4938
4939 grub-editenv: Warn a user against editing environment block
4940 The environment block is a preallocated 1024-byte file which serves as
4941 persistent storage for environment variables. It has its own format
4942 which is sensitive to corruption if an editor does not know how to
4943 process it. Besides that the editor may inadvertently change grubenv
4944 file size and/or make it sparse which can lead to unexpected results.
4945
4946 This patch adds a message to the grubenv file to warn a user against
4947 editing it by tools other than grub-editenv.
4948
4949 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
4950 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4951
49522019-11-18 Michael Chang <MChang@suse.com>
4953
4954 hostdisk: Set linux file descriptor to O_CLOEXEC as default
4955 We are often bothered by this sort of lvm warning while running grub-install
4956 every now and then:
4957
4958 File descriptor 4 (/dev/vda1) leaked on vgs invocation. Parent PID 1991: /usr/sbin/grub2-install
4959
4960 The requirement related to the warning is dictated in the lvm man page:
4961
4962 "On invocation, lvm requires that only the standard file descriptors stdin,
4963 stdout and stderr are available. If others are found, they get closed and
4964 messages are issued warning about the leak. This warning can be suppressed by
4965 setting the environment variable LVM_SUPPRESS_FD_WARNINGS."
4966
4967 While it could be disabled through settings, most Linux distributions seem to
4968 enable it by default and the justification provided by the developer looks to
4969 be valid to me: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466138#15
4970
4971 Rather than trying to close and reopen the file descriptor to the same file
4972 multiple times, which is rather cumbersome, for the sake of no vgs invocation
4973 could happen in between. This patch enables the close-on-exec flag (O_CLOEXEC)
4974 for new file descriptor returned by the open() system call, making it closed
4975 thus not inherited by the child process forked and executed by the exec()
4976 family of functions.
4977
4978 Fixes Debian bug #466138.
4979
4980 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4981
49822019-10-28 Eli Schwartz <eschwartz@archlinux.org>
4983
4984 grub-mkconfig: Use portable "command -v" to detect installed programs
4985 The "which" utility is not guaranteed to be installed either, and if it
4986 is, its behavior is not portable either.
4987
4988 Conversely, the "command -v" shell builtin is required to exist in all
4989 POSIX 2008 compliant shells, and is thus guaranteed to work everywhere.
4990
4991 Examples of open-source shells likely to be installed as /bin/sh on
4992 Linux, which implement the 11-year-old standard: ash, bash, busybox,
4993 dash, ksh, mksh and zsh.
4994
4995 A side benefit of using the POSIX portable option is that it requires
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches