git: 586e826accbb - main - amd64/vmm: Reject reserved DR6 bits supplied by userspace
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 27 Nov 2026 08:03:57 UTC
The branch main has been updated by hayzam:
URL: https://cgit.FreeBSD.org/src/commit/?id=586e826accbb430c28943b3dac8f181b93811eca
commit 586e826accbb430c28943b3dac8f181b93811eca
Author: Hayzam Sherif <hayzam@FreeBSD.org>
AuthorDate: 2026-11-27 07:34:38 +0000
Commit: Hayzam Sherif <hayzam@FreeBSD.org>
CommitDate: 2026-11-27 07:34:38 +0000
amd64/vmm: Reject reserved DR6 bits supplied by userspace
On Intel hosts the guest's DR6 is kept in the vCPU context and loaded
into the host's register before guest entry. VM_SET_REGISTER and the
snapshot restore path store any value there. Loading a value with any
of bits 63:32 set raises #GP, which panics the host.
Fail with EINVAL instead.
Reviewed by: markj
Approved by: markj
Fixes: 65eefbe42218 (Save and restore guest debug registers.)
MFC after: 1 week
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61732
---
sys/amd64/vmm/intel/vmx.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c
index e606ef108731..b3d016e7b967 100644
--- a/sys/amd64/vmm/intel/vmx.c
+++ b/sys/amd64/vmm/intel/vmx.c
@@ -3337,6 +3337,12 @@ vmxctx_setreg(struct vmxctx *vmxctx, int reg, uint64_t val)
register_t *regp;
if ((regp = vmxctx_regptr(vmxctx, reg)) != NULL) {
+ /*
+ * DR6 is loaded into the host's register before guest entry,
+ * where setting any of bits 63:32 raises #GP.
+ */
+ if (reg == VM_REG_GUEST_DR6 && (val >> 32) != 0)
+ return (EINVAL);
*regp = val;
return (0);
} else
@@ -4166,6 +4172,7 @@ vmx_vcpu_snapshot(void *vcpui, struct vm_snapshot_meta *meta)
struct vmx *vmx;
struct vmx_vcpu *vcpu;
struct vmxctx *vmxctx;
+ uint64_t dr6;
uint64_t guest_msrs[GUEST_MSR_NUM];
int err, run, hostcpu;
@@ -4271,7 +4278,10 @@ vmx_vcpu_snapshot(void *vcpui, struct vm_snapshot_meta *meta)
SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_dr1, meta, err, done);
SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_dr2, meta, err, done);
SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_dr3, meta, err, done);
- SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_dr6, meta, err, done);
+ dr6 = vmxctx->guest_dr6;
+ SNAPSHOT_VAR_OR_LEAVE(dr6, meta, err, done);
+ if (meta->op == VM_SNAPSHOT_RESTORE)
+ err = vmxctx_setreg(vmxctx, VM_REG_GUEST_DR6, dr6);
done:
return (err);