From 7fc87071e5fa7ab9ae23c56174c191609dab0dff Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 23 Jul 2024 15:18:22 +0200 Subject: [PATCH] libvirt-10.5.0-4.el9 - virt-host-validate: Allow longer list of CPU flags (RHEL-39969) Resolves: RHEL-39969 --- ...idate-Allow-longer-list-of-CPU-flags.patch | 85 +++++++++++++++++++ libvirt.spec | 6 +- 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 libvirt-virt-host-validate-Allow-longer-list-of-CPU-flags.patch diff --git a/libvirt-virt-host-validate-Allow-longer-list-of-CPU-flags.patch b/libvirt-virt-host-validate-Allow-longer-list-of-CPU-flags.patch new file mode 100644 index 0000000..1c63537 --- /dev/null +++ b/libvirt-virt-host-validate-Allow-longer-list-of-CPU-flags.patch @@ -0,0 +1,85 @@ +From f122faf68c4921d44b98700209766cae7507deec Mon Sep 17 00:00:00 2001 +Message-ID: +From: Michal Privoznik +Date: Tue, 23 Jul 2024 10:31:27 +0200 +Subject: [PATCH] virt-host-validate: Allow longer list of CPU flags + +On various occasions, virt-host-validate parses /proc/cpuinfo to +learn about CPU flags (see virHostValidateGetCPUFlags()). It does +so, by reading the file line by line until the line with CPU +flags is reached. Then the line is split into individual flags +(using space as a delimiter) and the list of flags is then +iterated over. + +This works, except for cases when the line with CPU flags is too +long. Problem is - the line is capped at 1024 bytes and on newer +CPUs (and newer kernels), the line can be significantly longer. +I've seen a line that's ~1200 characters long (with 164 flags +reported). + +Switch to unbounded read from the file (getline()). + +Resolves: https://issues.redhat.com/browse/RHEL-39969 +Signed-off-by: Michal Privoznik +Reviewed-by: Jiri Denemark +(cherry picked from commit e5232f6fd691668decd5be1b3a76cdbd3666d032) +Signed-off-by: Michal Privoznik +--- + tools/virt-host-validate-common.c | 18 +++++++----------- + 1 file changed, 7 insertions(+), 11 deletions(-) + +diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c +index 591143c24d..63cc3dbe7b 100644 +--- a/tools/virt-host-validate-common.c ++++ b/tools/virt-host-validate-common.c +@@ -106,21 +106,19 @@ virBitmap *virHostValidateGetCPUFlags(void) + { + FILE *fp; + virBitmap *flags = NULL; ++ g_autofree char *line = NULL; ++ size_t linelen = 0; + + if (!(fp = fopen("/proc/cpuinfo", "r"))) + return NULL; + + flags = virBitmapNew(VIR_HOST_VALIDATE_CPU_FLAG_LAST); + +- do { +- char line[1024]; ++ while (getline(&line, &linelen, fp) > 0) { + char *start; + g_auto(GStrv) tokens = NULL; + GStrv next; + +- if (!fgets(line, sizeof(line), fp)) +- break; +- + /* The line we're interested in is marked differently depending + * on the architecture, so check possible prefixes */ + if (!STRPREFIX(line, "flags") && +@@ -129,11 +127,9 @@ virBitmap *virHostValidateGetCPUFlags(void) + !STRPREFIX(line, "facilities")) + continue; + +- /* fgets() includes the trailing newline in the output buffer, +- * so we need to clean that up ourselves. We can safely access +- * line[strlen(line) - 1] because the checks above would cause +- * us to skip empty strings */ +- line[strlen(line) - 1] = '\0'; ++ /* getline() may include the trailing newline in the output ++ * buffer, so we need to clean that up ourselves. */ ++ virStringTrimOptionalNewline(line); + + /* Skip to the separator */ + if (!(start = strchr(line, ':'))) +@@ -153,7 +149,7 @@ virBitmap *virHostValidateGetCPUFlags(void) + if ((value = virHostValidateCPUFlagTypeFromString(*next)) >= 0) + ignore_value(virBitmapSetBit(flags, value)); + } +- } while (1); ++ } + + VIR_FORCE_FCLOSE(fp); + +-- +2.45.2 diff --git a/libvirt.spec b/libvirt.spec index a7fad61..9f25b70 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -289,7 +289,7 @@ Summary: Library providing a simple virtualization API Name: libvirt Version: 10.5.0 -Release: 3%{?dist}%{?extra_release} +Release: 4%{?dist}%{?extra_release} License: GPL-2.0-or-later AND LGPL-2.1-only AND LGPL-2.1-or-later AND OFL-1.1 URL: https://libvirt.org/ @@ -306,6 +306,7 @@ Patch6: libvirt-qemu-migration-allow-migration-for-virtiofs.patch Patch7: libvirt-virt-host-validate-Drop-extra-PASS.patch Patch8: libvirt-qemu-Don-t-leave-beingDestroyed-true-on-inactive-domain.patch Patch9: libvirt-vmx-Be-even-more-lax-when-trying-to-comprehend-serial-ports.patch +Patch10: libvirt-virt-host-validate-Allow-longer-list-of-CPU-flags.patch Requires: libvirt-daemon = %{version}-%{release} @@ -2634,6 +2635,9 @@ exit 0 %endif %changelog +* Tue Jul 23 2024 Jiri Denemark - 10.5.0-4 +- virt-host-validate: Allow longer list of CPU flags (RHEL-39969) + * Mon Jul 22 2024 Jiri Denemark - 10.5.0-3 - vmx: Be even more lax when trying to comprehend serial ports (RHEL-32182)