mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Yi Wang <foxywang@tencent.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] KVM: fix an error code in kvm_create_vm()
Date: Fri, 14 Jun 2024 08:00:54 +0300	[thread overview]
Message-ID: <29ed61a4-5f06-4c27-aed4-5ac3de3f45ae@moroto.mountain> (raw)
In-Reply-To: <ZmuF2PsVot33fS1x@google.com>

On Thu, Jun 13, 2024 at 04:50:48PM -0700, Sean Christopherson wrote:
> On Thu, Jun 13, 2024, Dan Carpenter wrote:
> > This error path used to return -ENOMEM from the where r is initialized
> > at the top of the function.  But a new "r = kvm_init_irq_routing(kvm);"
> > was introduced in the middle of the function so now the error code is
> > not set and it eventually leads to a NULL dereference.  Set the error
> > code back to -ENOMEM.
> > 
> > Fixes: fbe4a7e881d4 ("KVM: Setup empty IRQ routing when creating a VM")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> >  virt/kvm/kvm_main.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index 07ec9b67a202..ea7e32d722c9 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -1212,8 +1212,10 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
> >  	for (i = 0; i < KVM_NR_BUSES; i++) {
> >  		rcu_assign_pointer(kvm->buses[i],
> >  			kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT));
> > -		if (!kvm->buses[i])
> > +		if (!kvm->buses[i]) {
> > +			r = -ENOMEM;
> >  			goto out_err_no_arch_destroy_vm;
> > +		}
> >  	}
> 
> Drat.  Any objection to tweaking this slightly to guard against similar bugs in
> the future?  If not, I'll apply+push the below.

No objections from me.  :)

regards,
dan carpenter


  reply	other threads:[~2024-06-14  5:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13 14:33 Dan Carpenter
2024-06-13 23:50 ` Sean Christopherson
2024-06-14  5:00   ` Dan Carpenter [this message]
2024-06-14  6:45 ` Markus Elfring
2024-06-15  0:02 ` Sean Christopherson

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=29ed61a4-5f06-4c27-aed4-5ac3de3f45ae@moroto.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=foxywang@tencent.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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

all inboxes | Powered by JetHome®