From 0c7cd8023e96aad15254c074e597274313347261 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sun, 11 Oct 2020 19:38:10 +0200 Subject: [PATCH 01/12] Bump version 5.4 --- buildroot-external/meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildroot-external/meta b/buildroot-external/meta index 72e3fd037..2a80f1a2f 100644 --- a/buildroot-external/meta +++ b/buildroot-external/meta @@ -1,5 +1,5 @@ VERSION_MAJOR=5 -VERSION_BUILD=3 +VERSION_BUILD=4 HASSOS_NAME="HassOS" HASSOS_ID="hassos" From 3337cd0f79e2ef04027b4e35e5c37f9219ebb7e4 Mon Sep 17 00:00:00 2001 From: Aman Gupta Karmani Date: Mon, 12 Oct 2020 12:41:12 -0700 Subject: [PATCH 02/12] Fix var-lib-NetworkManager.mount dependencies (#895) --- .../usr/lib/systemd/system/var-lib-NetworkManager.mount | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/var-lib-NetworkManager.mount b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/var-lib-NetworkManager.mount index e4e685499..054cc1fd7 100644 --- a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/var-lib-NetworkManager.mount +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/var-lib-NetworkManager.mount @@ -1,7 +1,7 @@ [Unit] Description=NetworkManager persistent data -Requires=mnt-data.mount -After=mnt-data.mount +Requires=mnt-overlay.mount +After=mnt-overlay.mount hassos-overlay.service Before=NetworkManager.service [Mount] From 59b8636bc83249062eb66394d67125b1ada36185 Mon Sep 17 00:00:00 2001 From: Aman Gupta Karmani Date: Mon, 12 Oct 2020 15:38:04 -0700 Subject: [PATCH 03/12] Fix systemd-time-wait-sync getting stuck with upstream patches (#897) --- ...02-time-wait-sync-log-inotify-errors.patch | 23 ++++++++ .../systemd/0003-fix-inotify-watches.patch | 54 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 buildroot-external/patches/systemd/0002-time-wait-sync-log-inotify-errors.patch create mode 100644 buildroot-external/patches/systemd/0003-fix-inotify-watches.patch diff --git a/buildroot-external/patches/systemd/0002-time-wait-sync-log-inotify-errors.patch b/buildroot-external/patches/systemd/0002-time-wait-sync-log-inotify-errors.patch new file mode 100644 index 000000000..35ae36b2d --- /dev/null +++ b/buildroot-external/patches/systemd/0002-time-wait-sync-log-inotify-errors.patch @@ -0,0 +1,23 @@ +From 4a4298ef78e943d36f3b8d8e78bfa21b1506961e Mon Sep 17 00:00:00 2001 +From: Aman Gupta Karmani +Date: Mon, 12 Oct 2020 13:39:26 -0700 +Subject: [PATCH] time-wait-sync: log errors trying to watch + /run/systemd/timesync + +--- + src/time-wait-sync/time-wait-sync.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/time-wait-sync/time-wait-sync.c b/src/time-wait-sync/time-wait-sync.c +index 96072445f6e..c8ec4850426 100644 +--- a/src/time-wait-sync/time-wait-sync.c ++++ b/src/time-wait-sync/time-wait-sync.c +@@ -50,7 +50,7 @@ static void clock_state_release(ClockState *sp) { + static int clock_state_update(ClockState *sp, sd_event *event); + + static int update_notify_run_systemd_timesync(ClockState *sp) { +- sp->run_systemd_timesync_wd = inotify_add_watch(sp->inotify_fd, "/run/systemd/timesync", IN_CREATE|IN_DELETE_SELF); ++ sp->run_systemd_timesync_wd = inotify_add_watch_and_warn(sp->inotify_fd, "/run/systemd/timesync", IN_CREATE|IN_DELETE_SELF); + return sp->run_systemd_timesync_wd; + } + diff --git a/buildroot-external/patches/systemd/0003-fix-inotify-watches.patch b/buildroot-external/patches/systemd/0003-fix-inotify-watches.patch new file mode 100644 index 000000000..30d322691 --- /dev/null +++ b/buildroot-external/patches/systemd/0003-fix-inotify-watches.patch @@ -0,0 +1,54 @@ +From f6f4f5fe5395a57f10dd446c7266c53f0673eaac Mon Sep 17 00:00:00 2001 +From: Balaji Punnuru +Date: Thu, 9 Apr 2020 12:21:49 -0400 +Subject: [PATCH] util: return the correct correct wd from inotify helpers + +We need to propagate the acquired watch descriptors because our callers +are counting on them. + +[Lennart: this is split out of #15381 and simplified] +--- + src/basic/fs-util.c | 14 ++++++++------ + 1 file changed, 8 insertions(+), 6 deletions(-) + +diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c +index 558cafbcaf5..ef3b5a51842 100644 +--- a/src/basic/fs-util.c ++++ b/src/basic/fs-util.c +@@ -692,28 +692,30 @@ int unlink_or_warn(const char *filename) { + + int inotify_add_watch_fd(int fd, int what, uint32_t mask) { + char path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; +- int r; ++ int wd; + + /* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */ + xsprintf(path, "/proc/self/fd/%i", what); + +- r = inotify_add_watch(fd, path, mask); +- if (r < 0) ++ wd = inotify_add_watch(fd, path, mask); ++ if (wd < 0) + return -errno; + +- return r; ++ return wd; + } + + int inotify_add_watch_and_warn(int fd, const char *pathname, uint32_t mask) { ++ int wd; + +- if (inotify_add_watch(fd, pathname, mask) < 0) { ++ wd = inotify_add_watch(fd, pathname, mask); ++ if (wd < 0) { + if (errno == ENOSPC) + return log_error_errno(errno, "Failed to add a watch for %s: inotify watch limit reached", pathname); + + return log_error_errno(errno, "Failed to add a watch for %s: %m", pathname); + } + +- return 0; ++ return wd; + } + + static bool unsafe_transition(const struct stat *a, const struct stat *b) { From b4fad0361342c0d22e1d357ff0462993c5e9b8eb Mon Sep 17 00:00:00 2001 From: Souradip Mookerjee Date: Thu, 15 Oct 2020 10:49:08 +0100 Subject: [PATCH 04/12] Make clear this should be with UNIX line endings (#884) --- Documentation/network.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/network.md b/Documentation/network.md index 7c1f101f4..09ce0213a 100644 --- a/Documentation/network.md +++ b/Documentation/network.md @@ -10,6 +10,8 @@ Only a manual configuration using NetworkManager connection files is supported. You can read the [NetworkManager manual][nm-manual] or find many configuration examples across the internet. Keep in mind that the system is read-only. If you don't want the IP address to change on every boot, you should modify the UUID property to a generic [UUID4][uuid]. Inside the `\CONFIG\network\` directory on the USB drive or SD card, create a file called `my-network` and add the appropriate contents below: +**NOTE: Please make sure to save this file with UNIX line endings (LF, and not Windows' default CRLF endings). You can do this using Notepad these days!** + ### Default A preinstalled connection profile is provided by default: From dade3adf801e7ae304e449232165bda990909b0b Mon Sep 17 00:00:00 2001 From: Aman Gupta Karmani Date: Fri, 16 Oct 2020 06:12:35 -0700 Subject: [PATCH 05/12] bump rpi-firmware to latest stable release (sep 2020) (#899) --- buildroot-patches/0002-rpi-firmware-Bump-firmware.patch | 4 ++-- buildroot/package/rpi-firmware/rpi-firmware.hash | 2 +- buildroot/package/rpi-firmware/rpi-firmware.mk | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/buildroot-patches/0002-rpi-firmware-Bump-firmware.patch b/buildroot-patches/0002-rpi-firmware-Bump-firmware.patch index e8e832988..7bd88826d 100644 --- a/buildroot-patches/0002-rpi-firmware-Bump-firmware.patch +++ b/buildroot-patches/0002-rpi-firmware-Bump-firmware.patch @@ -16,7 +16,7 @@ index 59ab1da0c6..e3ba1bf99c 100644 @@ -1,3 +1,3 @@ # Locally computed -sha256 31a84340be08be319570a9d1439f25c0e3513fed73065a56aa5dd61dd605d5d9 rpi-firmware-01ecfd2ba2b7cf3a2f4aa75ada895ee4a3e729f5.tar.gz -+sha256 4789d4422b3bc7eab157471ba36aebd54efc2a6de4c937f5cfdb4392af04fe80 rpi-firmware-7caead9416f64b2d33361c703fb243b8e157eba4.tar.gz ++sha256 6e5f1bf068995078d4d6a01899a7f7fe094b92a4f5cc19f0d4f67040a3175aa9 rpi-firmware-2b41f509710d99758a5b8efa88d95dd0e9169c0a.tar.gz sha256 c7283ff51f863d93a275c66e3b4cb08021a5dd4d8c1e7acc47d872fbe52d3d6b boot/LICENCE.broadcom diff --git a/package/rpi-firmware/rpi-firmware.mk b/package/rpi-firmware/rpi-firmware.mk index 6fee60b08c..2177ca9859 100644 @@ -27,7 +27,7 @@ index 6fee60b08c..2177ca9859 100644 ################################################################################ -RPI_FIRMWARE_VERSION = 01ecfd2ba2b7cf3a2f4aa75ada895ee4a3e729f5 -+RPI_FIRMWARE_VERSION = 7caead9416f64b2d33361c703fb243b8e157eba4 ++RPI_FIRMWARE_VERSION = 2b41f509710d99758a5b8efa88d95dd0e9169c0a RPI_FIRMWARE_SITE = $(call github,raspberrypi,firmware,$(RPI_FIRMWARE_VERSION)) RPI_FIRMWARE_LICENSE = BSD-3-Clause RPI_FIRMWARE_LICENSE_FILES = boot/LICENCE.broadcom diff --git a/buildroot/package/rpi-firmware/rpi-firmware.hash b/buildroot/package/rpi-firmware/rpi-firmware.hash index 54607d0a4..1add953cb 100644 --- a/buildroot/package/rpi-firmware/rpi-firmware.hash +++ b/buildroot/package/rpi-firmware/rpi-firmware.hash @@ -1,3 +1,3 @@ # Locally computed -sha256 4789d4422b3bc7eab157471ba36aebd54efc2a6de4c937f5cfdb4392af04fe80 rpi-firmware-7caead9416f64b2d33361c703fb243b8e157eba4.tar.gz +sha256 6e5f1bf068995078d4d6a01899a7f7fe094b92a4f5cc19f0d4f67040a3175aa9 rpi-firmware-2b41f509710d99758a5b8efa88d95dd0e9169c0a.tar.gz sha256 c7283ff51f863d93a275c66e3b4cb08021a5dd4d8c1e7acc47d872fbe52d3d6b boot/LICENCE.broadcom diff --git a/buildroot/package/rpi-firmware/rpi-firmware.mk b/buildroot/package/rpi-firmware/rpi-firmware.mk index 8d73aa698..dd44bd758 100644 --- a/buildroot/package/rpi-firmware/rpi-firmware.mk +++ b/buildroot/package/rpi-firmware/rpi-firmware.mk @@ -4,7 +4,7 @@ # ################################################################################ -RPI_FIRMWARE_VERSION = 7caead9416f64b2d33361c703fb243b8e157eba4 +RPI_FIRMWARE_VERSION = 2b41f509710d99758a5b8efa88d95dd0e9169c0a RPI_FIRMWARE_SITE = $(call github,raspberrypi,firmware,$(RPI_FIRMWARE_VERSION)) RPI_FIRMWARE_LICENSE = BSD-3-Clause RPI_FIRMWARE_LICENSE_FILES = boot/LICENCE.broadcom From 2b0fff31a367da05a8b6e171ab11860d4c7edee0 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sat, 17 Oct 2020 13:14:47 +0200 Subject: [PATCH 06/12] Bump ODROID boards to Linux 5.9 (#898) * Bump ODROID boards to Linux 5.9.1 This makes quite some patches obsolete which since have been upstreamed. * Drop Linux 5.7 header symbols Since we do not introduce new packages which actually require a newer kernel headers, there is no value in having config symbols for the new kernel version. Buildroot is still using the headers from our kernel, and hence gets the latest version of the headers. --- ...nfig-enable-meson-gx-audio-as-module.patch | 43 ----- ...dts-meson-convert-ODROID-N2-to-dtsi.patch} | 10 +- ...-imply-acodec-glue-on-axg-sound-card.patch | 28 --- ...mlogic-add-support-for-the-ODROID-N.patch} | 21 ++- ...eson-gx-card-fix-sound-dai-dt-schema.patch | 47 ----- ...meson-add-support-for-the-ODROID-N2.patch} | 16 +- ...arm64-dts-meson-g12-add-internal-DAC.patch | 39 ---- ...son-g12a-mark-fclk_div2-as-critical.patch} | 12 +- ...-dts-meson-g12-add-internal-DAC-glue.patch | 39 ---- ...g12b-odroid-n2-enable-audio-loopback.patch | 123 ------------- ...odroid-n2-add-jack-audio-output-supp.patch | 168 ------------------ .../configs/odroid_c2_defconfig | 4 +- .../configs/odroid_n2_defconfig | 4 +- .../configs/odroid_xu4_defconfig | 4 +- buildroot-patches/0008-Linux-5.7.patch | 68 ------- .../package/linux-headers/Config.in.host | 4 - buildroot/toolchain/Config.in | 5 - .../Config.in.options | 4 - 18 files changed, 34 insertions(+), 605 deletions(-) delete mode 100644 buildroot-external/board/hardkernel/patches/linux/0001-arm64-defconfig-enable-meson-gx-audio-as-module.patch rename buildroot-external/board/hardkernel/patches/linux/{0008-arm64-dts-meson-convert-ODROID-N2-to-dtsi.patch => 0001-arm64-dts-meson-convert-ODROID-N2-to-dtsi.patch} (98%) delete mode 100644 buildroot-external/board/hardkernel/patches/linux/0002-ASoC-meson-imply-acodec-glue-on-axg-sound-card.patch rename buildroot-external/board/hardkernel/patches/linux/{0009-dt-bindings-arm-amlogic-add-support-for-the-ODROID-N.patch => 0002-dt-bindings-arm-amlogic-add-support-for-the-ODROID-N.patch} (62%) delete mode 100644 buildroot-external/board/hardkernel/patches/linux/0003-ASoC-meson-gx-card-fix-sound-dai-dt-schema.patch rename buildroot-external/board/hardkernel/patches/linux/{0010-arm64-dts-meson-add-support-for-the-ODROID-N2.patch => 0003-arm64-dts-meson-add-support-for-the-ODROID-N2.patch} (85%) delete mode 100644 buildroot-external/board/hardkernel/patches/linux/0004-arm64-dts-meson-g12-add-internal-DAC.patch rename buildroot-external/board/hardkernel/patches/linux/{0011-clk-meson-g12a-mark-fclk_div2-as-critical.patch => 0004-clk-meson-g12a-mark-fclk_div2-as-critical.patch} (71%) delete mode 100644 buildroot-external/board/hardkernel/patches/linux/0005-arm64-dts-meson-g12-add-internal-DAC-glue.patch delete mode 100644 buildroot-external/board/hardkernel/patches/linux/0006-arm64-dts-meson-g12b-odroid-n2-enable-audio-loopback.patch delete mode 100644 buildroot-external/board/hardkernel/patches/linux/0007-arm64-dts-meson-odroid-n2-add-jack-audio-output-supp.patch delete mode 100644 buildroot-patches/0008-Linux-5.7.patch diff --git a/buildroot-external/board/hardkernel/patches/linux/0001-arm64-defconfig-enable-meson-gx-audio-as-module.patch b/buildroot-external/board/hardkernel/patches/linux/0001-arm64-defconfig-enable-meson-gx-audio-as-module.patch deleted file mode 100644 index d323d6860..000000000 --- a/buildroot-external/board/hardkernel/patches/linux/0001-arm64-defconfig-enable-meson-gx-audio-as-module.patch +++ /dev/null @@ -1,43 +0,0 @@ -From e2b93751cfd0722801b65b4603b588ab9df4c12b Mon Sep 17 00:00:00 2001 -From: Jerome Brunet -Date: Tue, 21 Apr 2020 18:39:30 +0200 -Subject: [PATCH 2/8] arm64: defconfig: enable meson gx audio as module - -Enable the module config for the Amlogic GX audio card. -This module will imply the internal components usually associated -with it to make a functional sound card on these platforms. - -Also enable the simple amplifier module which often used on the -output stage of those cards. - -Signed-off-by: Jerome Brunet -Signed-off-by: Kevin Hilman -Tested-by: Christian Hewitt -Link: https://lore.kernel.org/r/20200421163935.775935-2-jbrunet@baylibre.com ---- - arch/arm64/configs/defconfig | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig -index 03d0189f7d68..ceb60ee9c340 100644 ---- a/arch/arm64/configs/defconfig -+++ b/arch/arm64/configs/defconfig -@@ -644,6 +644,7 @@ CONFIG_SND_HDA_CODEC_HDMI=m - CONFIG_SND_SOC=y - CONFIG_SND_BCM2835_SOC_I2S=m - CONFIG_SND_MESON_AXG_SOUND_CARD=m -+CONFIG_SND_MESON_GX_SOUND_CARD=m - CONFIG_SND_SOC_SDM845=m - CONFIG_SND_SOC_ROCKCHIP=m - CONFIG_SND_SOC_ROCKCHIP_SPDIF=m -@@ -656,6 +657,7 @@ CONFIG_SND_SOC_AK4613=m - CONFIG_SND_SOC_ES7134=m - CONFIG_SND_SOC_ES7241=m - CONFIG_SND_SOC_PCM3168A_I2C=m -+CONFIG_SND_SOC_SIMPLE_AMPLIFIER=m - CONFIG_SND_SOC_TAS571X=m - CONFIG_SND_SOC_WCD934X=m - CONFIG_SND_SOC_WSA881X=m --- -2.17.1 - diff --git a/buildroot-external/board/hardkernel/patches/linux/0008-arm64-dts-meson-convert-ODROID-N2-to-dtsi.patch b/buildroot-external/board/hardkernel/patches/linux/0001-arm64-dts-meson-convert-ODROID-N2-to-dtsi.patch similarity index 98% rename from buildroot-external/board/hardkernel/patches/linux/0008-arm64-dts-meson-convert-ODROID-N2-to-dtsi.patch rename to buildroot-external/board/hardkernel/patches/linux/0001-arm64-dts-meson-convert-ODROID-N2-to-dtsi.patch index 335f704c6..5f2f534bc 100644 --- a/buildroot-external/board/hardkernel/patches/linux/0008-arm64-dts-meson-convert-ODROID-N2-to-dtsi.patch +++ b/buildroot-external/board/hardkernel/patches/linux/0001-arm64-dts-meson-convert-ODROID-N2-to-dtsi.patch @@ -1,10 +1,8 @@ -From 9443f2cd21a8ebd08f0fb64f5b3a8ccb6cd77d8e Mon Sep 17 00:00:00 2001 -Message-Id: <9443f2cd21a8ebd08f0fb64f5b3a8ccb6cd77d8e.1596660075.git.stefan@agner.ch> -In-Reply-To: -References: +From d35db3d5f943fea569dde8e83f15565254643385 Mon Sep 17 00:00:00 2001 +Message-Id: From: Christian Hewitt Date: Sun, 19 Jul 2020 14:10:32 +0000 -Subject: [PATCH 08/10] arm64: dts: meson: convert ODROID-N2 to dtsi +Subject: [PATCH 1/4] arm64: dts: meson: convert ODROID-N2 to dtsi Convert the current ODROID-N2 dts into a common dtsi in preparation for adding ODROID-N2+ support. @@ -1283,5 +1281,5 @@ index 000000000000..e5bc132ce7d5 + phy-supply = <&hub_5v>; +}; -- -2.27.0 +2.28.0 diff --git a/buildroot-external/board/hardkernel/patches/linux/0002-ASoC-meson-imply-acodec-glue-on-axg-sound-card.patch b/buildroot-external/board/hardkernel/patches/linux/0002-ASoC-meson-imply-acodec-glue-on-axg-sound-card.patch deleted file mode 100644 index b068aa1e4..000000000 --- a/buildroot-external/board/hardkernel/patches/linux/0002-ASoC-meson-imply-acodec-glue-on-axg-sound-card.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 821b8ac21b1675910423ee69d37cb1977b8f271e Mon Sep 17 00:00:00 2001 -From: Jerome Brunet -Date: Mon, 30 Mar 2020 17:39:04 +0200 -Subject: [PATCH 3/8] ASoC: meson: imply acodec glue on axg sound card - -When axg card driver support is enabled, lets enable the related -internal DAC glue by default. - -Signed-off-by: Jerome Brunet ---- - sound/soc/meson/Kconfig | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/sound/soc/meson/Kconfig b/sound/soc/meson/Kconfig -index 8b6295283989..363dc3b1bbe4 100644 ---- a/sound/soc/meson/Kconfig -+++ b/sound/soc/meson/Kconfig -@@ -68,6 +68,7 @@ config SND_MESON_AXG_SOUND_CARD - imply SND_MESON_AXG_SPDIFOUT - imply SND_MESON_AXG_SPDIFIN - imply SND_MESON_AXG_PDM -+ imply SND_MESON_G12A_TOACODEC - imply SND_MESON_G12A_TOHDMITX if DRM_MESON_DW_HDMI - help - Select Y or M to add support for the AXG SoC sound card --- -2.17.1 - diff --git a/buildroot-external/board/hardkernel/patches/linux/0009-dt-bindings-arm-amlogic-add-support-for-the-ODROID-N.patch b/buildroot-external/board/hardkernel/patches/linux/0002-dt-bindings-arm-amlogic-add-support-for-the-ODROID-N.patch similarity index 62% rename from buildroot-external/board/hardkernel/patches/linux/0009-dt-bindings-arm-amlogic-add-support-for-the-ODROID-N.patch rename to buildroot-external/board/hardkernel/patches/linux/0002-dt-bindings-arm-amlogic-add-support-for-the-ODROID-N.patch index 23b58efb2..39ff63029 100644 --- a/buildroot-external/board/hardkernel/patches/linux/0009-dt-bindings-arm-amlogic-add-support-for-the-ODROID-N.patch +++ b/buildroot-external/board/hardkernel/patches/linux/0002-dt-bindings-arm-amlogic-add-support-for-the-ODROID-N.patch @@ -1,11 +1,10 @@ -From 54d8ae2ae7a10dab6998b2d4ac507aec96c6f1da Mon Sep 17 00:00:00 2001 -Message-Id: <54d8ae2ae7a10dab6998b2d4ac507aec96c6f1da.1595882680.git.stefan@agner.ch> -In-Reply-To: -References: +From 4b9d9159ed5a79ceac5b831012b3cb44cce2516c Mon Sep 17 00:00:00 2001 +Message-Id: <4b9d9159ed5a79ceac5b831012b3cb44cce2516c.1602360581.git.stefan@agner.ch> +In-Reply-To: +References: From: Christian Hewitt Date: Sun, 19 Jul 2020 14:10:33 +0000 -Subject: [PATCH 09/10] dt-bindings: arm: amlogic: add support for the - ODROID-N2+ +Subject: [PATCH 2/4] dt-bindings: arm: amlogic: add support for the ODROID-N2+ HardKernel ODROID-N2+ uses a revised Amlogic S922X v2 chip that supports higher cpu clock speeds than the original ODROID-N2. @@ -16,17 +15,17 @@ Signed-off-by: Christian Hewitt 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/arm/amlogic.yaml b/Documentation/devicetree/bindings/arm/amlogic.yaml -index f74aba48cec1..915ef4f355ad 100644 +index 5eba9f48823e..12ba8d074370 100644 --- a/Documentation/devicetree/bindings/arm/amlogic.yaml +++ b/Documentation/devicetree/bindings/arm/amlogic.yaml -@@ -149,6 +149,7 @@ properties: - items: - - enum: +@@ -153,6 +153,7 @@ properties: + - azw,gtking + - azw,gtking-pro - hardkernel,odroid-n2 + - hardkernel,odroid-n2-plus - khadas,vim3 - ugoos,am6 - const: amlogic,s922x -- -2.27.0 +2.28.0 diff --git a/buildroot-external/board/hardkernel/patches/linux/0003-ASoC-meson-gx-card-fix-sound-dai-dt-schema.patch b/buildroot-external/board/hardkernel/patches/linux/0003-ASoC-meson-gx-card-fix-sound-dai-dt-schema.patch deleted file mode 100644 index 2799dc30f..000000000 --- a/buildroot-external/board/hardkernel/patches/linux/0003-ASoC-meson-gx-card-fix-sound-dai-dt-schema.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 60164df03c6314d8f5f3afef56b0bf97962ec9ee Mon Sep 17 00:00:00 2001 -From: Jerome Brunet -Date: Mon, 24 Feb 2020 14:35:17 +0100 -Subject: [PATCH 4/8] ASoC: meson: gx-card: fix sound-dai dt schema - -There is a fair amount of warnings when running 'make dtbs_check' with -amlogic,gx-sound-card.yaml. - -Ex: -arch/arm64/boot/dts/amlogic/meson-gxm-q200.dt.yaml: sound: dai-link-0:sound-dai:0:1: missing phandle tag in 0 -arch/arm64/boot/dts/amlogic/meson-gxm-q200.dt.yaml: sound: dai-link-0:sound-dai:0:2: missing phandle tag in 0 -arch/arm64/boot/dts/amlogic/meson-gxm-q200.dt.yaml: sound: dai-link-0:sound-dai:0: [66, 0, 0] is too long - -The reason is that the sound-dai phandle provided has cells, and in such -case the schema should use 'phandle-array' instead of 'phandle'. - -Fixes: fd00366b8e41 ("ASoC: meson: gx: add sound card dt-binding documentation") -Signed-off-by: Jerome Brunet ---- - .../devicetree/bindings/sound/amlogic,gx-sound-card.yaml | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/Documentation/devicetree/bindings/sound/amlogic,gx-sound-card.yaml b/Documentation/devicetree/bindings/sound/amlogic,gx-sound-card.yaml -index fb374c659be1..a48222e8cd08 100644 ---- a/Documentation/devicetree/bindings/sound/amlogic,gx-sound-card.yaml -+++ b/Documentation/devicetree/bindings/sound/amlogic,gx-sound-card.yaml -@@ -57,7 +57,7 @@ patternProperties: - rate - - sound-dai: -- $ref: /schemas/types.yaml#/definitions/phandle -+ $ref: /schemas/types.yaml#/definitions/phandle-array - description: phandle of the CPU DAI - - patternProperties: -@@ -71,7 +71,7 @@ patternProperties: - - properties: - sound-dai: -- $ref: /schemas/types.yaml#/definitions/phandle -+ $ref: /schemas/types.yaml#/definitions/phandle-array - description: phandle of the codec DAI - - required: --- -2.17.1 - diff --git a/buildroot-external/board/hardkernel/patches/linux/0010-arm64-dts-meson-add-support-for-the-ODROID-N2.patch b/buildroot-external/board/hardkernel/patches/linux/0003-arm64-dts-meson-add-support-for-the-ODROID-N2.patch similarity index 85% rename from buildroot-external/board/hardkernel/patches/linux/0010-arm64-dts-meson-add-support-for-the-ODROID-N2.patch rename to buildroot-external/board/hardkernel/patches/linux/0003-arm64-dts-meson-add-support-for-the-ODROID-N2.patch index 42ebf9903..61a55fa7d 100644 --- a/buildroot-external/board/hardkernel/patches/linux/0010-arm64-dts-meson-add-support-for-the-ODROID-N2.patch +++ b/buildroot-external/board/hardkernel/patches/linux/0003-arm64-dts-meson-add-support-for-the-ODROID-N2.patch @@ -1,10 +1,10 @@ -From 188bc924b34b7d845324eb2e0e7493a9eaeb2cb5 Mon Sep 17 00:00:00 2001 -Message-Id: <188bc924b34b7d845324eb2e0e7493a9eaeb2cb5.1595882680.git.stefan@agner.ch> -In-Reply-To: -References: +From 81b5af6c3ce3e0f312be0897bec0b3c942e2ce97 Mon Sep 17 00:00:00 2001 +Message-Id: <81b5af6c3ce3e0f312be0897bec0b3c942e2ce97.1602360581.git.stefan@agner.ch> +In-Reply-To: +References: From: Christian Hewitt Date: Sun, 19 Jul 2020 14:10:34 +0000 -Subject: [PATCH 10/10] arm64: dts: meson: add support for the ODROID-N2+ +Subject: [PATCH 3/4] arm64: dts: meson: add support for the ODROID-N2+ HardKernel ODROID-N2+ uses an Amlogic S922X rev. C chip capable of higher clock speeds than the original ODROID-N2. Hardkernel supports the big cpu @@ -22,10 +22,10 @@ Signed-off-by: Stefan Agner create mode 100644 arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2-plus.dts diff --git a/arch/arm64/boot/dts/amlogic/Makefile b/arch/arm64/boot/dts/amlogic/Makefile -index eef0045320f2..7524cf9680f5 100644 +index 4e2239ffcaa5..b0b3d6791499 100644 --- a/arch/arm64/boot/dts/amlogic/Makefile +++ b/arch/arm64/boot/dts/amlogic/Makefile -@@ -6,6 +6,7 @@ dtb-$(CONFIG_ARCH_MESON) += meson-g12a-x96-max.dtb +@@ -8,6 +8,7 @@ dtb-$(CONFIG_ARCH_MESON) += meson-g12b-gtking-pro.dtb dtb-$(CONFIG_ARCH_MESON) += meson-g12b-a311d-khadas-vim3.dtb dtb-$(CONFIG_ARCH_MESON) += meson-g12b-s922x-khadas-vim3.dtb dtb-$(CONFIG_ARCH_MESON) += meson-g12b-odroid-n2.dtb @@ -93,5 +93,5 @@ index 000000000000..4ebb448d233f +}; + -- -2.27.0 +2.28.0 diff --git a/buildroot-external/board/hardkernel/patches/linux/0004-arm64-dts-meson-g12-add-internal-DAC.patch b/buildroot-external/board/hardkernel/patches/linux/0004-arm64-dts-meson-g12-add-internal-DAC.patch deleted file mode 100644 index 4059bf8b0..000000000 --- a/buildroot-external/board/hardkernel/patches/linux/0004-arm64-dts-meson-g12-add-internal-DAC.patch +++ /dev/null @@ -1,39 +0,0 @@ -From e128dd1ca079c5ee558ab100387d9f81bd4f3980 Mon Sep 17 00:00:00 2001 -From: Jerome Brunet -Date: Thu, 7 May 2020 00:16:55 +0200 -Subject: [PATCH 5/8] arm64: dts: meson: g12: add internal DAC - -add internal audio DAC support on the g12 and sm1 SoC family - -Signed-off-by: Jerome Brunet -Signed-off-by: Kevin Hilman -Link: https://lore.kernel.org/r/20200506221656.477379-7-jbrunet@baylibre.com ---- - arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi | 11 +++++++++++ - 1 file changed, 11 insertions(+) - -diff --git a/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi b/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi -index c0aef7d69117..593a006f4b7b 100644 ---- a/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi -+++ b/arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi -@@ -250,6 +250,17 @@ - }; - }; - -+ acodec: audio-controller@32000 { -+ compatible = "amlogic,t9015"; -+ reg = <0x0 0x32000 0x0 0x14>; -+ #sound-dai-cells = <0>; -+ sound-name-prefix = "ACODEC"; -+ clocks = <&clkc CLKID_AUDIO_CODEC>; -+ clock-names = "pclk"; -+ resets = <&reset RESET_AUDIO_CODEC>; -+ status = "disabled"; -+ }; -+ - periphs: bus@34400 { - compatible = "simple-bus"; - reg = <0x0 0x34400 0x0 0x400>; --- -2.17.1 - diff --git a/buildroot-external/board/hardkernel/patches/linux/0011-clk-meson-g12a-mark-fclk_div2-as-critical.patch b/buildroot-external/board/hardkernel/patches/linux/0004-clk-meson-g12a-mark-fclk_div2-as-critical.patch similarity index 71% rename from buildroot-external/board/hardkernel/patches/linux/0011-clk-meson-g12a-mark-fclk_div2-as-critical.patch rename to buildroot-external/board/hardkernel/patches/linux/0004-clk-meson-g12a-mark-fclk_div2-as-critical.patch index 2095a67ba..dcd0d723c 100644 --- a/buildroot-external/board/hardkernel/patches/linux/0011-clk-meson-g12a-mark-fclk_div2-as-critical.patch +++ b/buildroot-external/board/hardkernel/patches/linux/0004-clk-meson-g12a-mark-fclk_div2-as-critical.patch @@ -1,10 +1,10 @@ -From c33df0ebe8be16b56741ce7f873221ab9087a0a6 Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: +From 6a7c42785788faa862aeb7902cb2b3b08f033ca0 Mon Sep 17 00:00:00 2001 +Message-Id: <6a7c42785788faa862aeb7902cb2b3b08f033ca0.1602360581.git.stefan@agner.ch> +In-Reply-To: +References: From: Stefan Agner Date: Thu, 27 Aug 2020 23:29:57 +0200 -Subject: [PATCH 11/11] clk: meson: g12a: mark fclk_div2 as critical +Subject: [PATCH 4/4] clk: meson: g12a: mark fclk_div2 as critical On Amlogic Meson G12b platform, similar to fclk_div3, the fclk_div2 seems to be necessary for the system to operate correctly as well. @@ -22,7 +22,7 @@ Signed-off-by: Stefan Agner 1 file changed, 1 insertion(+) diff --git a/drivers/clk/meson/g12a.c b/drivers/clk/meson/g12a.c -index fad616cac01e..2214b974f748 100644 +index 9803d44bb157..9a6722a1dc19 100644 --- a/drivers/clk/meson/g12a.c +++ b/drivers/clk/meson/g12a.c @@ -298,6 +298,7 @@ static struct clk_regmap g12a_fclk_div2 = { diff --git a/buildroot-external/board/hardkernel/patches/linux/0005-arm64-dts-meson-g12-add-internal-DAC-glue.patch b/buildroot-external/board/hardkernel/patches/linux/0005-arm64-dts-meson-g12-add-internal-DAC-glue.patch deleted file mode 100644 index 515ba0574..000000000 --- a/buildroot-external/board/hardkernel/patches/linux/0005-arm64-dts-meson-g12-add-internal-DAC-glue.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 5ea4085da165fd3f3aa211cb3664dd166d0d5fd7 Mon Sep 17 00:00:00 2001 -From: Jerome Brunet -Date: Thu, 7 May 2020 00:16:56 +0200 -Subject: [PATCH 6/8] arm64: dts: meson: g12: add internal DAC glue - -add the internal DAC glue support on the g12 and sm1 family -This glue connects the different TDM interfaces of the SoC to -the internal audio DAC codec. - -Signed-off-by: Jerome Brunet -Signed-off-by: Kevin Hilman -Link: https://lore.kernel.org/r/20200506221656.477379-8-jbrunet@baylibre.com ---- - arch/arm64/boot/dts/amlogic/meson-g12.dtsi | 9 +++++++++ - 1 file changed, 9 insertions(+) - -diff --git a/arch/arm64/boot/dts/amlogic/meson-g12.dtsi b/arch/arm64/boot/dts/amlogic/meson-g12.dtsi -index 55d39020ec72..0d14409f509c 100644 ---- a/arch/arm64/boot/dts/amlogic/meson-g12.dtsi -+++ b/arch/arm64/boot/dts/amlogic/meson-g12.dtsi -@@ -343,6 +343,15 @@ - status = "disabled"; - }; - -+ toacodec: audio-controller@740 { -+ compatible = "amlogic,g12a-toacodec"; -+ reg = <0x0 0x740 0x0 0x4>; -+ #sound-dai-cells = <1>; -+ sound-name-prefix = "TOACODEC"; -+ resets = <&clkc_audio AUD_RESET_TOACODEC>; -+ status = "disabled"; -+ }; -+ - tohdmitx: audio-controller@744 { - compatible = "amlogic,g12a-tohdmitx"; - reg = <0x0 0x744 0x0 0x4>; --- -2.17.1 - diff --git a/buildroot-external/board/hardkernel/patches/linux/0006-arm64-dts-meson-g12b-odroid-n2-enable-audio-loopback.patch b/buildroot-external/board/hardkernel/patches/linux/0006-arm64-dts-meson-g12b-odroid-n2-enable-audio-loopback.patch deleted file mode 100644 index 0a4741d94..000000000 --- a/buildroot-external/board/hardkernel/patches/linux/0006-arm64-dts-meson-g12b-odroid-n2-enable-audio-loopback.patch +++ /dev/null @@ -1,123 +0,0 @@ -From 15b3cef2ea75c4d81cb067264be1cf49c49f81b1 Mon Sep 17 00:00:00 2001 -From: Jerome Brunet -Date: Mon, 15 Jun 2020 15:38:44 +0200 -Subject: [PATCH 7/8] arm64: dts: meson-g12b: odroid-n2: enable audio loopback - -Add capture pcm interfaces and loopback routes to the odroid-n2 - -Signed-off-by: Jerome Brunet ---- - .../boot/dts/amlogic/meson-g12b-odroid-n2.dts | 65 +++++++++++++++++-- - 1 file changed, 61 insertions(+), 4 deletions(-) - -diff --git a/arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dts b/arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dts -index 169ea283d4ee..d4421ad164bd 100644 ---- a/arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dts -+++ b/arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dts -@@ -209,11 +209,28 @@ - sound { - compatible = "amlogic,axg-sound-card"; - model = "G12B-ODROID-N2"; -- audio-aux-devs = <&tdmout_b>; -+ audio-aux-devs = <&tdmout_b>, <&tdmin_a>, <&tdmin_b>, -+ <&tdmin_c>, <&tdmin_lb>; - audio-routing = "TDMOUT_B IN 0", "FRDDR_A OUT 1", - "TDMOUT_B IN 1", "FRDDR_B OUT 1", - "TDMOUT_B IN 2", "FRDDR_C OUT 1", -- "TDM_B Playback", "TDMOUT_B OUT"; -+ "TDM_B Playback", "TDMOUT_B OUT", -+ "TDMIN_A IN 4", "TDM_B Loopback", -+ "TDMIN_B IN 4", "TDM_B Loopback", -+ "TDMIN_C IN 4", "TDM_B Loopback", -+ "TDMIN_LB IN 1", "TDM_B Loopback", -+ "TODDR_A IN 0", "TDMIN_A OUT", -+ "TODDR_B IN 0", "TDMIN_A OUT", -+ "TODDR_C IN 0", "TDMIN_A OUT", -+ "TODDR_A IN 1", "TDMIN_B OUT", -+ "TODDR_B IN 1", "TDMIN_B OUT", -+ "TODDR_C IN 1", "TDMIN_B OUT", -+ "TODDR_A IN 2", "TDMIN_C OUT", -+ "TODDR_B IN 2", "TDMIN_C OUT", -+ "TODDR_C IN 2", "TDMIN_C OUT", -+ "TODDR_A IN 6", "TDMIN_LB OUT", -+ "TODDR_B IN 6", "TDMIN_LB OUT", -+ "TODDR_C IN 6", "TDMIN_LB OUT"; - - assigned-clocks = <&clkc CLKID_MPLL2>, - <&clkc CLKID_MPLL0>, -@@ -236,8 +253,20 @@ - sound-dai = <&frddr_c>; - }; - -- /* 8ch hdmi interface */ - dai-link-3 { -+ sound-dai = <&toddr_a>; -+ }; -+ -+ dai-link-4 { -+ sound-dai = <&toddr_b>; -+ }; -+ -+ dai-link-5 { -+ sound-dai = <&toddr_c>; -+ }; -+ -+ /* 8ch hdmi interface */ -+ dai-link-6 { - sound-dai = <&tdmif_b>; - dai-format = "i2s"; - dai-tdm-slot-tx-mask-0 = <1 1>; -@@ -252,7 +281,7 @@ - }; - - /* hdmi glue */ -- dai-link-4 { -+ dai-link-7 { - sound-dai = <&tohdmitx TOHDMITX_I2S_OUT>; - - codec { -@@ -476,6 +505,22 @@ - status = "okay"; - }; - -+&tdmin_a { -+ status = "okay"; -+}; -+ -+&tdmin_b { -+ status = "okay"; -+}; -+ -+&tdmin_c { -+ status = "okay"; -+}; -+ -+&tdmin_lb { -+ status = "okay"; -+}; -+ - &tdmout_b { - status = "okay"; - }; -@@ -484,6 +529,18 @@ - status = "okay"; - }; - -+&toddr_a { -+ status = "okay"; -+}; -+ -+&toddr_b { -+ status = "okay"; -+}; -+ -+&toddr_c { -+ status = "okay"; -+}; -+ - &uart_AO { - status = "okay"; - pinctrl-0 = <&uart_ao_a_pins>; --- -2.17.1 - diff --git a/buildroot-external/board/hardkernel/patches/linux/0007-arm64-dts-meson-odroid-n2-add-jack-audio-output-supp.patch b/buildroot-external/board/hardkernel/patches/linux/0007-arm64-dts-meson-odroid-n2-add-jack-audio-output-supp.patch deleted file mode 100644 index b3f613ef1..000000000 --- a/buildroot-external/board/hardkernel/patches/linux/0007-arm64-dts-meson-odroid-n2-add-jack-audio-output-supp.patch +++ /dev/null @@ -1,168 +0,0 @@ -From 978cc250574b7f1ab45f494cc2a094e3c9fd1fa4 Mon Sep 17 00:00:00 2001 -From: Jerome Brunet -Date: Mon, 15 Jun 2020 16:34:37 +0200 -Subject: [PATCH 8/8] arm64: dts: meson: odroid-n2: add jack audio output - support - -Signed-off-by: Jerome Brunet ---- - .../boot/dts/amlogic/meson-g12b-odroid-n2.dts | 79 +++++++++++++++++-- - 1 file changed, 74 insertions(+), 5 deletions(-) - -diff --git a/arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dts b/arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dts -index d4421ad164bd..34fffa6d859d 100644 ---- a/arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dts -+++ b/arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dts -@@ -9,6 +9,7 @@ - #include "meson-g12b-s922x.dtsi" - #include - #include -+#include - #include - - / { -@@ -20,6 +21,14 @@ - ethernet0 = ðmac; - }; - -+ dioo2133: audio-amplifier-0 { -+ compatible = "simple-audio-amplifier"; -+ enable-gpios = <&gpio_ao GPIOAO_2 GPIO_ACTIVE_HIGH>; -+ VCC-supply = <&vcc_5v>; -+ sound-name-prefix = "U19"; -+ status = "okay"; -+ }; -+ - chosen { - stdout-path = "serial0:115200n8"; - }; -@@ -209,16 +218,26 @@ - sound { - compatible = "amlogic,axg-sound-card"; - model = "G12B-ODROID-N2"; -- audio-aux-devs = <&tdmout_b>, <&tdmin_a>, <&tdmin_b>, -- <&tdmin_c>, <&tdmin_lb>; -+ audio-widgets = "Line", "Lineout"; -+ audio-aux-devs = <&tdmout_b>, <&tdmout_c>, <&tdmin_a>, -+ <&tdmin_b>, <&tdmin_c>, <&tdmin_lb>, -+ <&dioo2133>; - audio-routing = "TDMOUT_B IN 0", "FRDDR_A OUT 1", - "TDMOUT_B IN 1", "FRDDR_B OUT 1", - "TDMOUT_B IN 2", "FRDDR_C OUT 1", - "TDM_B Playback", "TDMOUT_B OUT", -+ "TDMOUT_C IN 0", "FRDDR_A OUT 2", -+ "TDMOUT_C IN 1", "FRDDR_B OUT 2", -+ "TDMOUT_C IN 2", "FRDDR_C OUT 2", -+ "TDM_C Playback", "TDMOUT_C OUT", - "TDMIN_A IN 4", "TDM_B Loopback", - "TDMIN_B IN 4", "TDM_B Loopback", - "TDMIN_C IN 4", "TDM_B Loopback", - "TDMIN_LB IN 1", "TDM_B Loopback", -+ "TDMIN_A IN 5", "TDM_C Loopback", -+ "TDMIN_B IN 5", "TDM_C Loopback", -+ "TDMIN_C IN 5", "TDM_C Loopback", -+ "TDMIN_LB IN 2", "TDM_C Loopback", - "TODDR_A IN 0", "TDMIN_A OUT", - "TODDR_B IN 0", "TDMIN_A OUT", - "TODDR_C IN 0", "TDMIN_A OUT", -@@ -230,7 +249,11 @@ - "TODDR_C IN 2", "TDMIN_C OUT", - "TODDR_A IN 6", "TDMIN_LB OUT", - "TODDR_B IN 6", "TDMIN_LB OUT", -- "TODDR_C IN 6", "TDMIN_LB OUT"; -+ "TODDR_C IN 6", "TDMIN_LB OUT", -+ "U19 INL", "ACODEC LOLP", -+ "U19 INR", "ACODEC LORP", -+ "Lineout", "U19 OUTL", -+ "Lineout", "U19 OUTR"; - - assigned-clocks = <&clkc CLKID_MPLL2>, - <&clkc CLKID_MPLL0>, -@@ -275,22 +298,56 @@ - dai-tdm-slot-tx-mask-3 = <1 1>; - mclk-fs = <256>; - -- codec { -+ codec-0 { - sound-dai = <&tohdmitx TOHDMITX_I2S_IN_B>; - }; -+ -+ codec-1 { -+ sound-dai = <&toacodec TOACODEC_IN_B>; -+ }; - }; - -- /* hdmi glue */ -+ /* i2s jack output interface */ - dai-link-7 { -+ sound-dai = <&tdmif_c>; -+ dai-format = "i2s"; -+ dai-tdm-slot-tx-mask-0 = <1 1>; -+ mclk-fs = <256>; -+ -+ codec-0 { -+ sound-dai = <&tohdmitx TOHDMITX_I2S_IN_C>; -+ }; -+ -+ codec-1 { -+ sound-dai = <&toacodec TOACODEC_IN_C>; -+ }; -+ }; -+ -+ /* hdmi glue */ -+ dai-link-8 { - sound-dai = <&tohdmitx TOHDMITX_I2S_OUT>; - - codec { - sound-dai = <&hdmi_tx>; - }; - }; -+ -+ /* acodec glue */ -+ dai-link-9 { -+ sound-dai = <&toacodec TOACODEC_OUT>; -+ -+ codec { -+ sound-dai = <&acodec>; -+ }; -+ }; - }; - }; - -+&acodec { -+ AVDD-supply = <&vddao_1v8>; -+ status = "okay"; -+}; -+ - &arb { - status = "okay"; - }; -@@ -505,6 +562,10 @@ - status = "okay"; - }; - -+&tdmif_c { -+ status = "okay"; -+}; -+ - &tdmin_a { - status = "okay"; - }; -@@ -525,6 +586,14 @@ - status = "okay"; - }; - -+&tdmout_c { -+ status = "okay"; -+}; -+ -+&toacodec { -+ status = "okay"; -+}; -+ - &tohdmitx { - status = "okay"; - }; --- -2.17.1 - diff --git a/buildroot-external/configs/odroid_c2_defconfig b/buildroot-external/configs/odroid_c2_defconfig index dd73aed0f..54f15a685 100644 --- a/buildroot-external/configs/odroid_c2_defconfig +++ b/buildroot-external/configs/odroid_c2_defconfig @@ -22,7 +22,7 @@ BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_HASSOS_PATH)/scripts/post-image.sh" BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-c2 $(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-c2/hassos-hook.sh" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.7.19" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.9.1" BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/kernel-amlogic.config" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/kernel/hassos.config $(BR2_EXTERNAL_HASSOS_PATH)/kernel/docker.config $(BR2_EXTERNAL_HASSOS_PATH)/kernel/device-support.config" @@ -89,7 +89,7 @@ BR2_TARGET_UBOOT_BOARD_DEFCONFIG="odroid-c2" BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/uboot.config $(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-c2/uboot.config" BR2_TARGET_UBOOT_BOOT_SCRIPT=y BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="$(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-c2/uboot-boot.ush" -BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_7=y +BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4=y BR2_PACKAGE_HOST_DOSFSTOOLS=y BR2_PACKAGE_HOST_E2FSPROGS=y BR2_PACKAGE_HOST_GPTFDISK=y diff --git a/buildroot-external/configs/odroid_n2_defconfig b/buildroot-external/configs/odroid_n2_defconfig index 3b1fcecb5..bf50b00dd 100644 --- a/buildroot-external/configs/odroid_n2_defconfig +++ b/buildroot-external/configs/odroid_n2_defconfig @@ -22,7 +22,7 @@ BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_HASSOS_PATH)/scripts/post-image.sh" BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-n2 $(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-n2/hassos-hook.sh" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.7.19" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.9.1" BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/kernel-amlogic.config" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/kernel/hassos.config $(BR2_EXTERNAL_HASSOS_PATH)/kernel/docker.config $(BR2_EXTERNAL_HASSOS_PATH)/kernel/device-support.config" @@ -89,7 +89,7 @@ BR2_TARGET_UBOOT_BOARD_DEFCONFIG="odroid-n2" BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/uboot.config $(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-n2/uboot.config" BR2_TARGET_UBOOT_BOOT_SCRIPT=y BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="$(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-n2/uboot-boot.ush" -BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_7=y +BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4=y BR2_PACKAGE_HOST_DOSFSTOOLS=y BR2_PACKAGE_HOST_E2FSPROGS=y BR2_PACKAGE_HOST_GPTFDISK=y diff --git a/buildroot-external/configs/odroid_xu4_defconfig b/buildroot-external/configs/odroid_xu4_defconfig index ecc84e65e..1a3e27d6b 100644 --- a/buildroot-external/configs/odroid_xu4_defconfig +++ b/buildroot-external/configs/odroid_xu4_defconfig @@ -23,7 +23,7 @@ BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_HASSOS_PATH)/scripts/post-image.sh" BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-xu4 $(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-xu4/hassos-hook.sh" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.7.19" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.9.1" BR2_LINUX_KERNEL_DEFCONFIG="exynos" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/kernel/hassos.config $(BR2_EXTERNAL_HASSOS_PATH)/kernel/docker.config $(BR2_EXTERNAL_HASSOS_PATH)/kernel/device-support.config" BR2_LINUX_KERNEL_LZ4=y @@ -93,7 +93,7 @@ BR2_TARGET_UBOOT_FORMAT_DTB_BIN=y BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/uboot.config $(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-xu4/uboot.config" BR2_TARGET_UBOOT_BOOT_SCRIPT=y BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="$(BR2_EXTERNAL_HASSOS_PATH)/board/hardkernel/odroid-xu4/uboot-boot.ush" -BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_7=y +BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4=y BR2_PACKAGE_HOST_DOSFSTOOLS=y BR2_PACKAGE_HOST_E2FSPROGS=y BR2_PACKAGE_HOST_GPTFDISK=y diff --git a/buildroot-patches/0008-Linux-5.7.patch b/buildroot-patches/0008-Linux-5.7.patch deleted file mode 100644 index e26780a70..000000000 --- a/buildroot-patches/0008-Linux-5.7.patch +++ /dev/null @@ -1,68 +0,0 @@ -From e36dc9a2a030204b5b6c6868348878b596f88de3 Mon Sep 17 00:00:00 2001 -From: Pascal Vizeli -Date: Fri, 5 Jun 2020 14:18:26 +0000 -Subject: [PATCH 1/1] Linux 5.7 - -Signed-off-by: Pascal Vizeli ---- - package/linux-headers/Config.in.host | 4 ++++ - toolchain/Config.in | 5 +++++ - .../toolchain-external-custom/Config.in.options | 4 ++++ - 3 files changed, 13 insertions(+) - -diff --git a/package/linux-headers/Config.in.host b/package/linux-headers/Config.in.host -index 95e85a00..88b9ff99 100644 ---- a/package/linux-headers/Config.in.host -+++ b/package/linux-headers/Config.in.host -@@ -127,6 +127,10 @@ choice - If your kernel headers are more recent than the latest version - in the choice, then select the latest version. - -+config BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_7 -+ bool "5.7.x or later" -+ select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_7 -+ - config BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4 - bool "5.4.x or later" - select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 -diff --git a/toolchain/Config.in b/toolchain/Config.in -index bff57280..c07a92ce 100644 ---- a/toolchain/Config.in -+++ b/toolchain/Config.in -@@ -470,6 +470,10 @@ config BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 - select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_3 - select BR2_TOOLCHAIN_HEADERS_LATEST - -+config BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_7 -+ bool -+ select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 -+ - # This should be selected by the latest version, above, to indicate that - # Buildroot does not know of more recent headers than the ones selected. - # This allows using toolchains with headers more recent than Buildroot -@@ -481,6 +485,7 @@ config BR2_TOOLCHAIN_HEADERS_LATEST - # stops affecting a value on the first matching default. - config BR2_TOOLCHAIN_HEADERS_AT_LEAST - string -+ default "5.7" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_7 - default "5.4" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 - default "5.3" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_3 - default "5.2" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_2 -diff --git a/toolchain/toolchain-external/toolchain-external-custom/Config.in.options b/toolchain/toolchain-external/toolchain-external-custom/Config.in.options -index 8c38dd9f..b49231e1 100644 ---- a/toolchain/toolchain-external/toolchain-external-custom/Config.in.options -+++ b/toolchain/toolchain-external/toolchain-external-custom/Config.in.options -@@ -115,6 +115,10 @@ choice - If your toolchain uses headers newer than the latest version - in the choice, then select the latest version. - -+config BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_7 -+ bool "5.7.x or later" -+ select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_7 -+ - config BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_4 - bool "5.4.x or later" - select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 --- -2.17.1 - diff --git a/buildroot/package/linux-headers/Config.in.host b/buildroot/package/linux-headers/Config.in.host index 1b2e2e5bf..7fbd07015 100644 --- a/buildroot/package/linux-headers/Config.in.host +++ b/buildroot/package/linux-headers/Config.in.host @@ -127,10 +127,6 @@ choice If your kernel headers are more recent than the latest version in the choice, then select the latest version. -config BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_7 - bool "5.7.x or later" - select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_7 - config BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_4 bool "5.4.x or later" select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 diff --git a/buildroot/toolchain/Config.in b/buildroot/toolchain/Config.in index c07a92ce5..bff572805 100644 --- a/buildroot/toolchain/Config.in +++ b/buildroot/toolchain/Config.in @@ -470,10 +470,6 @@ config BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_3 select BR2_TOOLCHAIN_HEADERS_LATEST -config BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_7 - bool - select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 - # This should be selected by the latest version, above, to indicate that # Buildroot does not know of more recent headers than the ones selected. # This allows using toolchains with headers more recent than Buildroot @@ -485,7 +481,6 @@ config BR2_TOOLCHAIN_HEADERS_LATEST # stops affecting a value on the first matching default. config BR2_TOOLCHAIN_HEADERS_AT_LEAST string - default "5.7" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_7 default "5.4" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 default "5.3" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_3 default "5.2" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_2 diff --git a/buildroot/toolchain/toolchain-external/toolchain-external-custom/Config.in.options b/buildroot/toolchain/toolchain-external/toolchain-external-custom/Config.in.options index b49231e16..8c38dd9fc 100644 --- a/buildroot/toolchain/toolchain-external/toolchain-external-custom/Config.in.options +++ b/buildroot/toolchain/toolchain-external/toolchain-external-custom/Config.in.options @@ -115,10 +115,6 @@ choice If your toolchain uses headers newer than the latest version in the choice, then select the latest version. -config BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_7 - bool "5.7.x or later" - select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_7 - config BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_4 bool "5.4.x or later" select BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_4 From fc3b098170970cb860996a8e975eaf28b528d810 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sat, 17 Oct 2020 13:16:08 +0200 Subject: [PATCH 07/12] Fix CDC ACM error recovery path (#712) (#905) Revert CDC ACM cool-down patch. This should fix the error recovery paths in the CDC ACM driver and allow CDC ACM devices to continue working even in the event of USB issues. --- ...Revert-cdc-acm-introduce-a-cool-down.patch | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 buildroot-external/board/hardkernel/patches/linux/0001-Revert-cdc-acm-introduce-a-cool-down.patch diff --git a/buildroot-external/board/hardkernel/patches/linux/0001-Revert-cdc-acm-introduce-a-cool-down.patch b/buildroot-external/board/hardkernel/patches/linux/0001-Revert-cdc-acm-introduce-a-cool-down.patch new file mode 100644 index 000000000..8f45af028 --- /dev/null +++ b/buildroot-external/board/hardkernel/patches/linux/0001-Revert-cdc-acm-introduce-a-cool-down.patch @@ -0,0 +1,132 @@ +From 5edf98e1fa176a480686ec77a5782b61eb009842 Mon Sep 17 00:00:00 2001 +From: Jerome Brunet +Date: Thu, 15 Oct 2020 13:58:14 +0200 +Subject: [PATCH] Revert "cdc-acm: introduce a cool down" + +This reverts commit a4e7279cd1d19f48f0af2a10ed020febaa9ac092. +--- + drivers/usb/class/cdc-acm.c | 30 ++---------------------------- + drivers/usb/class/cdc-acm.h | 5 +---- + 2 files changed, 3 insertions(+), 32 deletions(-) + +diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c +index f1a9043bdfe5..0f47d74c857d 100644 +--- a/drivers/usb/class/cdc-acm.c ++++ b/drivers/usb/class/cdc-acm.c +@@ -410,12 +410,9 @@ static void acm_ctrl_irq(struct urb *urb) + + exit: + retval = usb_submit_urb(urb, GFP_ATOMIC); +- if (retval && retval != -EPERM && retval != -ENODEV) ++ if (retval && retval != -EPERM) + dev_err(&acm->control->dev, + "%s - usb_submit_urb failed: %d\n", __func__, retval); +- else +- dev_vdbg(&acm->control->dev, +- "control resubmission terminated %d\n", retval); + } + + static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags) +@@ -431,8 +428,6 @@ static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags) + dev_err(&acm->data->dev, + "urb %d failed submission with %d\n", + index, res); +- } else { +- dev_vdbg(&acm->data->dev, "intended failure %d\n", res); + } + set_bit(index, &acm->read_urbs_free); + return res; +@@ -474,7 +469,6 @@ static void acm_read_bulk_callback(struct urb *urb) + int status = urb->status; + bool stopped = false; + bool stalled = false; +- bool cooldown = false; + + dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n", + rb->index, urb->actual_length, status); +@@ -501,14 +495,6 @@ static void acm_read_bulk_callback(struct urb *urb) + __func__, status); + stopped = true; + break; +- case -EOVERFLOW: +- case -EPROTO: +- dev_dbg(&acm->data->dev, +- "%s - cooling babbling device\n", __func__); +- usb_mark_last_busy(acm->dev); +- set_bit(rb->index, &acm->urbs_in_error_delay); +- cooldown = true; +- break; + default: + dev_dbg(&acm->data->dev, + "%s - nonzero urb status received: %d\n", +@@ -530,11 +516,9 @@ static void acm_read_bulk_callback(struct urb *urb) + */ + smp_mb__after_atomic(); + +- if (stopped || stalled || cooldown) { ++ if (stopped || stalled) { + if (stalled) + schedule_work(&acm->work); +- else if (cooldown) +- schedule_delayed_work(&acm->dwork, HZ / 2); + return; + } + +@@ -581,12 +565,6 @@ static void acm_softint(struct work_struct *work) + } + } + +- if (test_and_clear_bit(ACM_ERROR_DELAY, &acm->flags)) { +- for (i = 0; i < acm->rx_buflimit; i++) +- if (test_and_clear_bit(i, &acm->urbs_in_error_delay)) +- acm_submit_read_urb(acm, i, GFP_NOIO); +- } +- + if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags)) + tty_port_tty_wakeup(&acm->port); + } +@@ -1353,7 +1331,6 @@ static int acm_probe(struct usb_interface *intf, + acm->readsize = readsize; + acm->rx_buflimit = num_rx_buf; + INIT_WORK(&acm->work, acm_softint); +- INIT_DELAYED_WORK(&acm->dwork, acm_softint); + init_waitqueue_head(&acm->wioctl); + spin_lock_init(&acm->write_lock); + spin_lock_init(&acm->read_lock); +@@ -1563,7 +1540,6 @@ static void acm_disconnect(struct usb_interface *intf) + + acm_kill_urbs(acm); + cancel_work_sync(&acm->work); +- cancel_delayed_work_sync(&acm->dwork); + + tty_unregister_device(acm_tty_driver, acm->minor); + +@@ -1606,8 +1582,6 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) + + acm_kill_urbs(acm); + cancel_work_sync(&acm->work); +- cancel_delayed_work_sync(&acm->dwork); +- acm->urbs_in_error_delay = 0; + + return 0; + } +diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h +index cd5e9d8ab237..ca1c026382c2 100644 +--- a/drivers/usb/class/cdc-acm.h ++++ b/drivers/usb/class/cdc-acm.h +@@ -109,11 +109,8 @@ struct acm { + # define EVENT_TTY_WAKEUP 0 + # define EVENT_RX_STALL 1 + # define ACM_THROTTLED 2 +-# define ACM_ERROR_DELAY 3 +- unsigned long urbs_in_error_delay; /* these need to be restarted after a delay */ + struct usb_cdc_line_coding line; /* bits, stop, parity */ +- struct work_struct work; /* work queue entry for various purposes*/ +- struct delayed_work dwork; /* for cool downs needed in error recovery */ ++ struct work_struct work; /* work queue entry for line discipline waking up */ + unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ + unsigned int ctrlout; /* output control lines (DTR, RTS) */ + struct async_icount iocount; /* counters for control line changes */ +-- +2.25.4 + From fa242e32d7bed4bb419c6ddb1daf3e1a4f10cf89 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sun, 18 Oct 2020 15:08:11 +0200 Subject: [PATCH 08/12] Remove not needed partition magic (#901) * Update Documentation/partition.md Co-authored-by: Stefan Agner --- Documentation/partition.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Documentation/partition.md b/Documentation/partition.md index b9d53f832..8cc52da13 100644 --- a/Documentation/partition.md +++ b/Documentation/partition.md @@ -51,15 +51,7 @@ Log in as `root` to get to the Home Assistant CLI and then enter `login` to cont Confirm your USB SSD/HD is connected and recognized using `fdisk -l`. -It is recommended to use fdisk to remove the existing partition(s) before proceeding. - -- Type `fdisk /dev/XXX` (replacing XXX with your drive) -- Type `d` to delete a partition. -- Continue if needed, then write the changes. - -Creating a new partition is not necessary. - -With the drive now prepared, use the below command (again, replacing XXX with your drive) +Make sure the drive has no partition named `hassos-data` (or no partition at all). With the drive, use the below command (again, replacing XXX with your drive) ```sh $ datactl move /dev/xxx From 0495ba25ad7bba5f3c374c2ee97185e698fabb16 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 20 Oct 2020 19:08:19 +0200 Subject: [PATCH 09/12] RaspberryPI: Fix issue with correct SYMLINK with ttyAMA (#915) --- .../udev/rules.d/{99-rpi.rules => 99-com.rules} | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) rename buildroot-external/board/raspberrypi/rootfs-overlay/usr/lib/udev/rules.d/{99-rpi.rules => 99-com.rules} (57%) diff --git a/buildroot-external/board/raspberrypi/rootfs-overlay/usr/lib/udev/rules.d/99-rpi.rules b/buildroot-external/board/raspberrypi/rootfs-overlay/usr/lib/udev/rules.d/99-com.rules similarity index 57% rename from buildroot-external/board/raspberrypi/rootfs-overlay/usr/lib/udev/rules.d/99-rpi.rules rename to buildroot-external/board/raspberrypi/rootfs-overlay/usr/lib/udev/rules.d/99-com.rules index 65ee59e11..e1dfa79f5 100644 --- a/buildroot-external/board/raspberrypi/rootfs-overlay/usr/lib/udev/rules.d/99-rpi.rules +++ b/buildroot-external/board/raspberrypi/rootfs-overlay/usr/lib/udev/rules.d/99-com.rules @@ -1,4 +1,5 @@ -KERNEL=="ttyAMA[01]", ATTR{iomem_base}=="0xFE201000", PROGRAM="/bin/sh -c '\ + +KERNEL=="ttyAMA0", PROGRAM="/bin/sh -c '\ ALIASES=/proc/device-tree/aliases; \ if cmp -s $ALIASES/uart0 $ALIASES/serial0; then \ echo 0;\ @@ -9,6 +10,19 @@ KERNEL=="ttyAMA[01]", ATTR{iomem_base}=="0xFE201000", PROGRAM="/bin/sh -c '\ fi\ '", SYMLINK+="serial%c" +KERNEL=="ttyAMA1", PROGRAM="/bin/sh -c '\ + ALIASES=/proc/device-tree/aliases; \ + if [ -e /dev/ttyAMA0 ]; then \ + exit 1; \ + elif cmp -s $ALIASES/uart0 $ALIASES/serial0; then \ + echo 0;\ + elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then \ + echo 1; \ + else \ + exit 1; \ + fi\ +'", SYMLINK+="serial%c" + KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\ ALIASES=/proc/device-tree/aliases; \ if cmp -s $ALIASES/uart1 $ALIASES/serial0; then \ From 5f0a8fe627dcb540aa31ce80f62409f403504ad5 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 20 Oct 2020 22:39:59 +0200 Subject: [PATCH 10/12] Bump firmware to RPi bluez-firmware 1.2-4+rpt6 release (#918) This addresses recent Bluetooth secruity vulnerabilities. --- .../package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk b/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk index 684bf8560..5769c1c30 100644 --- a/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk +++ b/buildroot-external/package/bluetooth-bcm43xx/bluetooth-bcm43xx.mk @@ -11,8 +11,8 @@ BLUETOOTH_BCM43XX_SITE = $(BR2_EXTERNAL_HASSOS_PATH)/package/bluetooth-bcm43xx BLUETOOTH_BCM43XX_SITE_METHOD = local define BLUETOOTH_BCM43XX_BUILD_CMDS - curl -L -o $(@D)/BCM43430A1.hcd https://raw.githubusercontent.com/RPi-Distro/bluez-firmware/fff76cb15527c435ce99a9787848eacd6288282c/broadcom/BCM43430A1.hcd - curl -L -o $(@D)/BCM4345C0.hcd https://raw.githubusercontent.com/RPi-Distro/bluez-firmware/fff76cb15527c435ce99a9787848eacd6288282c/broadcom/BCM4345C0.hcd + curl -L -o $(@D)/BCM43430A1.hcd https://raw.githubusercontent.com/RPi-Distro/bluez-firmware/a4e08822e3f24a6211f6ac94bc98b7ef87700c70/broadcom/BCM43430A1.hcd + curl -L -o $(@D)/BCM4345C0.hcd https://raw.githubusercontent.com/RPi-Distro/bluez-firmware/a4e08822e3f24a6211f6ac94bc98b7ef87700c70/broadcom/BCM4345C0.hcd curl -L -o $(@D)/btuart https://raw.githubusercontent.com/RPi-Distro/pi-bluetooth/cbdbcb66bcc5b9af05f1a9fffe2254c872bb0ace/usr/bin/btuart curl -L -o $(@D)/bthelper https://raw.githubusercontent.com/RPi-Distro/pi-bluetooth/cbdbcb66bcc5b9af05f1a9fffe2254c872bb0ace/usr/bin/bthelper curl -L -o $(@D)/90-pi-bluetooth.rules https://raw.githubusercontent.com/RPi-Distro/pi-bluetooth/cbdbcb66bcc5b9af05f1a9fffe2254c872bb0ace/lib/udev/rules.d/90-pi-bluetooth.rules From fdcb94f0d83991eca837d5cf5606b631e048c4e0 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 21 Oct 2020 20:34:26 +0200 Subject: [PATCH 11/12] Actually fix CDC ACM error recovery path (#712) (#921) Instead of reverting the CDC ACM cool-down patch fix the intention of that change. This should fix the error recovery paths in the CDC ACM driver and allow CDC ACM devices to continue working even in the event of USB issues. --- ...Revert-cdc-acm-introduce-a-cool-down.patch | 132 ------------------ ...1-usb-cdc-acm-fix-cooldown-mechanism.patch | 124 ++++++++++++++++ 2 files changed, 124 insertions(+), 132 deletions(-) delete mode 100644 buildroot-external/board/hardkernel/patches/linux/0001-Revert-cdc-acm-introduce-a-cool-down.patch create mode 100644 buildroot-external/board/hardkernel/patches/linux/0001-usb-cdc-acm-fix-cooldown-mechanism.patch diff --git a/buildroot-external/board/hardkernel/patches/linux/0001-Revert-cdc-acm-introduce-a-cool-down.patch b/buildroot-external/board/hardkernel/patches/linux/0001-Revert-cdc-acm-introduce-a-cool-down.patch deleted file mode 100644 index 8f45af028..000000000 --- a/buildroot-external/board/hardkernel/patches/linux/0001-Revert-cdc-acm-introduce-a-cool-down.patch +++ /dev/null @@ -1,132 +0,0 @@ -From 5edf98e1fa176a480686ec77a5782b61eb009842 Mon Sep 17 00:00:00 2001 -From: Jerome Brunet -Date: Thu, 15 Oct 2020 13:58:14 +0200 -Subject: [PATCH] Revert "cdc-acm: introduce a cool down" - -This reverts commit a4e7279cd1d19f48f0af2a10ed020febaa9ac092. ---- - drivers/usb/class/cdc-acm.c | 30 ++---------------------------- - drivers/usb/class/cdc-acm.h | 5 +---- - 2 files changed, 3 insertions(+), 32 deletions(-) - -diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c -index f1a9043bdfe5..0f47d74c857d 100644 ---- a/drivers/usb/class/cdc-acm.c -+++ b/drivers/usb/class/cdc-acm.c -@@ -410,12 +410,9 @@ static void acm_ctrl_irq(struct urb *urb) - - exit: - retval = usb_submit_urb(urb, GFP_ATOMIC); -- if (retval && retval != -EPERM && retval != -ENODEV) -+ if (retval && retval != -EPERM) - dev_err(&acm->control->dev, - "%s - usb_submit_urb failed: %d\n", __func__, retval); -- else -- dev_vdbg(&acm->control->dev, -- "control resubmission terminated %d\n", retval); - } - - static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags) -@@ -431,8 +428,6 @@ static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags) - dev_err(&acm->data->dev, - "urb %d failed submission with %d\n", - index, res); -- } else { -- dev_vdbg(&acm->data->dev, "intended failure %d\n", res); - } - set_bit(index, &acm->read_urbs_free); - return res; -@@ -474,7 +469,6 @@ static void acm_read_bulk_callback(struct urb *urb) - int status = urb->status; - bool stopped = false; - bool stalled = false; -- bool cooldown = false; - - dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n", - rb->index, urb->actual_length, status); -@@ -501,14 +495,6 @@ static void acm_read_bulk_callback(struct urb *urb) - __func__, status); - stopped = true; - break; -- case -EOVERFLOW: -- case -EPROTO: -- dev_dbg(&acm->data->dev, -- "%s - cooling babbling device\n", __func__); -- usb_mark_last_busy(acm->dev); -- set_bit(rb->index, &acm->urbs_in_error_delay); -- cooldown = true; -- break; - default: - dev_dbg(&acm->data->dev, - "%s - nonzero urb status received: %d\n", -@@ -530,11 +516,9 @@ static void acm_read_bulk_callback(struct urb *urb) - */ - smp_mb__after_atomic(); - -- if (stopped || stalled || cooldown) { -+ if (stopped || stalled) { - if (stalled) - schedule_work(&acm->work); -- else if (cooldown) -- schedule_delayed_work(&acm->dwork, HZ / 2); - return; - } - -@@ -581,12 +565,6 @@ static void acm_softint(struct work_struct *work) - } - } - -- if (test_and_clear_bit(ACM_ERROR_DELAY, &acm->flags)) { -- for (i = 0; i < acm->rx_buflimit; i++) -- if (test_and_clear_bit(i, &acm->urbs_in_error_delay)) -- acm_submit_read_urb(acm, i, GFP_NOIO); -- } -- - if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags)) - tty_port_tty_wakeup(&acm->port); - } -@@ -1353,7 +1331,6 @@ static int acm_probe(struct usb_interface *intf, - acm->readsize = readsize; - acm->rx_buflimit = num_rx_buf; - INIT_WORK(&acm->work, acm_softint); -- INIT_DELAYED_WORK(&acm->dwork, acm_softint); - init_waitqueue_head(&acm->wioctl); - spin_lock_init(&acm->write_lock); - spin_lock_init(&acm->read_lock); -@@ -1563,7 +1540,6 @@ static void acm_disconnect(struct usb_interface *intf) - - acm_kill_urbs(acm); - cancel_work_sync(&acm->work); -- cancel_delayed_work_sync(&acm->dwork); - - tty_unregister_device(acm_tty_driver, acm->minor); - -@@ -1606,8 +1582,6 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) - - acm_kill_urbs(acm); - cancel_work_sync(&acm->work); -- cancel_delayed_work_sync(&acm->dwork); -- acm->urbs_in_error_delay = 0; - - return 0; - } -diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h -index cd5e9d8ab237..ca1c026382c2 100644 ---- a/drivers/usb/class/cdc-acm.h -+++ b/drivers/usb/class/cdc-acm.h -@@ -109,11 +109,8 @@ struct acm { - # define EVENT_TTY_WAKEUP 0 - # define EVENT_RX_STALL 1 - # define ACM_THROTTLED 2 --# define ACM_ERROR_DELAY 3 -- unsigned long urbs_in_error_delay; /* these need to be restarted after a delay */ - struct usb_cdc_line_coding line; /* bits, stop, parity */ -- struct work_struct work; /* work queue entry for various purposes*/ -- struct delayed_work dwork; /* for cool downs needed in error recovery */ -+ struct work_struct work; /* work queue entry for line discipline waking up */ - unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ - unsigned int ctrlout; /* output control lines (DTR, RTS) */ - struct async_icount iocount; /* counters for control line changes */ --- -2.25.4 - diff --git a/buildroot-external/board/hardkernel/patches/linux/0001-usb-cdc-acm-fix-cooldown-mechanism.patch b/buildroot-external/board/hardkernel/patches/linux/0001-usb-cdc-acm-fix-cooldown-mechanism.patch new file mode 100644 index 000000000..af192c5c1 --- /dev/null +++ b/buildroot-external/board/hardkernel/patches/linux/0001-usb-cdc-acm-fix-cooldown-mechanism.patch @@ -0,0 +1,124 @@ +From f6fce2e974fe091fd233301bd7c127ca18304039 Mon Sep 17 00:00:00 2001 +Message-Id: +From: Jerome Brunet +Date: Mon, 19 Oct 2020 19:07:02 +0200 +Subject: [PATCH] usb: cdc-acm: fix cooldown mechanism + +Commit a4e7279cd1d1 ("cdc-acm: introduce a cool down") is causing +regression if there is some USB error, such as -EPROTO. + +This has been reported on some samples of the Odroid-N2 using the Combee II +Zibgee USB dongle. + +> struct acm *acm = container_of(work, struct acm, work) + +is incorrect in case of a delayed work and causes warnings, usually from +the workqueue: + +> WARNING: CPU: 0 PID: 0 at kernel/workqueue.c:1474 __queue_work+0x480/0x528. + +When this happens, USB eventually stops working completely after a while. +Also the ACM_ERROR_DELAY bit is never set, so the cooldown mechanism +previously introduced cannot be triggered and acm_submit_read_urb() is +never called. + +This changes makes the cdc-acm driver use a single delayed work, fixing the +pointer arithmetic in acm_softint() and set the ACM_ERROR_DELAY when the +cooldown mechanism appear to be needed. + +Fixes: a4e7279cd1d1 ("cdc-acm: introduce a cool down") +Reported-by: Pascal Vizeli +Cc: Oliver Neukum +Signed-off-by: Jerome Brunet +--- + drivers/usb/class/cdc-acm.c | 12 +++++------- + drivers/usb/class/cdc-acm.h | 3 +-- + 2 files changed, 6 insertions(+), 9 deletions(-) + +diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c +index 7f6f3ab5b8a6..8f087499196a 100644 +--- a/drivers/usb/class/cdc-acm.c ++++ b/drivers/usb/class/cdc-acm.c +@@ -507,6 +507,7 @@ static void acm_read_bulk_callback(struct urb *urb) + "%s - cooling babbling device\n", __func__); + usb_mark_last_busy(acm->dev); + set_bit(rb->index, &acm->urbs_in_error_delay); ++ set_bit(ACM_ERROR_DELAY, &acm->flags); + cooldown = true; + break; + default: +@@ -532,7 +533,7 @@ static void acm_read_bulk_callback(struct urb *urb) + + if (stopped || stalled || cooldown) { + if (stalled) +- schedule_work(&acm->work); ++ schedule_delayed_work(&acm->dwork, 0); + else if (cooldown) + schedule_delayed_work(&acm->dwork, HZ / 2); + return; +@@ -562,13 +563,13 @@ static void acm_write_bulk(struct urb *urb) + acm_write_done(acm, wb); + spin_unlock_irqrestore(&acm->write_lock, flags); + set_bit(EVENT_TTY_WAKEUP, &acm->flags); +- schedule_work(&acm->work); ++ schedule_delayed_work(&acm->dwork, 0); + } + + static void acm_softint(struct work_struct *work) + { + int i; +- struct acm *acm = container_of(work, struct acm, work); ++ struct acm *acm = container_of(work, struct acm, dwork.work); + + if (test_bit(EVENT_RX_STALL, &acm->flags)) { + smp_mb(); /* against acm_suspend() */ +@@ -584,7 +585,7 @@ static void acm_softint(struct work_struct *work) + if (test_and_clear_bit(ACM_ERROR_DELAY, &acm->flags)) { + for (i = 0; i < acm->rx_buflimit; i++) + if (test_and_clear_bit(i, &acm->urbs_in_error_delay)) +- acm_submit_read_urb(acm, i, GFP_NOIO); ++ acm_submit_read_urb(acm, i, GFP_KERNEL); + } + + if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags)) +@@ -1352,7 +1353,6 @@ static int acm_probe(struct usb_interface *intf, + acm->ctrlsize = ctrlsize; + acm->readsize = readsize; + acm->rx_buflimit = num_rx_buf; +- INIT_WORK(&acm->work, acm_softint); + INIT_DELAYED_WORK(&acm->dwork, acm_softint); + init_waitqueue_head(&acm->wioctl); + spin_lock_init(&acm->write_lock); +@@ -1562,7 +1562,6 @@ static void acm_disconnect(struct usb_interface *intf) + } + + acm_kill_urbs(acm); +- cancel_work_sync(&acm->work); + cancel_delayed_work_sync(&acm->dwork); + + tty_unregister_device(acm_tty_driver, acm->minor); +@@ -1605,7 +1604,6 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) + return 0; + + acm_kill_urbs(acm); +- cancel_work_sync(&acm->work); + cancel_delayed_work_sync(&acm->dwork); + acm->urbs_in_error_delay = 0; + +diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h +index cd5e9d8ab237..b95ff769072e 100644 +--- a/drivers/usb/class/cdc-acm.h ++++ b/drivers/usb/class/cdc-acm.h +@@ -112,8 +112,7 @@ struct acm { + # define ACM_ERROR_DELAY 3 + unsigned long urbs_in_error_delay; /* these need to be restarted after a delay */ + struct usb_cdc_line_coding line; /* bits, stop, parity */ +- struct work_struct work; /* work queue entry for various purposes*/ +- struct delayed_work dwork; /* for cool downs needed in error recovery */ ++ struct delayed_work dwork; /* work queue entry for various purposes */ + unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ + unsigned int ctrlout; /* output control lines (DTR, RTS) */ + struct async_icount iocount; /* counters for control line changes */ +-- +2.28.0 + From dcfb296dcf2881275f7cba54aac24726ac906cff Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 22 Oct 2020 17:05:36 +0200 Subject: [PATCH 12/12] Update buildroot to 2020.02.7 (#923) Signed-off-by: Pascal Vizeli --- buildroot/.gitlab-ci.yml | 42 +- buildroot/.gitlab-ci.yml.in | 42 +- buildroot/CHANGES | 91 + buildroot/DEVELOPERS | 15 +- buildroot/Makefile | 36 +- buildroot/boot/at91bootstrap3/Config.in | 2 +- buildroot/boot/barebox/barebox.mk | 26 +- ...lexer-fatal-errors-actually-be-fatal.patch | 73 + ...e-arithmetic-primitives-that-check-f.patch | 128 ++ ...-we-always-have-an-overflow-checking.patch | 246 +++ ...005-calloc-Use-calloc-at-most-places.patch | 1840 +++++++++++++++++ ...low-checking-primitives-where-we-do-.patch | 1326 ++++++++++++ ...on-t-leak-memory-on-realloc-failures.patch | 72 + ...-not-load-more-than-one-NAME-section.patch | 41 + ...fxmenu-Fix-double-free-in-load_image.patch | 39 + ...ree-in-grub_xnu_devprop_add_property.patch | 58 + ...sure-we-don-t-dereference-past-array.patch | 55 + ...012-term-Fix-overflow-on-user-inputs.patch | 69 + .../boot/grub2/0013-udf-Fix-memory-leak.patch | 59 + ...emory-leak-if-grub_create_loader_cmd.patch | 38 + .../0015-tftp-Do-not-use-priority-queue.patch | 283 +++ ...t-grub_relocator_alloc_chunk_addr-in.patch | 153 ++ ...t-grub_relocator_alloc_chunk_align-m.patch | 341 +++ ...used-fields-from-grub_script_functio.patch | 37 + ...se-after-free-when-redefining-a-func.patch | 113 + ...ub_relocator_alloc_chunk_align-top-m.patch | 49 + .../0021-hfsplus-Fix-two-more-overflows.patch | 61 + ...-potential-data-dependent-alloc-over.patch | 116 ++ .../0023-emu-Make-grub_free-NULL-safe.patch | 38 + ...formed-device-path-arithmetic-errors.patch | 239 +++ ...Propagate-errors-from-copy_file_path.patch | 78 + ...x-use-after-free-in-halt-reboot-path.patch | 183 ++ ...id-overflow-on-initrd-size-calculati.patch | 32 + ...er-overflows-in-initrd-size-handling.patch | 173 ++ buildroot/boot/grub2/grub2.mk | 11 + buildroot/boot/uboot/uboot.mk | 5 +- .../docs/manual/adding-board-support.txt | 18 +- .../docs/manual/adding-packages-cargo.txt | 41 +- buildroot/docs/manual/adding-packages-waf.txt | 2 +- buildroot/docs/manual/contribute.txt | 31 + buildroot/docs/manual/manual.html | 86 +- buildroot/docs/manual/manual.pdf | Bin 565242 -> 567183 bytes buildroot/docs/manual/manual.text | 93 +- buildroot/fs/cpio/init | 11 + buildroot/linux/Config.in | 10 +- buildroot/linux/linux.hash | 14 +- buildroot/linux/linux.mk | 6 +- buildroot/package/alsa-utils/alsa-utils.mk | 4 +- buildroot/package/apache/apache.hash | 5 +- buildroot/package/apache/apache.mk | 2 +- buildroot/package/avahi/avahi.mk | 1 + .../package/bandwidthd/bandwidthd.service | 2 +- buildroot/package/bash/0017-bash50-017.patch | 293 +++ buildroot/package/bash/0018-bash50-018.patch | 49 + ...ut.h-add-missing-include-on-stdio.h.patch} | 0 ...20-locale.c-fix-build-without-wchar.patch} | 0 buildroot/package/bind/bind.hash | 4 +- buildroot/package/bind/bind.mk | 2 +- buildroot/package/bison/bison.mk | 1 + buildroot/package/boost/boost.mk | 1 + ...g-BUILD_SHARED_LIBS-to-choose-static.patch | 92 +- ...time-linker-path-to-pkg-config-files.patch | 51 + buildroot/package/brotli/brotli.hash | 2 +- buildroot/package/brotli/brotli.mk | 2 +- buildroot/package/busybox/busybox.mk | 13 + buildroot/package/busybox/udhcpc.script | 6 +- buildroot/package/capnproto/capnproto.mk | 7 + buildroot/package/chrony/chrony.hash | 7 +- buildroot/package/chrony/chrony.mk | 2 +- ...-installing-mount.smb3-and-optionall.patch | 41 + buildroot/package/cifs-utils/cifs-utils.hash | 4 +- buildroot/package/cifs-utils/cifs-utils.mk | 7 +- buildroot/package/collectd/Config.in | 1 - buildroot/package/cpio/0001-Minor-fix.patch | 30 + ...d-support-for-upcoming-json-c-0.14.0.patch | 179 ++ ...name-clash-with-newer-json-c-library.patch | 512 +++++ ...move-man-from-BUILDDIRS-in-configure.patch | 8 +- .../cups/0002-Do-not-use-genstrings.patch | 14 +- ...0004-Remove-PIE-flags-from-the-build.patch | 8 +- buildroot/package/cups/70-usb-printers.rules | 3 + buildroot/package/cups/S81cupsd | 48 + buildroot/package/cups/cups.hash | 2 +- buildroot/package/cups/cups.mk | 29 +- buildroot/package/cvs/cvs.mk | 4 +- buildroot/package/dbus/dbus.mk | 1 + buildroot/package/dhcpcd/dhcpcd.service | 2 +- buildroot/package/dhcpdump/dhcpdump.mk | 2 +- buildroot/package/docker-cli/docker-cli.hash | 2 +- buildroot/package/docker-cli/docker-cli.mk | 6 +- buildroot/package/docker-engine/Config.in | 1 + .../package/docker-engine/docker-engine.hash | 2 +- .../package/docker-engine/docker-engine.mk | 2 +- buildroot/package/domoticz/Config.in | 8 +- .../dovecot-pigeonhole.hash | 4 +- .../dovecot-pigeonhole/dovecot-pigeonhole.mk | 2 +- buildroot/package/dovecot/dovecot.hash | 2 +- buildroot/package/dovecot/dovecot.mk | 2 +- ...-scp-Port-OpenSSH-CVE-2018-20685-fix.patch | 24 + .../package/ecryptfs-utils/ecryptfs-utils.mk | 1 + buildroot/package/efl/Config.in | 17 +- buildroot/package/elixir/elixir.mk | 2 +- .../0002-fsck.f2fs-correct-return-value.patch | 195 ++ buildroot/package/fail2ban/fail2ban.mk | 7 + buildroot/package/ffmpeg/ffmpeg.hash | 2 +- buildroot/package/ffmpeg/ffmpeg.mk | 2 +- buildroot/package/freetype/freetype.mk | 23 +- buildroot/package/gcc/gcc.mk | 15 + ...-pointer-dereference-in-gdImageClone.patch | 44 + ...f-Bounds-Write-on-Heap-CVE-2019-6977.patch | 39 + buildroot/package/gd/gd.mk | 13 + buildroot/package/gdb/gdb.mk | 3 +- buildroot/package/gdk-pixbuf/gdk-pixbuf.hash | 6 +- buildroot/package/gdk-pixbuf/gdk-pixbuf.mk | 2 +- .../0001-Fix-cross-compilation-issue.patch | 36 - .../package/ghostscript/ghostscript.hash | 6 +- buildroot/package/ghostscript/ghostscript.mk | 8 +- .../glibc.hash | 2 +- buildroot/package/glibc/glibc.mk | 2 +- buildroot/package/gnutls/gnutls.hash | 4 +- buildroot/package/gnutls/gnutls.mk | 2 +- buildroot/package/go/go.hash | 2 +- buildroot/package/go/go.mk | 2 +- ...l-a-libtool-file-with-static-library.patch | 67 + buildroot/package/graphite2/Config.in | 7 +- buildroot/package/graphite2/graphite2.hash | 6 +- buildroot/package/graphite2/graphite2.mk | 5 +- ...son-allow-the-user-to-disable-opencv.patch | 31 + .../gst1-plugins-base/gst1-plugins-base.mk | 11 +- .../gst1-plugins-ugly/gst1-plugins-ugly.mk | 2 +- buildroot/package/hostapd/hostapd.hash | 3 + buildroot/package/hostapd/hostapd.mk | 7 + .../package/imagemagick/imagemagick.hash | 4 +- buildroot/package/imagemagick/imagemagick.mk | 5 +- ...-Fix-buffer-overflow-vulnerabilities.patch | 132 ++ ...uffer-overflow-in-ipmi_spd_print_fru.patch | 52 + ...er-overflow-in-ipmi_get_session_info.patch | 52 + .../0011-channel-Fix-buffer-overflow.patch | 46 + ...er-overflows-in-get_lan_param_select.patch | 92 + ...u-sdr-Fix-id_string-buffer-overflows.patch | 141 ++ buildroot/package/ipmitool/ipmitool.mk | 8 + buildroot/package/iputils/iputils.mk | 7 +- buildroot/package/janus-gateway/Config.in | 6 +- ...001-verify-data-range-CVE-2018-19541.patch | 35 - ...ck-null-in-jp2_decode-CVE-2018-19542.patch | 24 - .../0003-test-asclen-CVE-2018-19540.patch | 29 - buildroot/package/jasper/jasper.hash | 2 +- buildroot/package/jasper/jasper.mk | 4 +- buildroot/package/json-c/json-c.hash | 4 +- buildroot/package/json-c/json-c.mk | 14 +- ...ix-build-with-disabled-proxy-support.patch | 50 - ...ix-build-with-disabled-proxy-support.patch | 159 -- buildroot/package/libcurl/libcurl.hash | 4 +- buildroot/package/libcurl/libcurl.mk | 2 +- buildroot/package/libeXosip2/Config.in | 4 +- ...001-htp.pc.in-add-lz-to-Libs.private.patch | 29 - buildroot/package/libhtp/libhtp.hash | 2 +- buildroot/package/libhtp/libhtp.mk | 2 +- buildroot/package/libraw/libraw.hash | 8 +- buildroot/package/libraw/libraw.mk | 13 +- .../0001-libssh.h-bump-to-version-0.9.4.patch | 29 - ...eturning-SSH_AGAIN-from-ssh_channel_.patch | 45 - buildroot/package/libssh/libssh.hash | 4 +- buildroot/package/libssh/libssh.mk | 2 +- buildroot/package/libwebsockets/Config.in | 1 - .../libxml-parser-perl/libxml-parser-perl.mk | 9 +- ...of-bounds-read-with-xmllint--htmlout.patch | 40 + buildroot/package/libxml2/libxml2.mk | 2 + .../package/linux-headers/Config.in.host | 10 +- buildroot/package/live555/live555.hash | 4 +- buildroot/package/live555/live555.mk | 8 +- buildroot/package/localedef/localedef.mk | 1 + buildroot/package/lua/5.1.5/lua.hash | 6 + .../lua/5.3.5/0003-fix-revision-number.patch | 31 - .../lua/{5.3.5 => 5.3.6}/0001-root-path.patch | 0 .../0002-shared-libs-for-lua.patch | 0 .../0003-linenoise.patch} | 0 buildroot/package/lua/5.3.6/lua.hash | 6 + buildroot/package/lua/lua.hash | 8 - buildroot/package/lua/lua.mk | 2 +- buildroot/package/mbedtls/mbedtls.hash | 3 +- buildroot/package/mbedtls/mbedtls.mk | 4 +- ...nfigure-Fix-cross-compilation-errors.patch | 142 -- ...onfigure-Simplify-pointer-size-check.patch | 76 - buildroot/package/memcached/memcached.hash | 8 +- buildroot/package/memcached/memcached.mk | 5 +- buildroot/package/mesa3d/Config.in | 9 +- buildroot/package/meson/meson.mk | 6 + .../minidlna/0001-fix-build-with-gcc-10.patch | 49 + ...x-CallStranger-a.k.a.-CVE-2020-12695.patch | 133 ++ buildroot/package/minidlna/minidlnad.service | 2 +- buildroot/package/mosquitto/mosquitto.hash | 4 +- buildroot/package/mosquitto/mosquitto.mk | 5 +- buildroot/package/mpv/Config.in | 4 +- buildroot/package/mpv/mpv.mk | 4 + buildroot/package/nginx/nginx.service | 2 +- buildroot/package/nodejs/nodejs.hash | 6 +- buildroot/package/nodejs/nodejs.mk | 10 +- buildroot/package/nss-pam-ldapd/nslcd.service | 2 +- .../package/nvidia-driver/nvidia-driver.mk | 4 +- ...0001-Fix-build-of-grfmt_jpeg2000-cpp.patch | 37 + ...0001-Fix-build-of-grfmt_jpeg2000-cpp.patch | 37 + ...on-input-directory-with-mix-of-valid.patch | 43 + buildroot/package/openjpeg/openjpeg.mk | 3 + .../package/openvmtools/vmtoolsd.service | 4 +- buildroot/package/paho-mqtt-c/Config.in | 5 +- .../package/paho-mqtt-c/paho-mqtt-c.hash | 2 +- buildroot/package/paho-mqtt-c/paho-mqtt-c.mk | 16 +- ...ke-the-rpath-relative-under-a-specif.patch | 16 +- buildroot/package/perl/perl.hash | 12 +- buildroot/package/perl/perl.mk | 4 +- .../0002-iconv-tweak-iconv-detection.patch | 4 +- ...0003-configure-disable-the-phar-tool.patch | 4 +- buildroot/package/php/php.hash | 2 +- buildroot/package/php/php.mk | 2 +- buildroot/package/pkg-kconfig.mk | 11 +- buildroot/package/pkg-meson.mk | 4 +- buildroot/package/pkg-utils.mk | 31 +- buildroot/package/postgresql/pg_config | 8 +- buildroot/package/postgresql/postgresql.hash | 10 +- buildroot/package/postgresql/postgresql.mk | 3 +- .../package/postgresql/postgresql.service | 1 - .../package/python-aenum/python-aenum.mk | 9 + .../python-autobahn/python-autobahn.mk | 11 + buildroot/package/python-cycler/Config.in | 1 - .../package/python-django/python-django.hash | 4 +- .../package/python-django/python-django.mk | 4 +- .../python-engineio/python-engineio.mk | 10 + buildroot/package/python-fire/python-fire.mk | 9 + buildroot/package/python-gunicorn/Config.in | 1 + ...st-11983-from-anntzer-builddepchecks.patch | 170 ++ .../python-pymodbus/python-pymodbus.mk | 9 + .../0001-Small-Python-2-fix.patch | 26 + .../package/python-semver/python-semver.hash | 6 +- .../package/python-semver/python-semver.mk | 4 +- .../python-sentry-sdk/python-sentry-sdk.mk | 10 + .../python-socketio/python-socketio.mk | 10 + .../python-texttable/python-texttable.hash | 6 +- .../python-texttable/python-texttable.mk | 4 +- buildroot/package/python-tinyrpc/Config.in | 1 + .../python-txtorcon/python-txtorcon.mk | 9 + buildroot/package/python/python.mk | 7 +- buildroot/package/python3/python3.hash | 8 +- buildroot/package/python3/python3.mk | 9 +- buildroot/package/qt5/qt5base/qt5base.mk | 3 + buildroot/package/ripgrep/ripgrep.mk | 11 +- buildroot/package/rtl8188eu/rtl8188eu.hash | 2 +- buildroot/package/rtl8188eu/rtl8188eu.mk | 2 +- ...-fallthrough-comments-for-kernel-5.3.patch | 7 +- ...river-crashes-from-aircrack-ng-rtl88.patch | 5 +- ...f-for-extending-string-which-causes-.patch | 339 +++ buildroot/package/ruby/ruby.hash | 4 +- buildroot/package/ruby/ruby.mk | 2 +- buildroot/package/runc/runc.hash | 2 +- buildroot/package/runc/runc.mk | 2 +- ...01-libreplace-disable-libbsd-support.patch | 4 +- ...uilt-heimdal-build-tools-in-case-of-.patch | 5 +- buildroot/package/samba4/samba4.hash | 4 +- buildroot/package/samba4/samba4.mk | 2 +- .../shadowsocks-libev/shadowsocks-libev.hash | 8 +- .../shadowsocks-libev/shadowsocks-libev.mk | 2 +- buildroot/package/squid/squid.hash | 8 +- buildroot/package/squid/squid.mk | 2 +- buildroot/package/strace/strace.mk | 10 +- ...Lists.txt-compile-squirrel-with-fPIC.patch | 35 + buildroot/package/suricata/suricata.hash | 2 +- buildroot/package/suricata/suricata.mk | 2 +- ...-Fix-build-with-libmicrohttpd-0.9.71.patch | 71 - ...add-missing-header-for-GRND_NONBLOCK.patch | 39 - buildroot/package/systemd/systemd.hash | 2 +- buildroot/package/systemd/systemd.mk | 4 +- buildroot/package/tovid/Config.in | 6 +- buildroot/package/tpm2-abrmd/tpm2-abrmd.hash | 4 +- buildroot/package/tpm2-abrmd/tpm2-abrmd.mk | 2 +- buildroot/package/tpm2-tools/tpm2-tools.hash | 4 +- buildroot/package/tpm2-tools/tpm2-tools.mk | 2 +- ...-security-issues-that-are-present-if.patch | 90 + buildroot/package/trousers/trousers.mk | 3 + buildroot/package/uacme/Config.in | 21 +- buildroot/package/uacme/uacme.hash | 4 +- buildroot/package/uacme/uacme.mk | 15 +- buildroot/package/uclibc/uclibc.mk | 5 + .../package/usb_modeswitch/usb_modeswitch.mk | 3 +- buildroot/package/vlc/vlc.mk | 3 + ...419.patch => 0002-fix-CVE-2015-1419.patch} | 0 ...003-Prevent-hang-in-SIGCHLD-handler.patch} | 0 .../wayland-protocols/wayland-protocols.mk | 2 +- buildroot/package/webkitgtk/webkitgtk.hash | 8 +- buildroot/package/webkitgtk/webkitgtk.mk | 2 +- .../wireguard-linux-compat.hash | 4 +- .../wireguard-linux-compat.mk | 2 +- buildroot/package/wireshark/wireshark.hash | 6 +- buildroot/package/wireshark/wireshark.mk | 2 +- ...-available-for-big-and-little-endian.patch | 32 + buildroot/package/wolfssl/wolfssl.hash | 6 +- buildroot/package/wolfssl/wolfssl.mk | 6 +- .../package/wpa_supplicant/wpa_supplicant.mk | 2 +- buildroot/package/wpewebkit/wpewebkit.hash | 8 +- buildroot/package/wpewebkit/wpewebkit.mk | 2 +- .../x11r7/xlib_libX11/xlib_libX11.hash | 11 +- .../package/x11r7/xlib_libX11/xlib_libX11.mk | 2 +- ...ure.ac-Fix-check-for-CLOCK_MONOTONIC.patch | 66 - .../0001-modesettings-needs-dri2.patch | 2 +- ...02-Remove-check-for-useSIGIO-option.patch} | 2 +- ...003-include-misc.h-fix-uClibc-build.patch} | 0 ...d-Makefile.am-fix-build-without-glx.patch} | 0 ...on-xf86Init.c-fix-build-without-glx.patch} | 4 +- ...probing-a-non-PCI-platform-device-on.patch | 33 + .../x11r7/xserver_xorg-server/Config.in | 4 +- .../xserver_xorg-server.hash | 14 +- buildroot/package/xen/xen.hash | 1 + buildroot/package/xen/xen.mk | 2 + ...guage.patch => 0001-only-c-language.patch} | 0 ...4-add-latomic-to-PKGCFG_LIBS_PRIVATE.patch | 36 - buildroot/package/zeromq/zeromq.hash | 10 +- buildroot/package/zeromq/zeromq.mk | 4 +- buildroot/package/zstd/zstd.mk | 2 +- .../support/dependencies/dependencies.sh | 6 + buildroot/support/docker/Dockerfile | 4 +- buildroot/support/misc/Vagrantfile | 2 +- buildroot/support/scripts/apply-patches.sh | 5 +- buildroot/support/scripts/pkg-stats | 449 ++-- buildroot/support/scripts/pycompile.py | 124 +- buildroot/support/scripts/setlocalversion | 37 +- buildroot/support/testing/infra/__init__.py | 4 +- .../testing/tests/core/test_timezone.py | 8 +- .../tests/package/test_docker_compose.py | 1 - buildroot/utils/check-package | 34 +- buildroot/utils/checkpackagelib/lib_config.py | 4 +- buildroot/utils/checkpackagelib/lib_mk.py | 60 +- buildroot/utils/checkpackagelib/lib_patch.py | 6 +- buildroot/utils/getdeveloperlib.py | 10 +- buildroot/utils/scanpypi | 8 +- 332 files changed, 10767 insertions(+), 1806 deletions(-) create mode 100644 buildroot/boot/grub2/0002-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch create mode 100644 buildroot/boot/grub2/0003-safemath-Add-some-arithmetic-primitives-that-check-f.patch create mode 100644 buildroot/boot/grub2/0004-calloc-Make-sure-we-always-have-an-overflow-checking.patch create mode 100644 buildroot/boot/grub2/0005-calloc-Use-calloc-at-most-places.patch create mode 100644 buildroot/boot/grub2/0006-malloc-Use-overflow-checking-primitives-where-we-do-.patch create mode 100644 buildroot/boot/grub2/0007-iso9660-Don-t-leak-memory-on-realloc-failures.patch create mode 100644 buildroot/boot/grub2/0008-font-Do-not-load-more-than-one-NAME-section.patch create mode 100644 buildroot/boot/grub2/0009-gfxmenu-Fix-double-free-in-load_image.patch create mode 100644 buildroot/boot/grub2/0010-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch create mode 100644 buildroot/boot/grub2/0011-lzma-Make-sure-we-don-t-dereference-past-array.patch create mode 100644 buildroot/boot/grub2/0012-term-Fix-overflow-on-user-inputs.patch create mode 100644 buildroot/boot/grub2/0013-udf-Fix-memory-leak.patch create mode 100644 buildroot/boot/grub2/0014-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch create mode 100644 buildroot/boot/grub2/0015-tftp-Do-not-use-priority-queue.patch create mode 100644 buildroot/boot/grub2/0016-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch create mode 100644 buildroot/boot/grub2/0017-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch create mode 100644 buildroot/boot/grub2/0018-script-Remove-unused-fields-from-grub_script_functio.patch create mode 100644 buildroot/boot/grub2/0019-script-Avoid-a-use-after-free-when-redefining-a-func.patch create mode 100644 buildroot/boot/grub2/0020-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch create mode 100644 buildroot/boot/grub2/0021-hfsplus-Fix-two-more-overflows.patch create mode 100644 buildroot/boot/grub2/0022-lvm-Fix-two-more-potential-data-dependent-alloc-over.patch create mode 100644 buildroot/boot/grub2/0023-emu-Make-grub_free-NULL-safe.patch create mode 100644 buildroot/boot/grub2/0024-efi-Fix-some-malformed-device-path-arithmetic-errors.patch create mode 100644 buildroot/boot/grub2/0025-efi-chainloader-Propagate-errors-from-copy_file_path.patch create mode 100644 buildroot/boot/grub2/0026-efi-Fix-use-after-free-in-halt-reboot-path.patch create mode 100644 buildroot/boot/grub2/0027-loader-linux-Avoid-overflow-on-initrd-size-calculati.patch create mode 100644 buildroot/boot/grub2/0028-linux-Fix-integer-overflows-in-initrd-size-handling.patch create mode 100644 buildroot/package/bash/0017-bash50-017.patch create mode 100644 buildroot/package/bash/0018-bash50-018.patch rename buildroot/package/bash/{0017-input.h-add-missing-include-on-stdio.h.patch => 0019-input.h-add-missing-include-on-stdio.h.patch} (100%) rename buildroot/package/bash/{0018-locale.c-fix-build-without-wchar.patch => 0020-locale.c-fix-build-without-wchar.patch} (100%) create mode 100644 buildroot/package/brotli/0002-Revert-Add-runtime-linker-path-to-pkg-config-files.patch create mode 100644 buildroot/package/cifs-utils/0001-Use-DESTDIR-when-installing-mount.smb3-and-optionall.patch create mode 100644 buildroot/package/cpio/0001-Minor-fix.patch create mode 100644 buildroot/package/cryptsetup/0002-Add-support-for-upcoming-json-c-0.14.0.patch create mode 100644 buildroot/package/cryptsetup/0003-Avoid-name-clash-with-newer-json-c-library.patch create mode 100644 buildroot/package/cups/70-usb-printers.rules create mode 100644 buildroot/package/cups/S81cupsd create mode 100644 buildroot/package/dropbear/0001-scp-Port-OpenSSH-CVE-2018-20685-fix.patch create mode 100644 buildroot/package/f2fs-tools/0002-fsck.f2fs-correct-return-value.patch create mode 100644 buildroot/package/gd/0005-Fix-potential-NULL-pointer-dereference-in-gdImageClone.patch create mode 100644 buildroot/package/gd/0006-Fix-497-gdImageColorMatch-Out-Of-Bounds-Write-on-Heap-CVE-2019-6977.patch delete mode 100644 buildroot/package/ghostscript/0001-Fix-cross-compilation-issue.patch rename buildroot/package/glibc/{2.30-67-g4748829f86a458b76642f3e98b1d80f7b868e427 => 2.30-73-gd59630f9959b0bb8991964758ab854ff4378b20d}/glibc.hash (70%) create mode 100644 buildroot/package/graphite2/0001-don-t-install-a-libtool-file-with-static-library.patch create mode 100644 buildroot/package/gstreamer1/gst1-plugins-bad/0002-meson-allow-the-user-to-disable-opencv.patch create mode 100644 buildroot/package/ipmitool/0008-fru-Fix-buffer-overflow-vulnerabilities.patch create mode 100644 buildroot/package/ipmitool/0009-fru-Fix-buffer-overflow-in-ipmi_spd_print_fru.patch create mode 100644 buildroot/package/ipmitool/0010-session-Fix-buffer-overflow-in-ipmi_get_session_info.patch create mode 100644 buildroot/package/ipmitool/0011-channel-Fix-buffer-overflow.patch create mode 100644 buildroot/package/ipmitool/0012-lanp-Fix-buffer-overflows-in-get_lan_param_select.patch create mode 100644 buildroot/package/ipmitool/0013-fru-sdr-Fix-id_string-buffer-overflows.patch delete mode 100644 buildroot/package/jasper/0001-verify-data-range-CVE-2018-19541.patch delete mode 100644 buildroot/package/jasper/0002-check-null-in-jp2_decode-CVE-2018-19542.patch delete mode 100644 buildroot/package/jasper/0003-test-asclen-CVE-2018-19540.patch delete mode 100644 buildroot/package/libcurl/0001-bearssl-fix-build-with-disabled-proxy-support.patch delete mode 100644 buildroot/package/libcurl/0002-nss-fix-build-with-disabled-proxy-support.patch delete mode 100644 buildroot/package/libhtp/0001-htp.pc.in-add-lz-to-Libs.private.patch delete mode 100644 buildroot/package/libssh/0001-libssh.h-bump-to-version-0.9.4.patch delete mode 100644 buildroot/package/libssh/0002-channels-Avoid-returning-SSH_AGAIN-from-ssh_channel_.patch create mode 100644 buildroot/package/libxml2/0003-Fix-out-of-bounds-read-with-xmllint--htmlout.patch create mode 100644 buildroot/package/lua/5.1.5/lua.hash delete mode 100644 buildroot/package/lua/5.3.5/0003-fix-revision-number.patch rename buildroot/package/lua/{5.3.5 => 5.3.6}/0001-root-path.patch (100%) rename buildroot/package/lua/{5.3.5 => 5.3.6}/0002-shared-libs-for-lua.patch (100%) rename buildroot/package/lua/{5.3.5/0011-linenoise.patch => 5.3.6/0003-linenoise.patch} (100%) create mode 100644 buildroot/package/lua/5.3.6/lua.hash delete mode 100644 buildroot/package/lua/lua.hash delete mode 100644 buildroot/package/memcached/0001-configure-Fix-cross-compilation-errors.patch delete mode 100644 buildroot/package/memcached/0002-configure-Simplify-pointer-size-check.patch create mode 100644 buildroot/package/minidlna/0001-fix-build-with-gcc-10.patch create mode 100644 buildroot/package/minidlna/0002-upnphttp.c-fix-CallStranger-a.k.a.-CVE-2020-12695.patch create mode 100644 buildroot/package/opencv/0001-Fix-build-of-grfmt_jpeg2000-cpp.patch create mode 100644 buildroot/package/opencv3/0001-Fix-build-of-grfmt_jpeg2000-cpp.patch create mode 100644 buildroot/package/openjpeg/0008-opj_decompress-fix-double-free-on-input-directory-with-mix-of-valid.patch create mode 100644 buildroot/package/python-matplotlib/0002-Merge-pull-request-11983-from-anntzer-builddepchecks.patch create mode 100644 buildroot/package/python-scapy/0001-Small-Python-2-fix.patch create mode 100644 buildroot/package/rtl8821au/0003-Fix-using-sprintf-for-extending-string-which-causes-.patch create mode 100644 buildroot/package/supertux/0001-CMakeLists.txt-compile-squirrel-with-fPIC.patch delete mode 100644 buildroot/package/systemd/0001-Fix-build-with-libmicrohttpd-0.9.71.patch delete mode 100644 buildroot/package/systemd/0001-random-seed-add-missing-header-for-GRND_NONBLOCK.patch create mode 100644 buildroot/package/trousers/0003-Correct-multiple-security-issues-that-are-present-if.patch rename buildroot/package/vsftpd/{0003-fix-CVE-2015-1419.patch => 0002-fix-CVE-2015-1419.patch} (100%) rename buildroot/package/vsftpd/{0004-Prevent-hang-in-SIGCHLD-handler.patch => 0003-Prevent-hang-in-SIGCHLD-handler.patch} (100%) create mode 100644 buildroot/package/wolfssl/0001-Make-ByteReverseWords-available-for-big-and-little-endian.patch delete mode 100644 buildroot/package/x11r7/xserver_xorg-server/1.20.8/0002-configure.ac-Fix-check-for-CLOCK_MONOTONIC.patch rename buildroot/package/x11r7/xserver_xorg-server/{1.20.8 => 1.20.9}/0001-modesettings-needs-dri2.patch (97%) rename buildroot/package/x11r7/xserver_xorg-server/{1.20.8/0003-Remove-check-for-useSIGIO-option.patch => 1.20.9/0002-Remove-check-for-useSIGIO-option.patch} (96%) rename buildroot/package/x11r7/xserver_xorg-server/{1.20.8/0004-include-misc.h-fix-uClibc-build.patch => 1.20.9/0003-include-misc.h-fix-uClibc-build.patch} (100%) rename buildroot/package/x11r7/xserver_xorg-server/{1.20.8/0005-hw-xwayland-Makefile.am-fix-build-without-glx.patch => 1.20.9/0004-hw-xwayland-Makefile.am-fix-build-without-glx.patch} (100%) rename buildroot/package/x11r7/xserver_xorg-server/{1.20.8/0006-hw-xfree86-common-xf86Init.c-fix-build-without-glx.patch => 1.20.9/0005-hw-xfree86-common-xf86Init.c-fix-build-without-glx.patch} (97%) create mode 100644 buildroot/package/x11r7/xserver_xorg-server/1.20.9/0006-Fix-segfault-on-probing-a-non-PCI-platform-device-on.patch rename buildroot/package/ympd/{0002-only-c-language.patch => 0001-only-c-language.patch} (100%) delete mode 100644 buildroot/package/zeromq/0001-acinclude.m4-add-latomic-to-PKGCFG_LIBS_PRIVATE.patch diff --git a/buildroot/.gitlab-ci.yml b/buildroot/.gitlab-ci.yml index b4dad3173..c838ff3c2 100644 --- a/buildroot/.gitlab-ci.yml +++ b/buildroot/.gitlab-ci.yml @@ -4,12 +4,13 @@ # It needs to be regenerated every time a defconfig is added, using # "make .gitlab-ci.yml". -image: buildroot/base:20191027.2027 +image: buildroot/base:20200814.2228 .check_base: - except: - - /^.*-.*_defconfig$/ - - /^.*-tests\..*$/ + rules: + - if: '$CI_COMMIT_REF_NAME =~ /^.*-.*_defconfig$/ || $CI_COMMIT_REF_NAME =~ /^.*-tests\..*$/' + when: never + - when: always check-DEVELOPERS: extends: .check_base @@ -27,7 +28,7 @@ check-flake8: - find * -type f -print0 | xargs -0 file | grep 'Python script' | cut -d':' -f1 >> files.txt - sort -u files.txt | tee files.processed script: - - python -m flake8 --statistics --count --max-line-length=132 $(cat files.processed) + - python3 -m flake8 --statistics --count --max-line-length=132 $(cat files.processed) after_script: - wc -l files.processed @@ -69,17 +70,21 @@ check-package: extends: .defconfig_base # Running the defconfigs for every push is too much, so limit to # explicit triggers through the API. - only: - - triggers - - tags - - /-defconfigs$/ + rules: + # For tags, create a pipeline. + - if: '$CI_COMMIT_TAG' + # For pipeline created by using a trigger token. + - if: '$CI_PIPELINE_TRIGGERED' + # For the branch or tag name named *-defconfigs, create a pipeline. + - if: '$CI_COMMIT_REF_NAME =~ /^.*-defconfigs$/' before_script: - DEFCONFIG_NAME=${CI_JOB_NAME} one-defconfig: extends: .defconfig_base - only: - - /^.*-.*_defconfig$/ + rules: + # For the branch or tag name named *-*_defconfigs, create a pipeline. + - if: '$CI_COMMIT_REF_NAME =~ /^.*-.*_defconfig$/' before_script: - DEFCONFIG_NAME=$(echo ${CI_COMMIT_REF_NAME} | sed -e 's,^.*-,,g') @@ -103,17 +108,20 @@ one-defconfig: extends: .runtime_test_base # Running the runtime tests for every push is too much, so limit to # explicit triggers through the API. - only: - - triggers - - tags - - /-runtime-tests$/ + rules: + # For tags, create a pipeline. + - if: '$CI_COMMIT_TAG' + # For pipeline created by using a trigger token. + - if: '$CI_PIPELINE_TRIGGERED' + # For the branch or tag name named *-runtime-tests, create a pipeline. + - if: '$CI_COMMIT_REF_NAME =~ /^.*-runtime-tests$/' before_script: - TEST_CASE_NAME=${CI_JOB_NAME} one-runtime_test: extends: .runtime_test_base - only: - - /^.*-tests\..*$/ + rules: + - if: '$CI_COMMIT_REF_NAME =~ /^.*-tests\..*$/' before_script: - TEST_CASE_NAME=$(echo ${CI_COMMIT_REF_NAME} | sed -e 's,^.*-,,g') aarch64_efi_defconfig: { extends: .defconfig } diff --git a/buildroot/.gitlab-ci.yml.in b/buildroot/.gitlab-ci.yml.in index 7e6a7598a..08a714f32 100644 --- a/buildroot/.gitlab-ci.yml.in +++ b/buildroot/.gitlab-ci.yml.in @@ -4,12 +4,13 @@ # It needs to be regenerated every time a defconfig is added, using # "make .gitlab-ci.yml". -image: buildroot/base:20191027.2027 +image: buildroot/base:20200814.2228 .check_base: - except: - - /^.*-.*_defconfig$/ - - /^.*-tests\..*$/ + rules: + - if: '$CI_COMMIT_REF_NAME =~ /^.*-.*_defconfig$/ || $CI_COMMIT_REF_NAME =~ /^.*-tests\..*$/' + when: never + - when: always check-DEVELOPERS: extends: .check_base @@ -27,7 +28,7 @@ check-flake8: - find * -type f -print0 | xargs -0 file | grep 'Python script' | cut -d':' -f1 >> files.txt - sort -u files.txt | tee files.processed script: - - python -m flake8 --statistics --count --max-line-length=132 $(cat files.processed) + - python3 -m flake8 --statistics --count --max-line-length=132 $(cat files.processed) after_script: - wc -l files.processed @@ -69,17 +70,21 @@ check-package: extends: .defconfig_base # Running the defconfigs for every push is too much, so limit to # explicit triggers through the API. - only: - - triggers - - tags - - /-defconfigs$/ + rules: + # For tags, create a pipeline. + - if: '$CI_COMMIT_TAG' + # For pipeline created by using a trigger token. + - if: '$CI_PIPELINE_TRIGGERED' + # For the branch or tag name named *-defconfigs, create a pipeline. + - if: '$CI_COMMIT_REF_NAME =~ /^.*-defconfigs$/' before_script: - DEFCONFIG_NAME=${CI_JOB_NAME} one-defconfig: extends: .defconfig_base - only: - - /^.*-.*_defconfig$/ + rules: + # For the branch or tag name named *-*_defconfigs, create a pipeline. + - if: '$CI_COMMIT_REF_NAME =~ /^.*-.*_defconfig$/' before_script: - DEFCONFIG_NAME=$(echo ${CI_COMMIT_REF_NAME} | sed -e 's,^.*-,,g') @@ -103,16 +108,19 @@ one-defconfig: extends: .runtime_test_base # Running the runtime tests for every push is too much, so limit to # explicit triggers through the API. - only: - - triggers - - tags - - /-runtime-tests$/ + rules: + # For tags, create a pipeline. + - if: '$CI_COMMIT_TAG' + # For pipeline created by using a trigger token. + - if: '$CI_PIPELINE_TRIGGERED' + # For the branch or tag name named *-runtime-tests, create a pipeline. + - if: '$CI_COMMIT_REF_NAME =~ /^.*-runtime-tests$/' before_script: - TEST_CASE_NAME=${CI_JOB_NAME} one-runtime_test: extends: .runtime_test_base - only: - - /^.*-tests\..*$/ + rules: + - if: '$CI_COMMIT_REF_NAME =~ /^.*-tests\..*$/' before_script: - TEST_CASE_NAME=$(echo ${CI_COMMIT_REF_NAME} | sed -e 's,^.*-,,g') diff --git a/buildroot/CHANGES b/buildroot/CHANGES index 86ecec8f7..77e274f5c 100644 --- a/buildroot/CHANGES +++ b/buildroot/CHANGES @@ -1,3 +1,94 @@ +2020.02.7, released October 12th, 2020 + + Important / security related fixes. + + meson: Correct SDK cross-compilation.conf file when + per-package builds were used to build SDK. + + systemd: Use /run rather than /var/run for PID files in units. + + Toolchain: use Secure-PLT rather than BSS-PLT for PowerPC 32. + + support/script/pycompile: Rework logic to ensure .pyc files + contain absolute target paths, fixing code inspection at + runtime when executed with cwd != '/'. + + support/scripts/setlocalversion: Correct Mercurial output to + match behaviour with Git. + + support/scripts/apply-patches.sh: Use patch + --no-backup-if-mismatch, so we no longer blindly have to + remove *.orig files after patching, fixing issues with + packages containing such files. + + Updated/fixed packages: bandwidthd, barebox, bash, bison, + brotli, cifs-utils, cryptsetup, dhcpcd, dhcpdump, docker-cli, + docker-engine, ecryptfs-utils, efl, fail2ban, freetype, gcc, + gdb, ghostscript, gnutls, go, gst1-plugins-base, + gst1-plugins-ugly, ipmitool, libhtp, libraw, libssh, libxml2, + libxml-parser-perl, localedef, lua, memcached, mesa3d, meson, + minidlna, nginx, nodejs, nss-pam-ldapd, openvmtools, php, + postgresql, python, python-aenum, python-autobahn, + python-engineio, python-fire, python-pymodbus, python-scapy, + python-semver, python-sentry-sdk, python-socketio, + python-texttable, python-tinyrpc, python-txtorcon, python3, + qt5base, runc, samba4, strace, supertux, suricata, systemd, + vlc, wayland-protocols, wireguard-linux-compat, wireshark, + xserver_xorg-server, zeromq, zstd + + Issues resolved (http://bugs.uclibc.org): + + #12911: usb_modeswitch installation race condition + #13251: cryptsetup does not work on branch 2020.02 following.. + +2020.02.6, released September 5th, 2020 + + Important / security related fixes. + + Fix a 2020.02.5 build regression in busybox when systemd (and + not less) are enabled because of missing infrastructure. + + Updated/fixed packages: alsa-utils, avahi, busybox, cups, + docker-cli, graphite2, imagemagick, libeXosip2, mbedtls, + nvidia-driver, paho-mqtt-c, python-django, systemd, uclibc, + usb_modeswitch, wolfssl + + Issues resolved (http://bugs.uclibc.org): + + #12911: usb_modeswitch installation race condition + +2020.02.5, released August 29th, 2020 + + Important / security related fixes. + + Infrastructure: Ensure RPATH entries that may be needed for + dlopen() are not dropped by patchelf. + + BR_VERSION_FULL/setlocalversion (used by make print-version + and /etc/os-release): Properly handle local git tags + + Updated/fixed packages: apache, at91bootstrap3, bind, boost, + busybox, capnproto, chrony, collectd, cpio, cryptsetup, cups, + cvs, dbus, docker-engine, domoticz, dovecot, + dovecot-pigeonhole, dropbear, efl, elixir, f2fs-tools, ffmpeg, + gd, gdk-pixbuf, ghostscript, glibc, grub2, gst1-plugins-bad, + hostapd, iputils, jasper, json-c, libcurl, libwebsockets, + linux, live555, mesa3d, mosquitto, mpv, nodejs, opencv, + opencv3, openjpeg, patchelf, perl, php, postgresql, + python-django, python-gunicorn, python-matplotlib, ripgrep, + rtl8188eu, rtl8821au, ruby, shadowsocks-libev, squid, + tpm2-abrmd, tpm2-tools, trousers, uacme, webkitgtk, wireshark, + wolfssl, wpa_supplicant, wpewebkit, xen, xlib_libX11, + xserver_xorg-server + + Issues resolved (http://bugs.uclibc.org): + + #12876: nodejs fails to build when host-icu has been built before + #13111: python-gunicorn: missing dependency on python-setuptools + #13121: wpa_supplicant fails to build without libopenssl enabled + #13141: Target-finalize fail with "depmod: ERROR: Bad version passed" + #13156: package live555 new license + 2020.02.4, released July 26th, 2020 Important / security related fixes. diff --git a/buildroot/DEVELOPERS b/buildroot/DEVELOPERS index 66ef194dd..5abdb916a 100644 --- a/buildroot/DEVELOPERS +++ b/buildroot/DEVELOPERS @@ -186,18 +186,25 @@ F: package/rauc/ N: Angelo Compagnucci F: package/corkscrew/ +F: package/cups/ +F: package/cups-filters/ F: package/fail2ban/ +F: package/grep/ F: package/i2c-tools/ +F: package/jq/ +F: package/libb64/ F: package/mender/ F: package/mender-artifact/ F: package/mono/ F: package/mono-gtksharp3/ F: package/monolite/ +F: package/openjpeg/ F: package/python-can/ F: package/python-pillow/ F: package/python-pydal/ F: package/python-spidev/ F: package/python-web2py/ +F: package/sam-ba/ F: package/sshguard/ F: package/sunwait/ F: package/sysdig/ @@ -211,6 +218,8 @@ N: Anthony Viallard F: package/gnuplot/ N: Antoine Ténart +F: package/libselinux/ +F: package/refpolicy/ F: package/wf111/ N: Antony Pavlov @@ -1035,6 +1044,7 @@ N: Gwenhael Goavec-Merou F: package/gnuradio/ F: package/gqrx/ F: package/gr-osmosdr/ +F: package/librtlsdr/ F: package/libusbgx/ F: package/python-cheetah/ F: package/python-markdown/ @@ -1713,9 +1723,6 @@ F: package/systemd-bootchart/ F: package/tinyalsa/ F: package/tinyxml/ -N: Maxime Ripard -F: package/kmsxx/ - N: Michael Durrant F: board/arcturus/ F: configs/arcturus_ucp1020_defconfig @@ -1810,6 +1817,7 @@ F: package/tpm-tools/ F: package/trousers/ N: Norbert Lange +F: package/systemd/ F: package/tcf-agent/ N: Nylon Chen @@ -2135,6 +2143,7 @@ F: package/davfs2/ N: Ryan Barnett F: package/atftp/ +F: package/c-periphery/ F: package/miraclecast/ F: package/python-pyasn/ F: package/python-pysnmp/ diff --git a/buildroot/Makefile b/buildroot/Makefile index b2dfce197..bf17f52f8 100644 --- a/buildroot/Makefile +++ b/buildroot/Makefile @@ -92,9 +92,9 @@ all: .PHONY: all # Set and export the version string -export BR2_VERSION := 2020.02.4 +export BR2_VERSION := 2020.02.7 # Actual time the release is cut (for reproducible builds) -BR2_VERSION_EPOCH = 1595750000 +BR2_VERSION_EPOCH = 1602538000 # Save running make version since it's clobbered by the make package RUNNING_MAKE_VERSION := $(MAKE_VERSION) @@ -113,7 +113,13 @@ DATE := $(shell date +%Y%m%d) # Compute the full local version string so packages can use it as-is # Need to export it, so it can be got from environment in children (eg. mconf) -export BR2_VERSION_FULL := $(BR2_VERSION)$(shell $(TOPDIR)/support/scripts/setlocalversion) + +BR2_LOCALVERSION := $(shell $(TOPDIR)/support/scripts/setlocalversion) +ifeq ($(BR2_LOCALVERSION),) +export BR2_VERSION_FULL := $(BR2_VERSION) +else +export BR2_VERSION_FULL := $(BR2_LOCALVERSION) +endif # List of targets and target patterns for which .config doesn't need to be read in noconfig_targets := menuconfig nconfig gconfig xconfig config oldconfig randconfig \ @@ -793,9 +799,9 @@ endif # counterparts are appropriately setup as symlinks ones to the others. ifeq ($(BR2_ROOTFS_MERGED_USR),y) - @$(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ - $(call MESSAGE,"Sanity check in overlay $(d)"); \ - not_merged_dirs="$$(support/scripts/check-merged-usr.sh $(d))"; \ + $(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ + @$(call MESSAGE,"Sanity check in overlay $(d)")$(sep) \ + $(Q)not_merged_dirs="$$(support/scripts/check-merged-usr.sh $(d))"; \ test -n "$$not_merged_dirs" && { \ echo "ERROR: The overlay in $(d) is not" \ "using a merged /usr for the following directories:" \ @@ -805,20 +811,20 @@ ifeq ($(BR2_ROOTFS_MERGED_USR),y) endif # merged /usr - @$(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ - $(call MESSAGE,"Copying overlay $(d)"); \ - $(call SYSTEM_RSYNC,$(d),$(TARGET_DIR))$(sep)) + $(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ + @$(call MESSAGE,"Copying overlay $(d)")$(sep) \ + $(Q)$(call SYSTEM_RSYNC,$(d),$(TARGET_DIR))$(sep)) - $(if $(TARGET_DIR_FILES_LISTS), \ + $(Q)$(if $(TARGET_DIR_FILES_LISTS), \ cat $(TARGET_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list.txt - $(if $(HOST_DIR_FILES_LISTS), \ + $(Q)$(if $(HOST_DIR_FILES_LISTS), \ cat $(HOST_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list-host.txt - $(if $(STAGING_DIR_FILES_LISTS), \ + $(Q)$(if $(STAGING_DIR_FILES_LISTS), \ cat $(STAGING_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list-staging.txt - @$(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_BUILD_SCRIPT)), \ - $(call MESSAGE,"Executing post-build script $(s)"); \ - $(EXTRA_ENV) $(s) $(TARGET_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep)) + $(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_BUILD_SCRIPT)), \ + @$(call MESSAGE,"Executing post-build script $(s)")$(sep) \ + $(Q)$(EXTRA_ENV) $(s) $(TARGET_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep)) touch $(TARGET_DIR)/usr diff --git a/buildroot/boot/at91bootstrap3/Config.in b/buildroot/boot/at91bootstrap3/Config.in index faab7635d..bd3873860 100644 --- a/buildroot/boot/at91bootstrap3/Config.in +++ b/buildroot/boot/at91bootstrap3/Config.in @@ -1,6 +1,6 @@ config BR2_TARGET_AT91BOOTSTRAP3 bool "AT91 Bootstrap 3" - depends on BR2_arm926t || BR2_cortex_a5 + depends on BR2_arm926t || BR2_cortex_a5 || BR2_cortex_a7 help AT91Bootstrap is a first level bootloader for the Atmel AT91 devices. It integrates algorithms for: diff --git a/buildroot/boot/barebox/barebox.mk b/buildroot/boot/barebox/barebox.mk index 1efe5665d..9d62037e7 100644 --- a/buildroot/boot/barebox/barebox.mk +++ b/buildroot/boot/barebox/barebox.mk @@ -88,13 +88,6 @@ $(1)_KCONFIG_DEPENDENCIES = \ $(BR2_BISON_HOST_DEPENDENCY) \ $(BR2_FLEX_HOST_DEPENDENCY) -ifeq ($$(BR2_TARGET_$(1)_BAREBOXENV),y) -define $(1)_BUILD_BAREBOXENV_CMDS - $$(TARGET_CC) $$(TARGET_CFLAGS) $$(TARGET_LDFLAGS) -o $$(@D)/bareboxenv \ - $$(@D)/scripts/bareboxenv.c -endef -endif - ifeq ($$(BR2_TARGET_$(1)_CUSTOM_ENV),y) $(1)_ENV_NAME = $$(notdir $$(call qstrip,\ $$(BR2_TARGET_$(1)_CUSTOM_ENV_PATH))) @@ -109,12 +102,23 @@ endef endif ifneq ($$($(1)_CUSTOM_EMBEDDED_ENV_PATH),) -define $(1)_KCONFIG_FIXUP_CMDS - $$(call KCONFIG_ENABLE_OPT,CONFIG_DEFAULT_ENVIRONMENT,$$(@D)/.config) - $$(call KCONFIG_SET_OPT,CONFIG_DEFAULT_ENVIRONMENT_PATH,"$$($(1)_CUSTOM_EMBEDDED_ENV_PATH)",$$(@D)/.config) +define $(1)_KCONFIG_FIXUP_CUSTOM_EMBEDDED_ENV_PATH + $$(call KCONFIG_ENABLE_OPT,CONFIG_DEFAULT_ENVIRONMENT) + $$(call KCONFIG_SET_OPT,CONFIG_DEFAULT_ENVIRONMENT_PATH,"$$($(1)_CUSTOM_EMBEDDED_ENV_PATH)") endef endif +define $(1)_KCONFIG_FIXUP_BAREBOXENV + $$(if $$(BR2_TARGET_$(1)_BAREBOXENV),\ + $$(call KCONFIG_ENABLE_OPT,CONFIG_BAREBOXENV_TARGET),\ + $$(call KCONFIG_DISABLE_OPT,CONFIG_BAREBOXENV_TARGET)) +endef + +define $(1)_KCONFIG_FIXUP_CMDS + $$($(1)_KCONFIG_FIXUP_CUSTOM_EMBEDDED_ENV_PATH) + $$($(1)_KCONFIG_FIXUP_BAREBOXENV) +endef + define $(1)_BUILD_CMDS $$($(1)_BUILD_BAREBOXENV_CMDS) $$(TARGET_MAKE_ENV) $$(MAKE) $$($(1)_MAKE_FLAGS) -C $$(@D) @@ -136,7 +140,7 @@ endef ifeq ($$(BR2_TARGET_$(1)_BAREBOXENV),y) define $(1)_INSTALL_TARGET_CMDS - cp $$(@D)/bareboxenv $$(TARGET_DIR)/usr/bin + cp $$(@D)/scripts/bareboxenv-target $$(TARGET_DIR)/usr/bin/bareboxenv endef endif diff --git a/buildroot/boot/grub2/0002-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch b/buildroot/boot/grub2/0002-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch new file mode 100644 index 000000000..001dda820 --- /dev/null +++ b/buildroot/boot/grub2/0002-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch @@ -0,0 +1,73 @@ +From a7ab0cc98fa89a3d5098c29cbe44bcd24b0a6454 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 15 Apr 2020 15:45:02 -0400 +Subject: [PATCH] yylex: Make lexer fatal errors actually be fatal +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +When presented with a command that can't be tokenized to anything +smaller than YYLMAX characters, the parser calls YY_FATAL_ERROR(errmsg), +expecting that will stop further processing, as such: + + #define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + if ( yyleng >= YYLMAX ) \ + YY_FATAL_ERROR( "token too large, exceeds YYLMAX" ); \ + yy_flex_strncpy( yytext, yyg->yytext_ptr, yyleng + 1 , yyscanner); \ + yyg->yy_c_buf_p = yy_cp; + +The code flex generates expects that YY_FATAL_ERROR() will either return +for it or do some form of longjmp(), or handle the error in some way at +least, and so the strncpy() call isn't in an "else" clause, and thus if +YY_FATAL_ERROR() is *not* actually fatal, it does the call with the +questionable limit, and predictable results ensue. + +Unfortunately, our implementation of YY_FATAL_ERROR() is: + + #define YY_FATAL_ERROR(msg) \ + do { \ + grub_printf (_("fatal error: %s\n"), _(msg)); \ + } while (0) + +The same pattern exists in yyless(), and similar problems exist in users +of YY_INPUT(), several places in the main parsing loop, +yy_get_next_buffer(), yy_load_buffer_state(), yyensure_buffer_stack, +yy_scan_buffer(), etc. + +All of these callers expect YY_FATAL_ERROR() to actually be fatal, and +the things they do if it returns after calling it are wildly unsafe. + +Fixes: CVE-2020-10713 + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/script/yylex.l | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l +index 7b44c37b7..b7203c823 100644 +--- a/grub-core/script/yylex.l ++++ b/grub-core/script/yylex.l +@@ -37,11 +37,11 @@ + + /* + * As we don't have access to yyscanner, we cannot do much except to +- * print the fatal error. ++ * print the fatal error and exit. + */ + #define YY_FATAL_ERROR(msg) \ + do { \ +- grub_printf (_("fatal error: %s\n"), _(msg)); \ ++ grub_fatal (_("fatal error: %s\n"), _(msg));\ + } while (0) + + #define COPY(str, hint) \ +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0003-safemath-Add-some-arithmetic-primitives-that-check-f.patch b/buildroot/boot/grub2/0003-safemath-Add-some-arithmetic-primitives-that-check-f.patch new file mode 100644 index 000000000..5c5211346 --- /dev/null +++ b/buildroot/boot/grub2/0003-safemath-Add-some-arithmetic-primitives-that-check-f.patch @@ -0,0 +1,128 @@ +From 782a4580a5e347793443aa8e9152db1bf4a0fff8 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 15 Jun 2020 10:58:42 -0400 +Subject: [PATCH] safemath: Add some arithmetic primitives that check for + overflow +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This adds a new header, include/grub/safemath.h, that includes easy to +use wrappers for __builtin_{add,sub,mul}_overflow() declared like: + + bool OP(a, b, res) + +where OP is grub_add, grub_sub or grub_mul. OP() returns true in the +case where the operation would overflow and res is not modified. +Otherwise, false is returned and the operation is executed. + +These arithmetic primitives require newer compiler versions. So, bump +these requirements in the INSTALL file too. + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + INSTALL | 22 ++-------------------- + include/grub/compiler.h | 8 ++++++++ + include/grub/safemath.h | 37 +++++++++++++++++++++++++++++++++++++ + 3 files changed, 47 insertions(+), 20 deletions(-) + create mode 100644 include/grub/safemath.h + +diff --git a/INSTALL b/INSTALL +index 8acb40902..dcb9b7d7b 100644 +--- a/INSTALL ++++ b/INSTALL +@@ -11,27 +11,9 @@ GRUB depends on some software packages installed into your system. If + you don't have any of them, please obtain and install them before + configuring the GRUB. + +-* GCC 4.1.3 or later +- Note: older versions may work but support is limited +- +- Experimental support for clang 3.3 or later (results in much bigger binaries) ++* GCC 5.1.0 or later ++ Experimental support for clang 3.8.0 or later (results in much bigger binaries) + for i386, x86_64, arm (including thumb), arm64, mips(el), powerpc, sparc64 +- Note: clang 3.2 or later works for i386 and x86_64 targets but results in +- much bigger binaries. +- earlier versions not tested +- Note: clang 3.2 or later works for arm +- earlier versions not tested +- Note: clang on arm64 is not supported due to +- https://llvm.org/bugs/show_bug.cgi?id=26030 +- Note: clang 3.3 or later works for mips(el) +- earlier versions fail to generate .reginfo and hence gprel relocations +- fail. +- Note: clang 3.2 or later works for powerpc +- earlier versions not tested +- Note: clang 3.5 or later works for sparc64 +- earlier versions return "error: unable to interface with target machine" +- Note: clang has no support for ia64 and hence you can't compile GRUB +- for ia64 with clang + * GNU Make + * GNU Bison 2.3 or later + * GNU gettext 0.17 or later +diff --git a/include/grub/compiler.h b/include/grub/compiler.h +index c9e1d7a73..8f3be3ae7 100644 +--- a/include/grub/compiler.h ++++ b/include/grub/compiler.h +@@ -48,4 +48,12 @@ + # define WARN_UNUSED_RESULT + #endif + ++#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) ++# define CLANG_PREREQ(maj,min) \ ++ ((__clang_major__ > (maj)) || \ ++ (__clang_major__ == (maj) && __clang_minor__ >= (min))) ++#else ++# define CLANG_PREREQ(maj,min) 0 ++#endif ++ + #endif /* ! GRUB_COMPILER_HEADER */ +diff --git a/include/grub/safemath.h b/include/grub/safemath.h +new file mode 100644 +index 000000000..c17b89bba +--- /dev/null ++++ b/include/grub/safemath.h +@@ -0,0 +1,37 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ * ++ * Arithmetic operations that protect against overflow. ++ */ ++ ++#ifndef GRUB_SAFEMATH_H ++#define GRUB_SAFEMATH_H 1 ++ ++#include ++ ++/* These appear in gcc 5.1 and clang 3.8. */ ++#if GNUC_PREREQ(5, 1) || CLANG_PREREQ(3, 8) ++ ++#define grub_add(a, b, res) __builtin_add_overflow(a, b, res) ++#define grub_sub(a, b, res) __builtin_sub_overflow(a, b, res) ++#define grub_mul(a, b, res) __builtin_mul_overflow(a, b, res) ++ ++#else ++#error gcc 5.1 or newer or clang 3.8 or newer is required ++#endif ++ ++#endif /* GRUB_SAFEMATH_H */ +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0004-calloc-Make-sure-we-always-have-an-overflow-checking.patch b/buildroot/boot/grub2/0004-calloc-Make-sure-we-always-have-an-overflow-checking.patch new file mode 100644 index 000000000..a2e19f0ea --- /dev/null +++ b/buildroot/boot/grub2/0004-calloc-Make-sure-we-always-have-an-overflow-checking.patch @@ -0,0 +1,246 @@ +From 5775eb40862b67468ced816e6d7560dbe22a3670 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 15 Jun 2020 12:15:29 -0400 +Subject: [PATCH] calloc: Make sure we always have an overflow-checking + calloc() available +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This tries to make sure that everywhere in this source tree, we always have +an appropriate version of calloc() (i.e. grub_calloc(), xcalloc(), etc.) +available, and that they all safely check for overflow and return NULL when +it would occur. + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/kern/emu/misc.c | 12 +++++++++ + grub-core/kern/emu/mm.c | 10 ++++++++ + grub-core/kern/mm.c | 40 ++++++++++++++++++++++++++++++ + grub-core/lib/libgcrypt_wrap/mem.c | 11 ++++++-- + grub-core/lib/posix_wrap/stdlib.h | 8 +++++- + include/grub/emu/misc.h | 1 + + include/grub/mm.h | 6 +++++ + 7 files changed, 85 insertions(+), 3 deletions(-) + +diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c +index 65db79baa..dfd8a8ec4 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -85,6 +85,18 @@ grub_util_error (const char *fmt, ...) + exit (1); + } + ++void * ++xcalloc (grub_size_t nmemb, grub_size_t size) ++{ ++ void *p; ++ ++ p = calloc (nmemb, size); ++ if (!p) ++ grub_util_error ("%s", _("out of memory")); ++ ++ return p; ++} ++ + void * + xmalloc (grub_size_t size) + { +diff --git a/grub-core/kern/emu/mm.c b/grub-core/kern/emu/mm.c +index f262e95e3..145b01d37 100644 +--- a/grub-core/kern/emu/mm.c ++++ b/grub-core/kern/emu/mm.c +@@ -25,6 +25,16 @@ + #include + #include + ++void * ++grub_calloc (grub_size_t nmemb, grub_size_t size) ++{ ++ void *ret; ++ ret = calloc (nmemb, size); ++ if (!ret) ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ return ret; ++} ++ + void * + grub_malloc (grub_size_t size) + { +diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c +index ee88ff611..f2822a836 100644 +--- a/grub-core/kern/mm.c ++++ b/grub-core/kern/mm.c +@@ -67,8 +67,10 @@ + #include + #include + #include ++#include + + #ifdef MM_DEBUG ++# undef grub_calloc + # undef grub_malloc + # undef grub_zalloc + # undef grub_realloc +@@ -375,6 +377,30 @@ grub_memalign (grub_size_t align, grub_size_t size) + return 0; + } + ++/* ++ * Allocate NMEMB instances of SIZE bytes and return the pointer, or error on ++ * integer overflow. ++ */ ++void * ++grub_calloc (grub_size_t nmemb, grub_size_t size) ++{ ++ void *ret; ++ grub_size_t sz = 0; ++ ++ if (grub_mul (nmemb, size, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return NULL; ++ } ++ ++ ret = grub_memalign (0, sz); ++ if (!ret) ++ return NULL; ++ ++ grub_memset (ret, 0, sz); ++ return ret; ++} ++ + /* Allocate SIZE bytes and return the pointer. */ + void * + grub_malloc (grub_size_t size) +@@ -561,6 +587,20 @@ grub_mm_dump (unsigned lineno) + grub_printf ("\n"); + } + ++void * ++grub_debug_calloc (const char *file, int line, grub_size_t nmemb, grub_size_t size) ++{ ++ void *ptr; ++ ++ if (grub_mm_debug) ++ grub_printf ("%s:%d: calloc (0x%" PRIxGRUB_SIZE ", 0x%" PRIxGRUB_SIZE ") = ", ++ file, line, size); ++ ptr = grub_calloc (nmemb, size); ++ if (grub_mm_debug) ++ grub_printf ("%p\n", ptr); ++ return ptr; ++} ++ + void * + grub_debug_malloc (const char *file, int line, grub_size_t size) + { +diff --git a/grub-core/lib/libgcrypt_wrap/mem.c b/grub-core/lib/libgcrypt_wrap/mem.c +index beeb661a3..74c6eafe5 100644 +--- a/grub-core/lib/libgcrypt_wrap/mem.c ++++ b/grub-core/lib/libgcrypt_wrap/mem.c +@@ -4,6 +4,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -36,7 +37,10 @@ void * + gcry_xcalloc (size_t n, size_t m) + { + void *ret; +- ret = grub_zalloc (n * m); ++ size_t sz; ++ if (grub_mul (n, m, &sz)) ++ grub_fatal ("gcry_xcalloc would overflow"); ++ ret = grub_zalloc (sz); + if (!ret) + grub_fatal ("gcry_xcalloc failed"); + return ret; +@@ -56,7 +60,10 @@ void * + gcry_xcalloc_secure (size_t n, size_t m) + { + void *ret; +- ret = grub_zalloc (n * m); ++ size_t sz; ++ if (grub_mul (n, m, &sz)) ++ grub_fatal ("gcry_xcalloc would overflow"); ++ ret = grub_zalloc (sz); + if (!ret) + grub_fatal ("gcry_xcalloc failed"); + return ret; +diff --git a/grub-core/lib/posix_wrap/stdlib.h b/grub-core/lib/posix_wrap/stdlib.h +index 3b46f47ff..7a8d385e9 100644 +--- a/grub-core/lib/posix_wrap/stdlib.h ++++ b/grub-core/lib/posix_wrap/stdlib.h +@@ -21,6 +21,7 @@ + + #include + #include ++#include + + static inline void + free (void *ptr) +@@ -37,7 +38,12 @@ malloc (grub_size_t size) + static inline void * + calloc (grub_size_t size, grub_size_t nelem) + { +- return grub_zalloc (size * nelem); ++ grub_size_t sz; ++ ++ if (grub_mul (size, nelem, &sz)) ++ return NULL; ++ ++ return grub_zalloc (sz); + } + + static inline void * +diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h +index ce464cfd0..ff9c48a64 100644 +--- a/include/grub/emu/misc.h ++++ b/include/grub/emu/misc.h +@@ -47,6 +47,7 @@ grub_util_device_is_mapped (const char *dev); + #define GRUB_HOST_PRIuLONG_LONG "llu" + #define GRUB_HOST_PRIxLONG_LONG "llx" + ++void * EXPORT_FUNC(xcalloc) (grub_size_t nmemb, grub_size_t size) WARN_UNUSED_RESULT; + void * EXPORT_FUNC(xmalloc) (grub_size_t size) WARN_UNUSED_RESULT; + void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size) WARN_UNUSED_RESULT; + char * EXPORT_FUNC(xstrdup) (const char *str) WARN_UNUSED_RESULT; +diff --git a/include/grub/mm.h b/include/grub/mm.h +index 28e2e53eb..9c38dd3ca 100644 +--- a/include/grub/mm.h ++++ b/include/grub/mm.h +@@ -29,6 +29,7 @@ + #endif + + void grub_mm_init_region (void *addr, grub_size_t size); ++void *EXPORT_FUNC(grub_calloc) (grub_size_t nmemb, grub_size_t size); + void *EXPORT_FUNC(grub_malloc) (grub_size_t size); + void *EXPORT_FUNC(grub_zalloc) (grub_size_t size); + void EXPORT_FUNC(grub_free) (void *ptr); +@@ -48,6 +49,9 @@ extern int EXPORT_VAR(grub_mm_debug); + void grub_mm_dump_free (void); + void grub_mm_dump (unsigned lineno); + ++#define grub_calloc(nmemb, size) \ ++ grub_debug_calloc (GRUB_FILE, __LINE__, nmemb, size) ++ + #define grub_malloc(size) \ + grub_debug_malloc (GRUB_FILE, __LINE__, size) + +@@ -63,6 +67,8 @@ void grub_mm_dump (unsigned lineno); + #define grub_free(ptr) \ + grub_debug_free (GRUB_FILE, __LINE__, ptr) + ++void *EXPORT_FUNC(grub_debug_calloc) (const char *file, int line, ++ grub_size_t nmemb, grub_size_t size); + void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line, + grub_size_t size); + void *EXPORT_FUNC(grub_debug_zalloc) (const char *file, int line, +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0005-calloc-Use-calloc-at-most-places.patch b/buildroot/boot/grub2/0005-calloc-Use-calloc-at-most-places.patch new file mode 100644 index 000000000..096c2dfc4 --- /dev/null +++ b/buildroot/boot/grub2/0005-calloc-Use-calloc-at-most-places.patch @@ -0,0 +1,1840 @@ +From 8185711241d73931269f402bb6799f7e2c58f04b Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 15 Jun 2020 12:26:01 -0400 +Subject: [PATCH] calloc: Use calloc() at most places +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This modifies most of the places we do some form of: + + X = malloc(Y * Z); + +to use calloc(Y, Z) instead. + +Among other issues, this fixes: + - allocation of integer overflow in grub_png_decode_image_header() + reported by Chris Coulson, + - allocation of integer overflow in luks_recover_key() + reported by Chris Coulson, + - allocation of integer overflow in grub_lvm_detect() + reported by Chris Coulson. + +Fixes: CVE-2020-14308 + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/bus/usb/usbhub.c | 8 ++++---- + grub-core/commands/efi/lsefisystab.c | 3 ++- + grub-core/commands/legacycfg.c | 6 +++--- + grub-core/commands/menuentry.c | 2 +- + grub-core/commands/nativedisk.c | 2 +- + grub-core/commands/parttool.c | 12 +++++++++--- + grub-core/commands/regexp.c | 2 +- + grub-core/commands/search_wrap.c | 2 +- + grub-core/disk/diskfilter.c | 4 ++-- + grub-core/disk/ieee1275/ofdisk.c | 2 +- + grub-core/disk/ldm.c | 14 +++++++------- + grub-core/disk/luks.c | 2 +- + grub-core/disk/lvm.c | 8 ++++---- + grub-core/disk/xen/xendisk.c | 2 +- + grub-core/efiemu/loadcore.c | 2 +- + grub-core/efiemu/mm.c | 6 +++--- + grub-core/font/font.c | 3 +-- + grub-core/fs/affs.c | 6 +++--- + grub-core/fs/btrfs.c | 6 +++--- + grub-core/fs/hfs.c | 2 +- + grub-core/fs/hfsplus.c | 6 +++--- + grub-core/fs/iso9660.c | 2 +- + grub-core/fs/ntfs.c | 4 ++-- + grub-core/fs/sfs.c | 2 +- + grub-core/fs/tar.c | 2 +- + grub-core/fs/udf.c | 4 ++-- + grub-core/fs/zfs/zfs.c | 4 ++-- + grub-core/gfxmenu/gui_string_util.c | 2 +- + grub-core/gfxmenu/widget-box.c | 4 ++-- + grub-core/io/gzio.c | 2 +- + grub-core/kern/efi/efi.c | 6 +++--- + grub-core/kern/emu/hostdisk.c | 2 +- + grub-core/kern/fs.c | 2 +- + grub-core/kern/misc.c | 2 +- + grub-core/kern/parser.c | 2 +- + grub-core/kern/uboot/uboot.c | 2 +- + grub-core/lib/libgcrypt/cipher/ac.c | 8 ++++---- + grub-core/lib/libgcrypt/cipher/primegen.c | 4 ++-- + grub-core/lib/libgcrypt/cipher/pubkey.c | 4 ++-- + grub-core/lib/priority_queue.c | 2 +- + grub-core/lib/reed_solomon.c | 7 +++---- + grub-core/lib/relocator.c | 10 +++++----- + grub-core/lib/zstd/fse_decompress.c | 2 +- + grub-core/loader/arm/linux.c | 2 +- + grub-core/loader/efi/chainloader.c | 2 +- + grub-core/loader/i386/bsdXX.c | 2 +- + grub-core/loader/i386/xnu.c | 4 ++-- + grub-core/loader/macho.c | 2 +- + grub-core/loader/multiboot_elfxx.c | 2 +- + grub-core/loader/xnu.c | 2 +- + grub-core/mmap/mmap.c | 4 ++-- + grub-core/net/bootp.c | 2 +- + grub-core/net/dns.c | 10 +++++----- + grub-core/net/net.c | 4 ++-- + grub-core/normal/charset.c | 10 +++++----- + grub-core/normal/cmdline.c | 14 +++++++------- + grub-core/normal/menu_entry.c | 14 +++++++------- + grub-core/normal/menu_text.c | 4 ++-- + grub-core/normal/term.c | 4 ++-- + grub-core/osdep/linux/getroot.c | 6 +++--- + grub-core/osdep/unix/config.c | 2 +- + grub-core/osdep/windows/getroot.c | 2 +- + grub-core/osdep/windows/hostdisk.c | 4 ++-- + grub-core/osdep/windows/init.c | 2 +- + grub-core/osdep/windows/platform.c | 4 ++-- + grub-core/osdep/windows/relpath.c | 2 +- + grub-core/partmap/gpt.c | 2 +- + grub-core/partmap/msdos.c | 2 +- + grub-core/script/execute.c | 2 +- + grub-core/tests/fake_input.c | 2 +- + grub-core/tests/video_checksum.c | 6 +++--- + grub-core/video/capture.c | 2 +- + grub-core/video/emu/sdl.c | 2 +- + grub-core/video/i386/pc/vga.c | 2 +- + grub-core/video/readers/png.c | 2 +- + include/grub/unicode.h | 4 ++-- + util/getroot.c | 2 +- + util/grub-file.c | 2 +- + util/grub-fstest.c | 4 ++-- + util/grub-install-common.c | 2 +- + util/grub-install.c | 4 ++-- + util/grub-mkimagexx.c | 6 ++---- + util/grub-mkrescue.c | 4 ++-- + util/grub-mkstandalone.c | 2 +- + util/grub-pe2elf.c | 12 +++++------- + util/grub-probe.c | 4 ++-- + 86 files changed, 176 insertions(+), 175 deletions(-) + +diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c +index 34a7ff1b5..a06cce302 100644 +--- a/grub-core/bus/usb/usbhub.c ++++ b/grub-core/bus/usb/usbhub.c +@@ -149,8 +149,8 @@ grub_usb_add_hub (grub_usb_device_t dev) + grub_usb_set_configuration (dev, 1); + + dev->nports = hubdesc.portcnt; +- dev->children = grub_zalloc (hubdesc.portcnt * sizeof (dev->children[0])); +- dev->ports = grub_zalloc (dev->nports * sizeof (dev->ports[0])); ++ dev->children = grub_calloc (hubdesc.portcnt, sizeof (dev->children[0])); ++ dev->ports = grub_calloc (dev->nports, sizeof (dev->ports[0])); + if (!dev->children || !dev->ports) + { + grub_free (dev->children); +@@ -268,8 +268,8 @@ grub_usb_controller_dev_register_iter (grub_usb_controller_t controller, void *d + + /* Query the number of ports the root Hub has. */ + hub->nports = controller->dev->hubports (controller); +- hub->devices = grub_zalloc (sizeof (hub->devices[0]) * hub->nports); +- hub->ports = grub_zalloc (sizeof (hub->ports[0]) * hub->nports); ++ hub->devices = grub_calloc (hub->nports, sizeof (hub->devices[0])); ++ hub->ports = grub_calloc (hub->nports, sizeof (hub->ports[0])); + if (!hub->devices || !hub->ports) + { + grub_free (hub->devices); +diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c +index df1030221..cd81507f5 100644 +--- a/grub-core/commands/efi/lsefisystab.c ++++ b/grub-core/commands/efi/lsefisystab.c +@@ -71,7 +71,8 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)), + grub_printf ("Vendor: "); + + for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++); +- vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1); ++ /* Allocate extra 3 bytes to simplify math. */ ++ vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1); + if (!vendor) + return grub_errno; + *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor, +diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c +index db7a8f002..5e3ec0d5e 100644 +--- a/grub-core/commands/legacycfg.c ++++ b/grub-core/commands/legacycfg.c +@@ -314,7 +314,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), + if (argc < 2) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); + +- cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1)); ++ cutargs = grub_calloc (argc - 1, sizeof (cutargs[0])); + if (!cutargs) + return grub_errno; + cutargc = argc - 1; +@@ -436,7 +436,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), + { + char rbuf[3] = "-r"; + bsdargc = cutargc + 2; +- bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc); ++ bsdargs = grub_calloc (bsdargc, sizeof (bsdargs[0])); + if (!bsdargs) + { + err = grub_errno; +@@ -559,7 +559,7 @@ grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"), + "module"); + +- newargs = grub_malloc ((argc + 1) * sizeof (newargs[0])); ++ newargs = grub_calloc (argc + 1, sizeof (newargs[0])); + if (!newargs) + return grub_errno; + grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0])); +diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c +index 2c5363da7..9164df744 100644 +--- a/grub-core/commands/menuentry.c ++++ b/grub-core/commands/menuentry.c +@@ -154,7 +154,7 @@ grub_normal_add_menu_entry (int argc, const char **args, + goto fail; + + /* Save argc, args to pass as parameters to block arg later. */ +- menu_args = grub_malloc (sizeof (char*) * (argc + 1)); ++ menu_args = grub_calloc (argc + 1, sizeof (char *)); + if (! menu_args) + goto fail; + +diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c +index 699447d11..7c8f97f6a 100644 +--- a/grub-core/commands/nativedisk.c ++++ b/grub-core/commands/nativedisk.c +@@ -195,7 +195,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), + else + path_prefix = prefix; + +- mods = grub_malloc (argc * sizeof (mods[0])); ++ mods = grub_calloc (argc, sizeof (mods[0])); + if (!mods) + return grub_errno; + +diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c +index 22b46b187..051e31320 100644 +--- a/grub-core/commands/parttool.c ++++ b/grub-core/commands/parttool.c +@@ -59,7 +59,13 @@ grub_parttool_register(const char *part_name, + for (nargs = 0; args[nargs].name != 0; nargs++); + cur->nargs = nargs; + cur->args = (struct grub_parttool_argdesc *) +- grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc)); ++ grub_calloc (nargs + 1, sizeof (struct grub_parttool_argdesc)); ++ if (!cur->args) ++ { ++ grub_free (cur); ++ curhandle--; ++ return -1; ++ } + grub_memcpy (cur->args, args, + (nargs + 1) * sizeof (struct grub_parttool_argdesc)); + +@@ -257,7 +263,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), + return err; + } + +- parsed = (int *) grub_zalloc (argc * sizeof (int)); ++ parsed = (int *) grub_calloc (argc, sizeof (int)); + + for (i = 1; i < argc; i++) + if (! parsed[i]) +@@ -290,7 +296,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), + } + ptool = cur; + pargs = (struct grub_parttool_args *) +- grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args)); ++ grub_calloc (ptool->nargs, sizeof (struct grub_parttool_args)); + for (j = i; j < argc; j++) + if (! parsed[j]) + { +diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c +index f00b184c8..4019164f3 100644 +--- a/grub-core/commands/regexp.c ++++ b/grub-core/commands/regexp.c +@@ -116,7 +116,7 @@ grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args) + if (ret) + goto fail; + +- matches = grub_zalloc (sizeof (*matches) * (regex.re_nsub + 1)); ++ matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches)); + if (! matches) + goto fail; + +diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c +index d7fd26b94..47fc8eb99 100644 +--- a/grub-core/commands/search_wrap.c ++++ b/grub-core/commands/search_wrap.c +@@ -122,7 +122,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) + for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) + nhints++; + +- hints = grub_malloc (sizeof (hints[0]) * nhints); ++ hints = grub_calloc (nhints, sizeof (hints[0])); + if (!hints) + return grub_errno; + j = 0; +diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c +index c3b578acf..68ca9e0be 100644 +--- a/grub-core/disk/diskfilter.c ++++ b/grub-core/disk/diskfilter.c +@@ -1134,7 +1134,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, + array->lvs->segments->node_count = nmemb; + array->lvs->segments->raid_member_size = disk_size; + array->lvs->segments->nodes +- = grub_zalloc (nmemb * sizeof (array->lvs->segments->nodes[0])); ++ = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0])); + array->lvs->segments->stripe_size = stripe_size; + for (i = 0; i < nmemb; i++) + { +@@ -1226,7 +1226,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, + grub_partition_t p; + for (p = disk->partition; p; p = p->parent) + s++; +- pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0])); ++ pv->partmaps = xcalloc (s, sizeof (pv->partmaps[0])); + s = 0; + for (p = disk->partition; p; p = p->parent) + pv->partmaps[s++] = xstrdup (p->partmap->name); +diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c +index f73257e66..03674cb47 100644 +--- a/grub-core/disk/ieee1275/ofdisk.c ++++ b/grub-core/disk/ieee1275/ofdisk.c +@@ -297,7 +297,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) + /* Power machines documentation specify 672 as maximum SAS disks in + one system. Using a slightly larger value to be safe. */ + table_size = 768; +- table = grub_malloc (table_size * sizeof (grub_uint64_t)); ++ table = grub_calloc (table_size, sizeof (grub_uint64_t)); + + if (!table) + { +diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c +index 2a22d2d6c..e6323701a 100644 +--- a/grub-core/disk/ldm.c ++++ b/grub-core/disk/ldm.c +@@ -323,8 +323,8 @@ make_vg (grub_disk_t disk, + lv->segments->type = GRUB_DISKFILTER_MIRROR; + lv->segments->node_count = 0; + lv->segments->node_alloc = 8; +- lv->segments->nodes = grub_zalloc (sizeof (*lv->segments->nodes) +- * lv->segments->node_alloc); ++ lv->segments->nodes = grub_calloc (lv->segments->node_alloc, ++ sizeof (*lv->segments->nodes)); + if (!lv->segments->nodes) + goto fail2; + ptr = vblk[i].dynamic; +@@ -543,8 +543,8 @@ make_vg (grub_disk_t disk, + { + comp->segment_alloc = 8; + comp->segment_count = 0; +- comp->segments = grub_malloc (sizeof (*comp->segments) +- * comp->segment_alloc); ++ comp->segments = grub_calloc (comp->segment_alloc, ++ sizeof (*comp->segments)); + if (!comp->segments) + goto fail2; + } +@@ -590,8 +590,8 @@ make_vg (grub_disk_t disk, + } + comp->segments->node_count = read_int (ptr + 1, *ptr); + comp->segments->node_alloc = comp->segments->node_count; +- comp->segments->nodes = grub_zalloc (sizeof (*comp->segments->nodes) +- * comp->segments->node_alloc); ++ comp->segments->nodes = grub_calloc (comp->segments->node_alloc, ++ sizeof (*comp->segments->nodes)); + if (!lv->segments->nodes) + goto fail2; + } +@@ -1017,7 +1017,7 @@ grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors, + *nsectors = lv->size; + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c +index 86c50c612..18b3a8bb1 100644 +--- a/grub-core/disk/luks.c ++++ b/grub-core/disk/luks.c +@@ -336,7 +336,7 @@ luks_recover_key (grub_disk_t source, + && grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes) + max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes); + +- split_key = grub_malloc (keysize * max_stripes); ++ split_key = grub_calloc (keysize, max_stripes); + if (!split_key) + return grub_errno; + +diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c +index 7b265c780..d1df640b3 100644 +--- a/grub-core/disk/lvm.c ++++ b/grub-core/disk/lvm.c +@@ -173,7 +173,7 @@ grub_lvm_detect (grub_disk_t disk, + first one. */ + + /* Allocate buffer space for the circular worst-case scenario. */ +- metadatabuf = grub_malloc (2 * mda_size); ++ metadatabuf = grub_calloc (2, mda_size); + if (! metadatabuf) + goto fail; + +@@ -426,7 +426,7 @@ grub_lvm_detect (grub_disk_t disk, + #endif + goto lvs_fail; + } +- lv->segments = grub_zalloc (sizeof (*seg) * lv->segment_count); ++ lv->segments = grub_calloc (lv->segment_count, sizeof (*seg)); + seg = lv->segments; + + for (i = 0; i < lv->segment_count; i++) +@@ -483,8 +483,8 @@ grub_lvm_detect (grub_disk_t disk, + if (seg->node_count != 1) + seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); + +- seg->nodes = grub_zalloc (sizeof (*stripe) +- * seg->node_count); ++ seg->nodes = grub_calloc (seg->node_count, ++ sizeof (*stripe)); + stripe = seg->nodes; + + p = grub_strstr (p, "stripes = ["); +diff --git a/grub-core/disk/xen/xendisk.c b/grub-core/disk/xen/xendisk.c +index 48476cbbf..d6612eebd 100644 +--- a/grub-core/disk/xen/xendisk.c ++++ b/grub-core/disk/xen/xendisk.c +@@ -426,7 +426,7 @@ grub_xendisk_init (void) + if (!ctr) + return; + +- virtdisks = grub_malloc (ctr * sizeof (virtdisks[0])); ++ virtdisks = grub_calloc (ctr, sizeof (virtdisks[0])); + if (!virtdisks) + return; + if (grub_xenstore_dir ("device/vbd", fill, &ctr)) +diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c +index 44085ef81..2b924623f 100644 +--- a/grub-core/efiemu/loadcore.c ++++ b/grub-core/efiemu/loadcore.c +@@ -201,7 +201,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e) + + grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize; + grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *) +- grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms); ++ grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym)); + + /* Relocators */ + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); +diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c +index 52a032f7b..9b8e0d0ad 100644 +--- a/grub-core/efiemu/mm.c ++++ b/grub-core/efiemu/mm.c +@@ -554,11 +554,11 @@ grub_efiemu_mmap_sort_and_uniq (void) + /* Initialize variables*/ + grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE); + scanline_events = (struct grub_efiemu_mmap_scan *) +- grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num); ++ grub_calloc (mmap_num, sizeof (struct grub_efiemu_mmap_scan) * 2); + + /* Number of chunks can't increase more than by factor of 2 */ + result = (grub_efi_memory_descriptor_t *) +- grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num); ++ grub_calloc (mmap_num, sizeof (grub_efi_memory_descriptor_t) * 2); + if (!result || !scanline_events) + { + grub_free (result); +@@ -660,7 +660,7 @@ grub_efiemu_mm_do_alloc (void) + + /* Preallocate mmap */ + efiemu_mmap = (grub_efi_memory_descriptor_t *) +- grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t)); ++ grub_calloc (mmap_reserved_size, sizeof (grub_efi_memory_descriptor_t)); + if (!efiemu_mmap) + { + grub_efiemu_unload (); +diff --git a/grub-core/font/font.c b/grub-core/font/font.c +index 85a292557..8e118b315 100644 +--- a/grub-core/font/font.c ++++ b/grub-core/font/font.c +@@ -293,8 +293,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct + font->num_chars = sect_length / FONT_CHAR_INDEX_ENTRY_SIZE; + + /* Allocate the character index array. */ +- font->char_index = grub_malloc (font->num_chars +- * sizeof (struct char_index_entry)); ++ font->char_index = grub_calloc (font->num_chars, sizeof (struct char_index_entry)); + if (!font->char_index) + return 1; + font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t)); +diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c +index 6b6a2bc91..220b3712f 100644 +--- a/grub-core/fs/affs.c ++++ b/grub-core/fs/affs.c +@@ -301,7 +301,7 @@ grub_affs_read_symlink (grub_fshelp_node_t node) + return 0; + } + latin1[symlink_size] = 0; +- utf8 = grub_malloc (symlink_size * GRUB_MAX_UTF8_PER_LATIN1 + 1); ++ utf8 = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, symlink_size); + if (!utf8) + { + grub_free (latin1); +@@ -422,7 +422,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, + return 1; + } + +- hashtable = grub_zalloc (data->htsize * sizeof (*hashtable)); ++ hashtable = grub_calloc (data->htsize, sizeof (*hashtable)); + if (!hashtable) + return 1; + +@@ -628,7 +628,7 @@ grub_affs_label (grub_device_t device, char **label) + len = file.namelen; + if (len > sizeof (file.name)) + len = sizeof (file.name); +- *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); ++ *label = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, len); + if (*label) + *grub_latin1_to_utf8 ((grub_uint8_t *) *label, file.name, len) = '\0'; + } +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 48bd3d04a..11272efc1 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -413,7 +413,7 @@ lower_bound (struct grub_btrfs_data *data, + { + desc->allocated = 16; + desc->depth = 0; +- desc->data = grub_malloc (sizeof (desc->data[0]) * desc->allocated); ++ desc->data = grub_calloc (desc->allocated, sizeof (desc->data[0])); + if (!desc->data) + return grub_errno; + } +@@ -752,7 +752,7 @@ raid56_read_retry (struct grub_btrfs_data *data, + grub_err_t ret = GRUB_ERR_OUT_OF_MEMORY; + grub_uint64_t i, failed_devices; + +- buffers = grub_zalloc (sizeof(*buffers) * nstripes); ++ buffers = grub_calloc (nstripes, sizeof (*buffers)); + if (!buffers) + goto cleanup; + +@@ -2160,7 +2160,7 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), + *nsectors = 64 * 2 - 1; + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c +index ac0a40990..3fe842b4d 100644 +--- a/grub-core/fs/hfs.c ++++ b/grub-core/fs/hfs.c +@@ -1360,7 +1360,7 @@ grub_hfs_label (grub_device_t device, char **label) + grub_size_t len = data->sblock.volname[0]; + if (len > sizeof (data->sblock.volname) - 1) + len = sizeof (data->sblock.volname) - 1; +- *label = grub_malloc (len * MAX_UTF8_PER_MAC_ROMAN + 1); ++ *label = grub_calloc (MAX_UTF8_PER_MAC_ROMAN + 1, len); + if (*label) + macroman_to_utf8 (*label, data->sblock.volname + 1, + len + 1, 0); +diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c +index 54786bb1c..dae43becc 100644 +--- a/grub-core/fs/hfsplus.c ++++ b/grub-core/fs/hfsplus.c +@@ -720,7 +720,7 @@ list_nodes (void *record, void *hook_arg) + if (! filename) + return 0; + +- keyname = grub_malloc (grub_be_to_cpu16 (catkey->namelen) * sizeof (*keyname)); ++ keyname = grub_calloc (grub_be_to_cpu16 (catkey->namelen), sizeof (*keyname)); + if (!keyname) + { + grub_free (filename); +@@ -1007,7 +1007,7 @@ grub_hfsplus_label (grub_device_t device, char **label) + grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); + + label_len = grub_be_to_cpu16 (catkey->namelen); +- label_name = grub_malloc (label_len * sizeof (*label_name)); ++ label_name = grub_calloc (label_len, sizeof (*label_name)); + if (!label_name) + { + grub_free (node); +@@ -1029,7 +1029,7 @@ grub_hfsplus_label (grub_device_t device, char **label) + } + } + +- *label = grub_malloc (label_len * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ *label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1); + if (! *label) + { + grub_free (label_name); +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 49c0c632b..4f1b52a55 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -331,7 +331,7 @@ grub_iso9660_convert_string (grub_uint8_t *us, int len) + int i; + grub_uint16_t t[MAX_NAMELEN / 2 + 1]; + +- p = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ p = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); + if (! p) + return NULL; + +diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c +index fc4e1f678..2f34f76da 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -556,8 +556,8 @@ get_utf8 (grub_uint8_t *in, grub_size_t len) + grub_uint16_t *tmp; + grub_size_t i; + +- buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); +- tmp = grub_malloc (len * sizeof (tmp[0])); ++ buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); ++ tmp = grub_calloc (len, sizeof (tmp[0])); + if (!buf || !tmp) + { + grub_free (buf); +diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c +index 50c1fe72f..90f7fb379 100644 +--- a/grub-core/fs/sfs.c ++++ b/grub-core/fs/sfs.c +@@ -266,7 +266,7 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + node->next_extent = node->block; + node->cache_size = 0; + +- node->cache = grub_malloc (sizeof (node->cache[0]) * cache_size); ++ node->cache = grub_calloc (cache_size, sizeof (node->cache[0])); + if (!node->cache) + { + grub_errno = 0; +diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c +index 7d63e0c99..c551ed6b5 100644 +--- a/grub-core/fs/tar.c ++++ b/grub-core/fs/tar.c +@@ -120,7 +120,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + if (data->linkname_alloc < linksize + 1) + { + char *n; +- n = grub_malloc (2 * (linksize + 1)); ++ n = grub_calloc (2, linksize + 1); + if (!n) + return grub_errno; + grub_free (data->linkname); +diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c +index dc8b6e2d1..a83761674 100644 +--- a/grub-core/fs/udf.c ++++ b/grub-core/fs/udf.c +@@ -873,7 +873,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) + { + unsigned i; + utf16len = sz - 1; +- utf16 = grub_malloc (utf16len * sizeof (utf16[0])); ++ utf16 = grub_calloc (utf16len, sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) +@@ -883,7 +883,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) + { + unsigned i; + utf16len = (sz - 1) / 2; +- utf16 = grub_malloc (utf16len * sizeof (utf16[0])); ++ utf16 = grub_calloc (utf16len, sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index 2f72e42bf..381dde556 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -3325,7 +3325,7 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, + } + subvol->nkeys = 0; + zap_iterate (&keychain_dn, 8, count_zap_keys, &ctx, data); +- subvol->keyring = grub_zalloc (subvol->nkeys * sizeof (subvol->keyring[0])); ++ subvol->keyring = grub_calloc (subvol->nkeys, sizeof (subvol->keyring[0])); + if (!subvol->keyring) + { + grub_free (fsname); +@@ -4336,7 +4336,7 @@ grub_zfs_embed (grub_device_t device __attribute__ ((unused)), + *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS); + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/gfxmenu/gui_string_util.c b/grub-core/gfxmenu/gui_string_util.c +index a9a415e31..ba1e1eab3 100644 +--- a/grub-core/gfxmenu/gui_string_util.c ++++ b/grub-core/gfxmenu/gui_string_util.c +@@ -55,7 +55,7 @@ canonicalize_path (const char *path) + if (*p == '/') + components++; + +- char **path_array = grub_malloc (components * sizeof (*path_array)); ++ char **path_array = grub_calloc (components, sizeof (*path_array)); + if (! path_array) + return 0; + +diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c +index b60602889..470597ded 100644 +--- a/grub-core/gfxmenu/widget-box.c ++++ b/grub-core/gfxmenu/widget-box.c +@@ -303,10 +303,10 @@ grub_gfxmenu_create_box (const char *pixmaps_prefix, + box->content_height = 0; + box->raw_pixmaps = + (struct grub_video_bitmap **) +- grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); ++ grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); + box->scaled_pixmaps = + (struct grub_video_bitmap **) +- grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); ++ grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); + + /* Initialize all pixmap pointers to NULL so that proper destruction can + be performed if an error is encountered partway through construction. */ +diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c +index 6208a9763..43d98a7bd 100644 +--- a/grub-core/io/gzio.c ++++ b/grub-core/io/gzio.c +@@ -554,7 +554,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ + z = 1 << j; /* table entries for j-bit table */ + + /* allocate and link in new table */ +- q = (struct huft *) grub_zalloc ((z + 1) * sizeof (struct huft)); ++ q = (struct huft *) grub_calloc (z + 1, sizeof (struct huft)); + if (! q) + { + if (h) +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 6e1ceb905..dc31caa21 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -202,7 +202,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, + + len = grub_strlen (var); + len16 = len * GRUB_MAX_UTF16_PER_UTF8; +- var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); ++ var16 = grub_calloc (len16 + 1, sizeof (var16[0])); + if (!var16) + return grub_errno; + len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); +@@ -237,7 +237,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, + + len = grub_strlen (var); + len16 = len * GRUB_MAX_UTF16_PER_UTF8; +- var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); ++ var16 = grub_calloc (len16 + 1, sizeof (var16[0])); + if (!var16) + return NULL; + len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); +@@ -383,7 +383,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + while (len > 0 && fp->path_name[len - 1] == 0) + len--; + +- dup_name = grub_malloc (len * sizeof (*dup_name)); ++ dup_name = grub_calloc (len, sizeof (*dup_name)); + if (!dup_name) + { + grub_free (name); +diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c +index e9ec680cd..d975265b2 100644 +--- a/grub-core/kern/emu/hostdisk.c ++++ b/grub-core/kern/emu/hostdisk.c +@@ -615,7 +615,7 @@ static char * + grub_util_path_concat_real (size_t n, int ext, va_list ap) + { + size_t totlen = 0; +- char **l = xmalloc ((n + ext) * sizeof (l[0])); ++ char **l = xcalloc (n + ext, sizeof (l[0])); + char *r, *p, *pi; + size_t i; + int first = 1; +diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c +index 2b85f4950..f90be6566 100644 +--- a/grub-core/kern/fs.c ++++ b/grub-core/kern/fs.c +@@ -151,7 +151,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name) + while (p); + + /* Allocate a block list. */ +- blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1)); ++ blocks = grub_calloc (num + 1, sizeof (struct grub_fs_block)); + if (! blocks) + return 0; + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 3b633d51f..a7abd367a 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -690,7 +690,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, + args->ptr = args->prealloc; + else + { +- args->ptr = grub_malloc (args->count * sizeof (args->ptr[0])); ++ args->ptr = grub_calloc (args->count, sizeof (args->ptr[0])); + if (!args->ptr) + { + grub_errno = GRUB_ERR_NONE; +diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c +index 78175aac2..619db3122 100644 +--- a/grub-core/kern/parser.c ++++ b/grub-core/kern/parser.c +@@ -213,7 +213,7 @@ grub_parser_split_cmdline (const char *cmdline, + return grub_errno; + grub_memcpy (args, buffer, bp - buffer); + +- *argv = grub_malloc (sizeof (char *) * (*argc + 1)); ++ *argv = grub_calloc (*argc + 1, sizeof (char *)); + if (!*argv) + { + grub_free (args); +diff --git a/grub-core/kern/uboot/uboot.c b/grub-core/kern/uboot/uboot.c +index be4816fe6..aac8f9ae1 100644 +--- a/grub-core/kern/uboot/uboot.c ++++ b/grub-core/kern/uboot/uboot.c +@@ -133,7 +133,7 @@ grub_uboot_dev_enum (void) + return num_devices; + + max_devices = 2; +- enum_devices = grub_malloc (sizeof(struct device_info) * max_devices); ++ enum_devices = grub_calloc (max_devices, sizeof(struct device_info)); + if (!enum_devices) + return 0; + +diff --git a/grub-core/lib/libgcrypt/cipher/ac.c b/grub-core/lib/libgcrypt/cipher/ac.c +index f5e946a2d..63f6fcd11 100644 +--- a/grub-core/lib/libgcrypt/cipher/ac.c ++++ b/grub-core/lib/libgcrypt/cipher/ac.c +@@ -185,7 +185,7 @@ ac_data_mpi_copy (gcry_ac_mpi_t *data_mpis, unsigned int data_mpis_n, + gcry_mpi_t mpi; + char *label; + +- data_mpis_new = gcry_malloc (sizeof (*data_mpis_new) * data_mpis_n); ++ data_mpis_new = gcry_calloc (data_mpis_n, sizeof (*data_mpis_new)); + if (! data_mpis_new) + { + err = gcry_error_from_errno (errno); +@@ -572,7 +572,7 @@ _gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp, + } + + /* Add MPI list. */ +- arg_list = gcry_malloc (sizeof (*arg_list) * (data_n + 1)); ++ arg_list = gcry_calloc (data_n + 1, sizeof (*arg_list)); + if (! arg_list) + { + err = gcry_error_from_errno (errno); +@@ -1283,7 +1283,7 @@ ac_data_construct (const char *identifier, int include_flags, + /* We build a list of arguments to pass to + gcry_sexp_build_array(). */ + data_length = _gcry_ac_data_length (data); +- arg_list = gcry_malloc (sizeof (*arg_list) * (data_length * 2)); ++ arg_list = gcry_calloc (data_length, sizeof (*arg_list) * 2); + if (! arg_list) + { + err = gcry_error_from_errno (errno); +@@ -1593,7 +1593,7 @@ _gcry_ac_key_pair_generate (gcry_ac_handle_t handle, unsigned int nbits, + arg_list_n += 2; + + /* Allocate list. */ +- arg_list = gcry_malloc (sizeof (*arg_list) * arg_list_n); ++ arg_list = gcry_calloc (arg_list_n, sizeof (*arg_list)); + if (! arg_list) + { + err = gcry_error_from_errno (errno); +diff --git a/grub-core/lib/libgcrypt/cipher/primegen.c b/grub-core/lib/libgcrypt/cipher/primegen.c +index 2788e349f..b12e79b19 100644 +--- a/grub-core/lib/libgcrypt/cipher/primegen.c ++++ b/grub-core/lib/libgcrypt/cipher/primegen.c +@@ -383,7 +383,7 @@ prime_generate_internal (int need_q_factor, + } + + /* Allocate an array to track pool usage. */ +- pool_in_use = gcry_malloc (n * sizeof *pool_in_use); ++ pool_in_use = gcry_calloc (n, sizeof *pool_in_use); + if (!pool_in_use) + { + err = gpg_err_code_from_errno (errno); +@@ -765,7 +765,7 @@ gen_prime (unsigned int nbits, int secret, int randomlevel, + if (nbits < 16) + log_fatal ("can't generate a prime with less than %d bits\n", 16); + +- mods = gcry_xmalloc( no_of_small_prime_numbers * sizeof *mods ); ++ mods = gcry_xcalloc( no_of_small_prime_numbers, sizeof *mods); + /* Make nbits fit into gcry_mpi_t implementation. */ + val_2 = mpi_alloc_set_ui( 2 ); + val_3 = mpi_alloc_set_ui( 3); +diff --git a/grub-core/lib/libgcrypt/cipher/pubkey.c b/grub-core/lib/libgcrypt/cipher/pubkey.c +index 910982141..ca087ad75 100644 +--- a/grub-core/lib/libgcrypt/cipher/pubkey.c ++++ b/grub-core/lib/libgcrypt/cipher/pubkey.c +@@ -2941,7 +2941,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) + * array to a format string, so we have to do it this way :-(. */ + /* FIXME: There is now such a format specifier, so we can + change the code to be more clear. */ +- arg_list = malloc (nelem * sizeof *arg_list); ++ arg_list = calloc (nelem, sizeof *arg_list); + if (!arg_list) + { + rc = gpg_err_code_from_syserror (); +@@ -3233,7 +3233,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) + } + strcpy (p, "))"); + +- arg_list = malloc (nelem * sizeof *arg_list); ++ arg_list = calloc (nelem, sizeof *arg_list); + if (!arg_list) + { + rc = gpg_err_code_from_syserror (); +diff --git a/grub-core/lib/priority_queue.c b/grub-core/lib/priority_queue.c +index 659be0b7f..7d5e7c05a 100644 +--- a/grub-core/lib/priority_queue.c ++++ b/grub-core/lib/priority_queue.c +@@ -92,7 +92,7 @@ grub_priority_queue_new (grub_size_t elsize, + { + struct grub_priority_queue *ret; + void *els; +- els = grub_malloc (elsize * 8); ++ els = grub_calloc (8, elsize); + if (!els) + return 0; + ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret)); +diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c +index ee9fa7b4f..467305b46 100644 +--- a/grub-core/lib/reed_solomon.c ++++ b/grub-core/lib/reed_solomon.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#define xcalloc calloc + #define xmalloc malloc + #define grub_memset memset + #define grub_memcpy memcpy +@@ -158,11 +159,9 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) + gf_single_t *rs_polynomial; + int i, j; + gf_single_t *m; +- m = xmalloc ((s + rs) * sizeof (gf_single_t)); ++ m = xcalloc (s + rs, sizeof (gf_single_t)); + grub_memcpy (m, data, s * sizeof (gf_single_t)); +- grub_memset (m + s, 0, rs * sizeof (gf_single_t)); +- rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t)); +- grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t)); ++ rs_polynomial = xcalloc (rs + 1, sizeof (gf_single_t)); + rs_polynomial[rs] = 1; + /* Multiply with X - a^r */ + for (j = 0; j < rs; j++) +diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c +index ea3ebc719..5847aac36 100644 +--- a/grub-core/lib/relocator.c ++++ b/grub-core/lib/relocator.c +@@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator *rel, + } + #endif + +- eventt = grub_malloc (maxevents * sizeof (events[0])); ++ eventt = grub_calloc (maxevents, sizeof (events[0])); + counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0])); +- events = grub_malloc (maxevents * sizeof (events[0])); ++ events = grub_calloc (maxevents, sizeof (events[0])); + if (!events || !eventt || !counter) + { + grub_dprintf ("relocator", "events or counter allocation failed %d\n", +@@ -963,7 +963,7 @@ malloc_in_range (struct grub_relocator *rel, + #endif + unsigned cural = 0; + int oom = 0; +- res->subchunks = grub_malloc (sizeof (res->subchunks[0]) * nallocs); ++ res->subchunks = grub_calloc (nallocs, sizeof (res->subchunks[0])); + if (!res->subchunks) + oom = 1; + res->nsubchunks = nallocs; +@@ -1562,8 +1562,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr, + count[(chunk->src & 0xff) + 1]++; + } + } +- from = grub_malloc (nchunks * sizeof (sorted[0])); +- to = grub_malloc (nchunks * sizeof (sorted[0])); ++ from = grub_calloc (nchunks, sizeof (sorted[0])); ++ to = grub_calloc (nchunks, sizeof (sorted[0])); + if (!from || !to) + { + grub_free (from); +diff --git a/grub-core/lib/zstd/fse_decompress.c b/grub-core/lib/zstd/fse_decompress.c +index 72bbead5b..2227b84bc 100644 +--- a/grub-core/lib/zstd/fse_decompress.c ++++ b/grub-core/lib/zstd/fse_decompress.c +@@ -82,7 +82,7 @@ + FSE_DTable* FSE_createDTable (unsigned tableLog) + { + if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX; +- return (FSE_DTable*)malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) ); ++ return (FSE_DTable*)calloc( FSE_DTABLE_SIZE_U32(tableLog), sizeof (U32) ); + } + + void FSE_freeDTable (FSE_DTable* dt) +diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c +index 51684914c..d70c17486 100644 +--- a/grub-core/loader/arm/linux.c ++++ b/grub-core/loader/arm/linux.c +@@ -78,7 +78,7 @@ linux_prepare_atag (void *target_atag) + + /* some place for cmdline, initrd and terminator. */ + tmp_size = get_atag_size (atag_orig) + 20 + (arg_size) / 4; +- tmp_atag = grub_malloc (tmp_size * sizeof (grub_uint32_t)); ++ tmp_atag = grub_calloc (tmp_size, sizeof (grub_uint32_t)); + if (!tmp_atag) + return grub_errno; + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index cd92ea3f2..daf8c6b54 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -116,7 +116,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, + fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; + fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; + +- path_name = grub_malloc (len * GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); ++ path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); + if (!path_name) + return; + +diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c +index af6741d15..a8d8bf7da 100644 +--- a/grub-core/loader/i386/bsdXX.c ++++ b/grub-core/loader/i386/bsdXX.c +@@ -48,7 +48,7 @@ read_headers (grub_file_t file, const char *filename, Elf_Ehdr *e, char **shdr) + if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS)) + return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic")); + +- *shdr = grub_malloc ((grub_uint32_t) e->e_shnum * e->e_shentsize); ++ *shdr = grub_calloc (e->e_shnum, e->e_shentsize); + if (! *shdr) + return grub_errno; + +diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c +index e64ed08f5..b7d176b5d 100644 +--- a/grub-core/loader/i386/xnu.c ++++ b/grub-core/loader/i386/xnu.c +@@ -295,7 +295,7 @@ grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *d + return grub_errno; + + len = grub_strlen (name); +- utf16 = grub_malloc (sizeof (grub_uint16_t) * len); ++ utf16 = grub_calloc (len, sizeof (grub_uint16_t)); + if (!utf16) + { + grub_free (utf8); +@@ -331,7 +331,7 @@ grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor * + grub_uint16_t *utf16; + grub_err_t err; + +- utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen); ++ utf16 = grub_calloc (namelen, sizeof (grub_uint16_t)); + if (!utf16) + return grub_errno; + grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen); +diff --git a/grub-core/loader/macho.c b/grub-core/loader/macho.c +index 085f9c689..05710c48e 100644 +--- a/grub-core/loader/macho.c ++++ b/grub-core/loader/macho.c +@@ -97,7 +97,7 @@ grub_macho_file (grub_file_t file, const char *filename, int is_64bit) + if (grub_file_seek (macho->file, sizeof (struct grub_macho_fat_header)) + == (grub_off_t) -1) + goto fail; +- archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); ++ archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); + if (!archs) + goto fail; + if (grub_file_read (macho->file, archs, +diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c +index 70cd1db51..cc6853692 100644 +--- a/grub-core/loader/multiboot_elfxx.c ++++ b/grub-core/loader/multiboot_elfxx.c +@@ -217,7 +217,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) + { + grub_uint8_t *shdr, *shdrptr; + +- shdr = grub_malloc ((grub_uint32_t) ehdr->e_shnum * ehdr->e_shentsize); ++ shdr = grub_calloc (ehdr->e_shnum, ehdr->e_shentsize); + if (!shdr) + return grub_errno; + +diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c +index 7f74d1d6f..77d7060e1 100644 +--- a/grub-core/loader/xnu.c ++++ b/grub-core/loader/xnu.c +@@ -800,7 +800,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), + if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC) + { + narchs = grub_be_to_cpu32 (head.nfat_arch); +- archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); ++ archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); + if (! archs) + { + grub_file_close (file); +diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c +index 6a31cbae3..57b4e9a72 100644 +--- a/grub-core/mmap/mmap.c ++++ b/grub-core/mmap/mmap.c +@@ -143,9 +143,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) + + /* Initialize variables. */ + ctx.scanline_events = (struct grub_mmap_scan *) +- grub_malloc (sizeof (struct grub_mmap_scan) * 2 * mmap_num); ++ grub_calloc (mmap_num, sizeof (struct grub_mmap_scan) * 2); + +- present = grub_zalloc (sizeof (present[0]) * current_priority); ++ present = grub_calloc (current_priority, sizeof (present[0])); + + if (! ctx.scanline_events || !present) + { +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 04cfbb045..653957200 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -766,7 +766,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + if (ncards == 0) + return grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found")); + +- ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); ++ ifaces = grub_calloc (ncards, sizeof (ifaces[0])); + if (!ifaces) + return grub_errno; + +diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c +index 5d9afe093..e332d5eb4 100644 +--- a/grub-core/net/dns.c ++++ b/grub-core/net/dns.c +@@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), + ptr++; + ptr += 4; + } +- *data->addresses = grub_malloc (sizeof ((*data->addresses)[0]) +- * grub_be_to_cpu16 (head->ancount)); ++ *data->addresses = grub_calloc (grub_be_to_cpu16 (head->ancount), ++ sizeof ((*data->addresses)[0])); + if (!*data->addresses) + { + grub_errno = GRUB_ERR_NONE; +@@ -406,8 +406,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), + dns_cache[h].addresses = 0; + dns_cache[h].name = grub_strdup (data->oname); + dns_cache[h].naddresses = *data->naddresses; +- dns_cache[h].addresses = grub_malloc (*data->naddresses +- * sizeof (dns_cache[h].addresses[0])); ++ dns_cache[h].addresses = grub_calloc (*data->naddresses, ++ sizeof (dns_cache[h].addresses[0])); + dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all; + if (!dns_cache[h].addresses || !dns_cache[h].name) + { +@@ -479,7 +479,7 @@ grub_net_dns_lookup (const char *name, + } + } + +- sockets = grub_malloc (sizeof (sockets[0]) * n_servers); ++ sockets = grub_calloc (n_servers, sizeof (sockets[0])); + if (!sockets) + return grub_errno; + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index d5d726a31..38f19dfc9 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -333,8 +333,8 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)), + ncards++; + } + +- ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); +- slaacs = grub_zalloc (ncards * sizeof (slaacs[0])); ++ ifaces = grub_calloc (ncards, sizeof (ifaces[0])); ++ slaacs = grub_calloc (ncards, sizeof (slaacs[0])); + if (!ifaces || !slaacs) + { + grub_free (ifaces); +diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c +index b0ab47d73..d57fb72fa 100644 +--- a/grub-core/normal/charset.c ++++ b/grub-core/normal/charset.c +@@ -203,7 +203,7 @@ grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, + { + grub_size_t msg_len = grub_strlen (msg); + +- *unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); ++ *unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + + if (!*unicode_msg) + return -1; +@@ -488,7 +488,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, + } + else + { +- n = grub_malloc (sizeof (n[0]) * (out->ncomb + 1)); ++ n = grub_calloc (out->ncomb + 1, sizeof (n[0])); + if (!n) + { + grub_errno = GRUB_ERR_NONE; +@@ -842,7 +842,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, + } \ + } + +- visual = grub_malloc (sizeof (visual[0]) * logical_len); ++ visual = grub_calloc (logical_len, sizeof (visual[0])); + if (!visual) + return -1; + +@@ -1165,8 +1165,8 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical, + { + const grub_uint32_t *line_start = logical, *ptr; + struct grub_unicode_glyph *visual_ptr; +- *visual_out = visual_ptr = grub_malloc (3 * sizeof (visual_ptr[0]) +- * (logical_len + 2)); ++ *visual_out = visual_ptr = grub_calloc (logical_len + 2, ++ 3 * sizeof (visual_ptr[0])); + if (!visual_ptr) + return -1; + for (ptr = logical; ptr <= logical + logical_len; ptr++) +diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c +index c037d5050..c57242e2e 100644 +--- a/grub-core/normal/cmdline.c ++++ b/grub-core/normal/cmdline.c +@@ -41,7 +41,7 @@ grub_err_t + grub_set_history (int newsize) + { + grub_uint32_t **old_hist_lines = hist_lines; +- hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); ++ hist_lines = grub_calloc (newsize, sizeof (grub_uint32_t *)); + + /* Copy the old lines into the new buffer. */ + if (old_hist_lines) +@@ -114,7 +114,7 @@ static void + grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) + { + grub_free (hist_lines[pos]); +- hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); ++ hist_lines[pos] = grub_calloc (len + 1, sizeof (grub_uint32_t)); + if (!hist_lines[pos]) + { + grub_print_error (); +@@ -349,7 +349,7 @@ grub_cmdline_get (const char *prompt_translated) + char *ret; + unsigned nterms; + +- buf = grub_malloc (max_len * sizeof (grub_uint32_t)); ++ buf = grub_calloc (max_len, sizeof (grub_uint32_t)); + if (!buf) + return 0; + +@@ -377,7 +377,7 @@ grub_cmdline_get (const char *prompt_translated) + FOR_ACTIVE_TERM_OUTPUTS(cur) + nterms++; + +- cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); ++ cl_terms = grub_calloc (nterms, sizeof (cl_terms[0])); + if (!cl_terms) + { + grub_free (buf); +@@ -385,7 +385,7 @@ grub_cmdline_get (const char *prompt_translated) + } + cl_term_cur = cl_terms; + +- unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); ++ unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + if (!unicode_msg) + { + grub_free (buf); +@@ -495,7 +495,7 @@ grub_cmdline_get (const char *prompt_translated) + grub_uint32_t *insert; + + insertlen = grub_strlen (insertu8); +- insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); ++ insert = grub_calloc (insertlen + 1, sizeof (grub_uint32_t)); + if (!insert) + { + grub_free (insertu8); +@@ -602,7 +602,7 @@ grub_cmdline_get (const char *prompt_translated) + + grub_free (kill_buf); + +- kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t)); ++ kill_buf = grub_calloc (n + 1, sizeof (grub_uint32_t)); + if (grub_errno) + { + grub_print_error (); +diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c +index cdf3590a3..1993995be 100644 +--- a/grub-core/normal/menu_entry.c ++++ b/grub-core/normal/menu_entry.c +@@ -95,8 +95,8 @@ init_line (struct screen *screen, struct line *linep) + { + linep->len = 0; + linep->max_len = 80; +- linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0])); +- linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0])); ++ linep->buf = grub_calloc (linep->max_len + 1, sizeof (linep->buf[0])); ++ linep->pos = grub_calloc (screen->nterms, sizeof (linep->pos[0])); + if (! linep->buf || !linep->pos) + { + grub_free (linep->buf); +@@ -287,7 +287,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, + pos = linep->pos + (term_screen - screen->terms); + + if (!*pos) +- *pos = grub_zalloc ((linep->len + 1) * sizeof (**pos)); ++ *pos = grub_calloc (linep->len + 1, sizeof (**pos)); + + if (i == region_start || linep == screen->lines + screen->line + || (i > region_start && mode == ALL_LINES)) +@@ -471,7 +471,7 @@ insert_string (struct screen *screen, const char *s, int update) + + /* Insert the string. */ + current_linep = screen->lines + screen->line; +- unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t)); ++ unicode_msg = grub_calloc (p - s, sizeof (grub_uint32_t)); + + if (!unicode_msg) + return 0; +@@ -1023,7 +1023,7 @@ complete (struct screen *screen, int continuous, int update) + if (completion_buffer.buf) + { + buflen = grub_strlen (completion_buffer.buf); +- ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1)); ++ ucs4 = grub_calloc (buflen + 1, sizeof (grub_uint32_t)); + + if (!ucs4) + { +@@ -1268,7 +1268,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) + for (i = 0; i < (unsigned) screen->num_lines; i++) + { + grub_free (screen->lines[i].pos); +- screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0])); ++ screen->lines[i].pos = grub_calloc (screen->nterms, sizeof (screen->lines[i].pos[0])); + if (! screen->lines[i].pos) + { + grub_print_error (); +@@ -1278,7 +1278,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) + } + } + +- screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0])); ++ screen->terms = grub_calloc (screen->nterms, sizeof (screen->terms[0])); + if (!screen->terms) + { + grub_print_error (); +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index e22bb91f6..18240e76c 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -78,7 +78,7 @@ grub_print_message_indented_real (const char *msg, int margin_left, + grub_size_t msg_len = grub_strlen (msg) + 2; + int ret = 0; + +- unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); ++ unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + + if (!unicode_msg) + return 0; +@@ -211,7 +211,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, + + title = entry ? entry->title : ""; + title_len = grub_strlen (title); +- unicode_title = grub_malloc (title_len * sizeof (*unicode_title)); ++ unicode_title = grub_calloc (title_len, sizeof (*unicode_title)); + if (! unicode_title) + /* XXX How to show this error? */ + return; +diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c +index a1e5c5a0d..cc8c173b6 100644 +--- a/grub-core/normal/term.c ++++ b/grub-core/normal/term.c +@@ -264,7 +264,7 @@ grub_term_save_pos (void) + FOR_ACTIVE_TERM_OUTPUTS(cur) + cnt++; + +- ret = grub_malloc (cnt * sizeof (ret[0])); ++ ret = grub_calloc (cnt, sizeof (ret[0])); + if (!ret) + return NULL; + +@@ -1013,7 +1013,7 @@ grub_xnputs (const char *str, grub_size_t msg_len) + + grub_error_push (); + +- unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t)); ++ unicode_str = grub_calloc (msg_len, sizeof (grub_uint32_t)); + + grub_error_pop (); + +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 90d92d3ad..5b41ad022 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -168,7 +168,7 @@ grub_util_raid_getmembers (const char *name, int bootable) + if (ret != 0) + grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno)); + +- devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); ++ devicelist = xcalloc (info.nr_disks + 1, sizeof (char *)); + + for (i = 0, j = 0; j < info.nr_disks; i++) + { +@@ -241,7 +241,7 @@ grub_find_root_devices_from_btrfs (const char *dir) + return NULL; + } + +- ret = xmalloc ((fsi.num_devices + 1) * sizeof (ret[0])); ++ ret = xcalloc (fsi.num_devices + 1, sizeof (ret[0])); + + for (i = 1; i <= fsi.max_id && j < fsi.num_devices; i++) + { +@@ -396,7 +396,7 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) + if (relroot) + *relroot = NULL; + +- entries = xmalloc (entry_max * sizeof (*entries)); ++ entries = xcalloc (entry_max, sizeof (*entries)); + + again: + fp = grub_util_fopen ("/proc/self/mountinfo", "r"); +diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c +index 65effa9f3..7d6325138 100644 +--- a/grub-core/osdep/unix/config.c ++++ b/grub-core/osdep/unix/config.c +@@ -89,7 +89,7 @@ grub_util_load_config (struct grub_util_config *cfg) + argv[0] = "sh"; + argv[1] = "-c"; + +- script = xmalloc (4 * strlen (cfgfile) + 300); ++ script = xcalloc (4, strlen (cfgfile) + 300); + + ptr = script; + memcpy (ptr, ". '", 3); +diff --git a/grub-core/osdep/windows/getroot.c b/grub-core/osdep/windows/getroot.c +index 661d95461..eada663b2 100644 +--- a/grub-core/osdep/windows/getroot.c ++++ b/grub-core/osdep/windows/getroot.c +@@ -59,7 +59,7 @@ grub_get_mount_point (const TCHAR *path) + + for (ptr = path; *ptr; ptr++); + allocsize = (ptr - path + 10) * 2; +- out = xmalloc (allocsize * sizeof (out[0])); ++ out = xcalloc (allocsize, sizeof (out[0])); + + /* When pointing to EFI system partition GetVolumePathName fails + for ESP root and returns abberant information for everything +diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c +index 355100789..0be327394 100644 +--- a/grub-core/osdep/windows/hostdisk.c ++++ b/grub-core/osdep/windows/hostdisk.c +@@ -111,7 +111,7 @@ grub_util_get_windows_path_real (const char *path) + + while (1) + { +- fpa = xmalloc (alloc * sizeof (fpa[0])); ++ fpa = xcalloc (alloc, sizeof (fpa[0])); + + len = GetFullPathName (tpath, alloc, fpa, NULL); + if (len >= alloc) +@@ -399,7 +399,7 @@ grub_util_fd_opendir (const char *name) + for (l = 0; name_windows[l]; l++); + for (l--; l >= 0 && (name_windows[l] == '\\' || name_windows[l] == '/'); l--); + l++; +- pattern = xmalloc ((l + 3) * sizeof (pattern[0])); ++ pattern = xcalloc (l + 3, sizeof (pattern[0])); + memcpy (pattern, name_windows, l * sizeof (pattern[0])); + pattern[l] = '\\'; + pattern[l + 1] = '*'; +diff --git a/grub-core/osdep/windows/init.c b/grub-core/osdep/windows/init.c +index e8ffd62c6..6297de632 100644 +--- a/grub-core/osdep/windows/init.c ++++ b/grub-core/osdep/windows/init.c +@@ -161,7 +161,7 @@ grub_util_host_init (int *argc __attribute__ ((unused)), + LPWSTR *targv; + + targv = CommandLineToArgvW (tcmdline, argc); +- *argv = xmalloc ((*argc + 1) * sizeof (argv[0])); ++ *argv = xcalloc (*argc + 1, sizeof (argv[0])); + + for (i = 0; i < *argc; i++) + (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]); +diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c +index 7eb53fe01..1ef86bf58 100644 +--- a/grub-core/osdep/windows/platform.c ++++ b/grub-core/osdep/windows/platform.c +@@ -225,8 +225,8 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, + grub_util_error ("%s", _("no EFI routines are available when running in BIOS mode")); + + distrib8_len = grub_strlen (efi_distributor); +- distributor16 = xmalloc ((distrib8_len + 1) * GRUB_MAX_UTF16_PER_UTF8 +- * sizeof (grub_uint16_t)); ++ distributor16 = xcalloc (distrib8_len + 1, ++ GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_uint16_t)); + distrib16_len = grub_utf8_to_utf16 (distributor16, distrib8_len * GRUB_MAX_UTF16_PER_UTF8, + (const grub_uint8_t *) efi_distributor, + distrib8_len, 0); +diff --git a/grub-core/osdep/windows/relpath.c b/grub-core/osdep/windows/relpath.c +index cb0861744..478e8ef14 100644 +--- a/grub-core/osdep/windows/relpath.c ++++ b/grub-core/osdep/windows/relpath.c +@@ -72,7 +72,7 @@ grub_make_system_path_relative_to_its_root (const char *path) + if (dirwindows[0] && dirwindows[1] == ':') + offset = 2; + } +- ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2)); ++ ret = xcalloc (flen - offset + 2, sizeof (ret[0])); + if (dirwindows[offset] != '\\' + && dirwindows[offset] != '/' + && dirwindows[offset]) +diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c +index 103f6796f..72a2e37cd 100644 +--- a/grub-core/partmap/gpt.c ++++ b/grub-core/partmap/gpt.c +@@ -199,7 +199,7 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, + *nsectors = ctx.len; + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c +index 7b8e45076..ee3f24982 100644 +--- a/grub-core/partmap/msdos.c ++++ b/grub-core/partmap/msdos.c +@@ -337,7 +337,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, + avail_nsectors = *nsectors; + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index ee299fd0e..c8d6806fe 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -553,7 +553,7 @@ gettext_append (struct grub_script_argv *result, const char *orig_str) + for (iptr = orig_str; *iptr; iptr++) + if (*iptr == '$') + dollar_cnt++; +- ctx.allowed_strings = grub_malloc (sizeof (ctx.allowed_strings[0]) * dollar_cnt); ++ ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0])); + + if (parse_string (orig_str, gettext_save_allow, &ctx, 0)) + goto fail; +diff --git a/grub-core/tests/fake_input.c b/grub-core/tests/fake_input.c +index 2d6085298..b5eb516be 100644 +--- a/grub-core/tests/fake_input.c ++++ b/grub-core/tests/fake_input.c +@@ -49,7 +49,7 @@ grub_terminal_input_fake_sequence (int *seq_in, int nseq_in) + saved = grub_term_inputs; + if (seq) + grub_free (seq); +- seq = grub_malloc (nseq_in * sizeof (seq[0])); ++ seq = grub_calloc (nseq_in, sizeof (seq[0])); + if (!seq) + return; + +diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c +index 74d5b65e5..44d081069 100644 +--- a/grub-core/tests/video_checksum.c ++++ b/grub-core/tests/video_checksum.c +@@ -336,7 +336,7 @@ grub_video_capture_write_bmp (const char *fname, + { + case 4: + { +- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); ++ grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); + grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); + grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); +@@ -367,7 +367,7 @@ grub_video_capture_write_bmp (const char *fname, + } + case 3: + { +- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); ++ grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); + grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); + grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); +@@ -407,7 +407,7 @@ grub_video_capture_write_bmp (const char *fname, + } + case 2: + { +- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); ++ grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1); + grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1); + grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1); +diff --git a/grub-core/video/capture.c b/grub-core/video/capture.c +index 4f83c7441..4d3195e01 100644 +--- a/grub-core/video/capture.c ++++ b/grub-core/video/capture.c +@@ -89,7 +89,7 @@ grub_video_capture_start (const struct grub_video_mode_info *mode_info, + framebuffer.mode_info = *mode_info; + framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); + +- framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch); ++ framebuffer.ptr = grub_calloc (framebuffer.mode_info.height, framebuffer.mode_info.pitch); + if (!framebuffer.ptr) + return grub_errno; + +diff --git a/grub-core/video/emu/sdl.c b/grub-core/video/emu/sdl.c +index a2f639f66..0ebab6f57 100644 +--- a/grub-core/video/emu/sdl.c ++++ b/grub-core/video/emu/sdl.c +@@ -172,7 +172,7 @@ grub_video_sdl_set_palette (unsigned int start, unsigned int count, + if (start + count > mode_info.number_of_colors) + count = mode_info.number_of_colors - start; + +- tmp = grub_malloc (count * sizeof (tmp[0])); ++ tmp = grub_calloc (count, sizeof (tmp[0])); + for (i = 0; i < count; i++) + { + tmp[i].r = palette_data[i].r; +diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c +index 01f47112d..b2f776c99 100644 +--- a/grub-core/video/i386/pc/vga.c ++++ b/grub-core/video/i386/pc/vga.c +@@ -127,7 +127,7 @@ grub_video_vga_setup (unsigned int width, unsigned int height, + + vga_height = height ? : 480; + +- framebuffer.temporary_buffer = grub_malloc (vga_height * VGA_WIDTH); ++ framebuffer.temporary_buffer = grub_calloc (vga_height, VGA_WIDTH); + framebuffer.front_page = 0; + framebuffer.back_page = 0; + if (!framebuffer.temporary_buffer) +diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c +index 777e71334..61bd64537 100644 +--- a/grub-core/video/readers/png.c ++++ b/grub-core/video/readers/png.c +@@ -309,7 +309,7 @@ grub_png_decode_image_header (struct grub_png_data *data) + if (data->is_16bit || data->is_gray || data->is_palette) + #endif + { +- data->image_data = grub_malloc (data->image_height * data->row_bytes); ++ data->image_data = grub_calloc (data->image_height, data->row_bytes); + if (grub_errno) + return grub_errno; + +diff --git a/include/grub/unicode.h b/include/grub/unicode.h +index a0403e91f..4de986a85 100644 +--- a/include/grub/unicode.h ++++ b/include/grub/unicode.h +@@ -293,7 +293,7 @@ grub_unicode_glyph_dup (const struct grub_unicode_glyph *in) + grub_memcpy (out, in, sizeof (*in)); + if (in->ncomb > ARRAY_SIZE (out->combining_inline)) + { +- out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); ++ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); + if (!out->combining_ptr) + { + grub_free (out); +@@ -315,7 +315,7 @@ grub_unicode_set_glyph (struct grub_unicode_glyph *out, + grub_memcpy (out, in, sizeof (*in)); + if (in->ncomb > ARRAY_SIZE (out->combining_inline)) + { +- out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); ++ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); + if (!out->combining_ptr) + return; + grub_memcpy (out->combining_ptr, in->combining_ptr, +diff --git a/util/getroot.c b/util/getroot.c +index 847406fba..a5eaa64fd 100644 +--- a/util/getroot.c ++++ b/util/getroot.c +@@ -200,7 +200,7 @@ make_device_name (const char *drive) + char *ret, *ptr; + const char *iptr; + +- ret = xmalloc (strlen (drive) * 2); ++ ret = xcalloc (2, strlen (drive)); + ptr = ret; + for (iptr = drive; *iptr; iptr++) + { +diff --git a/util/grub-file.c b/util/grub-file.c +index 50c18b683..b2e7dd69f 100644 +--- a/util/grub-file.c ++++ b/util/grub-file.c +@@ -54,7 +54,7 @@ main (int argc, char *argv[]) + + grub_util_host_init (&argc, &argv); + +- argv2 = xmalloc (argc * sizeof (argv2[0])); ++ argv2 = xcalloc (argc, sizeof (argv2[0])); + + if (argc == 2 && strcmp (argv[1], "--version") == 0) + { +diff --git a/util/grub-fstest.c b/util/grub-fstest.c +index f14e02d97..57246af7c 100644 +--- a/util/grub-fstest.c ++++ b/util/grub-fstest.c +@@ -650,7 +650,7 @@ argp_parser (int key, char *arg, struct argp_state *state) + if (args_count < num_disks) + { + if (args_count == 0) +- images = xmalloc (num_disks * sizeof (images[0])); ++ images = xcalloc (num_disks, sizeof (images[0])); + images[args_count] = grub_canonicalize_file_name (arg); + args_count++; + return 0; +@@ -734,7 +734,7 @@ main (int argc, char *argv[]) + + grub_util_host_init (&argc, &argv); + +- args = xmalloc (argc * sizeof (args[0])); ++ args = xcalloc (argc, sizeof (args[0])); + + argp_parse (&argp, argc, argv, 0, 0, 0); + +diff --git a/util/grub-install-common.c b/util/grub-install-common.c +index ca0ac612a..0295d40f5 100644 +--- a/util/grub-install-common.c ++++ b/util/grub-install-common.c +@@ -286,7 +286,7 @@ handle_install_list (struct install_list *il, const char *val, + il->n_entries++; + } + il->n_alloc = il->n_entries + 1; +- il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0])); ++ il->entries = xcalloc (il->n_alloc, sizeof (il->entries[0])); + ptr = val; + for (ce = il->entries; ; ce++) + { +diff --git a/util/grub-install.c b/util/grub-install.c +index 8a55ad4b8..a82725f29 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -626,7 +626,7 @@ device_map_check_duplicates (const char *dev_map) + if (! fp) + return; + +- d = xmalloc (alloced * sizeof (d[0])); ++ d = xcalloc (alloced, sizeof (d[0])); + + while (fgets (buf, sizeof (buf), fp)) + { +@@ -1260,7 +1260,7 @@ main (int argc, char *argv[]) + ndev++; + } + +- grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1)); ++ grub_drives = xcalloc (ndev + 1, sizeof (grub_drives[0])); + + for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, + curdrive++) +diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c +index bc087c2b5..d97d0e7be 100644 +--- a/util/grub-mkimagexx.c ++++ b/util/grub-mkimagexx.c +@@ -2294,10 +2294,8 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, + + grub_host_to_target16 (e->e_shstrndx) * smd.section_entsize); + smd.strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); + +- smd.addrs = xmalloc (sizeof (*smd.addrs) * smd.num_sections); +- memset (smd.addrs, 0, sizeof (*smd.addrs) * smd.num_sections); +- smd.vaddrs = xmalloc (sizeof (*smd.vaddrs) * smd.num_sections); +- memset (smd.vaddrs, 0, sizeof (*smd.vaddrs) * smd.num_sections); ++ smd.addrs = xcalloc (smd.num_sections, sizeof (*smd.addrs)); ++ smd.vaddrs = xcalloc (smd.num_sections, sizeof (*smd.vaddrs)); + + SUFFIX (locate_sections) (e, kernel_path, &smd, layout, image_target); + +diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c +index ce2cbc4f1..51831027f 100644 +--- a/util/grub-mkrescue.c ++++ b/util/grub-mkrescue.c +@@ -441,8 +441,8 @@ main (int argc, char *argv[]) + xorriso = xstrdup ("xorriso"); + label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2"); + +- argp_argv = xmalloc (sizeof (argp_argv[0]) * argc); +- xorriso_tail_argv = xmalloc (sizeof (argp_argv[0]) * argc); ++ argp_argv = xcalloc (argc, sizeof (argp_argv[0])); ++ xorriso_tail_argv = xcalloc (argc, sizeof (argp_argv[0])); + + xorriso_tail_argc = 0; + /* Program name */ +diff --git a/util/grub-mkstandalone.c b/util/grub-mkstandalone.c +index 4907d44c0..edf309717 100644 +--- a/util/grub-mkstandalone.c ++++ b/util/grub-mkstandalone.c +@@ -296,7 +296,7 @@ main (int argc, char *argv[]) + grub_util_host_init (&argc, &argv); + grub_util_disable_fd_syncs (); + +- files = xmalloc ((argc + 1) * sizeof (files[0])); ++ files = xcalloc (argc + 1, sizeof (files[0])); + + argp_parse (&argp, argc, argv, 0, 0, 0); + +diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c +index 0d4084a10..11331294f 100644 +--- a/util/grub-pe2elf.c ++++ b/util/grub-pe2elf.c +@@ -100,9 +100,9 @@ write_section_data (FILE* fp, const char *name, char *image, + char *pe_strtab = (image + pe_chdr->symtab_offset + + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol)); + +- section_map = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (int)); ++ section_map = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (int)); + section_map[0] = 0; +- shdr = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (shdr[0])); ++ shdr = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (shdr[0])); + idx = 1; + idx_reloc = pe_chdr->num_sections + 1; + +@@ -233,7 +233,7 @@ write_reloc_section (FILE* fp, const char *name, char *image, + + pe_sec = pe_shdr + shdr[i].sh_link; + pe_rel = (struct grub_pe32_reloc *) (image + pe_sec->relocations_offset); +- rel = (elf_reloc_t *) xmalloc (pe_sec->num_relocations * sizeof (elf_reloc_t)); ++ rel = (elf_reloc_t *) xcalloc (pe_sec->num_relocations, sizeof (elf_reloc_t)); + num_rels = 0; + modified = 0; + +@@ -365,12 +365,10 @@ write_symbol_table (FILE* fp, const char *name, char *image, + pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset); + pe_strtab = (char *) (pe_symtab + pe_chdr->num_symbols); + +- symtab = (Elf_Sym *) xmalloc ((pe_chdr->num_symbols + 1) * +- sizeof (Elf_Sym)); +- memset (symtab, 0, (pe_chdr->num_symbols + 1) * sizeof (Elf_Sym)); ++ symtab = (Elf_Sym *) xcalloc (pe_chdr->num_symbols + 1, sizeof (Elf_Sym)); + num_syms = 1; + +- symtab_map = (int *) xmalloc (pe_chdr->num_symbols * sizeof (int)); ++ symtab_map = (int *) xcalloc (pe_chdr->num_symbols, sizeof (int)); + + for (i = 0; i < (int) pe_chdr->num_symbols; + i += pe_symtab->num_aux + 1, pe_symtab += pe_symtab->num_aux + 1) +diff --git a/util/grub-probe.c b/util/grub-probe.c +index 81d27eead..cbe6ed94c 100644 +--- a/util/grub-probe.c ++++ b/util/grub-probe.c +@@ -361,8 +361,8 @@ probe (const char *path, char **device_names, char delim) + grub_util_pull_device (*curdev); + ndev++; + } +- +- drives_names = xmalloc (sizeof (drives_names[0]) * (ndev + 1)); ++ ++ drives_names = xcalloc (ndev + 1, sizeof (drives_names[0])); + + for (curdev = device_names, curdrive = drives_names; *curdev; curdev++, + curdrive++) +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0006-malloc-Use-overflow-checking-primitives-where-we-do-.patch b/buildroot/boot/grub2/0006-malloc-Use-overflow-checking-primitives-where-we-do-.patch new file mode 100644 index 000000000..aaad72563 --- /dev/null +++ b/buildroot/boot/grub2/0006-malloc-Use-overflow-checking-primitives-where-we-do-.patch @@ -0,0 +1,1326 @@ +From 4ad7e85adc3803788d65707a9db11fd681aebe4a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 15 Jun 2020 12:28:27 -0400 +Subject: [PATCH] malloc: Use overflow checking primitives where we do + complex allocations +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This attempts to fix the places where we do the following where +arithmetic_expr may include unvalidated data: + + X = grub_malloc(arithmetic_expr); + +It accomplishes this by doing the arithmetic ahead of time using grub_add(), +grub_sub(), grub_mul() and testing for overflow before proceeding. + +Among other issues, this fixes: + - allocation of integer overflow in grub_video_bitmap_create() + reported by Chris Coulson, + - allocation of integer overflow in grub_png_decode_image_header() + reported by Chris Coulson, + - allocation of integer overflow in grub_squash_read_symlink() + reported by Chris Coulson, + - allocation of integer overflow in grub_ext2_read_symlink() + reported by Chris Coulson, + - allocation of integer overflow in read_section_as_string() + reported by Chris Coulson. + +Fixes: CVE-2020-14309, CVE-2020-14310, CVE-2020-14311 + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/commands/legacycfg.c | 29 +++++++++++++++---- + grub-core/commands/wildcard.c | 36 ++++++++++++++++++++---- + grub-core/disk/ldm.c | 32 +++++++++++++++------ + grub-core/font/font.c | 7 ++++- + grub-core/fs/btrfs.c | 28 +++++++++++++------ + grub-core/fs/ext2.c | 10 ++++++- + grub-core/fs/iso9660.c | 51 ++++++++++++++++++++++++---------- + grub-core/fs/sfs.c | 27 ++++++++++++++---- + grub-core/fs/squash4.c | 45 ++++++++++++++++++++++-------- + grub-core/fs/udf.c | 41 +++++++++++++++++---------- + grub-core/fs/xfs.c | 11 +++++--- + grub-core/fs/zfs/zfs.c | 22 ++++++++++----- + grub-core/fs/zfs/zfscrypt.c | 7 ++++- + grub-core/lib/arg.c | 20 +++++++++++-- + grub-core/loader/i386/bsd.c | 8 +++++- + grub-core/net/dns.c | 9 +++++- + grub-core/normal/charset.c | 10 +++++-- + grub-core/normal/cmdline.c | 14 ++++++++-- + grub-core/normal/menu_entry.c | 13 +++++++-- + grub-core/script/argv.c | 16 +++++++++-- + grub-core/script/lexer.c | 21 ++++++++++++-- + grub-core/video/bitmap.c | 25 +++++++++++------ + grub-core/video/readers/png.c | 13 +++++++-- + 23 files changed, 382 insertions(+), 113 deletions(-) + +diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c +index 5e3ec0d5e..cc5971f4d 100644 +--- a/grub-core/commands/legacycfg.c ++++ b/grub-core/commands/legacycfg.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -104,13 +105,22 @@ legacy_file (const char *filename) + if (newsuffix) + { + char *t; +- ++ grub_size_t sz; ++ ++ if (grub_add (grub_strlen (suffix), grub_strlen (newsuffix), &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ goto fail_0; ++ } ++ + t = suffix; +- suffix = grub_realloc (suffix, grub_strlen (suffix) +- + grub_strlen (newsuffix) + 1); ++ suffix = grub_realloc (suffix, sz); + if (!suffix) + { + grub_free (t); ++ ++ fail_0: + grub_free (entrysrc); + grub_free (parsed); + grub_free (newsuffix); +@@ -154,13 +164,22 @@ legacy_file (const char *filename) + else + { + char *t; ++ grub_size_t sz; ++ ++ if (grub_add (grub_strlen (entrysrc), grub_strlen (parsed), &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ goto fail_1; ++ } + + t = entrysrc; +- entrysrc = grub_realloc (entrysrc, grub_strlen (entrysrc) +- + grub_strlen (parsed) + 1); ++ entrysrc = grub_realloc (entrysrc, sz); + if (!entrysrc) + { + grub_free (t); ++ ++ fail_1: + grub_free (parsed); + grub_free (suffix); + return grub_errno; +diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c +index 4a106ca04..cc3290311 100644 +--- a/grub-core/commands/wildcard.c ++++ b/grub-core/commands/wildcard.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + #include + +@@ -48,6 +49,7 @@ merge (char **dest, char **ps) + int i; + int j; + char **p; ++ grub_size_t sz; + + if (! dest) + return ps; +@@ -60,7 +62,12 @@ merge (char **dest, char **ps) + for (j = 0; ps[j]; j++) + ; + +- p = grub_realloc (dest, sizeof (char*) * (i + j + 1)); ++ if (grub_add (i, j, &sz) || ++ grub_add (sz, 1, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ return dest; ++ ++ p = grub_realloc (dest, sz); + if (! p) + { + grub_free (dest); +@@ -115,8 +122,15 @@ make_regex (const char *start, const char *end, regex_t *regexp) + char ch; + int i = 0; + unsigned len = end - start; +- char *buffer = grub_malloc (len * 2 + 2 + 1); /* worst case size. */ ++ char *buffer; ++ grub_size_t sz; + ++ /* Worst case size is (len * 2 + 2 + 1). */ ++ if (grub_mul (len, 2, &sz) || ++ grub_add (sz, 3, &sz)) ++ return 1; ++ ++ buffer = grub_malloc (sz); + if (! buffer) + return 1; + +@@ -226,6 +240,7 @@ match_devices_iter (const char *name, void *data) + struct match_devices_ctx *ctx = data; + char **t; + char *buffer; ++ grub_size_t sz; + + /* skip partitions if asked to. */ + if (ctx->noparts && grub_strchr (name, ',')) +@@ -239,11 +254,16 @@ match_devices_iter (const char *name, void *data) + if (regexec (ctx->regexp, buffer, 0, 0, 0)) + { + grub_dprintf ("expand", "not matched\n"); ++ fail: + grub_free (buffer); + return 0; + } + +- t = grub_realloc (ctx->devs, sizeof (char*) * (ctx->ndev + 2)); ++ if (grub_add (ctx->ndev, 2, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ goto fail; ++ ++ t = grub_realloc (ctx->devs, sz); + if (! t) + { + grub_free (buffer); +@@ -300,6 +320,7 @@ match_files_iter (const char *name, + struct match_files_ctx *ctx = data; + char **t; + char *buffer; ++ grub_size_t sz; + + /* skip . and .. names */ + if (grub_strcmp(".", name) == 0 || grub_strcmp("..", name) == 0) +@@ -315,9 +336,14 @@ match_files_iter (const char *name, + if (! buffer) + return 1; + +- t = grub_realloc (ctx->files, sizeof (char*) * (ctx->nfile + 2)); +- if (! t) ++ if (grub_add (ctx->nfile, 2, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ goto fail; ++ ++ t = grub_realloc (ctx->files, sz); ++ if (!t) + { ++ fail: + grub_free (buffer); + return 1; + } +diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c +index e6323701a..58f8a53e1 100644 +--- a/grub-core/disk/ldm.c ++++ b/grub-core/disk/ldm.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + #ifdef GRUB_UTIL + #include +@@ -289,6 +290,7 @@ make_vg (grub_disk_t disk, + struct grub_ldm_vblk vblk[GRUB_DISK_SECTOR_SIZE + / sizeof (struct grub_ldm_vblk)]; + unsigned i; ++ grub_size_t sz; + err = grub_disk_read (disk, cursec, 0, + sizeof(vblk), &vblk); + if (err) +@@ -350,7 +352,13 @@ make_vg (grub_disk_t disk, + grub_free (lv); + goto fail2; + } +- lv->name = grub_malloc (*ptr + 1); ++ if (grub_add (*ptr, 1, &sz)) ++ { ++ grub_free (lv->internal_id); ++ grub_free (lv); ++ goto fail2; ++ } ++ lv->name = grub_malloc (sz); + if (!lv->name) + { + grub_free (lv->internal_id); +@@ -599,10 +607,13 @@ make_vg (grub_disk_t disk, + if (lv->segments->node_alloc == lv->segments->node_count) + { + void *t; +- lv->segments->node_alloc *= 2; +- t = grub_realloc (lv->segments->nodes, +- sizeof (*lv->segments->nodes) +- * lv->segments->node_alloc); ++ grub_size_t sz; ++ ++ if (grub_mul (lv->segments->node_alloc, 2, &lv->segments->node_alloc) || ++ grub_mul (lv->segments->node_alloc, sizeof (*lv->segments->nodes), &sz)) ++ goto fail2; ++ ++ t = grub_realloc (lv->segments->nodes, sz); + if (!t) + goto fail2; + lv->segments->nodes = t; +@@ -723,10 +734,13 @@ make_vg (grub_disk_t disk, + if (comp->segment_alloc == comp->segment_count) + { + void *t; +- comp->segment_alloc *= 2; +- t = grub_realloc (comp->segments, +- comp->segment_alloc +- * sizeof (*comp->segments)); ++ grub_size_t sz; ++ ++ if (grub_mul (comp->segment_alloc, 2, &comp->segment_alloc) || ++ grub_mul (comp->segment_alloc, sizeof (*comp->segments), &sz)) ++ goto fail2; ++ ++ t = grub_realloc (comp->segments, sz); + if (!t) + goto fail2; + comp->segments = t; +diff --git a/grub-core/font/font.c b/grub-core/font/font.c +index 8e118b315..5edb477ac 100644 +--- a/grub-core/font/font.c ++++ b/grub-core/font/font.c +@@ -30,6 +30,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -360,9 +361,13 @@ static char * + read_section_as_string (struct font_file_section *section) + { + char *str; ++ grub_size_t sz; + grub_ssize_t ret; + +- str = grub_malloc (section->length + 1); ++ if (grub_add (section->length, 1, &sz)) ++ return NULL; ++ ++ str = grub_malloc (sz); + if (!str) + return 0; + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 11272efc1..2b65bd56a 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -40,6 +40,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -329,9 +330,13 @@ save_ref (struct grub_btrfs_leaf_descriptor *desc, + if (desc->allocated < desc->depth) + { + void *newdata; +- desc->allocated *= 2; +- newdata = grub_realloc (desc->data, sizeof (desc->data[0]) +- * desc->allocated); ++ grub_size_t sz; ++ ++ if (grub_mul (desc->allocated, 2, &desc->allocated) || ++ grub_mul (desc->allocated, sizeof (desc->data[0]), &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ newdata = grub_realloc (desc->data, sz); + if (!newdata) + return grub_errno; + desc->data = newdata; +@@ -622,16 +627,21 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id) + if (data->n_devices_attached > data->n_devices_allocated) + { + void *tmp; +- data->n_devices_allocated = 2 * data->n_devices_attached + 1; +- data->devices_attached +- = grub_realloc (tmp = data->devices_attached, +- data->n_devices_allocated +- * sizeof (data->devices_attached[0])); ++ grub_size_t sz; ++ ++ if (grub_mul (data->n_devices_attached, 2, &data->n_devices_allocated) || ++ grub_add (data->n_devices_allocated, 1, &data->n_devices_allocated) || ++ grub_mul (data->n_devices_allocated, sizeof (data->devices_attached[0]), &sz)) ++ goto fail; ++ ++ data->devices_attached = grub_realloc (tmp = data->devices_attached, sz); + if (!data->devices_attached) + { ++ data->devices_attached = tmp; ++ ++ fail: + if (ctx.dev_found) + grub_device_close (ctx.dev_found); +- data->devices_attached = tmp; + return NULL; + } + } +diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c +index 9b389802a..ac33bcd68 100644 +--- a/grub-core/fs/ext2.c ++++ b/grub-core/fs/ext2.c +@@ -46,6 +46,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -703,6 +704,7 @@ grub_ext2_read_symlink (grub_fshelp_node_t node) + { + char *symlink; + struct grub_fshelp_node *diro = node; ++ grub_size_t sz; + + if (! diro->inode_read) + { +@@ -717,7 +719,13 @@ grub_ext2_read_symlink (grub_fshelp_node_t node) + } + } + +- symlink = grub_malloc (grub_le_to_cpu32 (diro->inode.size) + 1); ++ if (grub_add (grub_le_to_cpu32 (diro->inode.size), 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return NULL; ++ } ++ ++ symlink = grub_malloc (sz); + if (! symlink) + return 0; + +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 4f1b52a55..7ba5b300b 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -531,8 +532,13 @@ add_part (struct iterate_dir_ctx *ctx, + int len2) + { + int size = ctx->symlink ? grub_strlen (ctx->symlink) : 0; ++ grub_size_t sz; + +- ctx->symlink = grub_realloc (ctx->symlink, size + len2 + 1); ++ if (grub_add (size, len2, &sz) || ++ grub_add (sz, 1, &sz)) ++ return; ++ ++ ctx->symlink = grub_realloc (ctx->symlink, sz); + if (! ctx->symlink) + return; + +@@ -560,17 +566,24 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, + { + grub_size_t off = 0, csize = 1; + char *old; ++ grub_size_t sz; ++ + csize = entry->len - 5; + old = ctx->filename; + if (ctx->filename_alloc) + { + off = grub_strlen (ctx->filename); +- ctx->filename = grub_realloc (ctx->filename, csize + off + 1); ++ if (grub_add (csize, off, &sz) || ++ grub_add (sz, 1, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ctx->filename = grub_realloc (ctx->filename, sz); + } + else + { + off = 0; +- ctx->filename = grub_zalloc (csize + 1); ++ if (grub_add (csize, 1, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ctx->filename = grub_zalloc (sz); + } + if (!ctx->filename) + { +@@ -776,14 +789,18 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, + if (node->have_dirents >= node->alloc_dirents) + { + struct grub_fshelp_node *new_node; +- node->alloc_dirents *= 2; +- new_node = grub_realloc (node, +- sizeof (struct grub_fshelp_node) +- + ((node->alloc_dirents +- - ARRAY_SIZE (node->dirents)) +- * sizeof (node->dirents[0]))); ++ grub_size_t sz; ++ ++ if (grub_mul (node->alloc_dirents, 2, &node->alloc_dirents) || ++ grub_sub (node->alloc_dirents, ARRAY_SIZE (node->dirents), &sz) || ++ grub_mul (sz, sizeof (node->dirents[0]), &sz) || ++ grub_add (sz, sizeof (struct grub_fshelp_node), &sz)) ++ goto fail_0; ++ ++ new_node = grub_realloc (node, sz); + if (!new_node) + { ++ fail_0: + if (ctx.filename_alloc) + grub_free (ctx.filename); + grub_free (node); +@@ -799,14 +816,18 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, + * sizeof (node->dirents[0]) < grub_strlen (ctx.symlink) + 1) + { + struct grub_fshelp_node *new_node; +- new_node = grub_realloc (node, +- sizeof (struct grub_fshelp_node) +- + ((node->alloc_dirents +- - ARRAY_SIZE (node->dirents)) +- * sizeof (node->dirents[0])) +- + grub_strlen (ctx.symlink) + 1); ++ grub_size_t sz; ++ ++ if (grub_sub (node->alloc_dirents, ARRAY_SIZE (node->dirents), &sz) || ++ grub_mul (sz, sizeof (node->dirents[0]), &sz) || ++ grub_add (sz, sizeof (struct grub_fshelp_node) + 1, &sz) || ++ grub_add (sz, grub_strlen (ctx.symlink), &sz)) ++ goto fail_1; ++ ++ new_node = grub_realloc (node, sz); + if (!new_node) + { ++ fail_1: + if (ctx.filename_alloc) + grub_free (ctx.filename); + grub_free (node); +diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c +index 90f7fb379..de2b107a4 100644 +--- a/grub-core/fs/sfs.c ++++ b/grub-core/fs/sfs.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -307,10 +308,15 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + if (node->cache && node->cache_size >= node->cache_allocated) + { + struct cache_entry *e = node->cache; +- e = grub_realloc (node->cache,node->cache_allocated * 2 +- * sizeof (e[0])); ++ grub_size_t sz; ++ ++ if (grub_mul (node->cache_allocated, 2 * sizeof (e[0]), &sz)) ++ goto fail; ++ ++ e = grub_realloc (node->cache, sz); + if (!e) + { ++ fail: + grub_errno = 0; + grub_free (node->cache); + node->cache = 0; +@@ -477,10 +483,16 @@ grub_sfs_create_node (struct grub_fshelp_node **node, + grub_size_t len = grub_strlen (name); + grub_uint8_t *name_u8; + int ret; ++ grub_size_t sz; ++ ++ if (grub_mul (len, GRUB_MAX_UTF8_PER_LATIN1, &sz) || ++ grub_add (sz, 1, &sz)) ++ return 1; ++ + *node = grub_malloc (sizeof (**node)); + if (!*node) + return 1; +- name_u8 = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); ++ name_u8 = grub_malloc (sz); + if (!name_u8) + { + grub_free (*node); +@@ -724,8 +736,13 @@ grub_sfs_label (grub_device_t device, char **label) + data = grub_sfs_mount (disk); + if (data) + { +- grub_size_t len = grub_strlen (data->label); +- *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); ++ grub_size_t sz, len = grub_strlen (data->label); ++ ++ if (grub_mul (len, GRUB_MAX_UTF8_PER_LATIN1, &sz) || ++ grub_add (sz, 1, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ *label = grub_malloc (sz); + if (*label) + *grub_latin1_to_utf8 ((grub_uint8_t *) *label, + (const grub_uint8_t *) data->label, +diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c +index 95d5c1e1f..785123894 100644 +--- a/grub-core/fs/squash4.c ++++ b/grub-core/fs/squash4.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + #include + + #include "xz.h" +@@ -459,7 +460,17 @@ grub_squash_read_symlink (grub_fshelp_node_t node) + { + char *ret; + grub_err_t err; +- ret = grub_malloc (grub_le_to_cpu32 (node->ino.symlink.namelen) + 1); ++ grub_size_t sz; ++ ++ if (grub_add (grub_le_to_cpu32 (node->ino.symlink.namelen), 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return NULL; ++ } ++ ++ ret = grub_malloc (sz); ++ if (!ret) ++ return NULL; + + err = read_chunk (node->data, ret, + grub_le_to_cpu32 (node->ino.symlink.namelen), +@@ -506,11 +517,16 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + + { + grub_fshelp_node_t node; +- node = grub_malloc (sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ grub_size_t sz; ++ ++ if (grub_mul (dir->stsize, sizeof (dir->stack[0]), &sz) || ++ grub_add (sz, sizeof (*node), &sz)) ++ return 0; ++ ++ node = grub_malloc (sz); + if (!node) + return 0; +- grub_memcpy (node, dir, +- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ grub_memcpy (node, dir, sz); + if (hook (".", GRUB_FSHELP_DIR, node, hook_data)) + return 1; + +@@ -518,12 +534,15 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + { + grub_err_t err; + +- node = grub_malloc (sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ if (grub_mul (dir->stsize, sizeof (dir->stack[0]), &sz) || ++ grub_add (sz, sizeof (*node), &sz)) ++ return 0; ++ ++ node = grub_malloc (sz); + if (!node) + return 0; + +- grub_memcpy (node, dir, +- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ grub_memcpy (node, dir, sz); + + node->stsize--; + err = read_chunk (dir->data, &node->ino, sizeof (node->ino), +@@ -557,6 +576,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + enum grub_fshelp_filetype filetype = GRUB_FSHELP_REG; + struct grub_squash_dirent di; + struct grub_squash_inode ino; ++ grub_size_t sz; + + err = read_chunk (dir->data, &di, sizeof (di), + grub_le_to_cpu64 (dir->data->sb.diroffset) +@@ -589,13 +609,16 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_SYMLINK) + filetype = GRUB_FSHELP_SYMLINK; + +- node = grub_malloc (sizeof (*node) +- + (dir->stsize + 1) * sizeof (dir->stack[0])); ++ if (grub_add (dir->stsize, 1, &sz) || ++ grub_mul (sz, sizeof (dir->stack[0]), &sz) || ++ grub_add (sz, sizeof (*node), &sz)) ++ return 0; ++ ++ node = grub_malloc (sz); + if (! node) + return 0; + +- grub_memcpy (node, dir, +- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ grub_memcpy (node, dir, sz - sizeof(dir->stack[0])); + + node->ino = ino; + node->stack[node->stsize].ino_chunk = grub_le_to_cpu32 (dh.ino_chunk); +diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c +index a83761674..21ac7f446 100644 +--- a/grub-core/fs/udf.c ++++ b/grub-core/fs/udf.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -890,9 +891,19 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) + utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; + } + if (!outbuf) +- outbuf = grub_malloc (utf16len * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ { ++ grub_size_t size; ++ ++ if (grub_mul (utf16len, GRUB_MAX_UTF8_PER_UTF16, &size) || ++ grub_add (size, 1, &size)) ++ goto fail; ++ ++ outbuf = grub_malloc (size); ++ } + if (outbuf) + *grub_utf16_to_utf8 ((grub_uint8_t *) outbuf, utf16, utf16len) = '\0'; ++ ++ fail: + grub_free (utf16); + return outbuf; + } +@@ -1005,7 +1016,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + grub_size_t sz = U64 (node->block.fe.file_size); + grub_uint8_t *raw; + const grub_uint8_t *ptr; +- char *out, *optr; ++ char *out = NULL, *optr; + + if (sz < 4) + return NULL; +@@ -1013,14 +1024,16 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + if (!raw) + return NULL; + if (grub_udf_read_file (node, NULL, NULL, 0, sz, (char *) raw) < 0) +- { +- grub_free (raw); +- return NULL; +- } ++ goto fail_1; + +- out = grub_malloc (sz * 2 + 1); ++ if (grub_mul (sz, 2, &sz) || ++ grub_add (sz, 1, &sz)) ++ goto fail_0; ++ ++ out = grub_malloc (sz); + if (!out) + { ++ fail_0: + grub_free (raw); + return NULL; + } +@@ -1031,17 +1044,17 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + { + grub_size_t s; + if ((grub_size_t) (ptr - raw + 4) > sz) +- goto fail; ++ goto fail_1; + if (!(ptr[2] == 0 && ptr[3] == 0)) +- goto fail; ++ goto fail_1; + s = 4 + ptr[1]; + if ((grub_size_t) (ptr - raw + s) > sz) +- goto fail; ++ goto fail_1; + switch (*ptr) + { + case 1: + if (ptr[1]) +- goto fail; ++ goto fail_1; + /* Fallthrough. */ + case 2: + /* in 4 bytes. out: 1 byte. */ +@@ -1066,11 +1079,11 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + if (optr != out) + *optr++ = '/'; + if (!read_string (ptr + 4, s - 4, optr)) +- goto fail; ++ goto fail_1; + optr += grub_strlen (optr); + break; + default: +- goto fail; ++ goto fail_1; + } + ptr += s; + } +@@ -1078,7 +1091,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + grub_free (raw); + return out; + +- fail: ++ fail_1: + grub_free (raw); + grub_free (out); + grub_error (GRUB_ERR_BAD_FS, "invalid symlink"); +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index 96ffecbfc..ea6590290 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -899,6 +900,7 @@ static struct grub_xfs_data * + grub_xfs_mount (grub_disk_t disk) + { + struct grub_xfs_data *data = 0; ++ grub_size_t sz; + + data = grub_zalloc (sizeof (struct grub_xfs_data)); + if (!data) +@@ -913,10 +915,11 @@ grub_xfs_mount (grub_disk_t disk) + if (!grub_xfs_sb_valid(data)) + goto fail; + +- data = grub_realloc (data, +- sizeof (struct grub_xfs_data) +- - sizeof (struct grub_xfs_inode) +- + grub_xfs_inode_size(data) + 1); ++ if (grub_add (grub_xfs_inode_size (data), ++ sizeof (struct grub_xfs_data) - sizeof (struct grub_xfs_inode) + 1, &sz)) ++ goto fail; ++ ++ data = grub_realloc (data, sz); + + if (! data) + goto fail; +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index 381dde556..36d0373a6 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -55,6 +55,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -773,11 +774,14 @@ fill_vdev_info (struct grub_zfs_data *data, + if (data->n_devices_attached > data->n_devices_allocated) + { + void *tmp; +- data->n_devices_allocated = 2 * data->n_devices_attached + 1; +- data->devices_attached +- = grub_realloc (tmp = data->devices_attached, +- data->n_devices_allocated +- * sizeof (data->devices_attached[0])); ++ grub_size_t sz; ++ ++ if (grub_mul (data->n_devices_attached, 2, &data->n_devices_allocated) || ++ grub_add (data->n_devices_allocated, 1, &data->n_devices_allocated) || ++ grub_mul (data->n_devices_allocated, sizeof (data->devices_attached[0]), &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ data->devices_attached = grub_realloc (tmp = data->devices_attached, sz); + if (!data->devices_attached) + { + data->devices_attached = tmp; +@@ -3468,14 +3472,18 @@ grub_zfs_nvlist_lookup_nvlist (const char *nvlist, const char *name) + { + char *nvpair; + char *ret; +- grub_size_t size; ++ grub_size_t size, sz; + int found; + + found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST, &nvpair, + &size, 0); + if (!found) + return 0; +- ret = grub_zalloc (size + 3 * sizeof (grub_uint32_t)); ++ ++ if (grub_add (size, 3 * sizeof (grub_uint32_t), &sz)) ++ return 0; ++ ++ ret = grub_zalloc (sz); + if (!ret) + return 0; + grub_memcpy (ret, nvlist, sizeof (grub_uint32_t)); +diff --git a/grub-core/fs/zfs/zfscrypt.c b/grub-core/fs/zfs/zfscrypt.c +index 1402e0bc2..de3b015f5 100644 +--- a/grub-core/fs/zfs/zfscrypt.c ++++ b/grub-core/fs/zfs/zfscrypt.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -82,9 +83,13 @@ grub_zfs_add_key (grub_uint8_t *key_in, + int passphrase) + { + struct grub_zfs_wrap_key *key; ++ grub_size_t sz; ++ + if (!passphrase && keylen > 32) + keylen = 32; +- key = grub_malloc (sizeof (*key) + keylen); ++ if (grub_add (sizeof (*key), keylen, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ key = grub_malloc (sz); + if (!key) + return grub_errno; + key->is_passphrase = passphrase; +diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c +index fd7744a6f..3288609a5 100644 +--- a/grub-core/lib/arg.c ++++ b/grub-core/lib/arg.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + /* Built-in parser for default options. */ + static const struct grub_arg_option help_options[] = +@@ -216,7 +217,13 @@ static inline grub_err_t + add_arg (char ***argl, int *num, char *s) + { + char **p = *argl; +- *argl = grub_realloc (*argl, (++(*num) + 1) * sizeof (char *)); ++ grub_size_t sz; ++ ++ if (grub_add (++(*num), 1, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ ++ *argl = grub_realloc (*argl, sz); + if (! *argl) + { + grub_free (p); +@@ -431,6 +438,7 @@ grub_arg_list_alloc(grub_extcmd_t extcmd, int argc, + grub_size_t argcnt; + struct grub_arg_list *list; + const struct grub_arg_option *options; ++ grub_size_t sz0, sz1; + + options = extcmd->options; + if (! options) +@@ -443,7 +451,15 @@ grub_arg_list_alloc(grub_extcmd_t extcmd, int argc, + argcnt += ((grub_size_t) argc + 1) / 2 + 1; /* max possible for any option */ + } + +- list = grub_zalloc (sizeof (*list) * i + sizeof (char*) * argcnt); ++ if (grub_mul (sizeof (*list), i, &sz0) || ++ grub_mul (sizeof (char *), argcnt, &sz1) || ++ grub_add (sz0, sz1, &sz0)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return 0; ++ } ++ ++ list = grub_zalloc (sz0); + if (! list) + return 0; + +diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c +index 3730ed382..b92cbe98d 100644 +--- a/grub-core/loader/i386/bsd.c ++++ b/grub-core/loader/i386/bsd.c +@@ -35,6 +35,7 @@ + #include + #include + #include ++#include + #include + #ifdef GRUB_MACHINE_PCBIOS + #include +@@ -1012,11 +1013,16 @@ grub_netbsd_add_modules (void) + struct grub_netbsd_btinfo_modules *mods; + unsigned i; + grub_err_t err; ++ grub_size_t sz; + + for (mod = netbsd_mods; mod; mod = mod->next) + modcnt++; + +- mods = grub_malloc (sizeof (*mods) + sizeof (mods->mods[0]) * modcnt); ++ if (grub_mul (modcnt, sizeof (mods->mods[0]), &sz) || ++ grub_add (sz, sizeof (*mods), &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ mods = grub_malloc (sz); + if (!mods) + return grub_errno; + +diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c +index e332d5eb4..906ec7d67 100644 +--- a/grub-core/net/dns.c ++++ b/grub-core/net/dns.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + + struct dns_cache_element + { +@@ -51,9 +52,15 @@ grub_net_add_dns_server (const struct grub_net_network_level_address *s) + { + int na = dns_servers_alloc * 2; + struct grub_net_network_level_address *ns; ++ grub_size_t sz; ++ + if (na < 8) + na = 8; +- ns = grub_realloc (dns_servers, na * sizeof (ns[0])); ++ ++ if (grub_mul (na, sizeof (ns[0]), &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ ns = grub_realloc (dns_servers, sz); + if (!ns) + return grub_errno; + dns_servers_alloc = na; +diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c +index d57fb72fa..4dfcc3107 100644 +--- a/grub-core/normal/charset.c ++++ b/grub-core/normal/charset.c +@@ -48,6 +48,7 @@ + #include + #include + #include ++#include + + #if HAVE_FONT_SOURCE + #include "widthspec.h" +@@ -464,6 +465,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, + { + struct grub_unicode_combining *n; + unsigned j; ++ grub_size_t sz; + + if (!haveout) + continue; +@@ -477,10 +479,14 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, + n = out->combining_inline; + else if (out->ncomb > (int) ARRAY_SIZE (out->combining_inline)) + { +- n = grub_realloc (out->combining_ptr, +- sizeof (n[0]) * (out->ncomb + 1)); ++ if (grub_add (out->ncomb, 1, &sz) || ++ grub_mul (sz, sizeof (n[0]), &sz)) ++ goto fail; ++ ++ n = grub_realloc (out->combining_ptr, sz); + if (!n) + { ++ fail: + grub_errno = GRUB_ERR_NONE; + continue; + } +diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c +index c57242e2e..de03fe63b 100644 +--- a/grub-core/normal/cmdline.c ++++ b/grub-core/normal/cmdline.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + static grub_uint32_t *kill_buf; + +@@ -307,12 +308,21 @@ cl_insert (struct cmdline_term *cl_terms, unsigned nterms, + if (len + (*llen) >= (*max_len)) + { + grub_uint32_t *nbuf; +- (*max_len) *= 2; +- nbuf = grub_realloc ((*buf), sizeof (grub_uint32_t) * (*max_len)); ++ grub_size_t sz; ++ ++ if (grub_mul (*max_len, 2, max_len) || ++ grub_mul (*max_len, sizeof (grub_uint32_t), &sz)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ goto fail; ++ } ++ ++ nbuf = grub_realloc ((*buf), sz); + if (nbuf) + (*buf) = nbuf; + else + { ++ fail: + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + (*max_len) /= 2; +diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c +index 1993995be..50eef918c 100644 +--- a/grub-core/normal/menu_entry.c ++++ b/grub-core/normal/menu_entry.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + + enum update_mode + { +@@ -113,10 +114,18 @@ ensure_space (struct line *linep, int extra) + { + if (linep->max_len < linep->len + extra) + { +- linep->max_len = 2 * (linep->len + extra); +- linep->buf = grub_realloc (linep->buf, (linep->max_len + 1) * sizeof (linep->buf[0])); ++ grub_size_t sz0, sz1; ++ ++ if (grub_add (linep->len, extra, &sz0) || ++ grub_mul (sz0, 2, &sz0) || ++ grub_add (sz0, 1, &sz1) || ++ grub_mul (sz1, sizeof (linep->buf[0]), &sz1)) ++ return 0; ++ ++ linep->buf = grub_realloc (linep->buf, sz1); + if (! linep->buf) + return 0; ++ linep->max_len = sz0; + } + + return 1; +diff --git a/grub-core/script/argv.c b/grub-core/script/argv.c +index 217ec5d1e..5751fdd57 100644 +--- a/grub-core/script/argv.c ++++ b/grub-core/script/argv.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + + /* Return nearest power of two that is >= v. */ + static unsigned +@@ -81,11 +82,16 @@ int + grub_script_argv_next (struct grub_script_argv *argv) + { + char **p = argv->args; ++ grub_size_t sz; + + if (argv->args && argv->argc && argv->args[argv->argc - 1] == 0) + return 0; + +- p = grub_realloc (p, round_up_exp ((argv->argc + 2) * sizeof (char *))); ++ if (grub_add (argv->argc, 2, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ return 1; ++ ++ p = grub_realloc (p, round_up_exp (sz)); + if (! p) + return 1; + +@@ -105,13 +111,19 @@ grub_script_argv_append (struct grub_script_argv *argv, const char *s, + { + grub_size_t a; + char *p = argv->args[argv->argc - 1]; ++ grub_size_t sz; + + if (! s) + return 0; + + a = p ? grub_strlen (p) : 0; + +- p = grub_realloc (p, round_up_exp ((a + slen + 1) * sizeof (char))); ++ if (grub_add (a, slen, &sz) || ++ grub_add (sz, 1, &sz) || ++ grub_mul (sz, sizeof (char), &sz)) ++ return 1; ++ ++ p = grub_realloc (p, round_up_exp (sz)); + if (! p) + return 1; + +diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c +index c6bd3172f..5fb0cbd0b 100644 +--- a/grub-core/script/lexer.c ++++ b/grub-core/script/lexer.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + #define yytext_ptr char * + #include "grub_script.tab.h" +@@ -110,10 +111,14 @@ grub_script_lexer_record (struct grub_parser_param *parser, char *str) + old = lexer->recording; + if (lexer->recordlen < len) + lexer->recordlen = len; +- lexer->recordlen *= 2; ++ ++ if (grub_mul (lexer->recordlen, 2, &lexer->recordlen)) ++ goto fail; ++ + lexer->recording = grub_realloc (lexer->recording, lexer->recordlen); + if (!lexer->recording) + { ++ fail: + grub_free (old); + lexer->recordpos = 0; + lexer->recordlen = 0; +@@ -130,7 +135,7 @@ int + grub_script_lexer_yywrap (struct grub_parser_param *parserstate, + const char *input) + { +- grub_size_t len = 0; ++ grub_size_t len = 0, sz; + char *p = 0; + char *line = 0; + YY_BUFFER_STATE buffer; +@@ -168,12 +173,22 @@ grub_script_lexer_yywrap (struct grub_parser_param *parserstate, + } + else if (len && line[len - 1] != '\n') + { +- p = grub_realloc (line, len + 2); ++ if (grub_add (len, 2, &sz)) ++ { ++ grub_free (line); ++ grub_script_yyerror (parserstate, N_("overflow is detected")); ++ return 1; ++ } ++ ++ p = grub_realloc (line, sz); + if (p) + { + p[len++] = '\n'; + p[len] = '\0'; + } ++ else ++ grub_free (line); ++ + line = p; + } + +diff --git a/grub-core/video/bitmap.c b/grub-core/video/bitmap.c +index b2e031566..6256e209a 100644 +--- a/grub-core/video/bitmap.c ++++ b/grub-core/video/bitmap.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -58,7 +59,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, + enum grub_video_blit_format blit_format) + { + struct grub_video_mode_info *mode_info; +- unsigned int size; ++ grub_size_t size; + + if (!bitmap) + return grub_error (GRUB_ERR_BUG, "invalid argument"); +@@ -137,19 +138,25 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, + + mode_info->pitch = width * mode_info->bytes_per_pixel; + +- /* Calculate size needed for the data. */ +- size = (width * mode_info->bytes_per_pixel) * height; ++ /* Calculate size needed for the data. */ ++ if (grub_mul (width, mode_info->bytes_per_pixel, &size) || ++ grub_mul (size, height, &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ goto fail; ++ } + + (*bitmap)->data = grub_zalloc (size); + if (! (*bitmap)->data) +- { +- grub_free (*bitmap); +- *bitmap = 0; +- +- return grub_errno; +- } ++ goto fail; + + return GRUB_ERR_NONE; ++ ++ fail: ++ grub_free (*bitmap); ++ *bitmap = NULL; ++ ++ return grub_errno; + } + + /* Frees all resources allocated by bitmap. */ +diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c +index 61bd64537..0157ff742 100644 +--- a/grub-core/video/readers/png.c ++++ b/grub-core/video/readers/png.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -301,9 +302,17 @@ grub_png_decode_image_header (struct grub_png_data *data) + data->bpp <<= 1; + + data->color_bits = color_bits; +- data->row_bytes = data->image_width * data->bpp; ++ ++ if (grub_mul (data->image_width, data->bpp, &data->row_bytes)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ + if (data->color_bits <= 4) +- data->row_bytes = (data->image_width * data->color_bits + 7) / 8; ++ { ++ if (grub_mul (data->image_width, data->color_bits + 7, &data->row_bytes)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ ++ data->row_bytes >>= 3; ++ } + + #ifndef GRUB_CPU_WORDS_BIGENDIAN + if (data->is_16bit || data->is_gray || data->is_palette) +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0007-iso9660-Don-t-leak-memory-on-realloc-failures.patch b/buildroot/boot/grub2/0007-iso9660-Don-t-leak-memory-on-realloc-failures.patch new file mode 100644 index 000000000..6b0aee080 --- /dev/null +++ b/buildroot/boot/grub2/0007-iso9660-Don-t-leak-memory-on-realloc-failures.patch @@ -0,0 +1,72 @@ +From e0dd17a3ce79c6622dc78c96e1f2ef1b20e2bf7b Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sat, 4 Jul 2020 12:25:09 -0400 +Subject: [PATCH] iso9660: Don't leak memory on realloc() failures +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/fs/iso9660.c | 24 ++++++++++++++++++++---- + 1 file changed, 20 insertions(+), 4 deletions(-) + +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 7ba5b300b..5ec4433b8 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -533,14 +533,20 @@ add_part (struct iterate_dir_ctx *ctx, + { + int size = ctx->symlink ? grub_strlen (ctx->symlink) : 0; + grub_size_t sz; ++ char *new; + + if (grub_add (size, len2, &sz) || + grub_add (sz, 1, &sz)) + return; + +- ctx->symlink = grub_realloc (ctx->symlink, sz); +- if (! ctx->symlink) +- return; ++ new = grub_realloc (ctx->symlink, sz); ++ if (!new) ++ { ++ grub_free (ctx->symlink); ++ ctx->symlink = NULL; ++ return; ++ } ++ ctx->symlink = new; + + grub_memcpy (ctx->symlink + size, part, len2); + ctx->symlink[size + len2] = 0; +@@ -634,7 +640,12 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, + is the length. Both are part of the `Component + Record'. */ + if (ctx->symlink && !ctx->was_continue) +- add_part (ctx, "/", 1); ++ { ++ add_part (ctx, "/", 1); ++ if (grub_errno) ++ return grub_errno; ++ } ++ + add_part (ctx, (char *) &entry->data[pos + 2], + entry->data[pos + 1]); + ctx->was_continue = (entry->data[pos] & 1); +@@ -653,6 +664,11 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, + add_part (ctx, "/", 1); + break; + } ++ ++ /* Check if grub_realloc() failed in add_part(). */ ++ if (grub_errno) ++ return grub_errno; ++ + /* In pos + 1 the length of the `Component Record' is + stored. */ + pos += entry->data[pos + 1] + 2; +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0008-font-Do-not-load-more-than-one-NAME-section.patch b/buildroot/boot/grub2/0008-font-Do-not-load-more-than-one-NAME-section.patch new file mode 100644 index 000000000..f4616292f --- /dev/null +++ b/buildroot/boot/grub2/0008-font-Do-not-load-more-than-one-NAME-section.patch @@ -0,0 +1,41 @@ +From 73bc7a964c9496d5b0f00dbd69959dacf5adcebe Mon Sep 17 00:00:00 2001 +From: Daniel Kiper +Date: Tue, 7 Jul 2020 15:36:26 +0200 +Subject: [PATCH] font: Do not load more than one NAME section +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The GRUB font file can have one NAME section only. Though if somebody +crafts a broken font file with many NAME sections and loads it then the +GRUB leaks memory. So, prevent against that by loading first NAME +section and failing in controlled way on following one. + +Reported-by: Chris Coulson +Signed-off-by: Daniel Kiper +Reviewed-by: Jan Setje-Eilers +Signed-off-by: Stefan Sørensen +--- + grub-core/font/font.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/grub-core/font/font.c b/grub-core/font/font.c +index 5edb477ac..d09bb38d8 100644 +--- a/grub-core/font/font.c ++++ b/grub-core/font/font.c +@@ -532,6 +532,12 @@ grub_font_load (const char *filename) + if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME, + sizeof (FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0) + { ++ if (font->name != NULL) ++ { ++ grub_error (GRUB_ERR_BAD_FONT, "invalid font file: too many NAME sections"); ++ goto fail; ++ } ++ + font->name = read_section_as_string (§ion); + if (!font->name) + goto fail; +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0009-gfxmenu-Fix-double-free-in-load_image.patch b/buildroot/boot/grub2/0009-gfxmenu-Fix-double-free-in-load_image.patch new file mode 100644 index 000000000..732d16664 --- /dev/null +++ b/buildroot/boot/grub2/0009-gfxmenu-Fix-double-free-in-load_image.patch @@ -0,0 +1,39 @@ +From 9ff609f0e7798bc5fb04f791131c98e7693bdd9b Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Wed, 8 Jul 2020 20:41:56 +0000 +Subject: [PATCH] gfxmenu: Fix double free in load_image() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +self->bitmap should be zeroed after free. Otherwise, there is a chance +to double free (USE_AFTER_FREE) it later in rescale_image(). + +Fixes: CID 292472 + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/gfxmenu/gui_image.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/grub-core/gfxmenu/gui_image.c b/grub-core/gfxmenu/gui_image.c +index 29784ed2d..6b2e976f1 100644 +--- a/grub-core/gfxmenu/gui_image.c ++++ b/grub-core/gfxmenu/gui_image.c +@@ -195,7 +195,10 @@ load_image (grub_gui_image_t self, const char *path) + return grub_errno; + + if (self->bitmap && (self->bitmap != self->raw_bitmap)) +- grub_video_bitmap_destroy (self->bitmap); ++ { ++ grub_video_bitmap_destroy (self->bitmap); ++ self->bitmap = 0; ++ } + if (self->raw_bitmap) + grub_video_bitmap_destroy (self->raw_bitmap); + +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0010-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch b/buildroot/boot/grub2/0010-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch new file mode 100644 index 000000000..72cf58d44 --- /dev/null +++ b/buildroot/boot/grub2/0010-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch @@ -0,0 +1,58 @@ +From dc9777dc17697b196c415c53187a55861d41fd2a Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Wed, 8 Jul 2020 21:30:43 +0000 +Subject: [PATCH] xnu: Fix double free in grub_xnu_devprop_add_property() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +grub_xnu_devprop_add_property() should not free utf8 and utf16 as it get +allocated and freed in the caller. + +Minor improvement: do prop fields initialization after memory allocations. + +Fixes: CID 292442, CID 292457, CID 292460, CID 292466 + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/loader/i386/xnu.c | 17 ++++++++--------- + 1 file changed, 8 insertions(+), 9 deletions(-) + +diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c +index b7d176b5d..e9e119259 100644 +--- a/grub-core/loader/i386/xnu.c ++++ b/grub-core/loader/i386/xnu.c +@@ -262,20 +262,19 @@ grub_xnu_devprop_add_property (struct grub_xnu_devprop_device_descriptor *dev, + if (!prop) + return grub_errno; + +- prop->name = utf8; +- prop->name16 = utf16; +- prop->name16len = utf16len; +- +- prop->length = datalen; +- prop->data = grub_malloc (prop->length); ++ prop->data = grub_malloc (datalen); + if (!prop->data) + { +- grub_free (prop->name); +- grub_free (prop->name16); + grub_free (prop); + return grub_errno; + } +- grub_memcpy (prop->data, data, prop->length); ++ grub_memcpy (prop->data, data, datalen); ++ ++ prop->name = utf8; ++ prop->name16 = utf16; ++ prop->name16len = utf16len; ++ prop->length = datalen; ++ + grub_list_push (GRUB_AS_LIST_P (&dev->properties), + GRUB_AS_LIST (prop)); + return GRUB_ERR_NONE; +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0011-lzma-Make-sure-we-don-t-dereference-past-array.patch b/buildroot/boot/grub2/0011-lzma-Make-sure-we-don-t-dereference-past-array.patch new file mode 100644 index 000000000..a7d5a48e5 --- /dev/null +++ b/buildroot/boot/grub2/0011-lzma-Make-sure-we-don-t-dereference-past-array.patch @@ -0,0 +1,55 @@ +From 78829f0c230680e386fff9f420bb1631bc20f761 Mon Sep 17 00:00:00 2001 +From: Konrad Rzeszutek Wilk +Date: Thu, 9 Jul 2020 03:05:23 +0000 +Subject: [PATCH] lzma: Make sure we don't dereference past array +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The two dimensional array p->posSlotEncoder[4][64] is being dereferenced +using the GetLenToPosState() macro which checks if len is less than 5, +and if so subtracts 2 from it. If len = 0, that is 0 - 2 = 4294967294. +Obviously we don't want to dereference that far out so we check if the +position found is greater or equal kNumLenToPosStates (4) and bail out. + +N.B.: Upstream LZMA 18.05 and later has this function completely rewritten +without any history. + +Fixes: CID 51526 + +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/lib/LzmaEnc.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/grub-core/lib/LzmaEnc.c b/grub-core/lib/LzmaEnc.c +index f2ec04a8c..753e56a95 100644 +--- a/grub-core/lib/LzmaEnc.c ++++ b/grub-core/lib/LzmaEnc.c +@@ -1877,13 +1877,19 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize + } + else + { +- UInt32 posSlot; ++ UInt32 posSlot, lenToPosState; + RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); + p->state = kMatchNextStates[p->state]; + LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); + pos -= LZMA_NUM_REPS; + GetPosSlot(pos, posSlot); +- RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot); ++ lenToPosState = GetLenToPosState(len); ++ if (lenToPosState >= kNumLenToPosStates) ++ { ++ p->result = SZ_ERROR_DATA; ++ return CheckErrors(p); ++ } ++ RcTree_Encode(&p->rc, p->posSlotEncoder[lenToPosState], kNumPosSlotBits, posSlot); + + if (posSlot >= kStartPosModelIndex) + { +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0012-term-Fix-overflow-on-user-inputs.patch b/buildroot/boot/grub2/0012-term-Fix-overflow-on-user-inputs.patch new file mode 100644 index 000000000..77b01a481 --- /dev/null +++ b/buildroot/boot/grub2/0012-term-Fix-overflow-on-user-inputs.patch @@ -0,0 +1,69 @@ +From 8d3b6f9da468f666e3a7976657f2ab5c52762a21 Mon Sep 17 00:00:00 2001 +From: Konrad Rzeszutek Wilk +Date: Tue, 7 Jul 2020 15:12:25 -0400 +Subject: [PATCH] term: Fix overflow on user inputs +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This requires a very weird input from the serial interface but can cause +an overflow in input_buf (keys) overwriting the next variable (npending) +with the user choice: + +(pahole output) + +struct grub_terminfo_input_state { + int input_buf[6]; /* 0 24 */ + int npending; /* 24 4 */ <- CORRUPT + ...snip... + +The magic string requires causing this is "ESC,O,],0,1,2,q" and we overflow +npending with "q" (aka increase npending to 161). The simplest fix is to +just to disallow overwrites input_buf, which exactly what this patch does. + +Fixes: CID 292449 + +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/term/terminfo.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c +index d317efa36..5fa94c0c3 100644 +--- a/grub-core/term/terminfo.c ++++ b/grub-core/term/terminfo.c +@@ -398,7 +398,7 @@ grub_terminfo_getwh (struct grub_term_output *term) + } + + static void +-grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, ++grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int max_len, + int (*readkey) (struct grub_term_input *term)) + { + int c; +@@ -414,6 +414,9 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, + if (c == -1) \ + return; \ + \ ++ if (*len >= max_len) \ ++ return; \ ++ \ + keys[*len] = c; \ + (*len)++; \ + } +@@ -602,8 +605,8 @@ grub_terminfo_getkey (struct grub_term_input *termi) + return ret; + } + +- grub_terminfo_readkey (termi, data->input_buf, +- &data->npending, data->readkey); ++ grub_terminfo_readkey (termi, data->input_buf, &data->npending, ++ GRUB_TERMINFO_READKEY_MAX_LEN, data->readkey); + + #if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) + if (data->npending == 1 && data->input_buf[0] == GRUB_TERM_ESC +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0013-udf-Fix-memory-leak.patch b/buildroot/boot/grub2/0013-udf-Fix-memory-leak.patch new file mode 100644 index 000000000..d79de9059 --- /dev/null +++ b/buildroot/boot/grub2/0013-udf-Fix-memory-leak.patch @@ -0,0 +1,59 @@ +From 748b691761d31bfff7e9d0d210caa606294c2b52 Mon Sep 17 00:00:00 2001 +From: Konrad Rzeszutek Wilk +Date: Tue, 7 Jul 2020 22:02:31 -0400 +Subject: [PATCH] udf: Fix memory leak +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Fixes: CID 73796 + +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Daniel Kiper +Reviewed-by: Jan Setje-Eilers +Signed-off-by: Stefan Sørensen +--- + grub-core/fs/udf.c | 17 +++++++++++++---- + 1 file changed, 13 insertions(+), 4 deletions(-) + +diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c +index 21ac7f446..2ac5c1d00 100644 +--- a/grub-core/fs/udf.c ++++ b/grub-core/fs/udf.c +@@ -965,8 +965,10 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, + return 0; + + if (grub_udf_read_icb (dir->data, &dirent.icb, child)) +- return 0; +- ++ { ++ grub_free (child); ++ return 0; ++ } + if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT) + { + /* This is the parent directory. */ +@@ -988,11 +990,18 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, + dirent.file_ident_length, + (char *) raw)) + != dirent.file_ident_length) +- return 0; ++ { ++ grub_free (child); ++ return 0; ++ } + + filename = read_string (raw, dirent.file_ident_length, 0); + if (!filename) +- grub_print_error (); ++ { ++ /* As the hook won't get called. */ ++ grub_free (child); ++ grub_print_error (); ++ } + + if (filename && hook (filename, type, child, hook_data)) + { +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0014-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch b/buildroot/boot/grub2/0014-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch new file mode 100644 index 000000000..f3e2a0414 --- /dev/null +++ b/buildroot/boot/grub2/0014-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch @@ -0,0 +1,38 @@ +From 49bf3faa106498e151306fc780c63194a14751e3 Mon Sep 17 00:00:00 2001 +From: Konrad Rzeszutek Wilk +Date: Fri, 26 Jun 2020 10:51:43 -0400 +Subject: [PATCH] multiboot2: Fix memory leak if + grub_create_loader_cmdline() fails +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Fixes: CID 292468 + +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/loader/multiboot_mbi2.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c +index 53da78615..0efc66062 100644 +--- a/grub-core/loader/multiboot_mbi2.c ++++ b/grub-core/loader/multiboot_mbi2.c +@@ -1070,7 +1070,11 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size, + err = grub_create_loader_cmdline (argc, argv, newmod->cmdline, + newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE); + if (err) +- return err; ++ { ++ grub_free (newmod->cmdline); ++ grub_free (newmod); ++ return err; ++ } + + if (modules_last) + modules_last->next = newmod; +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0015-tftp-Do-not-use-priority-queue.patch b/buildroot/boot/grub2/0015-tftp-Do-not-use-priority-queue.patch new file mode 100644 index 000000000..833606bef --- /dev/null +++ b/buildroot/boot/grub2/0015-tftp-Do-not-use-priority-queue.patch @@ -0,0 +1,283 @@ +From b6c4a1b204740fe52b32e7f530831a59f4038e20 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Thu, 9 Jul 2020 08:10:40 +0000 +Subject: [PATCH] tftp: Do not use priority queue +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +There is not need to reassemble the order of blocks. Per RFC 1350, +server must wait for the ACK, before sending next block. Data packets +can be served immediately without putting them to priority queue. + +Logic to handle incoming packet is this: + - if packet block id equal to expected block id, then + process the packet, + - if packet block id is less than expected - this is retransmit + of old packet, then ACK it and drop the packet, + - if packet block id is more than expected - that shouldn't + happen, just drop the packet. + +It makes the tftp receive path code simpler, smaller and faster. +As a benefit, this change fixes CID# 73624 and CID# 96690, caused +by following while loop: + + while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0) + +where tftph pointer is not moving from one iteration to another, causing +to serve same packet again. Luckily, double serving didn't happen due to +data->block++ during the first iteration. + +Fixes: CID 73624, CID 96690 + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/net/tftp.c | 168 ++++++++++++++----------------------------- + 1 file changed, 53 insertions(+), 115 deletions(-) + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index 7d90bf66e..b4297bc8d 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -25,7 +25,6 @@ + #include + #include + #include +-#include + #include + + GRUB_MOD_LICENSE ("GPLv3+"); +@@ -106,31 +105,8 @@ typedef struct tftp_data + int have_oack; + struct grub_error_saved save_err; + grub_net_udp_socket_t sock; +- grub_priority_queue_t pq; + } *tftp_data_t; + +-static int +-cmp_block (grub_uint16_t a, grub_uint16_t b) +-{ +- grub_int16_t i = (grub_int16_t) (a - b); +- if (i > 0) +- return +1; +- if (i < 0) +- return -1; +- return 0; +-} +- +-static int +-cmp (const void *a__, const void *b__) +-{ +- struct grub_net_buff *a_ = *(struct grub_net_buff **) a__; +- struct grub_net_buff *b_ = *(struct grub_net_buff **) b__; +- struct tftphdr *a = (struct tftphdr *) a_->data; +- struct tftphdr *b = (struct tftphdr *) b_->data; +- /* We want the first elements to be on top. */ +- return -cmp_block (grub_be_to_cpu16 (a->u.data.block), grub_be_to_cpu16 (b->u.data.block)); +-} +- + static grub_err_t + ack (tftp_data_t data, grub_uint64_t block) + { +@@ -207,73 +183,60 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), + return GRUB_ERR_NONE; + } + +- err = grub_priority_queue_push (data->pq, &nb); +- if (err) +- return err; +- +- { +- struct grub_net_buff **nb_top_p, *nb_top; +- while (1) +- { +- nb_top_p = grub_priority_queue_top (data->pq); +- if (!nb_top_p) +- return GRUB_ERR_NONE; +- nb_top = *nb_top_p; +- tftph = (struct tftphdr *) nb_top->data; +- if (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) >= 0) +- break; +- ack (data, grub_be_to_cpu16 (tftph->u.data.block)); +- grub_netbuff_free (nb_top); +- grub_priority_queue_pop (data->pq); +- } +- while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0) +- { +- unsigned size; +- +- grub_priority_queue_pop (data->pq); +- +- if (file->device->net->packs.count < 50) ++ /* Ack old/retransmitted block. */ ++ if (grub_be_to_cpu16 (tftph->u.data.block) < data->block + 1) ++ ack (data, grub_be_to_cpu16 (tftph->u.data.block)); ++ /* Ignore unexpected block. */ ++ else if (grub_be_to_cpu16 (tftph->u.data.block) > data->block + 1) ++ grub_dprintf ("tftp", "TFTP unexpected block # %d\n", tftph->u.data.block); ++ else ++ { ++ unsigned size; ++ ++ if (file->device->net->packs.count < 50) ++ { + err = ack (data, data->block + 1); +- else +- { +- file->device->net->stall = 1; +- err = 0; +- } +- if (err) +- return err; +- +- err = grub_netbuff_pull (nb_top, sizeof (tftph->opcode) + +- sizeof (tftph->u.data.block)); +- if (err) +- return err; +- size = nb_top->tail - nb_top->data; +- +- data->block++; +- if (size < data->block_size) +- { +- if (data->ack_sent < data->block) +- ack (data, data->block); +- file->device->net->eof = 1; +- file->device->net->stall = 1; +- grub_net_udp_close (data->sock); +- data->sock = NULL; +- } +- /* Prevent garbage in broken cards. Is it still necessary +- given that IP implementation has been fixed? +- */ +- if (size > data->block_size) +- { +- err = grub_netbuff_unput (nb_top, size - data->block_size); +- if (err) +- return err; +- } +- /* If there is data, puts packet in socket list. */ +- if ((nb_top->tail - nb_top->data) > 0) +- grub_net_put_packet (&file->device->net->packs, nb_top); +- else +- grub_netbuff_free (nb_top); +- } +- } ++ if (err) ++ return err; ++ } ++ else ++ file->device->net->stall = 1; ++ ++ err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + ++ sizeof (tftph->u.data.block)); ++ if (err) ++ return err; ++ size = nb->tail - nb->data; ++ ++ data->block++; ++ if (size < data->block_size) ++ { ++ if (data->ack_sent < data->block) ++ ack (data, data->block); ++ file->device->net->eof = 1; ++ file->device->net->stall = 1; ++ grub_net_udp_close (data->sock); ++ data->sock = NULL; ++ } ++ /* ++ * Prevent garbage in broken cards. Is it still necessary ++ * given that IP implementation has been fixed? ++ */ ++ if (size > data->block_size) ++ { ++ err = grub_netbuff_unput (nb, size - data->block_size); ++ if (err) ++ return err; ++ } ++ /* If there is data, puts packet in socket list. */ ++ if ((nb->tail - nb->data) > 0) ++ { ++ grub_net_put_packet (&file->device->net->packs, nb); ++ /* Do not free nb. */ ++ return GRUB_ERR_NONE; ++ } ++ } ++ grub_netbuff_free (nb); + return GRUB_ERR_NONE; + case TFTP_ERROR: + data->have_oack = 1; +@@ -287,19 +250,6 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), + } + } + +-static void +-destroy_pq (tftp_data_t data) +-{ +- struct grub_net_buff **nb_p; +- while ((nb_p = grub_priority_queue_top (data->pq))) +- { +- grub_netbuff_free (*nb_p); +- grub_priority_queue_pop (data->pq); +- } +- +- grub_priority_queue_destroy (data->pq); +-} +- + static grub_err_t + tftp_open (struct grub_file *file, const char *filename) + { +@@ -372,17 +322,9 @@ tftp_open (struct grub_file *file, const char *filename) + file->not_easily_seekable = 1; + file->data = data; + +- data->pq = grub_priority_queue_new (sizeof (struct grub_net_buff *), cmp); +- if (!data->pq) +- { +- grub_free (data); +- return grub_errno; +- } +- + err = grub_net_resolve_address (file->device->net->server, &addr); + if (err) + { +- destroy_pq (data); + grub_free (data); + return err; + } +@@ -392,7 +334,6 @@ tftp_open (struct grub_file *file, const char *filename) + file); + if (!data->sock) + { +- destroy_pq (data); + grub_free (data); + return grub_errno; + } +@@ -406,7 +347,6 @@ tftp_open (struct grub_file *file, const char *filename) + if (err) + { + grub_net_udp_close (data->sock); +- destroy_pq (data); + grub_free (data); + return err; + } +@@ -423,7 +363,6 @@ tftp_open (struct grub_file *file, const char *filename) + if (grub_errno) + { + grub_net_udp_close (data->sock); +- destroy_pq (data); + grub_free (data); + return grub_errno; + } +@@ -466,7 +405,6 @@ tftp_close (struct grub_file *file) + grub_print_error (); + grub_net_udp_close (data->sock); + } +- destroy_pq (data); + grub_free (data); + return GRUB_ERR_NONE; + } +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0016-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch b/buildroot/boot/grub2/0016-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch new file mode 100644 index 000000000..293b9f89b --- /dev/null +++ b/buildroot/boot/grub2/0016-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch @@ -0,0 +1,153 @@ +From 1c7b619c84f229c1602c1958bcd054b6d9937562 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Wed, 15 Jul 2020 06:42:37 +0000 +Subject: [PATCH] relocator: Protect grub_relocator_alloc_chunk_addr() + input args against integer underflow/overflow +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Use arithmetic macros from safemath.h to accomplish it. In this commit, +I didn't want to be too paranoid to check every possible math equation +for overflow/underflow. Only obvious places (with non zero chance of +overflow/underflow) were refactored. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/loader/i386/linux.c | 9 +++++++-- + grub-core/loader/i386/pc/linux.c | 9 +++++++-- + grub-core/loader/i386/xen.c | 12 ++++++++++-- + grub-core/loader/xnu.c | 11 +++++++---- + 4 files changed, 31 insertions(+), 10 deletions(-) + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index d0501e229..02a73463a 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -547,9 +548,13 @@ grub_linux_boot (void) + + { + grub_relocator_chunk_t ch; ++ grub_size_t sz; ++ ++ if (grub_add (ctx.real_size, efi_mmap_size, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ + err = grub_relocator_alloc_chunk_addr (relocator, &ch, +- ctx.real_mode_target, +- (ctx.real_size + efi_mmap_size)); ++ ctx.real_mode_target, sz); + if (err) + return err; + real_mode_mem = get_virtual_current_address (ch); +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 47ea2945e..31f09922b 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -35,6 +35,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -218,8 +219,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + setup_sects = GRUB_LINUX_DEFAULT_SETUP_SECTS; + + real_size = setup_sects << GRUB_DISK_SECTOR_BITS; +- grub_linux16_prot_size = grub_file_size (file) +- - real_size - GRUB_DISK_SECTOR_SIZE; ++ if (grub_sub (grub_file_size (file), real_size, &grub_linux16_prot_size) || ++ grub_sub (grub_linux16_prot_size, GRUB_DISK_SECTOR_SIZE, &grub_linux16_prot_size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ goto fail; ++ } + + if (! grub_linux_is_bzimage + && GRUB_LINUX_ZIMAGE_ADDR + grub_linux16_prot_size +diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c +index 8f662c8ac..cd24874ca 100644 +--- a/grub-core/loader/i386/xen.c ++++ b/grub-core/loader/i386/xen.c +@@ -41,6 +41,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -636,6 +637,7 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), + grub_relocator_chunk_t ch; + grub_addr_t kern_start; + grub_addr_t kern_end; ++ grub_size_t sz; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); +@@ -703,8 +705,14 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), + + xen_state.max_addr = ALIGN_UP (kern_end, PAGE_SIZE); + +- err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, +- kern_end - kern_start); ++ ++ if (grub_sub (kern_end, kern_start, &sz)) ++ { ++ err = GRUB_ERR_OUT_OF_RANGE; ++ goto fail; ++ } ++ ++ err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, sz); + if (err) + goto fail; + kern_chunk_src = get_virtual_current_address (ch); +diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c +index 77d7060e1..9ae4ceb35 100644 +--- a/grub-core/loader/xnu.c ++++ b/grub-core/loader/xnu.c +@@ -34,6 +34,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -59,15 +60,17 @@ grub_xnu_heap_malloc (int size, void **src, grub_addr_t *target) + { + grub_err_t err; + grub_relocator_chunk_t ch; ++ grub_addr_t tgt; ++ ++ if (grub_add (grub_xnu_heap_target_start, grub_xnu_heap_size, &tgt)) ++ return GRUB_ERR_OUT_OF_RANGE; + +- err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, +- grub_xnu_heap_target_start +- + grub_xnu_heap_size, size); ++ err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, tgt, size); + if (err) + return err; + + *src = get_virtual_current_address (ch); +- *target = grub_xnu_heap_target_start + grub_xnu_heap_size; ++ *target = tgt; + grub_xnu_heap_size += size; + grub_dprintf ("xnu", "val=%p\n", *src); + return GRUB_ERR_NONE; +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0017-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch b/buildroot/boot/grub2/0017-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch new file mode 100644 index 000000000..e04e72aba --- /dev/null +++ b/buildroot/boot/grub2/0017-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch @@ -0,0 +1,341 @@ +From 0cfbbca3ccd84d36ffb1bcd6644ada7c73b19fc0 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Wed, 8 Jul 2020 01:44:38 +0000 +Subject: [PATCH] relocator: Protect grub_relocator_alloc_chunk_align() + max_addr against integer underflow +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This commit introduces integer underflow mitigation in max_addr calculation +in grub_relocator_alloc_chunk_align() invocation. + +It consists of 2 fixes: + 1. Introduced grub_relocator_alloc_chunk_align_safe() wrapper function to perform + sanity check for min/max and size values, and to make safe invocation of + grub_relocator_alloc_chunk_align() with validated max_addr value. Replace all + invocations such as grub_relocator_alloc_chunk_align(..., min_addr, max_addr - size, size, ...) + by grub_relocator_alloc_chunk_align_safe(..., min_addr, max_addr, size, ...). + 2. Introduced UP_TO_TOP32(s) macro for the cases where max_addr is 32-bit top + address (0xffffffff - size + 1) or similar. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/lib/i386/relocator.c | 28 ++++++++++---------------- + grub-core/lib/mips/relocator.c | 6 ++---- + grub-core/lib/powerpc/relocator.c | 6 ++---- + grub-core/lib/x86_64/efi/relocator.c | 7 +++---- + grub-core/loader/i386/linux.c | 5 ++--- + grub-core/loader/i386/multiboot_mbi.c | 7 +++---- + grub-core/loader/i386/pc/linux.c | 6 ++---- + grub-core/loader/mips/linux.c | 9 +++------ + grub-core/loader/multiboot.c | 2 +- + grub-core/loader/multiboot_elfxx.c | 10 ++++----- + grub-core/loader/multiboot_mbi2.c | 10 ++++----- + grub-core/loader/xnu_resume.c | 2 +- + include/grub/relocator.h | 29 +++++++++++++++++++++++++++ + 13 files changed, 69 insertions(+), 58 deletions(-) + +diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c +index 71dd4f0ab..34cbe834f 100644 +--- a/grub-core/lib/i386/relocator.c ++++ b/grub-core/lib/i386/relocator.c +@@ -83,11 +83,10 @@ grub_relocator32_boot (struct grub_relocator *rel, + /* Specific memory range due to Global Descriptor Table for use by payload + that we will store in returned chunk. The address range and preference + are based on "THE LINUX/x86 BOOT PROTOCOL" specification. */ +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0x1000, +- 0x9a000 - RELOCATOR_SIZEOF (32), +- RELOCATOR_SIZEOF (32), 16, +- GRUB_RELOCATOR_PREFERENCE_LOW, +- avoid_efi_bootservices); ++ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x1000, 0x9a000, ++ RELOCATOR_SIZEOF (32), 16, ++ GRUB_RELOCATOR_PREFERENCE_LOW, ++ avoid_efi_bootservices); + if (err) + return err; + +@@ -125,13 +124,10 @@ grub_relocator16_boot (struct grub_relocator *rel, + grub_relocator_chunk_t ch; + + /* Put it higher than the byte it checks for A20 check. */ +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0x8010, +- 0xa0000 - RELOCATOR_SIZEOF (16) +- - GRUB_RELOCATOR16_STACK_SIZE, +- RELOCATOR_SIZEOF (16) +- + GRUB_RELOCATOR16_STACK_SIZE, 16, +- GRUB_RELOCATOR_PREFERENCE_NONE, +- 0); ++ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x8010, 0xa0000, ++ RELOCATOR_SIZEOF (16) + ++ GRUB_RELOCATOR16_STACK_SIZE, 16, ++ GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; + +@@ -183,11 +179,9 @@ grub_relocator64_boot (struct grub_relocator *rel, + void *relst; + grub_relocator_chunk_t ch; + +- err = grub_relocator_alloc_chunk_align (rel, &ch, min_addr, +- max_addr - RELOCATOR_SIZEOF (64), +- RELOCATOR_SIZEOF (64), 16, +- GRUB_RELOCATOR_PREFERENCE_NONE, +- 0); ++ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, min_addr, max_addr, ++ RELOCATOR_SIZEOF (64), 16, ++ GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; + +diff --git a/grub-core/lib/mips/relocator.c b/grub-core/lib/mips/relocator.c +index 9d5f49cb9..743b213e6 100644 +--- a/grub-core/lib/mips/relocator.c ++++ b/grub-core/lib/mips/relocator.c +@@ -120,10 +120,8 @@ grub_relocator32_boot (struct grub_relocator *rel, + unsigned i; + grub_addr_t vtarget; + +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, +- (0xffffffff - stateset_size) +- + 1, stateset_size, +- sizeof (grub_uint32_t), ++ err = grub_relocator_alloc_chunk_align (rel, &ch, 0, UP_TO_TOP32 (stateset_size), ++ stateset_size, sizeof (grub_uint32_t), + GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; +diff --git a/grub-core/lib/powerpc/relocator.c b/grub-core/lib/powerpc/relocator.c +index bdf2b111b..8ffb8b686 100644 +--- a/grub-core/lib/powerpc/relocator.c ++++ b/grub-core/lib/powerpc/relocator.c +@@ -115,10 +115,8 @@ grub_relocator32_boot (struct grub_relocator *rel, + unsigned i; + grub_relocator_chunk_t ch; + +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, +- (0xffffffff - stateset_size) +- + 1, stateset_size, +- sizeof (grub_uint32_t), ++ err = grub_relocator_alloc_chunk_align (rel, &ch, 0, UP_TO_TOP32 (stateset_size), ++ stateset_size, sizeof (grub_uint32_t), + GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; +diff --git a/grub-core/lib/x86_64/efi/relocator.c b/grub-core/lib/x86_64/efi/relocator.c +index 3caef7a40..7d200a125 100644 +--- a/grub-core/lib/x86_64/efi/relocator.c ++++ b/grub-core/lib/x86_64/efi/relocator.c +@@ -50,10 +50,9 @@ grub_relocator64_efi_boot (struct grub_relocator *rel, + * 64-bit relocator code may live above 4 GiB quite well. + * However, I do not want ask for problems. Just in case. + */ +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, +- 0x100000000 - RELOCATOR_SIZEOF (64_efi), +- RELOCATOR_SIZEOF (64_efi), 16, +- GRUB_RELOCATOR_PREFERENCE_NONE, 1); ++ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0, 0x100000000, ++ RELOCATOR_SIZEOF (64_efi), 16, ++ GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) + return err; + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 02a73463a..efbb99307 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -181,9 +181,8 @@ allocate_pages (grub_size_t prot_size, grub_size_t *align, + for (; err && *align + 1 > min_align; (*align)--) + { + grub_errno = GRUB_ERR_NONE; +- err = grub_relocator_alloc_chunk_align (relocator, &ch, +- 0x1000000, +- 0xffffffff & ~prot_size, ++ err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, ++ UP_TO_TOP32 (prot_size), + prot_size, 1 << *align, + GRUB_RELOCATOR_PREFERENCE_LOW, + 1); +diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c +index ad3cc292f..a67d9d0a8 100644 +--- a/grub-core/loader/i386/multiboot_mbi.c ++++ b/grub-core/loader/i386/multiboot_mbi.c +@@ -466,10 +466,9 @@ grub_multiboot_make_mbi (grub_uint32_t *target) + + bufsize = grub_multiboot_get_mbi_size (); + +- err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, +- 0x10000, 0xa0000 - bufsize, +- bufsize, 4, +- GRUB_RELOCATOR_PREFERENCE_NONE, 0); ++ err = grub_relocator_alloc_chunk_align_safe (grub_multiboot_relocator, &ch, ++ 0x10000, 0xa0000, bufsize, 4, ++ GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; + ptrorig = get_virtual_current_address (ch); +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 31f09922b..5fed5ffdf 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -453,10 +453,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + + { + grub_relocator_chunk_t ch; +- err = grub_relocator_alloc_chunk_align (relocator, &ch, +- addr_min, addr_max - size, +- size, 0x1000, +- GRUB_RELOCATOR_PREFERENCE_HIGH, 0); ++ err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, addr_min, addr_max, size, ++ 0x1000, GRUB_RELOCATOR_PREFERENCE_HIGH, 0); + if (err) + return err; + initrd_chunk = get_virtual_current_address (ch); +diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c +index 7b723bf18..e4ed95921 100644 +--- a/grub-core/loader/mips/linux.c ++++ b/grub-core/loader/mips/linux.c +@@ -442,12 +442,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + { + grub_relocator_chunk_t ch; + +- err = grub_relocator_alloc_chunk_align (relocator, &ch, +- (target_addr & 0x1fffffff) +- + linux_size + 0x10000, +- (0x10000000 - size), +- size, 0x10000, +- GRUB_RELOCATOR_PREFERENCE_NONE, 0); ++ err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, (target_addr & 0x1fffffff) + ++ linux_size + 0x10000, 0x10000000, size, ++ 0x10000, GRUB_RELOCATOR_PREFERENCE_NONE, 0); + + if (err) + goto fail; +diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c +index 4a98d7082..facb13f3d 100644 +--- a/grub-core/loader/multiboot.c ++++ b/grub-core/loader/multiboot.c +@@ -403,7 +403,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), + { + grub_relocator_chunk_t ch; + err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, +- lowest_addr, (0xffffffff - size) + 1, ++ lowest_addr, UP_TO_TOP32 (size), + size, MULTIBOOT_MOD_ALIGN, + GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) +diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c +index cc6853692..f2318e0d1 100644 +--- a/grub-core/loader/multiboot_elfxx.c ++++ b/grub-core/loader/multiboot_elfxx.c +@@ -109,10 +109,10 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) + if (load_size > mld->max_addr || mld->min_addr > mld->max_addr - load_size) + return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size"); + +- err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, +- mld->min_addr, mld->max_addr - load_size, +- load_size, mld->align ? mld->align : 1, +- mld->preference, mld->avoid_efi_boot_services); ++ err = grub_relocator_alloc_chunk_align_safe (GRUB_MULTIBOOT (relocator), &ch, ++ mld->min_addr, mld->max_addr, ++ load_size, mld->align ? mld->align : 1, ++ mld->preference, mld->avoid_efi_boot_services); + + if (err) + { +@@ -256,7 +256,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) + continue; + + err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, 0, +- (0xffffffff - sh->sh_size) + 1, ++ UP_TO_TOP32 (sh->sh_size), + sh->sh_size, sh->sh_addralign, + GRUB_RELOCATOR_PREFERENCE_NONE, + mld->avoid_efi_boot_services); +diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c +index 0efc66062..03967839c 100644 +--- a/grub-core/loader/multiboot_mbi2.c ++++ b/grub-core/loader/multiboot_mbi2.c +@@ -295,10 +295,10 @@ grub_multiboot2_load (grub_file_t file, const char *filename) + return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size"); + } + +- err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, +- mld.min_addr, mld.max_addr - code_size, +- code_size, mld.align ? mld.align : 1, +- mld.preference, keep_bs); ++ err = grub_relocator_alloc_chunk_align_safe (grub_multiboot2_relocator, &ch, ++ mld.min_addr, mld.max_addr, ++ code_size, mld.align ? mld.align : 1, ++ mld.preference, keep_bs); + } + else + err = grub_relocator_alloc_chunk_addr (grub_multiboot2_relocator, +@@ -708,7 +708,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) + COMPILE_TIME_ASSERT (MULTIBOOT_TAG_ALIGN % sizeof (grub_properly_aligned_t) == 0); + + err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, +- 0, 0xffffffff - bufsize, ++ 0, UP_TO_TOP32 (bufsize), + bufsize, MULTIBOOT_TAG_ALIGN, + GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) +diff --git a/grub-core/loader/xnu_resume.c b/grub-core/loader/xnu_resume.c +index 8089804d4..d648ef0cd 100644 +--- a/grub-core/loader/xnu_resume.c ++++ b/grub-core/loader/xnu_resume.c +@@ -129,7 +129,7 @@ grub_xnu_resume (char *imagename) + { + grub_relocator_chunk_t ch; + err = grub_relocator_alloc_chunk_align (grub_xnu_relocator, &ch, 0, +- (0xffffffff - hibhead.image_size) + 1, ++ UP_TO_TOP32 (hibhead.image_size), + hibhead.image_size, + GRUB_XNU_PAGESIZE, + GRUB_RELOCATOR_PREFERENCE_NONE, 0); +diff --git a/include/grub/relocator.h b/include/grub/relocator.h +index 24d8672d2..1b3bdd92a 100644 +--- a/include/grub/relocator.h ++++ b/include/grub/relocator.h +@@ -49,6 +49,35 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, + int preference, + int avoid_efi_boot_services); + ++/* ++ * Wrapper for grub_relocator_alloc_chunk_align() with purpose of ++ * protecting against integer underflow. ++ * ++ * Compare to its callee, max_addr has different meaning here. ++ * It covers entire chunk and not just start address of the chunk. ++ */ ++static inline grub_err_t ++grub_relocator_alloc_chunk_align_safe (struct grub_relocator *rel, ++ grub_relocator_chunk_t *out, ++ grub_phys_addr_t min_addr, ++ grub_phys_addr_t max_addr, ++ grub_size_t size, grub_size_t align, ++ int preference, ++ int avoid_efi_boot_services) ++{ ++ /* Sanity check and ensure following equation (max_addr - size) is safe. */ ++ if (max_addr < size || (max_addr - size) < min_addr) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ return grub_relocator_alloc_chunk_align (rel, out, min_addr, ++ max_addr - size, ++ size, align, preference, ++ avoid_efi_boot_services); ++} ++ ++/* Top 32-bit address minus s bytes and plus 1 byte. */ ++#define UP_TO_TOP32(s) ((~(s) & 0xffffffff) + 1) ++ + #define GRUB_RELOCATOR_PREFERENCE_NONE 0 + #define GRUB_RELOCATOR_PREFERENCE_LOW 1 + #define GRUB_RELOCATOR_PREFERENCE_HIGH 2 +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0018-script-Remove-unused-fields-from-grub_script_functio.patch b/buildroot/boot/grub2/0018-script-Remove-unused-fields-from-grub_script_functio.patch new file mode 100644 index 000000000..7b0a5e514 --- /dev/null +++ b/buildroot/boot/grub2/0018-script-Remove-unused-fields-from-grub_script_functio.patch @@ -0,0 +1,37 @@ +From 73aa0776457066ee6ebc93486c3cf0e6b755d1b8 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Fri, 10 Jul 2020 11:21:14 +0100 +Subject: [PATCH] script: Remove unused fields from grub_script_function + struct +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Chris Coulson +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + include/grub/script_sh.h | 5 ----- + 1 file changed, 5 deletions(-) + +diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h +index 360c2be1f..b382bcf09 100644 +--- a/include/grub/script_sh.h ++++ b/include/grub/script_sh.h +@@ -359,13 +359,8 @@ struct grub_script_function + /* The script function. */ + struct grub_script *func; + +- /* The flags. */ +- unsigned flags; +- + /* The next element. */ + struct grub_script_function *next; +- +- int references; + }; + typedef struct grub_script_function *grub_script_function_t; + +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0019-script-Avoid-a-use-after-free-when-redefining-a-func.patch b/buildroot/boot/grub2/0019-script-Avoid-a-use-after-free-when-redefining-a-func.patch new file mode 100644 index 000000000..0fd60357d --- /dev/null +++ b/buildroot/boot/grub2/0019-script-Avoid-a-use-after-free-when-redefining-a-func.patch @@ -0,0 +1,113 @@ +From 26349fcf80982b4d0120b73b2836e88bcf16853c Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Fri, 10 Jul 2020 14:41:45 +0100 +Subject: [PATCH] script: Avoid a use-after-free when redefining a + function during execution +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Defining a new function with the same name as a previously defined +function causes the grub_script and associated resources for the +previous function to be freed. If the previous function is currently +executing when a function with the same name is defined, this results +in use-after-frees when processing subsequent commands in the original +function. + +Instead, reject a new function definition if it has the same name as +a previously defined function, and that function is currently being +executed. Although a behavioural change, this should be backwards +compatible with existing configurations because they can't be +dependent on the current behaviour without being broken. + +Fixes: CVE-2020-15706 + +Signed-off-by: Chris Coulson +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/script/execute.c | 2 ++ + grub-core/script/function.c | 16 +++++++++++++--- + grub-core/script/parser.y | 3 ++- + include/grub/script_sh.h | 2 ++ + 4 files changed, 19 insertions(+), 4 deletions(-) + +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index c8d6806fe..7e028e135 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -838,7 +838,9 @@ grub_script_function_call (grub_script_function_t func, int argc, char **args) + old_scope = scope; + scope = &new_scope; + ++ func->executing++; + ret = grub_script_execute (func->func); ++ func->executing--; + + function_return = 0; + active_loops = loops; +diff --git a/grub-core/script/function.c b/grub-core/script/function.c +index d36655e51..3aad04bf9 100644 +--- a/grub-core/script/function.c ++++ b/grub-core/script/function.c +@@ -34,6 +34,7 @@ grub_script_function_create (struct grub_script_arg *functionname_arg, + func = (grub_script_function_t) grub_malloc (sizeof (*func)); + if (! func) + return 0; ++ func->executing = 0; + + func->name = grub_strdup (functionname_arg->str); + if (! func->name) +@@ -60,10 +61,19 @@ grub_script_function_create (struct grub_script_arg *functionname_arg, + grub_script_function_t q; + + q = *p; +- grub_script_free (q->func); +- q->func = cmd; + grub_free (func); +- func = q; ++ if (q->executing > 0) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, ++ N_("attempt to redefine a function being executed")); ++ func = NULL; ++ } ++ else ++ { ++ grub_script_free (q->func); ++ q->func = cmd; ++ func = q; ++ } + } + else + { +diff --git a/grub-core/script/parser.y b/grub-core/script/parser.y +index 4f0ab8319..f80b86b6f 100644 +--- a/grub-core/script/parser.y ++++ b/grub-core/script/parser.y +@@ -289,7 +289,8 @@ function: "function" "name" + grub_script_mem_free (state->func_mem); + else { + script->children = state->scripts; +- grub_script_function_create ($2, script); ++ if (!grub_script_function_create ($2, script)) ++ grub_script_free (script); + } + + state->scripts = $3; +diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h +index b382bcf09..6c48e0751 100644 +--- a/include/grub/script_sh.h ++++ b/include/grub/script_sh.h +@@ -361,6 +361,8 @@ struct grub_script_function + + /* The next element. */ + struct grub_script_function *next; ++ ++ unsigned executing; + }; + typedef struct grub_script_function *grub_script_function_t; + +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0020-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch b/buildroot/boot/grub2/0020-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch new file mode 100644 index 000000000..fc518c5f3 --- /dev/null +++ b/buildroot/boot/grub2/0020-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch @@ -0,0 +1,49 @@ +From 06aa91f79f902752cb7e5d22ac0ea8e13bffd056 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Fri, 17 Jul 2020 05:17:26 +0000 +Subject: [PATCH] relocator: Fix grub_relocator_alloc_chunk_align() top + memory allocation +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Current implementation of grub_relocator_alloc_chunk_align() +does not allow allocation of the top byte. + +Assuming input args are: + max_addr = 0xfffff000; + size = 0x1000; + +And this is valid. But following overflow protection will +unnecessarily move max_addr one byte down (to 0xffffefff): + if (max_addr > ~size) + max_addr = ~size; + +~size + 1 will fix the situation. In addition, check size +for non zero to do not zero max_addr. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/lib/relocator.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c +index 5847aac36..f2c1944c2 100644 +--- a/grub-core/lib/relocator.c ++++ b/grub-core/lib/relocator.c +@@ -1386,8 +1386,8 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, + }; + grub_addr_t min_addr2 = 0, max_addr2; + +- if (max_addr > ~size) +- max_addr = ~size; ++ if (size && (max_addr > ~size)) ++ max_addr = ~size + 1; + + #ifdef GRUB_MACHINE_PCBIOS + if (min_addr < 0x1000) +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0021-hfsplus-Fix-two-more-overflows.patch b/buildroot/boot/grub2/0021-hfsplus-Fix-two-more-overflows.patch new file mode 100644 index 000000000..9ea678021 --- /dev/null +++ b/buildroot/boot/grub2/0021-hfsplus-Fix-two-more-overflows.patch @@ -0,0 +1,61 @@ +From feec993673d8e13fcf22fe2389ac29222b6daebd Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 14:43:31 -0400 +Subject: [PATCH] hfsplus: Fix two more overflows +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Both node->size and node->namelen come from the supplied filesystem, +which may be user-supplied. We can't trust them for the math unless we +know they don't overflow. Making sure they go through grub_add() or +grub_calloc() first will give us that. + +Signed-off-by: Peter Jones +Reviewed-by: Darren Kenny +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/fs/hfsplus.c | 11 ++++++++--- + 1 file changed, 8 insertions(+), 3 deletions(-) + +diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c +index dae43becc..9c4e4c88c 100644 +--- a/grub-core/fs/hfsplus.c ++++ b/grub-core/fs/hfsplus.c +@@ -31,6 +31,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -475,8 +476,12 @@ grub_hfsplus_read_symlink (grub_fshelp_node_t node) + { + char *symlink; + grub_ssize_t numread; ++ grub_size_t sz = node->size; + +- symlink = grub_malloc (node->size + 1); ++ if (grub_add (sz, 1, &sz)) ++ return NULL; ++ ++ symlink = grub_malloc (sz); + if (!symlink) + return 0; + +@@ -715,8 +720,8 @@ list_nodes (void *record, void *hook_arg) + if (type == GRUB_FSHELP_UNKNOWN) + return 0; + +- filename = grub_malloc (grub_be_to_cpu16 (catkey->namelen) +- * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ filename = grub_calloc (grub_be_to_cpu16 (catkey->namelen), ++ GRUB_MAX_UTF8_PER_UTF16 + 1); + if (! filename) + return 0; + +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0022-lvm-Fix-two-more-potential-data-dependent-alloc-over.patch b/buildroot/boot/grub2/0022-lvm-Fix-two-more-potential-data-dependent-alloc-over.patch new file mode 100644 index 000000000..ad97ad0b1 --- /dev/null +++ b/buildroot/boot/grub2/0022-lvm-Fix-two-more-potential-data-dependent-alloc-over.patch @@ -0,0 +1,116 @@ +From a1845e90fc19fb5e904091bad8a378f458798e4a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 15:48:20 -0400 +Subject: [PATCH] lvm: Fix two more potential data-dependent alloc + overflows +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +It appears to be possible to make a (possibly invalid) lvm PV with +a metadata size field that overflows our type when adding it to the +address we've allocated. Even if it doesn't, it may be possible to do so +with the math using the outcome of that as an operand. Check them both. + +Signed-off-by: Peter Jones +Signed-off-by: Darren Kenny +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/disk/lvm.c | 48 ++++++++++++++++++++++++++++++++++++-------- + 1 file changed, 40 insertions(+), 8 deletions(-) + +diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c +index d1df640b3..139fafd47 100644 +--- a/grub-core/disk/lvm.c ++++ b/grub-core/disk/lvm.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + #ifdef GRUB_UTIL + #include +@@ -102,10 +103,11 @@ grub_lvm_detect (grub_disk_t disk, + { + grub_err_t err; + grub_uint64_t mda_offset, mda_size; ++ grub_size_t ptr; + char buf[GRUB_LVM_LABEL_SIZE]; + char vg_id[GRUB_LVM_ID_STRLEN+1]; + char pv_id[GRUB_LVM_ID_STRLEN+1]; +- char *metadatabuf, *p, *q, *vgname; ++ char *metadatabuf, *p, *q, *mda_end, *vgname; + struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; + struct grub_lvm_pv_header *pvh; + struct grub_lvm_disk_locn *dlocn; +@@ -205,19 +207,31 @@ grub_lvm_detect (grub_disk_t disk, + grub_le_to_cpu64 (rlocn->size) - + grub_le_to_cpu64 (mdah->size)); + } +- p = q = metadatabuf + grub_le_to_cpu64 (rlocn->offset); + +- while (*q != ' ' && q < metadatabuf + mda_size) +- q++; +- +- if (q == metadatabuf + mda_size) ++ if (grub_add ((grub_size_t)metadatabuf, ++ (grub_size_t)grub_le_to_cpu64 (rlocn->offset), ++ &ptr)) + { ++ error_parsing_metadata: + #ifdef GRUB_UTIL + grub_util_info ("error parsing metadata"); + #endif + goto fail2; + } + ++ p = q = (char *)ptr; ++ ++ if (grub_add ((grub_size_t)metadatabuf, (grub_size_t)mda_size, &ptr)) ++ goto error_parsing_metadata; ++ ++ mda_end = (char *)ptr; ++ ++ while (*q != ' ' && q < mda_end) ++ q++; ++ ++ if (q == mda_end) ++ goto error_parsing_metadata; ++ + vgname_len = q - p; + vgname = grub_malloc (vgname_len + 1); + if (!vgname) +@@ -367,8 +381,26 @@ grub_lvm_detect (grub_disk_t disk, + { + const char *iptr; + char *optr; +- lv->fullname = grub_malloc (sizeof ("lvm/") - 1 + 2 * vgname_len +- + 1 + 2 * s + 1); ++ ++ /* ++ * This is kind of hard to read with our safe (but rather ++ * baroque) math primatives, but it boils down to: ++ * ++ * sz0 = vgname_len * 2 + 1 + ++ * s * 2 + 1 + ++ * sizeof ("lvm/") - 1; ++ */ ++ grub_size_t sz0 = vgname_len, sz1 = s; ++ ++ if (grub_mul (sz0, 2, &sz0) || ++ grub_add (sz0, 1, &sz0) || ++ grub_mul (sz1, 2, &sz1) || ++ grub_add (sz1, 1, &sz1) || ++ grub_add (sz0, sz1, &sz0) || ++ grub_add (sz0, sizeof ("lvm/") - 1, &sz0)) ++ goto lvs_fail; ++ ++ lv->fullname = grub_malloc (sz0); + if (!lv->fullname) + goto lvs_fail; + +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0023-emu-Make-grub_free-NULL-safe.patch b/buildroot/boot/grub2/0023-emu-Make-grub_free-NULL-safe.patch new file mode 100644 index 000000000..f30e56a8b --- /dev/null +++ b/buildroot/boot/grub2/0023-emu-Make-grub_free-NULL-safe.patch @@ -0,0 +1,38 @@ +From 320e86747a32e4d46d24ee4b64493741c161da50 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 16:08:08 -0400 +Subject: [PATCH] emu: Make grub_free(NULL) safe +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The grub_free() implementation in grub-core/kern/mm.c safely handles +NULL pointers, and code at many places depends on this. We don't know +that the same is true on all host OSes, so we need to handle the same +behavior in grub-emu's implementation. + +Signed-off-by: Peter Jones +Reviewed-by: Darren Kenny +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/kern/emu/mm.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/emu/mm.c b/grub-core/kern/emu/mm.c +index 145b01d37..4d1046a21 100644 +--- a/grub-core/kern/emu/mm.c ++++ b/grub-core/kern/emu/mm.c +@@ -60,7 +60,8 @@ grub_zalloc (grub_size_t size) + void + grub_free (void *ptr) + { +- free (ptr); ++ if (ptr) ++ free (ptr); + } + + void * +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0024-efi-Fix-some-malformed-device-path-arithmetic-errors.patch b/buildroot/boot/grub2/0024-efi-Fix-some-malformed-device-path-arithmetic-errors.patch new file mode 100644 index 000000000..48b5b8912 --- /dev/null +++ b/buildroot/boot/grub2/0024-efi-Fix-some-malformed-device-path-arithmetic-errors.patch @@ -0,0 +1,239 @@ +From c330aa099a38bc5c4d3066954fe35767cc06adb1 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 16:53:27 -0400 +Subject: [PATCH] efi: Fix some malformed device path arithmetic errors +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Several places we take the length of a device path and subtract 4 from +it, without ever checking that it's >= 4. There are also cases where +this kind of malformation will result in unpredictable iteration, +including treating the length from one dp node as the type in the next +node. These are all errors, no matter where the data comes from. + +This patch adds a checking macro, GRUB_EFI_DEVICE_PATH_VALID(), which +can be used in several places, and makes GRUB_EFI_NEXT_DEVICE_PATH() +return NULL and GRUB_EFI_END_ENTIRE_DEVICE_PATH() evaluate as true when +the length is too small. Additionally, it makes several places in the +code check for and return errors in these cases. + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/kern/efi/efi.c | 64 +++++++++++++++++++++++++----- + grub-core/loader/efi/chainloader.c | 13 +++++- + grub-core/loader/i386/xnu.c | 9 +++-- + include/grub/efi/api.h | 14 ++++--- + 4 files changed, 79 insertions(+), 21 deletions(-) + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index dc31caa21..c97969a65 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -332,7 +332,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + + dp = dp0; + +- while (1) ++ while (dp) + { + grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); + grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); +@@ -342,9 +342,15 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + if (type == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE + && subtype == GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE) + { +- grub_efi_uint16_t len; +- len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) +- / sizeof (grub_efi_char16_t)); ++ grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ ++ if (len < 4) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "malformed EFI Device Path node has length=%d", len); ++ return NULL; ++ } ++ len = (len - 4) / sizeof (grub_efi_char16_t); + filesize += GRUB_MAX_UTF8_PER_UTF16 * len + 2; + } + +@@ -360,7 +366,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + if (!name) + return NULL; + +- while (1) ++ while (dp) + { + grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); + grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); +@@ -376,8 +382,15 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + + *p++ = '/'; + +- len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) +- / sizeof (grub_efi_char16_t)); ++ len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ if (len < 4) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "malformed EFI Device Path node has length=%d", len); ++ return NULL; ++ } ++ ++ len = (len - 4) / sizeof (grub_efi_char16_t); + fp = (grub_efi_file_path_device_path_t *) dp; + /* According to EFI spec Path Name is NULL terminated */ + while (len > 0 && fp->path_name[len - 1] == 0) +@@ -452,7 +465,26 @@ grub_efi_duplicate_device_path (const grub_efi_device_path_t *dp) + ; + p = GRUB_EFI_NEXT_DEVICE_PATH (p)) + { +- total_size += GRUB_EFI_DEVICE_PATH_LENGTH (p); ++ grub_size_t len = GRUB_EFI_DEVICE_PATH_LENGTH (p); ++ ++ /* ++ * In the event that we find a node that's completely garbage, for ++ * example if we get to 0x7f 0x01 0x02 0x00 ... (EndInstance with a size ++ * of 2), GRUB_EFI_END_ENTIRE_DEVICE_PATH() will be true and ++ * GRUB_EFI_NEXT_DEVICE_PATH() will return NULL, so we won't continue, ++ * and neither should our consumers, but there won't be any error raised ++ * even though the device path is junk. ++ * ++ * This keeps us from passing junk down back to our caller. ++ */ ++ if (len < 4) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "malformed EFI Device Path node has length=%d", len); ++ return NULL; ++ } ++ ++ total_size += len; + if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (p)) + break; + } +@@ -497,7 +529,7 @@ dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor) + void + grub_efi_print_device_path (grub_efi_device_path_t *dp) + { +- while (1) ++ while (GRUB_EFI_DEVICE_PATH_VALID (dp)) + { + grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); + grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); +@@ -909,7 +941,10 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, + /* Return non-zero. */ + return 1; + +- while (1) ++ if (dp1 == dp2) ++ return 0; ++ ++ while (GRUB_EFI_DEVICE_PATH_VALID (dp1) && GRUB_EFI_DEVICE_PATH_VALID (dp2)) + { + grub_efi_uint8_t type1, type2; + grub_efi_uint8_t subtype1, subtype2; +@@ -945,5 +980,14 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, + dp2 = (grub_efi_device_path_t *) ((char *) dp2 + len2); + } + ++ /* ++ * There's no "right" answer here, but we probably don't want to call a valid ++ * dp and an invalid dp equal, so pick one way or the other. ++ */ ++ if (GRUB_EFI_DEVICE_PATH_VALID (dp1) && !GRUB_EFI_DEVICE_PATH_VALID (dp2)) ++ return 1; ++ else if (!GRUB_EFI_DEVICE_PATH_VALID (dp1) && GRUB_EFI_DEVICE_PATH_VALID (dp2)) ++ return -1; ++ + return 0; + } +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index daf8c6b54..a8d7b9155 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -156,9 +156,18 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + + size = 0; + d = dp; +- while (1) ++ while (d) + { +- size += GRUB_EFI_DEVICE_PATH_LENGTH (d); ++ grub_size_t len = GRUB_EFI_DEVICE_PATH_LENGTH (d); ++ ++ if (len < 4) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "malformed EFI Device Path node has length=%d", len); ++ return NULL; ++ } ++ ++ size += len; + if ((GRUB_EFI_END_ENTIRE_DEVICE_PATH (d))) + break; + d = GRUB_EFI_NEXT_DEVICE_PATH (d); +diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c +index e9e119259..a70093607 100644 +--- a/grub-core/loader/i386/xnu.c ++++ b/grub-core/loader/i386/xnu.c +@@ -515,14 +515,15 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)), + + devhead = buf; + buf = devhead + 1; +- dpstart = buf; ++ dp = dpstart = buf; + +- do ++ while (GRUB_EFI_DEVICE_PATH_VALID (dp) && buf < bufend) + { +- dp = buf; + buf = (char *) buf + GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) ++ break; ++ dp = buf; + } +- while (!GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp) && buf < bufend); + + dev = grub_xnu_devprop_add_device (dpstart, (char *) buf + - (char *) dpstart); +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index addcbfa8f..cf1355a8c 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -625,6 +625,7 @@ typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; + #define GRUB_EFI_DEVICE_PATH_TYPE(dp) ((dp)->type & 0x7f) + #define GRUB_EFI_DEVICE_PATH_SUBTYPE(dp) ((dp)->subtype) + #define GRUB_EFI_DEVICE_PATH_LENGTH(dp) ((dp)->length) ++#define GRUB_EFI_DEVICE_PATH_VALID(dp) ((dp) != NULL && GRUB_EFI_DEVICE_PATH_LENGTH (dp) >= 4) + + /* The End of Device Path nodes. */ + #define GRUB_EFI_END_DEVICE_PATH_TYPE (0xff & 0x7f) +@@ -633,13 +634,16 @@ typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; + #define GRUB_EFI_END_THIS_DEVICE_PATH_SUBTYPE 0x01 + + #define GRUB_EFI_END_ENTIRE_DEVICE_PATH(dp) \ +- (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \ +- && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \ +- == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)) ++ (!GRUB_EFI_DEVICE_PATH_VALID (dp) || \ ++ (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \ ++ && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \ ++ == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE))) + + #define GRUB_EFI_NEXT_DEVICE_PATH(dp) \ +- ((grub_efi_device_path_t *) ((char *) (dp) \ +- + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) ++ (GRUB_EFI_DEVICE_PATH_VALID (dp) \ ++ ? ((grub_efi_device_path_t *) \ ++ ((char *) (dp) + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) \ ++ : NULL) + + /* Hardware Device Path. */ + #define GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE 1 +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0025-efi-chainloader-Propagate-errors-from-copy_file_path.patch b/buildroot/boot/grub2/0025-efi-chainloader-Propagate-errors-from-copy_file_path.patch new file mode 100644 index 000000000..eb3e0f0e2 --- /dev/null +++ b/buildroot/boot/grub2/0025-efi-chainloader-Propagate-errors-from-copy_file_path.patch @@ -0,0 +1,78 @@ +From fb55bc37dd510911df4eaf649da939f5fafdc7ce Mon Sep 17 00:00:00 2001 +From: Daniel Kiper +Date: Wed, 29 Jul 2020 13:38:31 +0200 +Subject: [PATCH] efi/chainloader: Propagate errors from copy_file_path() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Without any error propagated to the caller, make_file_path() +would then try to advance the invalid device path node with +GRUB_EFI_NEXT_DEVICE_PATH(), which would fail, returning a NULL +pointer that would subsequently be dereferenced. Hence, propagate +errors from copy_file_path(). + +Signed-off-by: Chris Coulson +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/loader/efi/chainloader.c | 19 +++++++++++++------ + 1 file changed, 13 insertions(+), 6 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index a8d7b9155..7b31c3fb9 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -106,7 +106,7 @@ grub_chainloader_boot (void) + return grub_errno; + } + +-static void ++static grub_err_t + copy_file_path (grub_efi_file_path_device_path_t *fp, + const char *str, grub_efi_uint16_t len) + { +@@ -118,7 +118,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, + + path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); + if (!path_name) +- return; ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "failed to allocate path buffer"); + + size = grub_utf8_to_utf16 (path_name, len * GRUB_MAX_UTF16_PER_UTF8, + (const grub_uint8_t *) str, len, 0); +@@ -131,6 +131,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, + fp->path_name[size++] = '\0'; + fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp); + grub_free (path_name); ++ return GRUB_ERR_NONE; + } + + static grub_efi_device_path_t * +@@ -189,13 +190,19 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + d = (grub_efi_device_path_t *) ((char *) file_path + + ((char *) d - (char *) dp)); + grub_efi_print_device_path (d); +- copy_file_path ((grub_efi_file_path_device_path_t *) d, +- dir_start, dir_end - dir_start); ++ if (copy_file_path ((grub_efi_file_path_device_path_t *) d, ++ dir_start, dir_end - dir_start) != GRUB_ERR_NONE) ++ { ++ fail: ++ grub_free (file_path); ++ return 0; ++ } + + /* Fill the file path for the file. */ + d = GRUB_EFI_NEXT_DEVICE_PATH (d); +- copy_file_path ((grub_efi_file_path_device_path_t *) d, +- dir_end + 1, grub_strlen (dir_end + 1)); ++ if (copy_file_path ((grub_efi_file_path_device_path_t *) d, ++ dir_end + 1, grub_strlen (dir_end + 1)) != GRUB_ERR_NONE) ++ goto fail; + + /* Fill the end of device path nodes. */ + d = GRUB_EFI_NEXT_DEVICE_PATH (d); +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0026-efi-Fix-use-after-free-in-halt-reboot-path.patch b/buildroot/boot/grub2/0026-efi-Fix-use-after-free-in-halt-reboot-path.patch new file mode 100644 index 000000000..75dd05d48 --- /dev/null +++ b/buildroot/boot/grub2/0026-efi-Fix-use-after-free-in-halt-reboot-path.patch @@ -0,0 +1,183 @@ +From 8a6d6299efcffd14c1130942195e6c0d9b50cacd Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Mon, 20 Jul 2020 23:03:05 +0000 +Subject: [PATCH] efi: Fix use-after-free in halt/reboot path +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +commit 92bfc33db984 ("efi: Free malloc regions on exit") +introduced memory freeing in grub_efi_fini(), which is +used not only by exit path but by halt/reboot one as well. +As result of memory freeing, code and data regions used by +modules, such as halt, reboot, acpi (used by halt) also got +freed. After return to module code, CPU executes, filled +by UEFI firmware (tested with edk2), 0xAFAFAFAF pattern as +a code. Which leads to #UD exception later. + +grub> halt +!!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!! +RIP - 0000000003F4EC28, CS - 0000000000000038, RFLAGS - 0000000000200246 +RAX - 0000000000000000, RCX - 00000000061DA188, RDX - 0A74C0854DC35D41 +RBX - 0000000003E10E08, RSP - 0000000007F0F860, RBP - 0000000000000000 +RSI - 00000000064DB768, RDI - 000000000832C5C3 +R8 - 0000000000000002, R9 - 0000000000000000, R10 - 00000000061E2E52 +R11 - 0000000000000020, R12 - 0000000003EE5C1F, R13 - 00000000061E0FF4 +R14 - 0000000003E10D80, R15 - 00000000061E2F60 +DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030 +GS - 0000000000000030, SS - 0000000000000030 +CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 0000000007C01000 +CR4 - 0000000000000668, CR8 - 0000000000000000 +DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000 +DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400 +GDTR - 00000000079EEA98 0000000000000047, LDTR - 0000000000000000 +IDTR - 0000000007598018 0000000000000FFF, TR - 0000000000000000 +FXSAVE_STATE - 0000000007F0F4C0 + +Proposal here is to continue to free allocated memory for +exit boot services path but keep it for halt/reboot path +as it won't be much security concern here. +Introduced GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY +loader flag to be used by efi halt/reboot path. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Darren Kenny +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/kern/arm/efi/init.c | 3 +++ + grub-core/kern/arm64/efi/init.c | 3 +++ + grub-core/kern/efi/efi.c | 3 ++- + grub-core/kern/efi/init.c | 1 - + grub-core/kern/i386/efi/init.c | 9 +++++++-- + grub-core/kern/ia64/efi/init.c | 9 +++++++-- + grub-core/kern/riscv/efi/init.c | 3 +++ + grub-core/lib/efi/halt.c | 3 ++- + include/grub/loader.h | 1 + + 9 files changed, 28 insertions(+), 7 deletions(-) + +diff --git a/grub-core/kern/arm/efi/init.c b/grub-core/kern/arm/efi/init.c +index 06df60e2f..40c3b467f 100644 +--- a/grub-core/kern/arm/efi/init.c ++++ b/grub-core/kern/arm/efi/init.c +@@ -71,4 +71,7 @@ grub_machine_fini (int flags) + efi_call_1 (b->close_event, tmr_evt); + + grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/arm64/efi/init.c b/grub-core/kern/arm64/efi/init.c +index 6224999ec..5010caefd 100644 +--- a/grub-core/kern/arm64/efi/init.c ++++ b/grub-core/kern/arm64/efi/init.c +@@ -57,4 +57,7 @@ grub_machine_fini (int flags) + return; + + grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index c97969a65..9cfd88d77 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -157,7 +157,8 @@ grub_efi_get_loaded_image (grub_efi_handle_t image_handle) + void + grub_reboot (void) + { +- grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); ++ grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | ++ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); + efi_call_4 (grub_efi_system_table->runtime_services->reset_system, + GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); + for (;;) ; +diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c +index 3dfdf2d22..2c31847bf 100644 +--- a/grub-core/kern/efi/init.c ++++ b/grub-core/kern/efi/init.c +@@ -80,5 +80,4 @@ grub_efi_fini (void) + { + grub_efidisk_fini (); + grub_console_fini (); +- grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/i386/efi/init.c b/grub-core/kern/i386/efi/init.c +index da499aba0..deb2eacd8 100644 +--- a/grub-core/kern/i386/efi/init.c ++++ b/grub-core/kern/i386/efi/init.c +@@ -39,6 +39,11 @@ grub_machine_init (void) + void + grub_machine_fini (int flags) + { +- if (flags & GRUB_LOADER_FLAG_NORETURN) +- grub_efi_fini (); ++ if (!(flags & GRUB_LOADER_FLAG_NORETURN)) ++ return; ++ ++ grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/ia64/efi/init.c b/grub-core/kern/ia64/efi/init.c +index b5ecbd091..f1965571b 100644 +--- a/grub-core/kern/ia64/efi/init.c ++++ b/grub-core/kern/ia64/efi/init.c +@@ -70,6 +70,11 @@ grub_machine_init (void) + void + grub_machine_fini (int flags) + { +- if (flags & GRUB_LOADER_FLAG_NORETURN) +- grub_efi_fini (); ++ if (!(flags & GRUB_LOADER_FLAG_NORETURN)) ++ return; ++ ++ grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/riscv/efi/init.c b/grub-core/kern/riscv/efi/init.c +index 7eb1969d0..38795fe67 100644 +--- a/grub-core/kern/riscv/efi/init.c ++++ b/grub-core/kern/riscv/efi/init.c +@@ -73,4 +73,7 @@ grub_machine_fini (int flags) + return; + + grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c +index 5859f0498..29d413641 100644 +--- a/grub-core/lib/efi/halt.c ++++ b/grub-core/lib/efi/halt.c +@@ -28,7 +28,8 @@ + void + grub_halt (void) + { +- grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); ++ grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | ++ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); + #if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && \ + !defined(__riscv) + grub_acpi_halt (); +diff --git a/include/grub/loader.h b/include/grub/loader.h +index 7f82a499f..b20864282 100644 +--- a/include/grub/loader.h ++++ b/include/grub/loader.h +@@ -33,6 +33,7 @@ enum + { + GRUB_LOADER_FLAG_NORETURN = 1, + GRUB_LOADER_FLAG_PXE_NOT_UNLOAD = 2, ++ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY = 4, + }; + + void EXPORT_FUNC (grub_loader_set) (grub_err_t (*boot) (void), +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0027-loader-linux-Avoid-overflow-on-initrd-size-calculati.patch b/buildroot/boot/grub2/0027-loader-linux-Avoid-overflow-on-initrd-size-calculati.patch new file mode 100644 index 000000000..823f20556 --- /dev/null +++ b/buildroot/boot/grub2/0027-loader-linux-Avoid-overflow-on-initrd-size-calculati.patch @@ -0,0 +1,32 @@ +From a2a7464e9f10a677d6f91e1c4fa527d084c22e7c Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 24 Jul 2020 13:57:27 -0400 +Subject: [PATCH] loader/linux: Avoid overflow on initrd size calculation +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/loader/linux.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c +index 471b214d6..4cd8c20c7 100644 +--- a/grub-core/loader/linux.c ++++ b/grub-core/loader/linux.c +@@ -151,8 +151,7 @@ grub_initrd_init (int argc, char *argv[], + initrd_ctx->nfiles = 0; + initrd_ctx->components = 0; + +- initrd_ctx->components = grub_zalloc (argc +- * sizeof (initrd_ctx->components[0])); ++ initrd_ctx->components = grub_calloc (argc, sizeof (initrd_ctx->components[0])); + if (!initrd_ctx->components) + return grub_errno; + +-- +2.26.2 + diff --git a/buildroot/boot/grub2/0028-linux-Fix-integer-overflows-in-initrd-size-handling.patch b/buildroot/boot/grub2/0028-linux-Fix-integer-overflows-in-initrd-size-handling.patch new file mode 100644 index 000000000..bf6590d8e --- /dev/null +++ b/buildroot/boot/grub2/0028-linux-Fix-integer-overflows-in-initrd-size-handling.patch @@ -0,0 +1,173 @@ +From 0367e7d1b9bac3a78608a672bf6e4ace6a28b964 Mon Sep 17 00:00:00 2001 +From: Colin Watson +Date: Sat, 25 Jul 2020 12:15:37 +0100 +Subject: [PATCH] linux: Fix integer overflows in initrd size handling +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +These could be triggered by a crafted filesystem with very large files. + +Fixes: CVE-2020-15707 + +Signed-off-by: Colin Watson +Reviewed-by: Jan Setje-Eilers +Reviewed-by: Daniel Kiper +Signed-off-by: Stefan Sørensen +--- + grub-core/loader/linux.c | 74 +++++++++++++++++++++++++++++----------- + 1 file changed, 54 insertions(+), 20 deletions(-) + +diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c +index 4cd8c20c7..3fe390f17 100644 +--- a/grub-core/loader/linux.c ++++ b/grub-core/loader/linux.c +@@ -4,6 +4,7 @@ + #include + #include + #include ++#include + + struct newc_head + { +@@ -98,13 +99,13 @@ free_dir (struct dir *root) + grub_free (root); + } + +-static grub_size_t ++static grub_err_t + insert_dir (const char *name, struct dir **root, +- grub_uint8_t *ptr) ++ grub_uint8_t *ptr, grub_size_t *size) + { + struct dir *cur, **head = root; + const char *cb, *ce = name; +- grub_size_t size = 0; ++ *size = 0; + while (1) + { + for (cb = ce; *cb == '/'; cb++); +@@ -130,14 +131,22 @@ insert_dir (const char *name, struct dir **root, + ptr = make_header (ptr, name, ce - name, + 040777, 0); + } +- size += ALIGN_UP ((ce - (char *) name) +- + sizeof (struct newc_head), 4); ++ if (grub_add (*size, ++ ALIGN_UP ((ce - (char *) name) ++ + sizeof (struct newc_head), 4), ++ size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ grub_free (n->name); ++ grub_free (n); ++ return grub_errno; ++ } + *head = n; + cur = n; + } + root = &cur->next; + } +- return size; ++ return GRUB_ERR_NONE; + } + + grub_err_t +@@ -172,26 +181,33 @@ grub_initrd_init (int argc, char *argv[], + eptr = grub_strchr (ptr, ':'); + if (eptr) + { ++ grub_size_t dir_size, name_len; ++ + initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr); +- if (!initrd_ctx->components[i].newc_name) ++ if (!initrd_ctx->components[i].newc_name || ++ insert_dir (initrd_ctx->components[i].newc_name, &root, 0, ++ &dir_size)) + { + grub_initrd_close (initrd_ctx); + return grub_errno; + } +- initrd_ctx->size +- += ALIGN_UP (sizeof (struct newc_head) +- + grub_strlen (initrd_ctx->components[i].newc_name), +- 4); +- initrd_ctx->size += insert_dir (initrd_ctx->components[i].newc_name, +- &root, 0); ++ name_len = grub_strlen (initrd_ctx->components[i].newc_name); ++ if (grub_add (initrd_ctx->size, ++ ALIGN_UP (sizeof (struct newc_head) + name_len, 4), ++ &initrd_ctx->size) || ++ grub_add (initrd_ctx->size, dir_size, &initrd_ctx->size)) ++ goto overflow; + newc = 1; + fname = eptr + 1; + } + } + else if (newc) + { +- initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) +- + sizeof ("TRAILER!!!") - 1, 4); ++ if (grub_add (initrd_ctx->size, ++ ALIGN_UP (sizeof (struct newc_head) ++ + sizeof ("TRAILER!!!") - 1, 4), ++ &initrd_ctx->size)) ++ goto overflow; + free_dir (root); + root = 0; + newc = 0; +@@ -207,19 +223,29 @@ grub_initrd_init (int argc, char *argv[], + initrd_ctx->nfiles++; + initrd_ctx->components[i].size + = grub_file_size (initrd_ctx->components[i].file); +- initrd_ctx->size += initrd_ctx->components[i].size; ++ if (grub_add (initrd_ctx->size, initrd_ctx->components[i].size, ++ &initrd_ctx->size)) ++ goto overflow; + } + + if (newc) + { + initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4); +- initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) +- + sizeof ("TRAILER!!!") - 1, 4); ++ if (grub_add (initrd_ctx->size, ++ ALIGN_UP (sizeof (struct newc_head) ++ + sizeof ("TRAILER!!!") - 1, 4), ++ &initrd_ctx->size)) ++ goto overflow; + free_dir (root); + root = 0; + } + + return GRUB_ERR_NONE; ++ ++ overflow: ++ free_dir (root); ++ grub_initrd_close (initrd_ctx); ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); + } + + grub_size_t +@@ -260,8 +286,16 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, + + if (initrd_ctx->components[i].newc_name) + { +- ptr += insert_dir (initrd_ctx->components[i].newc_name, +- &root, ptr); ++ grub_size_t dir_size; ++ ++ if (insert_dir (initrd_ctx->components[i].newc_name, &root, ptr, ++ &dir_size)) ++ { ++ free_dir (root); ++ grub_initrd_close (initrd_ctx); ++ return grub_errno; ++ } ++ ptr += dir_size; + ptr = make_header (ptr, initrd_ctx->components[i].newc_name, + grub_strlen (initrd_ctx->components[i].newc_name), + 0100777, +-- +2.26.2 + diff --git a/buildroot/boot/grub2/grub2.mk b/buildroot/boot/grub2/grub2.mk index f77dc0f9d..5fca2315e 100644 --- a/buildroot/boot/grub2/grub2.mk +++ b/buildroot/boot/grub2/grub2.mk @@ -21,6 +21,17 @@ endef GRUB2_POST_PATCH_HOOKS += GRUB2_AVOID_AUTORECONF HOST_GRUB2_POST_PATCH_HOOKS += GRUB2_AVOID_AUTORECONF +# 0002-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch +GRUB2_IGNORE_CVES += CVE-2020-10713 +# 0005-calloc-Use-calloc-at-most-places.patch +GRUB2_IGNORE_CVES += CVE-2020-14308 +# 0006-malloc-Use-overflow-checking-primitives-where-we-do-.patch +GRUB2_IGNORE_CVES += CVE-2020-14309 CVE-2020-14310 CVE-2020-14311 +# 0019-script-Avoid-a-use-after-free-when-redefining-a-func.patch +GRUB2_IGNORE_CVES += CVE-2020-15706 +# 0028-linux-Fix-integer-overflows-in-initrd-size-handling.patch +GRUB2_IGNORE_CVES += CVE-2020-15707 + ifeq ($(BR2_TARGET_GRUB2_INSTALL_TOOLS),y) GRUB2_INSTALL_TARGET = YES else diff --git a/buildroot/boot/uboot/uboot.mk b/buildroot/boot/uboot/uboot.mk index 2bfa50779..9cbd81b05 100644 --- a/buildroot/boot/uboot/uboot.mk +++ b/buildroot/boot/uboot/uboot.mk @@ -16,6 +16,7 @@ UBOOT_INSTALL_IMAGES = YES # u-boot 2020.01+ needs make 4.0+ UBOOT_DEPENDENCIES = $(BR2_MAKE_HOST_DEPENDENCY) +UBOOT_MAKE = $(BR2_MAKE) ifeq ($(UBOOT_VERSION),custom) # Handle custom U-Boot tarballs as specified by the configuration @@ -247,7 +248,7 @@ UBOOT_POST_PATCH_HOOKS += UBOOT_FIXUP_LIBFDT_INCLUDE ifeq ($(BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY),y) define UBOOT_CONFIGURE_CMDS $(TARGET_CONFIGURE_OPTS) \ - $(BR2_MAKE) -C $(@D) $(UBOOT_MAKE_OPTS) \ + $(UBOOT_MAKE) -C $(@D) $(UBOOT_MAKE_OPTS) \ $(UBOOT_BOARD_NAME)_config endef else ifeq ($(BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG),y) @@ -284,7 +285,7 @@ define UBOOT_BUILD_CMDS cp -f $(UBOOT_CUSTOM_DTS_PATH) $(@D)/arch/$(UBOOT_ARCH)/dts/ ) $(TARGET_CONFIGURE_OPTS) \ - $(BR2_MAKE) -C $(@D) $(UBOOT_MAKE_OPTS) \ + $(UBOOT_MAKE) -C $(@D) $(UBOOT_MAKE_OPTS) \ $(UBOOT_MAKE_TARGET) $(if $(BR2_TARGET_UBOOT_FORMAT_SD), $(@D)/tools/mxsboot sd $(@D)/u-boot.sb $(@D)/u-boot.sd) diff --git a/buildroot/docs/manual/adding-board-support.txt b/buildroot/docs/manual/adding-board-support.txt index f6d74ae1f..33ed70953 100644 --- a/buildroot/docs/manual/adding-board-support.txt +++ b/buildroot/docs/manual/adding-board-support.txt @@ -10,9 +10,9 @@ that is known to work. You are welcome to add support for other boards to Buildroot too. To do so, you need to create a normal Buildroot configuration that -builds a basic system for the hardware: toolchain, kernel, bootloader, -filesystem and a simple BusyBox-only userspace. No specific package -should be selected: the configuration should be as minimal as +builds a basic system for the hardware: (internal) toolchain, kernel, +bootloader, filesystem and a simple BusyBox-only userspace. No specific +package should be selected: the configuration should be as minimal as possible, and should only build a working basic BusyBox system for the target platform. You can of course use more complicated configurations for your internal projects, but the Buildroot project will only @@ -22,7 +22,17 @@ selections are highly application-specific. Once you have a known working configuration, run +make savedefconfig+. This will generate a minimal +defconfig+ file at the root of the Buildroot source tree. Move this file into the +configs/+ -directory, and rename it +_defconfig+. +directory, and rename it +_defconfig+. If the configuration +is a bit more complicated, it is nice to manually reformat it and +separate it into sections, with a comment before each section. Typical +sections are _Architecture_, _Toolchain options_ (typically just linux +headers version), _Firmware_, _Bootloader_, _Kernel_, and _Filesystem_. + +Always use fixed versions or commit hashes for the different +components, not the "latest" version. For example, set ++BR2_LINUX_KERNEL_CUSTOM_VERSION=y+ and ++BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE+ to the kernel version you tested +with. It is recommended to use as much as possible upstream versions of the Linux kernel and bootloaders, and to use as much as possible default diff --git a/buildroot/docs/manual/adding-packages-cargo.txt b/buildroot/docs/manual/adding-packages-cargo.txt index b6029e1ee..edf698e70 100644 --- a/buildroot/docs/manual/adding-packages-cargo.txt +++ b/buildroot/docs/manual/adding-packages-cargo.txt @@ -47,32 +47,31 @@ package. Let's start with an example: 13: FOO_DEPENDENCIES = host-cargo 14: 15: FOO_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo -16: FOO_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release) -17: -18: FOO_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(FOO_CARGO_MODE) -19: -20: FOO_CARGO_OPTS = \ -21: --$(FOO_CARGO_MODE) \ -22: --target=$(RUSTC_TARGET_NAME) \ -23: --manifest-path=$(@D)/Cargo.toml -24: -25: define FOO_BUILD_CMDS -26: $(TARGET_MAKE_ENV) $(FOO_CARGO_ENV) \ -27: cargo build $(FOO_CARGO_OPTS) -28: endef -29: -30: define FOO_INSTALL_TARGET_CMDS -31: $(INSTALL) -D -m 0755 $(@D)/$(FOO_BIN_DIR)/foo \ -32: $(TARGET_DIR)/usr/bin/foo -33: endef -34: -35: $(eval $(generic-package)) +16: +17: FOO_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(FOO_CARGO_MODE) +18: +19: FOO_CARGO_OPTS = \ +20: $(if $(BR2_ENABLE_DEBUG),,--release) \ +21: --target=$(RUSTC_TARGET_NAME) \ +22: --manifest-path=$(@D)/Cargo.toml +23: +24: define FOO_BUILD_CMDS +25: $(TARGET_MAKE_ENV) $(FOO_CARGO_ENV) \ +26: cargo build $(FOO_CARGO_OPTS) +27: endef +28: +29: define FOO_INSTALL_TARGET_CMDS +30: $(INSTALL) -D -m 0755 $(@D)/$(FOO_BIN_DIR)/foo \ +31: $(TARGET_DIR)/usr/bin/foo +32: endef +33: +34: $(eval $(generic-package)) -------------------------------- The Makefile starts with the definition of the standard variables for package declaration (lines 7 to 11). -As seen in line 35, it is based on the +As seen in line 34, it is based on the xref:generic-package-tutorial[+generic-package+ infrastructure]. So, it defines the variables required by this particular infrastructure, where Cargo is invoked: diff --git a/buildroot/docs/manual/adding-packages-waf.txt b/buildroot/docs/manual/adding-packages-waf.txt index ffc004c29..101cddf1f 100644 --- a/buildroot/docs/manual/adding-packages-waf.txt +++ b/buildroot/docs/manual/adding-packages-waf.txt @@ -34,7 +34,7 @@ will automatically download the tarball from this location. On line 10, we tell Buildroot what options to enable for libfoo. -On line 11, we tell Buildroot the depednencies of libfoo. +On line 11, we tell Buildroot the dependencies of libfoo. Finally, on line line 13, we invoke the +waf-package+ macro that generates all the Makefile rules that actually allows the diff --git a/buildroot/docs/manual/contribute.txt b/buildroot/docs/manual/contribute.txt index bde7543c2..70d178d00 100644 --- a/buildroot/docs/manual/contribute.txt +++ b/buildroot/docs/manual/contribute.txt @@ -371,6 +371,37 @@ in the following cases: * whenever you feel it will help presenting your work, your choices, the review process, etc. +==== Patches for maintenance branches + +When fixing bugs on a maintenance branch, bugs should be fixed on the +master branch first. The commit log for such a patch may then contain a +post-commit note specifying what branches are affected: + +---- +package/foo: fix stuff + +Signed-off-by: Your Real Name +--- +Backport to: 2020.02.x, 2020.05.x +(2020.08.x not affected as the version was bumped) +---- + +Those changes will then be backported by a maintainer to the affected +branches. + +However, some bugs may apply only to a specific release, for example +because it is using an older version of a package. In that case, patches +should be based off the maintenance branch, and the patch subject prefix +must include the maintenance branch name (for example "[PATCH 2020.02.x]"). +This can be done with the +git format-patch+ flag +--subject-prefix+: + +--------------------- +$ git format-patch --subject-prefix "PATCH 2020.02.x" \ + -M -s -o outgoing origin/2020.02.x +--------------------- + +Then send the patches with +git send-email+, as described above. + ==== Patch revision changelog When improvements are requested, the new revision of each commit diff --git a/buildroot/docs/manual/manual.html b/buildroot/docs/manual/manual.html index aca28363f..87aaa4f27 100644 --- a/buildroot/docs/manual/manual.html +++ b/buildroot/docs/manual/manual.html @@ -1,8 +1,8 @@ -The Buildroot user manual

The Buildroot user manual


Table of Contents

I. Getting started
1. About Buildroot
2. System requirements
2.1. Mandatory packages
2.2. Optional packages
3. Getting Buildroot
4. Buildroot quick start
5. Community resources
II. User guide
6. Buildroot configuration
6.1. Cross-compilation toolchain
6.2. /dev management
6.3. init system
7. Configuration of other components
8. General Buildroot usage
8.1. make tips
8.2. Understanding when a full rebuild is necessary
8.3. Understanding how to rebuild packages
8.4. Offline builds
8.5. Building out-of-tree
8.6. Environment variables
8.7. Dealing efficiently with filesystem images
8.8. Graphing the dependencies between packages
8.9. Graphing the build duration
8.10. Graphing the filesystem size contribution of packages
8.11. Top-level parallel build
8.12. Integration with Eclipse
8.13. Advanced usage
9. Project-specific customization
9.1. Recommended directory structure
9.2. Keeping customizations outside of Buildroot
9.3. Storing the Buildroot configuration
9.4. Storing the configuration of other components
9.5. Customizing the generated target filesystem
9.6. Adding custom user accounts
9.7. Customization after the images have been created
9.8. Adding project-specific patches
9.9. Adding project-specific packages
9.10. Quick guide to storing your project-specific customizations
10. Frequently Asked Questions & Troubleshooting
10.1. The boot hangs after Starting network…
10.2. Why is there no compiler on the target?
10.3. Why are there no development files on the target?
10.4. Why is there no documentation on the target?
10.5. Why are some packages not visible in the Buildroot config menu?
10.6. Why not use the target directory as a chroot directory?
10.7. Why doesn’t Buildroot generate binary packages (.deb, .ipkg…)?
10.8. How to speed-up the build process?
11. Known issues
12. Legal notice and licensing
12.1. Complying with open source licenses
12.2. Complying with the Buildroot license
13. Beyond Buildroot
13.1. Boot the generated images
13.2. Chroot
III. Developer guide
14. How Buildroot works
15. Coding style
15.1. Config.in file
15.2. The .mk file
15.3. The documentation
15.4. Support scripts
16. Adding support for a particular board
17. Adding new packages to Buildroot
17.1. Package directory
17.2. Config files
17.3. The .mk file
17.4. The .hash file
17.5. Infrastructure for packages with specific build systems
17.6. Infrastructure for autotools-based packages
17.7. Infrastructure for CMake-based packages
17.8. Infrastructure for Python packages
17.9. Infrastructure for LuaRocks-based packages
17.10. Infrastructure for Perl/CPAN packages
17.11. Infrastructure for virtual packages
17.12. Infrastructure for packages using kconfig for configuration files
17.13. Infrastructure for rebar-based packages
17.14. Infrastructure for Waf-based packages
17.15. Infrastructure for Meson-based packages
17.16. Integration of Cargo-based packages
17.17. Infrastructure for Go packages
17.18. Infrastructure for packages building kernel modules
17.19. Infrastructure for asciidoc documents
17.20. Infrastructure specific to the Linux kernel package
17.21. Hooks available in the various build steps
17.22. Gettext integration and interaction with packages
17.23. Tips and tricks
17.24. Conclusion
18. Patching a package
18.1. Providing patches
18.2. How patches are applied
18.3. Format and licensing of the package patches
18.4. Integrating patches found on the Web
19. Download infrastructure
20. Debugging Buildroot
21. Contributing to Buildroot
21.1. Reproducing, analyzing and fixing bugs
21.2. Analyzing and fixing autobuild failures
21.3. Reviewing and testing patches
21.4. Work on items from the TODO list
21.5. Submitting patches
21.6. Reporting issues/bugs or getting help
21.7. Using the run-tests framework
22. DEVELOPERS file and get-developers
23. Release Engineering
23.1. Releases
23.2. Development
IV. Appendix
24. Makedev syntax documentation
25. Makeusers syntax documentation
26. Migrating from older Buildroot versions
26.1. Migrating to 2016.11
26.2. Migrating to 2017.08

Buildroot 2020.02.4 manual generated on 2020-07-26 -08:11:28 UTC from git revision dee53013da

The Buildroot manual is written by the Buildroot developers. +The Buildroot user manual

The Buildroot user manual


Table of Contents

I. Getting started
1. About Buildroot
2. System requirements
2.1. Mandatory packages
2.2. Optional packages
3. Getting Buildroot
4. Buildroot quick start
5. Community resources
II. User guide
6. Buildroot configuration
6.1. Cross-compilation toolchain
6.2. /dev management
6.3. init system
7. Configuration of other components
8. General Buildroot usage
8.1. make tips
8.2. Understanding when a full rebuild is necessary
8.3. Understanding how to rebuild packages
8.4. Offline builds
8.5. Building out-of-tree
8.6. Environment variables
8.7. Dealing efficiently with filesystem images
8.8. Graphing the dependencies between packages
8.9. Graphing the build duration
8.10. Graphing the filesystem size contribution of packages
8.11. Top-level parallel build
8.12. Integration with Eclipse
8.13. Advanced usage
9. Project-specific customization
9.1. Recommended directory structure
9.2. Keeping customizations outside of Buildroot
9.3. Storing the Buildroot configuration
9.4. Storing the configuration of other components
9.5. Customizing the generated target filesystem
9.6. Adding custom user accounts
9.7. Customization after the images have been created
9.8. Adding project-specific patches
9.9. Adding project-specific packages
9.10. Quick guide to storing your project-specific customizations
10. Frequently Asked Questions & Troubleshooting
10.1. The boot hangs after Starting network…
10.2. Why is there no compiler on the target?
10.3. Why are there no development files on the target?
10.4. Why is there no documentation on the target?
10.5. Why are some packages not visible in the Buildroot config menu?
10.6. Why not use the target directory as a chroot directory?
10.7. Why doesn’t Buildroot generate binary packages (.deb, .ipkg…)?
10.8. How to speed-up the build process?
11. Known issues
12. Legal notice and licensing
12.1. Complying with open source licenses
12.2. Complying with the Buildroot license
13. Beyond Buildroot
13.1. Boot the generated images
13.2. Chroot
III. Developer guide
14. How Buildroot works
15. Coding style
15.1. Config.in file
15.2. The .mk file
15.3. The documentation
15.4. Support scripts
16. Adding support for a particular board
17. Adding new packages to Buildroot
17.1. Package directory
17.2. Config files
17.3. The .mk file
17.4. The .hash file
17.5. Infrastructure for packages with specific build systems
17.6. Infrastructure for autotools-based packages
17.7. Infrastructure for CMake-based packages
17.8. Infrastructure for Python packages
17.9. Infrastructure for LuaRocks-based packages
17.10. Infrastructure for Perl/CPAN packages
17.11. Infrastructure for virtual packages
17.12. Infrastructure for packages using kconfig for configuration files
17.13. Infrastructure for rebar-based packages
17.14. Infrastructure for Waf-based packages
17.15. Infrastructure for Meson-based packages
17.16. Integration of Cargo-based packages
17.17. Infrastructure for Go packages
17.18. Infrastructure for packages building kernel modules
17.19. Infrastructure for asciidoc documents
17.20. Infrastructure specific to the Linux kernel package
17.21. Hooks available in the various build steps
17.22. Gettext integration and interaction with packages
17.23. Tips and tricks
17.24. Conclusion
18. Patching a package
18.1. Providing patches
18.2. How patches are applied
18.3. Format and licensing of the package patches
18.4. Integrating patches found on the Web
19. Download infrastructure
20. Debugging Buildroot
21. Contributing to Buildroot
21.1. Reproducing, analyzing and fixing bugs
21.2. Analyzing and fixing autobuild failures
21.3. Reviewing and testing patches
21.4. Work on items from the TODO list
21.5. Submitting patches
21.6. Reporting issues/bugs or getting help
21.7. Using the run-tests framework
22. DEVELOPERS file and get-developers
23. Release Engineering
23.1. Releases
23.2. Development
IV. Appendix
24. Makedev syntax documentation
25. Makeusers syntax documentation
26. Migrating from older Buildroot versions
26.1. Migrating to 2016.11
26.2. Migrating to 2017.08

Buildroot 2020.02.7 manual generated on 2020-10-12 +21:37:29 UTC from git revision d8082db677

The Buildroot manual is written by the Buildroot developers. It is licensed under the GNU General Public License, version 2. Refer to the -COPYING +COPYING file in the Buildroot sources for the full text of this license.

Copyright © 2004-2020 The Buildroot developers

logo.png

Part I. Getting started

Chapter 1. About Buildroot

Buildroot is a tool that simplifies and automates the process of building a complete Linux system for an embedded system, using cross-compilation.

In order to achieve this, Buildroot is able to generate a @@ -2346,9 +2346,9 @@ Python and should follow the hardware boards, so that users of such a board can easily build a system that is known to work. You are welcome to add support for other boards to Buildroot too.

To do so, you need to create a normal Buildroot configuration that -builds a basic system for the hardware: toolchain, kernel, bootloader, -filesystem and a simple BusyBox-only userspace. No specific package -should be selected: the configuration should be as minimal as +builds a basic system for the hardware: (internal) toolchain, kernel, +bootloader, filesystem and a simple BusyBox-only userspace. No specific +package should be selected: the configuration should be as minimal as possible, and should only build a working basic BusyBox system for the target platform. You can of course use more complicated configurations for your internal projects, but the Buildroot project will only @@ -2356,7 +2356,15 @@ integrate basic board configurations. This is because package selections are highly application-specific.

Once you have a known working configuration, run make savedefconfig. This will generate a minimal defconfig file at the root of the Buildroot source tree. Move this file into the configs/ -directory, and rename it <boardname>_defconfig.

It is recommended to use as much as possible upstream versions of the +directory, and rename it <boardname>_defconfig. If the configuration +is a bit more complicated, it is nice to manually reformat it and +separate it into sections, with a comment before each section. Typical +sections are Architecture, Toolchain options (typically just linux +headers version), Firmware, Bootloader, Kernel, and Filesystem.

Always use fixed versions or commit hashes for the different +components, not the "latest" version. For example, set +BR2_LINUX_KERNEL_CUSTOM_VERSION=y and +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE to the kernel version you tested +with.

It is recommended to use as much as possible upstream versions of the Linux kernel and bootloaders, and to use as much as possible default kernel and bootloader configurations. If they are incorrect for your board, or no default exists, we encourage you to send fixes to the @@ -2849,7 +2857,7 @@ flags. The argument to be given to LIBFOO_CONFIG_SCRIPTS is the file name(s) of the shell script(s) needing fixing. All these names are relative to $(STAGING_DIR)/usr/bin and if needed multiple names can be given.

In addition, the scripts listed in LIBFOO_CONFIG_SCRIPTS are removed -from $(TARGET_DIR)/usr/bin, since they are not needed on the target.

Example 17.1. Config script: divine package

Package divine installs shell script $(STAGING_DIR)/usr/bin/divine-config.

So its fixup would be:

DIVINE_CONFIG_SCRIPTS = divine-config

Example 17.2. Config script: imagemagick package:

Package imagemagick installs the following scripts: +from $(TARGET_DIR)/usr/bin, since they are not needed on the target.

Example 17.1. Config script: divine package

Package divine installs shell script $(STAGING_DIR)/usr/bin/divine-config.

So its fixup would be:

DIVINE_CONFIG_SCRIPTS = divine-config

Example 17.2. Config script: imagemagick package:

Package imagemagick installs the following scripts: $(STAGING_DIR)/usr/bin/{Magick,Magick++,MagickCore,MagickWand,Wand}-config

So it’s fixup would be:

IMAGEMAGICK_CONFIG_SCRIPTS = \
    Magick-config Magick++-config \
    MagickCore-config MagickWand-config Wand-config

On line 14, we specify the list of dependencies this package relies @@ -4073,7 +4081,7 @@ an example :

01: ########################################
 12:
 13: $(eval $(waf-package))

On line 7, we declare the version of the package.

On line 8 and 9, we declare the name of the tarball (xz-ed tarball recommended) and the location of the tarball on the Web. Buildroot -will automatically download the tarball from this location.

On line 10, we tell Buildroot what options to enable for libfoo.

On line 11, we tell Buildroot the depednencies of libfoo.

Finally, on line line 13, we invoke the waf-package +will automatically download the tarball from this location.

On line 10, we tell Buildroot what options to enable for libfoo.

On line 11, we tell Buildroot the dependencies of libfoo.

Finally, on line line 13, we invoke the waf-package macro that generates all the Makefile rules that actually allows the package to be built.

17.14.2. waf-package reference

The main macro of the Waf package infrastructure is waf-package. It is similar to the generic-package macro.

Just like the generic infrastructure, the Waf infrastructure works @@ -4224,27 +4232,26 @@ package. Let’s start with an example:

01: #############
 13: FOO_DEPENDENCIES = host-cargo
 14:
 15: FOO_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo
-16: FOO_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release)
-17:
-18: FOO_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(FOO_CARGO_MODE)
-19:
-20: FOO_CARGO_OPTS = \
-21:   --$(FOO_CARGO_MODE) \
-22:     --target=$(RUSTC_TARGET_NAME) \
-23:     --manifest-path=$(@D)/Cargo.toml
-24:
-25: define FOO_BUILD_CMDS
-26:     $(TARGET_MAKE_ENV) $(FOO_CARGO_ENV) \
-27:             cargo build $(FOO_CARGO_OPTS)
-28: endef
-29:
-30: define FOO_INSTALL_TARGET_CMDS
-31:     $(INSTALL) -D -m 0755 $(@D)/$(FOO_BIN_DIR)/foo \
-32:             $(TARGET_DIR)/usr/bin/foo
-33: endef
-34:
-35: $(eval $(generic-package))

The Makefile starts with the definition of the standard variables for package -declaration (lines 7 to 11).

As seen in line 35, it is based on the +16: +17: FOO_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(FOO_CARGO_MODE) +18: +19: FOO_CARGO_OPTS = \ +20: $(if $(BR2_ENABLE_DEBUG),,--release) \ +21: --target=$(RUSTC_TARGET_NAME) \ +22: --manifest-path=$(@D)/Cargo.toml +23: +24: define FOO_BUILD_CMDS +25: $(TARGET_MAKE_ENV) $(FOO_CARGO_ENV) \ +26: cargo build $(FOO_CARGO_OPTS) +27: endef +28: +29: define FOO_INSTALL_TARGET_CMDS +30: $(INSTALL) -D -m 0755 $(@D)/$(FOO_BIN_DIR)/foo \ +31: $(TARGET_DIR)/usr/bin/foo +32: endef +33: +34: $(eval $(generic-package))

The Makefile starts with the definition of the standard variables for package +declaration (lines 7 to 11).

As seen in line 34, it is based on the generic-package infrastructure. So, it defines the variables required by this particular infrastructure, where Cargo is invoked:

  • @@ -5212,11 +5219,24 @@ large number of commits in the series;
  • deep impact of the changes in the rest of the project;
  • -RFC [4]; +RFC [4];
  • whenever you feel it will help presenting your work, your choices, the review process, etc. -

21.5.4. Patch revision changelog

When improvements are requested, the new revision of each commit +

21.5.4. Patches for maintenance branches

When fixing bugs on a maintenance branch, bugs should be fixed on the +master branch first. The commit log for such a patch may then contain a +post-commit note specifying what branches are affected:

package/foo: fix stuff
+
+Signed-off-by: Your Real Name <your@email.address>
+---
+Backport to: 2020.02.x, 2020.05.x
+(2020.08.x not affected as the version was bumped)

Those changes will then be backported by a maintainer to the affected +branches.

However, some bugs may apply only to a specific release, for example +because it is using an older version of a package. In that case, patches +should be based off the maintenance branch, and the patch subject prefix +must include the maintenance branch name (for example "[PATCH 2020.02.x]"). +This can be done with the git format-patch flag --subject-prefix:

$ git format-patch --subject-prefix "PATCH 2020.02.x" \
+    -M -s -o outgoing origin/2020.02.x

Then send the patches with git send-email, as described above.

21.5.5. Patch revision changelog

When improvements are requested, the new revision of each commit should include a changelog of the modifications between each submission. Note that when your patch series is introduced by a cover letter, an overall changelog may be added to the cover letter in @@ -5416,7 +5436,7 @@ to trigger all run-test test case jobs:

 $ git push gitlab HEAD:<name>-runtime-tests
  • to trigger one test case job, a specific branch naming string is used that includes the full test case name. -
 $ git push gitlab HEAD:<name>-<test case name>


[4] RFC: (Request for comments) change proposal

Chapter 22. DEVELOPERS file and get-developers

The main Buildroot directory contains a file named DEVELOPERS that +

 $ git push gitlab HEAD:<name>-<test case name>


[4] RFC: (Request for comments) change proposal

Chapter 22. DEVELOPERS file and get-developers

The main Buildroot directory contains a file named DEVELOPERS that lists the developers involved with various areas of Buildroot. Thanks to this file, the get-developers tool allows to: