kern: perform NULL check in unregister paths (command/extcmd)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 25 lines · On 2025-09-10 18:27, [email protected] wrote:
----------------------------------------------------------------------
Message: 1
Date: Tue, 9 Sep 2025 11:09:55 -0400
From: Stefan Berger <[email protected]>
To: Sudhakar Kuppusamy <[email protected]>, Srish Srinivasan
<[email protected]>
Cc: [email protected], [email protected], [email protected],
[email protected], [email protected]
Subject: Re: [PATCH v2] kern: perform NULL check in unregister paths
(command/extcmd)
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowedQuoted 8 lines · Sudhakar Kuppusamy
Quoted 8 lines · Srish Srinivasan
Many modules call grub_unregister_{command(),
extcmd()} fromGRUB_MOD_FINI()without checking for a failure in registration. This could lead to a NULL pointer dereference in unregistration.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Perform explicit NULL check in both the unregister helpers.
Signed-off-by Srish Srinivasan <[email protected]>Reviewed-by Sudhakar Kuppusamy <[email protected]>Reviewed-by Stefan Berger <[email protected]>
Hi Srish,
Thank you so much for the patch!
A failure in registration will anyways returns NULL. Re checking it might not make a sense. Do you have any specific scenario for this? Thank you!
Regards,
Avnish Chouhan
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 37 lines · Avnish Chouhan
Quoted 25 lines · On 2025-09-10 18:27, [email protected] wrote:
----------------------------------------------------------------------
Message: 1
Date: Tue, 9 Sep 2025 11:09:55 -0400
From: Stefan Berger <[email protected]>
To: Sudhakar Kuppusamy <[email protected]>, Srish Srinivasan <[email protected]>
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: [PATCH v2] kern: perform NULL check in unregister paths (command/extcmd)
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowedQuoted 8 lines · Sudhakar Kuppusamy
Quoted 8 lines · Srish Srinivasan
Many modules call grub_unregister_{command(),
extcmd()} fromGRUB_MOD_FINI()without checking for a failure in registration. This could lead to a NULL pointer dereference in unregistration.Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Perform explicit NULL check in both the unregister helpers.
Signed-off-by Srish Srinivasan <[email protected]>Reviewed-by Sudhakar Kuppusamy <[email protected]>Reviewed-by Stefan Berger <[email protected]>Hi Srish,
Thank you so much for the patch!
Quoted 6 lines
A failure in registration will anyways returns NULL. Re checking it might not make a sense. Do you have any specific scenario for this? Thank you!
Regards,
Avnish Chouhan
Hi Avnish,
During module registration, if there is a failure in memory allocation then a NULL is returned.
https://github.com/olafhering/grub/blob/master/grub-core/kern/command.c#L40
But during unregistration, not all modules check for this NULL.
here is an example where NULL is checked.
https://github.com/olafhering/grub/blob/master/grub-core/disk/diskfilter.c#L1491
But for example in
https://github.com/olafhering/grub/blob/master/grub-core/commands/efi/efitextmode.c#L151
there is no explicit check done before unregistration. And there are many such instances.
Thanks,
Srish
Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [RFC PATCH 1/2] target/i386: add compatibility property for arch_capabilities
In reply to a message not in the archiveQuoted 73 lines · On 2025-09-10 18:27, [email protected] wrote:
Message: 2
Date: Wed, 10 Sep 2025 10:24:31 +0200
From: Hector Cao <[email protected]>
To: [email protected]
Subject: [RFC PATCH 1/2] target/i386: add compatibility property for
arch_capabilities
Message-ID: <[email protected]>Prior to v10.1, if requested by user, arch-capabilities is always on despite the fact that CPUID advertises it to be off/unvailable. this causes a migration issue for VMs that are run on a machine without arch-capabilities and expect this feature to be present on the destination host with QEMU 10.1.
This commit add a compatibility property to restore the legacy behavior for all machines with version prior to 10.1
Signed-off-by Hector Cao <[email protected]>--- hw/core/machine.c | 1 + migration/migration.h | 12 ++++++++++++ migration/options.c | 3 +++ target/i386/kvm/kvm.c | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-)hw/core/machine.c +1
-0@@ -45,6 +45,7 @@ GlobalProperty hw_compat_10_0[] = { { "vfio-pci", "x-migration-load-config-after-iter", "off" }, { "ramfb", "use-legacy-x86-rom", "true"}, { "vfio-pci-nohotplug", "use-legacy-x86-rom", "true" }, + { "migration", "arch-cap-always-on", "true" }, };const size_t hw_compat_10_0_len =G_N_ELEMENTS (hw_compat_10_0);migration/migration.h +5
-0@@ -510,6 +510,18 @@ struct MigrationState {bool rdma_migration;GSource *hup_source; + +/* +* This variable allows to keep the backward compatibility with QEMU (<10.1) +* on the arch-capabilities detection. +* With the commit d3a2413 (since 10.1), the arch-capabilities feature is gated
+ * with the CPUID bit (CPUID_7_0_EDX_ARCH_CAPABILITIES) instead
of being always
+ * enabled when user requests for it. this new behavior breaks
migration of VMs
+ * created and run with older QEMU on machines withoutIA32_ARCH_CAPABILITIESMSR,
+ * those VMs might have arch-capabilities enabled and break when
migrating
+ * to a host with QEMU 10.1 with error : missing feature
arch-capabilitiesmigration/migration.h +2
-0+*/ +bool arch_cap_always_on; }; void migrate_set_state(MigrationStatus *state, MigrationStatus
old_state,migration/options.c +0
-0
migration/options.c const Property migration_properties[] = { · line 209
Quoted 7 lines
migration/options.c +2
-0@@ -203,6 +203,9 @@ const Property migration_properties[] = { MIGRATION_CAPABILITY_SWITCHOVER_ACK),DEFINE_PROP_MIG_CAP ("x-dirty-limit" ,MIGRATION_CAPABILITY_DIRTY_LIMIT ),DEFINE_PROP_MIG_CAP ("mapped-ram" ,MIGRATION_CAPABILITY_MAPPED_RAM ), + + DEFINE_PROP_BOOL("arch-cap-always-on", MigrationState,
Hi Hector,
Missing space before '('
Quoted 36 lines
migration/options.c +1
-0+ arch_cap_always_on, false), };const
size_tmigration_properties_count=ARRAY_SIZE(migration_properties);target/i386/kvm/kvm.c +2
-0@@ -42,6 +42,7 @@#include "xen-emu.h" #include "hyperv.h" #include "hyperv-proto.h" +#include "migration/migration.h" #include "gdbstub/enums.h" #include "qemu/host-utils.h" @@ -438,6 +439,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s,uint32_t function, uint32_t ret = 0;uint32_t cpuid_1_edx, unused;uint64_t bitmask; +MigrationState *ms =migrate_get_current (); cpuid =get_supported_cpuid (s);@@ -508,7 +510,8 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s,uint32_t function, * mcahines at all, do not show the fake ARCH_CAPABILITIES MSRthat
* KVM sets up.
*/
- if (!has_msr_arch_capabs || !(edx &CPUID_7_0_EDX_ARCH_CAPABILITIES)) {target/i386/kvm/kvm.c +2
-0+ if (!has_msr_arch_capabs + || (!(edx & CPUID_7_0_EDX_ARCH_CAPABILITIES) &&
Quoted 1 line
(!ms->arch_cap_always_on))) {
Please move '{' in the next line.
Thank you!
Regards,
Avnish Chouhan
Quoted 10 lines
ret &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES; } } else if (function == 7 && index == 1 && reg == R_EAX) {--
2.45.2------------------------------
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [RFC PATCH 2/2] target/i386: add compatibility property for pdcm feature
In reply to a message not in the archiveQuoted 71 lines · On 2025-09-10 18:27, [email protected] wrote:
Message: 3
Date: Wed, 10 Sep 2025 10:24:32 +0200
From: Hector Cao <[email protected]>
To: [email protected]
Subject: [RFC PATCH 2/2] target/i386: add compatibility property for
pdcm feature
Message-ID: <[email protected]>The pdcm feature is supposed to be disabled when PMU is not available. Up until v10.1, pdcm feature is enabled even when PMU is off. This behavior has been fixed but this change breaks the migration of VMs that are run with QEMU < 10.0 and expect the pdcm feature to be enabled on the destination host.
This commit restores the legacy behavior for machines with version prior to 10.1 to allow the migration from older QEMU to QEMU 10.1.
Signed-off-by Hector Cao <[email protected]>--- hw/core/machine.c | 1 + migration/migration.h | 11 +++++++++++ migration/options.c | 3 +++ target/i386/cpu.c | 17 ++++++++++++++--- 4 files changed, 29 insertions(+), 3 deletions(-)hw/core/machine.c +1
-0@@ -46,6 +46,7 @@ GlobalProperty hw_compat_10_0[] = { { "ramfb", "use-legacy-x86-rom", "true"}, { "vfio-pci-nohotplug", "use-legacy-x86-rom", "true" }, { "migration", "arch-cap-always-on", "true" }, + { "migration", "pdcm-on-even-without-pmu", "true" }, };const size_t hw_compat_10_0_len =G_N_ELEMENTS (hw_compat_10_0);migration/migration.h +0
-0@@ -522,6 +522,17 @@ struct MigrationState {* to a host with QEMU 10.1 with error : missing feature arch-capabilities
*/ bool arch_cap_always_on;migration/migration.h +3
-0+ +/* +* This variable allows to keep the backward compatibility with QEMU (<10.1)
+ * on the pdcm feature detection. The pdcm feature should be
disabled when
+ * PMU is not available. Prio to 10.1, there is a bug and pdcm can
still be
+ * enabled even if PMU is off. This behavior has been fixed by the
commitmigration/migration.h +2
-0+* e68ec29 (since 10.1). +* This new behavior breaks migration of VMs that expect, with the QEMU
migration/migration.h +3
-0+* (since 10.1), pdcm to be disabled. +*/ +bool pdcm_on_even_without_pmu; }; void migrate_set_state(MigrationStatus *state, MigrationStatus
old_state,migration/options.c +0
-0
migration/options.c const Property migration_properties[] = { · line 210
Quoted 5 lines
migration/options.c +2
-0@@ -206,6 +206,9 @@ const Property migration_properties[] = {DEFINE_PROP_BOOL ("arch-cap-always-on" , MigrationState, arch_cap_always_on, false), + + DEFINE_PROP_BOOL("pdcm-on-even-without-pmu", MigrationState,
Hi Hector,
Missing space before '('
Quoted 28 lines
migration/options.c +1
-0+ pdcm_on_even_without_pmu, false), };const size_t migration_properties_count =ARRAY_SIZE (migration_properties);target/i386/cpu.c +3
-0@@ -51,6 +51,8 @@#include "disas/capstone.h" #include "cpu-internal.h" +#include "migration/migration.h" +static void x86_cpu_realizefn (DeviceState *dev,Error **errp); static void x86_cpu_get_supported_cpuid(uint32_t func, uint32_t index, uint32_t *eax, uint32_t *ebx,@@ -7839,6 +7841,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t signature[3];X86CPUTopoInfo *topo_info = &env->topo_info;uint32_t threads_per_pkg; +MigrationState *ms =migrate_get_current (); threads_per_pkg =x86_threads_per_pkg (topo_info);
target/i386/cpu.c void cpu_x86_cpuid(CPUX86State *env, uint32_t · line 7901
Quoted 5 lines
target/i386/cpu.c +1
-0@@ -7894,6 +7897,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,/* Fixup overflow: max value for bits 23-16 is 255. */ *ebx |=MIN (num,255 ) <<16 ; } +if (ms->pdcm_on_even_without_pmu) {
Please move '{' to next line.
target/i386/cpu.c void cpu_x86_cpuid(CPUX86State *env, uint32_t · line 7902
Quoted 1 line
target/i386/cpu.c +1
-0+if (!cpu->enable_pmu) {
Same as above!
Quoted 16 lines
target/i386/cpu.c +3
-0+ *ecx &= ~CPUID_EXT_PDCM ; + } + }break ;case 2 : {/* cache info: needed for Pentium Pro compatibility */ const CPUCaches *caches;target/i386/cpu.c +1
-0@@ -8892,6 +8900,7 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)FeatureWord w;int i;GList *l; +MigrationState *ms =migrate_get_current ();for (l = plus_features; l; l = l->next) {const char *prop = l->data;
target/i386/cpu.c void x86_cpu_expand_features(X86CPU *cpu, Error · line 8957
Quoted 8 lines
target/i386/cpu.c +1
-3@@ -8944,9 +8953,11 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) } } -/* PDCM is fixed1 bit for TDX */ -if (!cpu->enable_pmu && !is_tdx_vm ()) { - env->features[FEAT_1_ECX ] &= ~CPUID_EXT_PDCM ; +if (!ms->pdcm_on_even_without_pmu) {
Same as above!
target/i386/cpu.c void x86_cpu_expand_features(X86CPU *cpu, Error · line 8959
Quoted 2 lines
target/i386/cpu.c +2
-0+/* PDCM is fixed1 bit for TDX */ +if (!cpu->enable_pmu && !is_tdx_vm ()) {
same as above!
Thank you!
Regards,
Avnish Chouhan
Quoted 9 lines
target/i386/cpu.c +2
-0+ env->features[FEAT_1_ECX ] &= ~CPUID_EXT_PDCM ; + } }for (i = 0; i < ARRAY_SIZE(feature_dependencies); i++) {--
2.45.2
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel