!416 backport patches from upstream and fix log printing in tpcm_kunpeng module

From: @zhangqiumiao 
Reviewed-by: @t_feng 
Signed-off-by: @t_feng
This commit is contained in:
openeuler-ci-bot 2024-06-19 01:43:56 +00:00 committed by Gitee
commit 6ea7eaf512
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 525 additions and 7 deletions

View File

@ -1,4 +1,4 @@
From 2d7ef4b34427e1e1b2f55fdcc7868e7ce001a194 Mon Sep 17 00:00:00 2001
From db79d9a6bf62ee1bf00d65a47bfffb9cd7480083 Mon Sep 17 00:00:00 2001
From: "t.feng" <fengtao40@huawei.com>
Date: Tue, 28 Feb 2023 16:25:30 +0800
Subject: [PATCH] add tpcm support with ipmi channel
@ -28,7 +28,7 @@ Signed-off-by: zhangqiumiao <zhangqiumiao1@huawei.com>
create mode 100644 include/grub/efi/tpcm.h
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 6b00eb5..ee6ff17 100644
index 6b00eb5..9e3f5ac 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -2564,6 +2564,12 @@ module = {
@ -46,7 +46,7 @@ index 6b00eb5..ee6ff17 100644
common = commands/tr.c;
diff --git a/grub-core/commands/efi/tpcm.c b/grub-core/commands/efi/tpcm.c
new file mode 100644
index 0000000..57a4cea
index 0000000..f7295ee
--- /dev/null
+++ b/grub-core/commands/efi/tpcm.c
@@ -0,0 +1,476 @@
@ -400,8 +400,8 @@ index 0000000..57a4cea
+ grub_dprintf ("tpcm", "tpcm control switch turned off, ignore excute_ipmi_cmd failure.\n");
+ else
+ {
+ err = grub_error (GRUB_ERR_BUG,
+ "excute_ipmi_cmd failed, request sub_cmd:0x%x, ret:%lu\n",
+ err = GRUB_ERR_BUG;
+ grub_dprintf ("tpcm", "excute_ipmi_cmd failed, request sub_cmd:0x%x, ret:%lu\n",
+ request_data->SubCmd, status);
+ }
+ goto fail;

View File

@ -0,0 +1,102 @@
From b2c72f4641b1992759f630abf8c22e480933b6c5 Mon Sep 17 00:00:00 2001
From: Julian Andres Klode <julian.klode@canonical.com>
Date: Tue, 13 Jun 2023 14:54:48 +0200
Subject: disk: Generalize MD_MAX_DISKS to GRUB_MDRAID_MAX_DISKS
Move the constant from grub-core/osdep/linux/getroot.c to
include/grub/disk.h and then reuse it in place of the
hardcoded 1024 limit in diskfilter.
Fixes: 2a5e3c1f2 (disk/diskfilter: Don't make a RAID array with more than 1024 disks)
Reference:https://git.savannah.gnu.org/cgit/grub.git/commit/?id=b2c72f4641b1992759f630abf8c22e480933b6c5
Conflict:NA
Cc: Daniel Axtens <dja@axtens.net>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
grub-core/disk/diskfilter.c | 4 ++--
grub-core/osdep/linux/getroot.c | 12 ++----------
include/grub/disk.h | 11 +++++++++++
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c
index 1c56892..61a311e 100644
--- a/grub-core/disk/diskfilter.c
+++ b/grub-core/disk/diskfilter.c
@@ -1046,8 +1046,8 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb,
struct grub_diskfilter_pv *pv;
grub_err_t err;
- /* We choose not to support more than 1024 disks. */
- if (nmemb < 1 || nmemb > 1024)
+ /* We choose not to support more than the specified number of disks. */
+ if (nmemb < 1 || nmemb > GRUB_MDRAID_MAX_DISKS)
{
grub_free (uuid);
return NULL;
diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c
index 9cf037e..7dd775d 100644
--- a/grub-core/osdep/linux/getroot.c
+++ b/grub-core/osdep/linux/getroot.c
@@ -44,6 +44,7 @@
#include <grub/mm.h>
#include <grub/misc.h>
+#include <grub/disk.h>
#include <grub/emu/misc.h>
#include <grub/emu/hostdisk.h>
#include <grub/emu/getroot.h>
@@ -130,15 +131,6 @@ struct mountinfo_entry
char fstype[ESCAPED_PATH_MAX + 1], device[ESCAPED_PATH_MAX + 1];
};
-/*
- * GET_DISK_INFO nr_disks (total count) does not map to disk.number,
- * which is an internal kernel index. Instead, do what mdadm does
- * and keep scanning until we find enough valid disks. The limit is
- * copied from there, which notes that it is sufficiently high given
- * that the on-disk metadata for v1.x can only support 1920.
- */
-#define MD_MAX_DISKS 4096
-
static char **
grub_util_raid_getmembers (const char *name, int bootable)
{
@@ -176,7 +168,7 @@ grub_util_raid_getmembers (const char *name, int bootable)
devicelist = xcalloc (info.nr_disks + 1, sizeof (char *));
remaining = info.nr_disks;
- for (i = 0, j = 0; i < MD_MAX_DISKS && remaining > 0; i++)
+ for (i = 0, j = 0; i < GRUB_MDRAID_MAX_DISKS && remaining > 0; i++)
{
disk.number = i;
ret = ioctl (fd, GET_DISK_INFO, &disk);
diff --git a/include/grub/disk.h b/include/grub/disk.h
index 071b2f7..a4b5d13 100644
--- a/include/grub/disk.h
+++ b/include/grub/disk.h
@@ -172,6 +172,17 @@ typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
/* The maximum number of disk caches. */
#define GRUB_DISK_CACHE_NUM 1021
+/*
+ * The maximum number of disks in an mdraid device.
+ *
+ * GET_DISK_INFO nr_disks (total count) does not map to disk.number,
+ * which is an internal kernel index. Instead, do what mdadm does
+ * and keep scanning until we find enough valid disks. The limit is
+ * copied from there, which notes that it is sufficiently high given
+ * that the on-disk metadata for v1.x can only support 1920.
+ */
+#define GRUB_MDRAID_MAX_DISKS 4096
+
/* The size of a disk cache in 512B units. Must be at least as big as the
largest supported sector size, currently 16K. */
#define GRUB_DISK_CACHE_BITS 6
--
cgit v1.1

View File

@ -0,0 +1,144 @@
From 99b4c0c3841bf71b0f2ef83607e9d6f13874c67c Mon Sep 17 00:00:00 2001
From: Lidong Chen <lidong.chen@oracle.com>
Date: Mon, 29 Apr 2024 16:38:03 +0000
Subject: disk/mdraid1x_linux: Prevent infinite recursion
The test corpus for version-1 RAID generated an infinite recursion
in grub_partition_iterate() while attempting to read the superblock.
The reason for the issue was that the data region overlapped with
the superblock.
The infinite call loop looks like this:
grub_partition_iterate() -> partmap->iterate() ->
-> grub_disk_read() -> grub_disk_read_small() ->
-> grub_disk_read_small_real() -> grub_diskfilter_read() ->
-> read_lv() -> read_segment() -> grub_diskfilter_read_node() ->
-> grub_disk_read() -> grub_disk_read_small() -> ...
The fix adds checks for both the superblock region and the data
region when parsing the superblock metadata in grub_mdraid_detect().
Reference:https://git.savannah.gnu.org/cgit/grub.git/commit/?id=99b4c0c3841bf71b0f2ef83607e9d6f13874c67c
Conflict:NA
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
grub-core/disk/mdraid1x_linux.c | 80 ++++++++++++++++++++++++++++++++-
1 file changed, 79 insertions(+), 1 deletion(-)
diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c
index 38444b0..2ee2475 100644
--- a/grub-core/disk/mdraid1x_linux.c
+++ b/grub-core/disk/mdraid1x_linux.c
@@ -23,6 +23,7 @@
#include <grub/err.h>
#include <grub/misc.h>
#include <grub/diskfilter.h>
+#include <grub/safemath.h>
GRUB_MOD_LICENSE ("GPLv3+");
@@ -103,6 +104,9 @@ struct grub_raid_super_1x
#define WriteMostly1 1 /* Mask for writemostly flag in above devflags. */
+#define GRUB_MD_SECTOR_SHIFT 9 /* Follow Linux kernel v6.8. */
+#define GRUB_MD_SECTOR_SIZE (1 << GRUB_MD_SECTOR_SHIFT)
+
static struct grub_diskfilter_vg *
grub_mdraid_detect (grub_disk_t disk,
struct grub_diskfilter_pv_id *id,
@@ -129,7 +133,8 @@ grub_mdraid_detect (grub_disk_t disk,
grub_uint32_t level;
struct grub_diskfilter_vg *array;
char *uuid;
-
+ grub_uint64_t sb_sz, data_end, sb_end;
+
if (size == GRUB_DISK_SIZE_UNKNOWN && minor_version == 0)
continue;
@@ -154,6 +159,79 @@ grub_mdraid_detect (grub_disk_t disk,
|| grub_le_to_cpu64 (sb.super_offset) != sector)
continue;
+ /*
+ * The first check follows the Linux kernel's data_size
+ * validation from v6.8-rc5.
+ */
+ if (grub_le_to_cpu64 (sb.data_size) < 10 ||
+ grub_le_to_cpu64 (sb.raid_disks) > GRUB_MDRAID_MAX_DISKS)
+ {
+ grub_dprintf ("mdraid1x", "Corrupted superblock\n");
+ return NULL;
+ }
+
+ /*
+ * Total size of superblock: 256 bytes plus 2 bytes per device
+ * in the array.
+ */
+ sb_sz = sizeof (struct grub_raid_super_1x) + grub_le_to_cpu64 (sb.raid_disks) * 2;
+
+ if (grub_add (grub_le_to_cpu64 (sb.super_offset),
+ (ALIGN_UP(sb_sz, GRUB_MD_SECTOR_SIZE) >> GRUB_MD_SECTOR_SHIFT), &sb_end))
+ {
+ grub_dprintf ("mdraid1x", "Invalid superblock end.\n");
+ return NULL;
+ }
+
+ if (grub_add (grub_le_to_cpu64 (sb.data_offset),
+ grub_le_to_cpu64 (sb.data_size), &data_end))
+ {
+ grub_dprintf ("mdraid1x", "Invalid data end.\n");
+ return NULL;
+ }
+
+ /* In minor versions 1 and 2, superblock is positioned before data. */
+ if (minor_version)
+ {
+ if (grub_le_to_cpu64 (sb.data_offset) < sb_end)
+ {
+ grub_dprintf ("mdraid1x",
+ "The superblock either overlaps with the data "
+ "or is behind it.\n");
+ return NULL;
+ }
+
+ if (data_end > size)
+ {
+ grub_dprintf ("mdraid1x",
+ "The data region ends at %" PRIuGRUB_UINT64_T ", "
+ "past the end of the disk (%" PRIuGRUB_UINT64_T ")\n",
+ data_end, size);
+ return NULL;
+ }
+ }
+ else
+ {
+ /* In minor version 0, superblock is at the end of the device. */
+ if (grub_le_to_cpu64 (sb.super_offset) < data_end)
+ {
+ grub_dprintf ("mdraid1x",
+ "The data either overlaps with the superblock "
+ "or is behind it.\n");
+ return NULL;
+ }
+
+ if (sb_end > size)
+ {
+ grub_dprintf ("mdraid1x",
+ "The superblock region ends at "
+ "%" PRIuGRUB_UINT64_T ", past the end of "
+ "the disk (%" PRIuGRUB_UINT64_T ")\n",
+ sb_end, size);
+ return NULL;
+ }
+ }
+
if (sb.major_version != grub_cpu_to_le32_compile_time (1))
/* Unsupported version. */
return NULL;
--
2.19.1

View File

@ -0,0 +1,159 @@
From e94b4f23277f7572aacbbeae50b8927e03be148a Mon Sep 17 00:00:00 2001
From: Petr Vorel <pvorel@suse.cz>
Date: Thu, 15 Jul 2021 17:35:27 +0200
Subject: osdep: Introduce include/grub/osdep/major.h and use it
... to factor out fix for glibc 2.25 introduced in 7a5b301e3 (build: Use
AC_HEADER_MAJOR to find device macros).
Note: Once glibc 2.25 is old enough and this fix is not needed also
AC_HEADER_MAJOR in configure.ac should be removed.
Referencehttps://git.savannah.gnu.org/cgit/grub.git/commit/?id=e94b4f23277f7572aacbbeae50b8927e03be148a
ConflictNA
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
configure.ac | 2 +-
grub-core/osdep/devmapper/getroot.c | 7 +------
grub-core/osdep/devmapper/hostdisk.c | 7 +------
grub-core/osdep/linux/getroot.c | 7 +------
grub-core/osdep/unix/getroot.c | 7 +------
include/grub/osdep/major.h | 33 +++++++++++++++++++++++++++++++++
6 files changed, 38 insertions(+), 25 deletions(-)
create mode 100644 include/grub/osdep/major.h
diff --git a/configure.ac b/configure.ac
index b025e1e..bee28db 100644
--- a/configure.ac
+++ b/configure.ac
@@ -424,7 +424,7 @@ AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h limits.h)
# glibc 2.25 still includes sys/sysmacros.h in sys/types.h but emits deprecation
# warning which causes compilation failure later with -Werror. So use -Werror here
-# as well to force proper sys/sysmacros.h detection.
+# as well to force proper sys/sysmacros.h detection. Used in include/grub/osdep/major.h.
SAVED_CFLAGS="$CFLAGS"
CFLAGS="$HOST_CFLAGS -Werror"
AC_HEADER_MAJOR
diff --git a/grub-core/osdep/devmapper/getroot.c b/grub-core/osdep/devmapper/getroot.c
index a13a39c..9ba5c98 100644
--- a/grub-core/osdep/devmapper/getroot.c
+++ b/grub-core/osdep/devmapper/getroot.c
@@ -40,12 +40,7 @@
#include <limits.h>
#endif
-#if defined(MAJOR_IN_MKDEV)
-#include <sys/mkdev.h>
-#elif defined(MAJOR_IN_SYSMACROS)
-#include <sys/sysmacros.h>
-#endif
-
+#include <grub/osdep/major.h>
#include <libdevmapper.h>
#include <grub/types.h>
diff --git a/grub-core/osdep/devmapper/hostdisk.c b/grub-core/osdep/devmapper/hostdisk.c
index a8afc0c..c805372 100644
--- a/grub-core/osdep/devmapper/hostdisk.c
+++ b/grub-core/osdep/devmapper/hostdisk.c
@@ -11,6 +11,7 @@
#include <grub/misc.h>
#include <grub/i18n.h>
#include <grub/list.h>
+#include <grub/osdep/major.h>
#include <stdio.h>
#include <stdlib.h>
@@ -24,12 +25,6 @@
#include <errno.h>
#include <limits.h>
-#if defined(MAJOR_IN_MKDEV)
-#include <sys/mkdev.h>
-#elif defined(MAJOR_IN_SYSMACROS)
-#include <sys/sysmacros.h>
-#endif
-
#ifdef HAVE_DEVICE_MAPPER
# include <libdevmapper.h>
diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c
index 001b818..cd58858 100644
--- a/grub-core/osdep/linux/getroot.c
+++ b/grub-core/osdep/linux/getroot.c
@@ -35,12 +35,7 @@
#include <limits.h>
#endif
-#if defined(MAJOR_IN_MKDEV)
-#include <sys/mkdev.h>
-#elif defined(MAJOR_IN_SYSMACROS)
-#include <sys/sysmacros.h>
-#endif
-
+#include <grub/osdep/major.h>
#include <grub/types.h>
#include <sys/ioctl.h> /* ioctl */
#include <sys/mount.h>
diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c
index 46d7116..74f6911 100644
--- a/grub-core/osdep/unix/getroot.c
+++ b/grub-core/osdep/unix/getroot.c
@@ -51,12 +51,7 @@
#endif /* ! FLOPPY_MAJOR */
#endif
-#include <sys/types.h>
-#if defined(MAJOR_IN_MKDEV)
-#include <sys/mkdev.h>
-#elif defined(MAJOR_IN_SYSMACROS)
-#include <sys/sysmacros.h>
-#endif
+#include <grub/osdep/major.h>
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
# include <grub/util/libzfs.h>
diff --git a/include/grub/osdep/major.h b/include/grub/osdep/major.h
new file mode 100644
index 0000000..84a9159
--- /dev/null
+++ b/include/grub/osdep/major.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2021 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 <http://www.gnu.org/licenses/>.
+ *
+ * Fix for glibc 2.25 which is deprecating the namespace pollution of
+ * sys/types.h injecting major(), minor(), and makedev() into the
+ * compilation environment.
+ */
+
+#ifndef GRUB_OSDEP_MAJOR_H
+#define GRUB_OSDEP_MAJOR_H 1
+
+#include <sys/types.h>
+
+#ifdef MAJOR_IN_MKDEV
+# include <sys/mkdev.h>
+#elif defined (MAJOR_IN_SYSMACROS)
+# include <sys/sysmacros.h>
+#endif
+#endif /* GRUB_OSDEP_MAJOR_H */
--
cgit v1.1

View File

@ -0,0 +1,99 @@
From 1ea4e5ef09c06552402bf676ce262a661372f08d Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Thu, 15 Jul 2021 17:35:28 +0200
Subject: osdep/linux/hostdisk: Use stat() instead of udevadm for partition
lookup
The sysfs_partition_path() calls udevadm to resolve the sysfs path for
a block device. That can be accomplished by stating the device node
and using the major/minor to follow the symlinks in /sys/dev/block/.
This cuts the execution time of grub-mkconfig to somewhere near 55% on
system without LVM (which uses libdevmapper instead sysfs_partition_path()).
Remove udevadm call as it does not help us more than calling stat() directly.
Referencehttps://git.savannah.gnu.org/cgit/grub.git/commit/?id=1ea4e5ef09c06552402bf676ce262a661372f08d
ConflictNA
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
grub-core/osdep/linux/hostdisk.c | 52 +++++-----------------------------------
1 file changed, 6 insertions(+), 46 deletions(-)
diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c
index da62f92..d3326d0 100644
--- a/grub-core/osdep/linux/hostdisk.c
+++ b/grub-core/osdep/linux/hostdisk.c
@@ -31,6 +31,7 @@
#include <grub/misc.h>
#include <grub/i18n.h>
#include <grub/list.h>
+#include <grub/osdep/major.h>
#include <stdio.h>
#include <stdlib.h>
@@ -98,54 +99,13 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec
static char *
sysfs_partition_path (const char *dev, const char *entry)
{
- const char *argv[7];
- int fd;
- pid_t pid;
- FILE *udevadm;
- char *buf = NULL;
- size_t len = 0;
- char *path = NULL;
-
- argv[0] = "udevadm";
- argv[1] = "info";
- argv[2] = "--query";
- argv[3] = "path";
- argv[4] = "--name";
- argv[5] = dev;
- argv[6] = NULL;
-
- pid = grub_util_exec_pipe (argv, &fd);
-
- if (!pid)
- return NULL;
-
- /* Parent. Read udevadm's output. */
- udevadm = fdopen (fd, "r");
- if (!udevadm)
- {
- grub_util_warn (_("Unable to open stream from %s: %s"),
- "udevadm", strerror (errno));
- close (fd);
- goto out;
- }
-
- if (getline (&buf, &len, udevadm) > 0)
- {
- char *newline;
-
- newline = strchr (buf, '\n');
- if (newline)
- *newline = '\0';
- path = xasprintf ("/sys%s/%s", buf, entry);
- }
+ struct stat st;
-out:
- if (udevadm)
- fclose (udevadm);
- waitpid (pid, NULL, 0);
- free (buf);
+ if (stat (dev, &st) == 0 && S_ISBLK (st.st_mode))
+ return xasprintf ("/sys/dev/block/%u:%u/%s",
+ major (st.st_rdev), minor (st.st_rdev), entry);
- return path;
+ return NULL;
}
static int
--
cgit v1.1

View File

@ -350,3 +350,7 @@ Patch0350: backport-CVE-2024-1048-grub-set-bootflag-Conservative-partial-fix.pat
Patch0351: backport-CVE-2024-1048-grub-set-bootflag-More-complete-fix.patch
Patch0352: backport-CVE-2024-1048-grub-set-bootflag-Exit-calmly-when-not.patch
Patch0353: backport-CVE-2021-46848-lib-libtasn1-Fix-ETYPE_OK-off-by-one-array.patch
Patch0354: backport-disk-Generalize-MD_MAX_DISKS-to-GRUB_MDRAID_MAX_DISKS.patch
Patch0355: backport-disk-mdraid1x_linux-Prevent-infinite-recursion.patch
Patch0356: backport-osdep-Introduce-include-grub-osdep-major-h-and-use-it.patch
Patch0357: backport-osdep-linux-hostdisk-Use-stat-instead-of-udevadm.patch

View File

@ -14,7 +14,7 @@
Name: grub2
Epoch: 1
Version: 2.06
Release: 46
Release: 47
Summary: Bootloader with support for Linux, Multiboot and more
License: GPLv3+
URL: http://www.gnu.org/software/grub/
@ -453,6 +453,16 @@ fi
%{_datadir}/man/man*
%changelog
* Tue Jun 18 2024 zhangqiumiao <zhangqiumiao1@huawei.com> - 1:2.06-47
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:fix log printing in tpcm_kunpeng moddule
osdep/linux/hostdisk: Use stat() instead of udevadm for partition lookup
osdep: Introduce include/grub/osdep/major.h and use it
disk/mdraid1x_linux: Prevent infinite recursion
disk: Generalize MD_MAX_DISKS to GRUB_MDRAID_MAX_DISKS
* Tue Jun 4 2024 zhangqiumiao <zhangqiumiao1@huawei.com> - 1:2.06-46
- Type:CVE
- CVE:CVE-2021-46848