From: Paolo Bonzini <pbonzini@redhat.com>
To: Leonardo Bras <leonardo@linux.ibm.com>,
Sean Christopherson <sean.j.christopherson@intel.com>,
kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Paul Mackerras" <paulus@ozlabs.org>,
"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
"Michael Ellerman" <mpe@ellerman.id.au>,
"Radim Krčmář" <rkrcmar@redhat.com>
Subject: Re: [PATCH 1/1] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm
Date: Wed, 27 Nov 2019 17:40:54 +0100 [thread overview]
Message-ID: <f3750cf8-88fc-cae7-1cfb-cb4b86b44704@redhat.com> (raw)
In-Reply-To: <20191126175212.377171-1-leonardo@linux.ibm.com>
On 26/11/19 18:52, Leonardo Bras wrote:
> Fixes a possible 'use after free' of kvm variable.
> It does use mutex_unlock(&kvm->lock) after possible freeing a variable
> with kvm_put_kvm(kvm).
>
> Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
> ---
> arch/powerpc/kvm/book3s_64_vio.c | 3 +--
> virt/kvm/kvm_main.c | 8 ++++----
> 2 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
> index 5834db0a54c6..a402ead833b6 100644
> --- a/arch/powerpc/kvm/book3s_64_vio.c
> +++ b/arch/powerpc/kvm/book3s_64_vio.c
> @@ -316,14 +316,13 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
>
> if (ret >= 0)
> list_add_rcu(&stt->list, &kvm->arch.spapr_tce_tables);
> - else
> - kvm_put_kvm(kvm);
>
> mutex_unlock(&kvm->lock);
>
> if (ret >= 0)
> return ret;
>
> + kvm_put_kvm(kvm);
> kfree(stt);
> fail_acct:
> account_locked_vm(current->mm, kvmppc_stt_pages(npages), false);
This part is a good change, as it makes the code clearer. The
virt/kvm/kvm_main.c bits, however, are not necessary as explained by Sean.
Paolo
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 13efc291b1c7..f37089b60d09 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2744,10 +2744,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
> /* Now it's all set up, let userspace reach it */
> kvm_get_kvm(kvm);
> r = create_vcpu_fd(vcpu);
> - if (r < 0) {
> - kvm_put_kvm(kvm);
> + if (r < 0)
> goto unlock_vcpu_destroy;
> - }
>
> kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu;
>
> @@ -2771,6 +2769,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
> mutex_lock(&kvm->lock);
> kvm->created_vcpus--;
> mutex_unlock(&kvm->lock);
> + if (r < 0)
> + kvm_put_kvm(kvm);
> return r;
> }
>
> @@ -3183,10 +3183,10 @@ static int kvm_ioctl_create_device(struct kvm *kvm,
> kvm_get_kvm(kvm);
> ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC);
> if (ret < 0) {
> - kvm_put_kvm(kvm);
> mutex_lock(&kvm->lock);
> list_del(&dev->vm_node);
> mutex_unlock(&kvm->lock);
> + kvm_put_kvm(kvm);
> ops->destroy(dev);
> return ret;
> }
>
next prev parent reply other threads:[~2019-11-27 16:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-26 17:52 [PATCH 1/1] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm Leonardo Bras
2019-11-26 18:14 ` Sean Christopherson
2019-11-27 16:40 ` Paolo Bonzini [this message]
2019-11-27 20:18 ` Leonardo Bras
2019-11-28 17:15 ` Leonardo Bras
2019-11-27 22:57 ` Paul Mackerras
2019-11-28 16:24 ` Leonardo Bras
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=f3750cf8-88fc-cae7-1cfb-cb4b86b44704@redhat.com \
--to=pbonzini@redhat.com \
--cc=benh@kernel.crashing.org \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=leonardo@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@ozlabs.org \
--cc=rkrcmar@redhat.com \
--cc=sean.j.christopherson@intel.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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).