From: Al Viro <viro@ZenIV.linux.org.uk>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
borntraeger@de.ibm.com, frankja@linux.vnet.ibm.com
Subject: Re: [PATCH v1 1/1] KVM: add missing kvm_put_kvm in case of failure
Date: Tue, 27 Jun 2017 14:50:07 +0100 [thread overview]
Message-ID: <20170627135007.GG10672@ZenIV.linux.org.uk> (raw)
In-Reply-To: <66c8737e-20f7-627f-a1dd-8139d3304959@redhat.com>
On Tue, Jun 27, 2017 at 03:08:32PM +0200, Paolo Bonzini wrote:
> On 27/06/2017 13:57, Claudio Imbrenda wrote:
> > If I'm not missing anything, in case kvm_create_vm_debugfs fails, we
> > will have a memory leak due to not freeing the kvm object.
> >
> > A call to kvm_put_kvm was accidentally removed from an error handling in
> > commit 506cfba9e726 ("KVM: don't use anon_inode_getfd() before possible failures")
> >
> > This patch simply restores the call to kvm_put_kvm, so that the kvm
> > object is destroyed before returning an error.
> >
> > Signed-off-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
> > Fixes: 506cfba9e726 ("KVM: don't use anon_inode_getfd() before possible failures")
> > ---
> > virt/kvm/kvm_main.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index f0fe9d0..257d2a8 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -3194,6 +3194,7 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
> > if (kvm_create_vm_debugfs(kvm, r) < 0) {
> > put_unused_fd(r);
> > fput(file);
> > + kvm_put_kvm(kvm);
> > return -ENOMEM;
> > }
> >
> >
>
> Queued, thanks.
It's broken. Look: once we are past the anon_inode_getfile(), the
reference we held on kvm is transferred into new struct file. After
that point we don't drop kvm - we drop file. And as long as that
file is held, it will keep holding what used to be our reference to
kvm. Once all references to file are gone, its ->release() will be
called and that's where kvm reference in it will be dropped.
IOW, this patch introduces a double-put.
next prev parent reply other threads:[~2017-06-27 13:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-27 11:57 [PATCH v1 1/1] KVM: add missing kvm_put_kvm in case of failure Claudio Imbrenda
2017-06-27 13:08 ` Paolo Bonzini
2017-06-27 13:50 ` Al Viro [this message]
2017-06-27 13:57 ` Paolo Bonzini
2017-06-27 13:34 ` Al Viro
2017-06-27 13:40 ` Paolo Bonzini
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=20170627135007.GG10672@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=borntraeger@de.ibm.com \
--cc=frankja@linux.vnet.ibm.com \
--cc=imbrenda@linux.vnet.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@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: link
Be 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.