From: Kees Cook <keescook@chromium.org> To: Paolo Bonzini <pbonzini@redhat.com> Cc: LKML <linux-kernel@vger.kernel.org>, KVM <kvm@vger.kernel.org>, "Christoffer Dall" <christoffer.dall@linaro.org>, "Marc Zyngier" <marc.zyngier@arm.com>, "Christian Borntraeger" <borntraeger@de.ibm.com>, "Cornelia Huck" <cohuck@redhat.com>, "James Hogan" <james.hogan@imgtec.com>, "Paul Mackerras" <paulus@samba.org>, kernel-hardening@lists.openwall.com, "Radim Krčmář" <rkrcmar@redhat.com> Subject: Re: [PATCH 2/2] kvm: x86: fix KVM_XEN_HVM_CONFIG ioctl Date: Thu, 26 Oct 2017 15:48:53 +0200 [thread overview] Message-ID: <CAGXu5jKc8zFR0q_DScdEvWfXyBR-TjefrZ6vx1VvMghE05ssiw@mail.gmail.com> (raw) In-Reply-To: <20171026134547.23664-3-pbonzini@redhat.com> On Thu, Oct 26, 2017 at 3:45 PM, Paolo Bonzini <pbonzini@redhat.com> wrote: > This ioctl is obsolete (it was used by Xenner as far as I know) but > still let's not break it gratuitously... Its handler is copying > directly into struct kvm. Go through a bounce buffer instead, with > the added benefit that we can actually do something useful with the > flags argument---the previous code was exiting with -EINVAL but still > doing the copy. > > This technically is a userspace ABI breakage, but since no one should be > using the ioctl, it's a good occasion to see if someone actually > complains. > > Cc: kernel-hardening@lists.openwall.com > Cc: Kees Cook <keescook@chromium.org> > Cc: Radim Krčmář <rkrcmar@redhat.com> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> > --- > arch/x86/kvm/x86.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 272320eb328c..f32fbfb833b3 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -4187,13 +4187,14 @@ long kvm_arch_vm_ioctl(struct file *filp, > mutex_unlock(&kvm->lock); > break; > case KVM_XEN_HVM_CONFIG: { > + struct kvm_xen_hvm_config xhc; > r = -EFAULT; > - if (copy_from_user(&kvm->arch.xen_hvm_config, argp, > - sizeof(struct kvm_xen_hvm_config))) > + if (copy_from_user(&xhc, argp, sizeof(xhc))) This is replacing a builtin_const size argument, which would already be allowed by usercopy hardening (const sizes are implicit whitelists, since they cannot change size at runtime). However, as you point out, this API should already have been doing a bounce copy to check the flags sanity. (I'll add this to the hardening series, thanks!) -Kees > goto out; > r = -EINVAL; > - if (kvm->arch.xen_hvm_config.flags) > + if (xhc.flags) > goto out; > + memcpy(&kvm->arch.xen_hvm_config, &xhc, sizeof(xhc)); > r = 0; > break; > } > -- > 2.14.2 > -- Kees Cook Pixel Security
WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org> To: Paolo Bonzini <pbonzini@redhat.com> Cc: LKML <linux-kernel@vger.kernel.org>, KVM <kvm@vger.kernel.org>, "Christoffer Dall" <christoffer.dall@linaro.org>, "Marc Zyngier" <marc.zyngier@arm.com>, "Christian Borntraeger" <borntraeger@de.ibm.com>, "Cornelia Huck" <cohuck@redhat.com>, "James Hogan" <james.hogan@imgtec.com>, "Paul Mackerras" <paulus@samba.org>, kernel-hardening@lists.openwall.com, "Radim Krčmář" <rkrcmar@redhat.com> Subject: [kernel-hardening] Re: [PATCH 2/2] kvm: x86: fix KVM_XEN_HVM_CONFIG ioctl Date: Thu, 26 Oct 2017 15:48:53 +0200 [thread overview] Message-ID: <CAGXu5jKc8zFR0q_DScdEvWfXyBR-TjefrZ6vx1VvMghE05ssiw@mail.gmail.com> (raw) In-Reply-To: <20171026134547.23664-3-pbonzini@redhat.com> On Thu, Oct 26, 2017 at 3:45 PM, Paolo Bonzini <pbonzini@redhat.com> wrote: > This ioctl is obsolete (it was used by Xenner as far as I know) but > still let's not break it gratuitously... Its handler is copying > directly into struct kvm. Go through a bounce buffer instead, with > the added benefit that we can actually do something useful with the > flags argument---the previous code was exiting with -EINVAL but still > doing the copy. > > This technically is a userspace ABI breakage, but since no one should be > using the ioctl, it's a good occasion to see if someone actually > complains. > > Cc: kernel-hardening@lists.openwall.com > Cc: Kees Cook <keescook@chromium.org> > Cc: Radim Krčmář <rkrcmar@redhat.com> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> > --- > arch/x86/kvm/x86.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 272320eb328c..f32fbfb833b3 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -4187,13 +4187,14 @@ long kvm_arch_vm_ioctl(struct file *filp, > mutex_unlock(&kvm->lock); > break; > case KVM_XEN_HVM_CONFIG: { > + struct kvm_xen_hvm_config xhc; > r = -EFAULT; > - if (copy_from_user(&kvm->arch.xen_hvm_config, argp, > - sizeof(struct kvm_xen_hvm_config))) > + if (copy_from_user(&xhc, argp, sizeof(xhc))) This is replacing a builtin_const size argument, which would already be allowed by usercopy hardening (const sizes are implicit whitelists, since they cannot change size at runtime). However, as you point out, this API should already have been doing a bounce copy to check the flags sanity. (I'll add this to the hardening series, thanks!) -Kees > goto out; > r = -EINVAL; > - if (kvm->arch.xen_hvm_config.flags) > + if (xhc.flags) > goto out; > + memcpy(&kvm->arch.xen_hvm_config, &xhc, sizeof(xhc)); > r = 0; > break; > } > -- > 2.14.2 > -- Kees Cook Pixel Security
next prev parent reply other threads:[~2017-10-26 13:49 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-10-26 13:45 [PATCH v2 0/2] KVM: fixes for the kernel-hardening tree Paolo Bonzini 2017-10-26 13:45 ` [kernel-hardening] " Paolo Bonzini 2017-10-26 13:45 ` [PATCH 1/2] kvm: whitelist struct kvm_vcpu_arch Paolo Bonzini 2017-10-26 13:45 ` [kernel-hardening] " Paolo Bonzini 2017-10-26 14:13 ` Cornelia Huck 2017-10-26 14:13 ` [kernel-hardening] " Cornelia Huck 2017-10-26 14:21 ` Christoffer Dall 2017-10-26 14:21 ` [kernel-hardening] " Christoffer Dall 2017-10-26 14:34 ` Marc Zyngier 2017-10-26 14:34 ` [kernel-hardening] " Marc Zyngier 2017-10-26 14:51 ` Christian Borntraeger 2017-10-26 14:51 ` [kernel-hardening] " Christian Borntraeger 2017-10-30 23:28 ` [kernel-hardening] " Eric Biggers 2017-10-30 23:51 ` Kees Cook 2017-10-26 13:45 ` [PATCH 2/2] kvm: x86: fix KVM_XEN_HVM_CONFIG ioctl Paolo Bonzini 2017-10-26 13:45 ` [kernel-hardening] " Paolo Bonzini 2017-10-26 13:48 ` Kees Cook [this message] 2017-10-26 13:48 ` [kernel-hardening] " Kees Cook 2017-11-30 20:40 ` Kees Cook 2017-11-30 20:40 ` [kernel-hardening] " Kees Cook 2017-12-01 8:29 ` Paolo Bonzini 2017-12-01 8:29 ` [kernel-hardening] " Paolo Bonzini 2017-10-27 5:25 ` [PATCH v2 0/2] KVM: fixes for the kernel-hardening tree Paul Mackerras 2017-10-27 5:25 ` [kernel-hardening] " Paul Mackerras
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=CAGXu5jKc8zFR0q_DScdEvWfXyBR-TjefrZ6vx1VvMghE05ssiw@mail.gmail.com \ --to=keescook@chromium.org \ --cc=borntraeger@de.ibm.com \ --cc=christoffer.dall@linaro.org \ --cc=cohuck@redhat.com \ --cc=james.hogan@imgtec.com \ --cc=kernel-hardening@lists.openwall.com \ --cc=kvm@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=marc.zyngier@arm.com \ --cc=paulus@samba.org \ --cc=pbonzini@redhat.com \ --cc=rkrcmar@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.