git: a3ec6dce02fb - main - vmm/amd64: VM_SET_CPUID ioctl should refuse zero-entry non-legacy cpuid cfg

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 25 Nov 2026 21:35:53 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=a3ec6dce02fbea4c878efa5d81332a9482ee6f06

commit a3ec6dce02fbea4c878efa5d81332a9482ee6f06
Author:     Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
AuthorDate: 2025-07-10 07:00:19 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-25 21:29:06 +0000

    vmm/amd64: VM_SET_CPUID ioctl should refuse zero-entry non-legacy cpuid cfg
    
    The kernel shouldn't accept a cpuid configuration that has no entries
    without having the legacy flag set and just return EINVAL. A VCPU cpuid
    configuration must either have zero cpuid entries and the legacy flag
    set, or it must have the legacy flag clear and at least one cpuid entry.
    
    Reviewed by:            markj
    MFC after:              1 month
    Sponsored by:           The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D51553
---
 sys/amd64/vmm/vmm_dev_machdep.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sys/amd64/vmm/vmm_dev_machdep.c b/sys/amd64/vmm/vmm_dev_machdep.c
index 5002dea94139..44be88b3ea8d 100644
--- a/sys/amd64/vmm/vmm_dev_machdep.c
+++ b/sys/amd64/vmm/vmm_dev_machdep.c
@@ -578,6 +578,13 @@ vmmdev_machdep_ioctl(struct vm *vm, struct vcpu *vcpu, u_long cmd, caddr_t data,
 				free(entries, M_VMMDEV);
 				break;
 			}
+		} else {
+			/*
+			 * Not using "legacy" handling and no cpuid entries
+			 * given isn't allowed either.
+			 */
+			error = EINVAL;
+			break;
 		}
 
 		vcpu_cpuid_config_t vm_cfg = {