Skip to content

Commit 2c10b61

Browse files
gregkhbonzini
authored andcommitted
kvm: initialize all of the kvm_debugregs structure before sending it to userspace
When calling the KVM_GET_DEBUGREGS ioctl, on some configurations, there might be some unitialized portions of the kvm_debugregs structure that could be copied to userspace. Prevent this as is done in the other kvm ioctls, by setting the whole structure to 0 before copying anything into it. Bonus is that this reduces the lines of code as the explicit flag setting and reserved space zeroing out can be removed. Cc: Sean Christopherson <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: stable <[email protected]> Reported-by: Xingyuan Mo <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Message-Id: <[email protected]> Tested-by: Xingyuan Mo <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4b4191b commit 2c10b61

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5263,12 +5263,11 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
52635263
{
52645264
unsigned long val;
52655265

5266+
memset(dbgregs, 0, sizeof(*dbgregs));
52665267
memcpy(dbgregs->db, vcpu->arch.db, sizeof(vcpu->arch.db));
52675268
kvm_get_dr(vcpu, 6, &val);
52685269
dbgregs->dr6 = val;
52695270
dbgregs->dr7 = vcpu->arch.dr7;
5270-
dbgregs->flags = 0;
5271-
memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
52725271
}
52735272

52745273
static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu,

0 commit comments

Comments
 (0)