Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: "Han, Weidong" <weidong.han@intel.com>
Cc: "'Avi Kivity'" <avi@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: [PATCH 2/4] kvm: qemu: Fix leak of ioperm data
Date: Wed, 10 Dec 2008 10:07:10 +0000	[thread overview]
Message-ID: <1228903630.5384.27.camel@blaa> (raw)
In-Reply-To: <715D42877B251141A38726ABF5CABF2C018BF9ACE0@pdsmsx503.ccr.corp.intel.com>

On Wed, 2008-12-10 at 17:44 +0800, Han, Weidong wrote:

> diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
> index 067cf03..283bfa9 100644
> --- a/qemu/qemu-kvm.c
> +++ b/qemu/qemu-kvm.c
> @@ -1145,6 +1145,18 @@ void kvm_add_ioperm_data(struct ioperm_data *data)
>      LIST_INSERT_HEAD(&ioperm_head, data, entries);
>  }
>  
> +void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num)
> +{
> +    struct ioperm_data *data;
> +
> +    LIST_FOREACH(data, &ioperm_head, entries) {
> +        if (data->start_port == start_port &&
> +            data->num == num)
> +            LIST_REMOVE(data, entries);
> +            qemu_free(data);

Two issues here:

  1) You've a "use after free bug" here; you free the structure and
     LIST_FOREACH de-references the pointer to it in order to obtain the
     pointer to the next structure.

  2) Even more serious, you're missing a set of braces so you're 
     actually freeing every structure.

What you need is:

{
    struct ioperm_data *data;

    data = LIST_FIRST(&ioperm_head);
    while (data) {
        struct ioperm_data *next = LIST_NEXT(data, entries);

        if (data->start_port == start_port && data->num == num) {
            LIST_REMOVE(data, entries);
            qemu_free(data);
        }

        data = next;
    }
}

Cheers,
Mark.


  reply	other threads:[~2008-12-10 10:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-10  9:44 [PATCH 2/4] kvm: qemu: Fix leak of ioperm data Han, Weidong
2008-12-10 10:07 ` Mark McLoughlin [this message]
2008-12-10 10:20   ` Han, Weidong

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=1228903630.5384.27.camel@blaa \
    --to=markmc@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=weidong.han@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