lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 27 Jun 2017 14:50:07 +0100
From:   Al Viro <viro@...IV.linux.org.uk>
To:     Paolo Bonzini <pbonzini@...hat.com>
Cc:     Claudio Imbrenda <imbrenda@...ux.vnet.ibm.com>,
        kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
        borntraeger@...ibm.com, frankja@...ux.vnet.ibm.com
Subject: Re: [PATCH v1 1/1] KVM: add missing kvm_put_kvm in case of failure

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@...ux.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ