* [patch v2] x86: kvm: x86: fix information leak to userland
@ 2010-10-30 18:54 ` Vasiliy Kulikov
0 siblings, 0 replies; 22+ messages in thread
From: Vasiliy Kulikov @ 2010-10-30 18:54 UTC (permalink / raw)
To: Jan Kiszka
Cc: kernel-janitors, Avi Kivity, Marcelo Tosatti, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, x86, kvm, linux-kernel
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.
Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
---
Compile tesed only.
arch/x86/kvm/x86.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index b0818f6..463c65b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2560,6 +2560,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
!kvm_exception_is_soft(vcpu->arch.exception.nr);
events->exception.nr = vcpu->arch.exception.nr;
events->exception.has_error_code = vcpu->arch.exception.has_error_code;
+ events->exception.pad = 0;
events->exception.error_code = vcpu->arch.exception.error_code;
events->interrupt.injected =
@@ -2573,12 +2574,14 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
events->nmi.injected = vcpu->arch.nmi_injected;
events->nmi.pending = vcpu->arch.nmi_pending;
events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu);
+ events->nmi.pad = 0;
events->sipi_vector = vcpu->arch.sipi_vector;
events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING
| KVM_VCPUEVENT_VALID_SIPI_VECTOR
| KVM_VCPUEVENT_VALID_SHADOW);
+ memset(&events->reserved, 0, sizeof(events->reserved));
}
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,
dbgregs->dr6 = vcpu->arch.dr6;
dbgregs->dr7 = vcpu->arch.dr7;
dbgregs->flags = 0;
+ memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
}
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)
sizeof(ps->channels));
ps->flags = kvm->arch.vpit->pit_state.flags;
mutex_unlock(&kvm->arch.vpit->pit_state.lock);
+ memset(&ps->reserved, 0, sizeof(ps->reserved));
return r;
}
@@ -3486,6 +3491,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
user_ns.clock = kvm->arch.kvmclock_offset + now_ns;
local_irq_enable();
user_ns.flags = 0;
+ memset(&user_ns.pad, 0, sizeof(user_ns.pad));
r = -EFAULT;
if (copy_to_user(argp, &user_ns, sizeof(user_ns)))
--
Vasiliy
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [patch v2] x86: kvm: x86: fix information leak to userland
2010-10-30 18:54 ` Vasiliy Kulikov
@ 2010-11-01 17:19 ` Marcelo Tosatti
-1 siblings, 0 replies; 22+ messages in thread
From: Marcelo Tosatti @ 2010-11-01 17:19 UTC (permalink / raw)
To: Vasiliy Kulikov
Cc: Jan Kiszka, kernel-janitors, Avi Kivity, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, x86, kvm, linux-kernel
On Sat, Oct 30, 2010 at 10:54:47PM +0400, Vasiliy Kulikov wrote:
> 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.
>
> Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
> ---
> Compile tesed only.
>
> arch/x86/kvm/x86.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
Applied, thanks.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [patch v2] x86: kvm: x86: fix information leak to userland
@ 2010-11-01 17:19 ` Marcelo Tosatti
0 siblings, 0 replies; 22+ messages in thread
From: Marcelo Tosatti @ 2010-11-01 17:19 UTC (permalink / raw)
To: Vasiliy Kulikov
Cc: Jan Kiszka, kernel-janitors, Avi Kivity, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, x86, kvm, linux-kernel
On Sat, Oct 30, 2010 at 10:54:47PM +0400, Vasiliy Kulikov wrote:
> 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.
>
> Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
> ---
> Compile tesed only.
>
> arch/x86/kvm/x86.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
Applied, thanks.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [patch v2] x86: kvm: x86: fix information leak to userland
2010-10-30 18:54 ` Vasiliy Kulikov
@ 2011-07-26 17:05 ` Alexander Graf
-1 siblings, 0 replies; 22+ messages in thread
From: Alexander Graf @ 2011-07-26 17:05 UTC (permalink / raw)
To: Vasiliy Kulikov
Cc: Jan Kiszka, kernel-janitors, Avi Kivity, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
On 30.10.2010, at 20:54, Vasiliy Kulikov wrote:
> 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.
>
> Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
> ---
> Compile tesed only.
>
> arch/x86/kvm/x86.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index b0818f6..463c65b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2560,6 +2560,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
> !kvm_exception_is_soft(vcpu->arch.exception.nr);
> events->exception.nr = vcpu->arch.exception.nr;
> events->exception.has_error_code = vcpu->arch.exception.has_error_code;
> + events->exception.pad = 0;
> events->exception.error_code = vcpu->arch.exception.error_code;
>
> events->interrupt.injected > @@ -2573,12 +2574,14 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
> events->nmi.injected = vcpu->arch.nmi_injected;
> events->nmi.pending = vcpu->arch.nmi_pending;
> events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu);
> + events->nmi.pad = 0;
>
> events->sipi_vector = vcpu->arch.sipi_vector;
>
> events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING
> | KVM_VCPUEVENT_VALID_SIPI_VECTOR
> | KVM_VCPUEVENT_VALID_SHADOW);
> + memset(&events->reserved, 0, sizeof(events->reserved));
> }
>
> 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,
> dbgregs->dr6 = vcpu->arch.dr6;
> dbgregs->dr7 = vcpu->arch.dr7;
> dbgregs->flags = 0;
> + memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
> }
>
> 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)
> sizeof(ps->channels));
> ps->flags = kvm->arch.vpit->pit_state.flags;
> mutex_unlock(&kvm->arch.vpit->pit_state.lock);
> + memset(&ps->reserved, 0, sizeof(ps->reserved));
struct kvm_pit_state2 {
struct kvm_pit_channel_state channels[3];
__u32 flags;
__u32 reserved[9];
};
So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
Alex
> return r;
> }
>
> @@ -3486,6 +3491,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
> user_ns.clock = kvm->arch.kvmclock_offset + now_ns;
> local_irq_enable();
> user_ns.flags = 0;
> + memset(&user_ns.pad, 0, sizeof(user_ns.pad));
>
> r = -EFAULT;
> if (copy_to_user(argp, &user_ns, sizeof(user_ns)))
> --
> Vasiliy
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [patch v2] x86: kvm: x86: fix information leak to userland
@ 2011-07-26 17:05 ` Alexander Graf
0 siblings, 0 replies; 22+ messages in thread
From: Alexander Graf @ 2011-07-26 17:05 UTC (permalink / raw)
To: Vasiliy Kulikov
Cc: Jan Kiszka, kernel-janitors, Avi Kivity, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
On 30.10.2010, at 20:54, Vasiliy Kulikov wrote:
> 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.
>
> Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
> ---
> Compile tesed only.
>
> arch/x86/kvm/x86.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index b0818f6..463c65b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2560,6 +2560,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
> !kvm_exception_is_soft(vcpu->arch.exception.nr);
> events->exception.nr = vcpu->arch.exception.nr;
> events->exception.has_error_code = vcpu->arch.exception.has_error_code;
> + events->exception.pad = 0;
> events->exception.error_code = vcpu->arch.exception.error_code;
>
> events->interrupt.injected =
> @@ -2573,12 +2574,14 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
> events->nmi.injected = vcpu->arch.nmi_injected;
> events->nmi.pending = vcpu->arch.nmi_pending;
> events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu);
> + events->nmi.pad = 0;
>
> events->sipi_vector = vcpu->arch.sipi_vector;
>
> events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING
> | KVM_VCPUEVENT_VALID_SIPI_VECTOR
> | KVM_VCPUEVENT_VALID_SHADOW);
> + memset(&events->reserved, 0, sizeof(events->reserved));
> }
>
> 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,
> dbgregs->dr6 = vcpu->arch.dr6;
> dbgregs->dr7 = vcpu->arch.dr7;
> dbgregs->flags = 0;
> + memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
> }
>
> 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)
> sizeof(ps->channels));
> ps->flags = kvm->arch.vpit->pit_state.flags;
> mutex_unlock(&kvm->arch.vpit->pit_state.lock);
> + memset(&ps->reserved, 0, sizeof(ps->reserved));
struct kvm_pit_state2 {
struct kvm_pit_channel_state channels[3];
__u32 flags;
__u32 reserved[9];
};
So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
Alex
> return r;
> }
>
> @@ -3486,6 +3491,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
> user_ns.clock = kvm->arch.kvmclock_offset + now_ns;
> local_irq_enable();
> user_ns.flags = 0;
> + memset(&user_ns.pad, 0, sizeof(user_ns.pad));
>
> r = -EFAULT;
> if (copy_to_user(argp, &user_ns, sizeof(user_ns)))
> --
> Vasiliy
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [patch v2] x86: kvm: x86: fix information leak to userland
2011-07-26 17:05 ` Alexander Graf
@ 2011-07-26 17:24 ` Avi Kivity
-1 siblings, 0 replies; 22+ messages in thread
From: Avi Kivity @ 2011-07-26 17:24 UTC (permalink / raw)
To: Alexander Graf
Cc: Vasiliy Kulikov, Jan Kiszka, kernel-janitors, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
On 07/26/2011 08:05 PM, Alexander Graf wrote:
> struct kvm_pit_state2 {
> struct kvm_pit_channel_state channels[3];
> __u32 flags;
> __u32 reserved[9];
> };
>
> So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
>
An address of an array is the array itself.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [patch v2] x86: kvm: x86: fix information leak to userland
@ 2011-07-26 17:24 ` Avi Kivity
0 siblings, 0 replies; 22+ messages in thread
From: Avi Kivity @ 2011-07-26 17:24 UTC (permalink / raw)
To: Alexander Graf
Cc: Vasiliy Kulikov, Jan Kiszka, kernel-janitors, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
On 07/26/2011 08:05 PM, Alexander Graf wrote:
> struct kvm_pit_state2 {
> struct kvm_pit_channel_state channels[3];
> __u32 flags;
> __u32 reserved[9];
> };
>
> So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
>
An address of an array is the array itself.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [patch v2] x86: kvm: x86: fix information leak to userland
2011-07-26 17:24 ` Avi Kivity
@ 2011-07-26 17:38 ` Alexander Graf
-1 siblings, 0 replies; 22+ messages in thread
From: Alexander Graf @ 2011-07-26 17:38 UTC (permalink / raw)
To: Avi Kivity
Cc: Vasiliy Kulikov, Jan Kiszka, kernel-janitors, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
On 26.07.2011, at 19:24, Avi Kivity wrote:
> On 07/26/2011 08:05 PM, Alexander Graf wrote:
>> struct kvm_pit_state2 {
>> struct kvm_pit_channel_state channels[3];
>> __u32 flags;
>> __u32 reserved[9];
>> };
>>
>> So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
>>
>
> An address of an array is the array itself.
Ah, nice. So it's really a matter of taste then rather than functionality. Good to know :)
Alex
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [patch v2] x86: kvm: x86: fix information leak to userland
@ 2011-07-26 17:38 ` Alexander Graf
0 siblings, 0 replies; 22+ messages in thread
From: Alexander Graf @ 2011-07-26 17:38 UTC (permalink / raw)
To: Avi Kivity
Cc: Vasiliy Kulikov, Jan Kiszka, kernel-janitors, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
On 26.07.2011, at 19:24, Avi Kivity wrote:
> On 07/26/2011 08:05 PM, Alexander Graf wrote:
>> struct kvm_pit_state2 {
>> struct kvm_pit_channel_state channels[3];
>> __u32 flags;
>> __u32 reserved[9];
>> };
>>
>> So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
>>
>
> An address of an array is the array itself.
Ah, nice. So it's really a matter of taste then rather than functionality. Good to know :)
Alex
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [patch v2] x86: kvm: x86: fix information leak to userland
2011-07-26 17:05 ` Alexander Graf
@ 2011-07-26 17:28 ` Vasiliy Kulikov
-1 siblings, 0 replies; 22+ messages in thread
From: Vasiliy Kulikov @ 2011-07-26 17:28 UTC (permalink / raw)
To: Alexander Graf
Cc: Jan Kiszka, kernel-janitors, Avi Kivity, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
Alexander,
On Tue, Jul 26, 2011 at 19:05 +0200, Alexander Graf wrote:
> > @@ -2623,6 +2626,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
> > dbgregs->dr6 = vcpu->arch.dr6;
> > dbgregs->dr7 = vcpu->arch.dr7;
> > dbgregs->flags = 0;
> > + memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
> > }
> >
> > 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)
> > sizeof(ps->channels));
> > ps->flags = kvm->arch.vpit->pit_state.flags;
> > mutex_unlock(&kvm->arch.vpit->pit_state.lock);
> > + memset(&ps->reserved, 0, sizeof(ps->reserved));
>
> struct kvm_pit_state2 {
> struct kvm_pit_channel_state channels[3];
> __u32 flags;
> __u32 reserved[9];
> };
>
> So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
No, the array name and an address of the array give the same address. I
could use ps->reserved instead of &ps->reserved, but it is a question of
coding style. I got opposite opinions on this question from different
maintainers.
Another thing is that sizeof() of the array name and the pointer to the
first array element differ. But I used sizeof(array) here, so it should
be correct.
Thanks,
--
Vasiliy Kulikov
http://www.openwall.com - bringing security into open computing environments
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [patch v2] x86: kvm: x86: fix information leak to userland
@ 2011-07-26 17:28 ` Vasiliy Kulikov
0 siblings, 0 replies; 22+ messages in thread
From: Vasiliy Kulikov @ 2011-07-26 17:28 UTC (permalink / raw)
To: Alexander Graf
Cc: Jan Kiszka, kernel-janitors, Avi Kivity, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
Alexander,
On Tue, Jul 26, 2011 at 19:05 +0200, Alexander Graf wrote:
> > @@ -2623,6 +2626,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
> > dbgregs->dr6 = vcpu->arch.dr6;
> > dbgregs->dr7 = vcpu->arch.dr7;
> > dbgregs->flags = 0;
> > + memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
> > }
> >
> > 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)
> > sizeof(ps->channels));
> > ps->flags = kvm->arch.vpit->pit_state.flags;
> > mutex_unlock(&kvm->arch.vpit->pit_state.lock);
> > + memset(&ps->reserved, 0, sizeof(ps->reserved));
>
> struct kvm_pit_state2 {
> struct kvm_pit_channel_state channels[3];
> __u32 flags;
> __u32 reserved[9];
> };
>
> So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
No, the array name and an address of the array give the same address. I
could use ps->reserved instead of &ps->reserved, but it is a question of
coding style. I got opposite opinions on this question from different
maintainers.
Another thing is that sizeof() of the array name and the pointer to the
first array element differ. But I used sizeof(array) here, so it should
be correct.
Thanks,
--
Vasiliy Kulikov
http://www.openwall.com - bringing security into open computing environments
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [patch v2] x86: kvm: x86: fix information leak to userland
2011-07-26 17:28 ` Vasiliy Kulikov
@ 2011-07-26 17:39 ` Alexander Graf
-1 siblings, 0 replies; 22+ messages in thread
From: Alexander Graf @ 2011-07-26 17:39 UTC (permalink / raw)
To: Vasiliy Kulikov
Cc: Jan Kiszka, kernel-janitors, Avi Kivity, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
On 26.07.2011, at 19:28, Vasiliy Kulikov wrote:
> Alexander,
>
> On Tue, Jul 26, 2011 at 19:05 +0200, Alexander Graf wrote:
>>> @@ -2623,6 +2626,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
>>> dbgregs->dr6 = vcpu->arch.dr6;
>>> dbgregs->dr7 = vcpu->arch.dr7;
>>> dbgregs->flags = 0;
>>> + memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
>>> }
>>>
>>> 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)
>>> sizeof(ps->channels));
>>> ps->flags = kvm->arch.vpit->pit_state.flags;
>>> mutex_unlock(&kvm->arch.vpit->pit_state.lock);
>>> + memset(&ps->reserved, 0, sizeof(ps->reserved));
>>
>> struct kvm_pit_state2 {
>> struct kvm_pit_channel_state channels[3];
>> __u32 flags;
>> __u32 reserved[9];
>> };
>>
>> So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
>
> No, the array name and an address of the array give the same address. I
> could use ps->reserved instead of &ps->reserved, but it is a question of
> coding style. I got opposite opinions on this question from different
> maintainers.
>
> Another thing is that sizeof() of the array name and the pointer to the
> first array element differ. But I used sizeof(array) here, so it should
> be correct.
Yup, the sizeof looks fine. I was really only puzzled about the &array part. But if it's standardized to return the same as array, then that's great and I can call myself more educated now :)
Alex
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [patch v2] x86: kvm: x86: fix information leak to userland
@ 2011-07-26 17:39 ` Alexander Graf
0 siblings, 0 replies; 22+ messages in thread
From: Alexander Graf @ 2011-07-26 17:39 UTC (permalink / raw)
To: Vasiliy Kulikov
Cc: Jan Kiszka, kernel-janitors, Avi Kivity, Marcelo Tosatti,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, kvm,
linux-kernel
On 26.07.2011, at 19:28, Vasiliy Kulikov wrote:
> Alexander,
>
> On Tue, Jul 26, 2011 at 19:05 +0200, Alexander Graf wrote:
>>> @@ -2623,6 +2626,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu,
>>> dbgregs->dr6 = vcpu->arch.dr6;
>>> dbgregs->dr7 = vcpu->arch.dr7;
>>> dbgregs->flags = 0;
>>> + memset(&dbgregs->reserved, 0, sizeof(dbgregs->reserved));
>>> }
>>>
>>> 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)
>>> sizeof(ps->channels));
>>> ps->flags = kvm->arch.vpit->pit_state.flags;
>>> mutex_unlock(&kvm->arch.vpit->pit_state.lock);
>>> + memset(&ps->reserved, 0, sizeof(ps->reserved));
>>
>> struct kvm_pit_state2 {
>> struct kvm_pit_channel_state channels[3];
>> __u32 flags;
>> __u32 reserved[9];
>> };
>>
>> So memset(&ps->reserved) would give you the a __u32 **, no? Same goes for all the other array sets in here. Or am I understanding some C logic wrong? :)
>
> No, the array name and an address of the array give the same address. I
> could use ps->reserved instead of &ps->reserved, but it is a question of
> coding style. I got opposite opinions on this question from different
> maintainers.
>
> Another thing is that sizeof() of the array name and the pointer to the
> first array element differ. But I used sizeof(array) here, so it should
> be correct.
Yup, the sizeof looks fine. I was really only puzzled about the &array part. But if it's standardized to return the same as array, then that's great and I can call myself more educated now :)
Alex
^ permalink raw reply [flat|nested] 22+ messages in thread