Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1581041 > unrolled thread
| Started by | David Gibson <david@gibson.dropbear.id.au> |
|---|---|
| First post | 2017-02-15 04:50 +0100 |
| Last post | 2017-02-28 13:10 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] KVM: Prevent double-free on HPT resize commit path David Gibson <david@gibson.dropbear.id.au> - 2017-02-15 04:50 +0100
Re: [PATCH] KVM: Prevent double-free on HPT resize commit path David Gibson <david@gibson.dropbear.id.au> - 2017-02-28 02:30 +0100
Re: [PATCH] KVM: Prevent double-free on HPT resize commit path Paul Mackerras <paulus@ozlabs.org> - 2017-02-28 13:10 +0100
| From | David Gibson <david@gibson.dropbear.id.au> |
|---|---|
| Date | 2017-02-15 04:50 +0100 |
| Subject | [PATCH] KVM: Prevent double-free on HPT resize commit path |
| Message-ID | <taYLo-2sg-7@gated-at.bofh.it> |
resize_hpt_release(), called once the HPT resize of a KVM guest is
completed (successfully or unsuccessfully) free()s the state structure for
the resize. It is currently not safe to call with a NULL pointer.
However, one of the error paths in kvm_vm_ioctl_resize_hpt_commit() can
invoke it with a NULL pointer. This will occur if userspace improperly
invokes KVM_PPC_RESIZE_HPT_COMMIT without previously calling
KVM_PPC_RESIZE_HPT_PREPARE, or if it calls COMMIT twice without an
intervening PREPARE.
To fix this potential crash bug - and maybe others like it, make it safe
(and a no-op) to call resize_hpt_release() with a NULL resize pointer.
Found by Dan Carpenter with a static checker.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
arch/powerpc/kvm/book3s_64_mmu_hv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 013552f..72ccac2 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -1407,6 +1407,9 @@ static void resize_hpt_release(struct kvm *kvm, struct kvm_resize_hpt *resize)
{
BUG_ON(kvm->arch.resize_hpt != resize);
+ if (!resize)
+ return;
+
if (resize->hpt.virt)
kvmppc_free_hpt(&resize->hpt);
--
2.9.3
[toc] | [next] | [standalone]
| From | David Gibson <david@gibson.dropbear.id.au> |
|---|---|
| Date | 2017-02-28 02:30 +0100 |
| Message-ID | <tfEM2-5AN-11@gated-at.bofh.it> |
| In reply to | #1581041 |
[Multipart message — attachments visible in raw view] — view raw
On Wed, Feb 15, 2017 at 02:40:04PM +1100, David Gibson wrote:
> resize_hpt_release(), called once the HPT resize of a KVM guest is
> completed (successfully or unsuccessfully) free()s the state structure for
> the resize. It is currently not safe to call with a NULL pointer.
>
> However, one of the error paths in kvm_vm_ioctl_resize_hpt_commit() can
> invoke it with a NULL pointer. This will occur if userspace improperly
> invokes KVM_PPC_RESIZE_HPT_COMMIT without previously calling
> KVM_PPC_RESIZE_HPT_PREPARE, or if it calls COMMIT twice without an
> intervening PREPARE.
>
> To fix this potential crash bug - and maybe others like it, make it safe
> (and a no-op) to call resize_hpt_release() with a NULL resize pointer.
>
> Found by Dan Carpenter with a static checker.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Ping,
Paul have you taken this one?
> ---
> arch/powerpc/kvm/book3s_64_mmu_hv.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index 013552f..72ccac2 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -1407,6 +1407,9 @@ static void resize_hpt_release(struct kvm *kvm, struct kvm_resize_hpt *resize)
> {
> BUG_ON(kvm->arch.resize_hpt != resize);
>
> + if (!resize)
> + return;
> +
> if (resize->hpt.virt)
> kvmppc_free_hpt(&resize->hpt);
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[toc] | [prev] | [next] | [standalone]
| From | Paul Mackerras <paulus@ozlabs.org> |
|---|---|
| Date | 2017-02-28 13:10 +0100 |
| Message-ID | <tfOLo-4dY-3@gated-at.bofh.it> |
| In reply to | #1589095 |
On Tue, Feb 28, 2017 at 11:56:55AM +1100, David Gibson wrote: > On Wed, Feb 15, 2017 at 02:40:04PM +1100, David Gibson wrote: > > resize_hpt_release(), called once the HPT resize of a KVM guest is > > completed (successfully or unsuccessfully) free()s the state structure for > > the resize. It is currently not safe to call with a NULL pointer. > > > > However, one of the error paths in kvm_vm_ioctl_resize_hpt_commit() can > > invoke it with a NULL pointer. This will occur if userspace improperly > > invokes KVM_PPC_RESIZE_HPT_COMMIT without previously calling > > KVM_PPC_RESIZE_HPT_PREPARE, or if it calls COMMIT twice without an > > intervening PREPARE. > > > > To fix this potential crash bug - and maybe others like it, make it safe > > (and a no-op) to call resize_hpt_release() with a NULL resize pointer. > > > > Found by Dan Carpenter with a static checker. > > > > Reported-by: Dan Carpenter <dan.carpenter@oracle.com> > > Signed-off-by: David Gibson <david@gibson.dropbear.id.au> > > Ping, > > Paul have you taken this one? Yes, thanks, it's in Linus' tree now. Paul.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web