From: Markus Armbruster <armbru@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org, Igor Mammedov <imammedo@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
David Hildenbrand <david@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2] hostmem: Validate host-nodes before setting bitmap
Date: Fri, 30 Nov 2018 14:22:21 +0100 [thread overview]
Message-ID: <87in0ek8du.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20181130122844.29103-1-ehabkost@redhat.com> (Eduardo Habkost's message of "Fri, 30 Nov 2018 10:28:44 -0200")
Eduardo Habkost <ehabkost@redhat.com> writes:
> host_memory_backend_set_host_nodes() was not validating
> host-nodes before writing to backend->host_nodes, making QEMU
> write beyond the end of the bitmap.
>
> Fix the crash and add a simple regression test for the fix.
>
> While at it, fix memory leak of the list returned by
> visit_type_uint16List().
>
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Changes v1 -> v2:
> * Remove extra `l = l->next` statement
> (reported by Stefano Garzarella)
> * Fix (existing) leak of `host_nodes`
> (reported by Markus Armbruster)
> ---
> backends/hostmem.c | 17 +++++++++----
> tests/acceptance/host-nodes-limit.py | 36 ++++++++++++++++++++++++++++
> 2 files changed, 49 insertions(+), 4 deletions(-)
> create mode 100644 tests/acceptance/host-nodes-limit.py
>
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 1a89342039..af800284e0 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -103,14 +103,23 @@ host_memory_backend_set_host_nodes(Object *obj, Visitor *v, const char *name,
> {
> #ifdef CONFIG_NUMA
> HostMemoryBackend *backend = MEMORY_BACKEND(obj);
> - uint16List *l = NULL;
> + uint16List *l, *host_nodes = NULL;
>
> - visit_type_uint16List(v, name, &l, errp);
> + visit_type_uint16List(v, name, &host_nodes, errp);
>
> - while (l) {
> + for (l = host_nodes; l; l = l->next) {
> + if (l->value >= MAX_NODES) {
> + error_setg(errp, "Invalid host-nodes value: %d", l->value);
> + goto out;
> + }
> + }
> +
> + for (l = host_nodes; l; l = l->next) {
> bitmap_set(backend->host_nodes, l->value, 1);
> - l = l->next;
> }
> +
> +out:
> + qapi_free_uint16List(host_nodes);
> #else
> error_setg(errp, "NUMA node binding are not supported by this QEMU");
> #endif
Care to fix the leak in host_memory_backend_get_host_nodes(), too?
[...]
Reviewed-by: Markus Armbruster <armbru@redhat.com>
next prev parent reply other threads:[~2018-11-30 13:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-30 12:28 [Qemu-devel] [PATCH v2] hostmem: Validate host-nodes before setting bitmap Eduardo Habkost
2018-11-30 12:35 ` Stefano Garzarella
2018-11-30 12:51 ` David Hildenbrand
2018-11-30 13:22 ` Markus Armbruster [this message]
2018-11-30 14:27 ` Eduardo Habkost
2018-11-30 15:47 ` Markus Armbruster
2018-11-30 14:53 ` [Qemu-devel] [PATCH for-3.1? " Eric Blake
2018-11-30 17:55 ` Markus Armbruster
2018-11-30 18:19 ` Eduardo Habkost
2018-12-04 13:29 ` [Qemu-devel] [PATCH " Igor Mammedov
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=87in0ek8du.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=david@redhat.com \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@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.