Skip to content

Commit 97e69aa

Browse files
segoonmatosatti
authored andcommitted
KVM: x86: fix information leak to userland
Structures kvm_vcpu_events, kvm_debugregs, kvm_pit_state2 and kvm_clock_data are copied to userland with some padding and reserved fields unitialized. It leads to leaking of contents of kernel stack memory. We have to initialize them to zero. In patch v1 Jan Kiszka suggested to fill reserved fields with zeros instead of memset'ting the whole struct. It makes sense as these fields are explicitly marked as padding. No more fields need zeroing. KVM-Stable-Tag. Signed-off-by: Vasiliy Kulikov <segooon@gmail.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
1 parent d8cdddc commit 97e69aa

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎arch/x86/kvm/x86.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
25602560
!kvm_exception_is_soft(vcpu->arch.exception.nr);
25612561
events->exception.nr = vcpu->arch.exception.nr;
25622562
events->exception.has_error_code = vcpu->arch.exception.has_error_code;
2563+
events->exception.pad = 0;
25632564
events->exception.error_code = vcpu->arch.exception.error_code;
25642565

25652566
events->interrupt.injected =
@@ -2573,12 +2574,14 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
25732574
events->nmi.injected = vcpu->arch.nmi_injected;
25742575
events->nmi.pending = vcpu->arch.nmi_pending;
25752576
events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu);
2577+
events->nmi.pad = 0;
25762578

25772579
events->sipi_vector = vcpu->arch.sipi_vector;
25782580

25792581
events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING
25802582
| KVM_VCPUEVENT_VALID_SIPI_VECTOR
25812583
| KVM_VCPUEVENT_VALID_SHADOW);
2584+
memset(&events->reserved, 0, sizeof(events->reserved));
25822585
}
25832586

25842587
static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
@@ -2623,6 +2626,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
26232626
dbgregs->dr6 = vcpu->arch.dr6;
26242627
dbgregs->dr7 = vcpu->arch.dr7;
26252628
dbgregs->flags = 0;
2629+
memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
26262630
}
26272631

26282632
static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu,
@@ -3106,6 +3110,7 @@ static int kvm_vm_ioctl_get_pit2(struct kvm *kvm, struct kvm_pit_state2 *ps)
31063110
sizeof(ps->channels));
31073111
ps->flags = kvm->arch.vpit->pit_state.flags;
31083112
mutex_unlock(&kvm->arch.vpit->pit_state.lock);
3113+
memset(&ps->reserved, 0, sizeof(ps->reserved));
31093114
return r;
31103115
}
31113116

@@ -3486,6 +3491,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
34863491
user_ns.clock = kvm->arch.kvmclock_offset + now_ns;
34873492
local_irq_enable();
34883493
user_ns.flags = 0;
3494+
memset(&user_ns.pad, 0, sizeof(user_ns.pad));
34893495

34903496
r = -EFAULT;
34913497
if (copy_to_user(argp, &user_ns, sizeof(user_ns)))

0 commit comments

Comments
 (0)