From: Alex Williamson <alex.williamson@redhat.com>
To: Baptiste Reynal <b.reynal@virtualopensystems.com>
Cc: eric.auger@linaro.org, tech@virtualopensystems.com,
qemu-devel@nongnu.org, kvmarm@lists.cs.columbia.edu
Subject: Re: [Qemu-devel] [RFC PATCH 2/4] hw/vfio/common.c : vfio_get_dev_property
Date: Mon, 12 Jan 2015 08:36:55 -0700 [thread overview]
Message-ID: <1421077015.6130.18.camel@redhat.com> (raw)
In-Reply-To: <1421068903-8981-3-git-send-email-b.reynal@virtualopensystems.com>
On Mon, 2015-01-12 at 14:21 +0100, Baptiste Reynal wrote:
> Add a function to handle ioctl VFIO_DEVICE_GET_DEV_PROPERTY
> to retrieve properties from a VFIO device.
>
> Signed-off-by: Baptiste Reynal <b.reynal@virtualopensystems.com>
> ---
> hw/vfio/common.c | 33 +++++++++++++++++++++++++++++++++
> include/hw/vfio/vfio-common.h | 2 ++
> 2 files changed, 35 insertions(+)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index ba00ec9..698d2c4 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -958,3 +958,36 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
>
> return vfio_container_do_ioctl(as, groupid, req, param);
> }
> +
> +struct vfio_dev_property *vfio_get_dev_property(int device, const char *name,
> + unsigned int type)
> +{
> + unsigned int length = 0;
> + struct vfio_dev_property *property = NULL;
> + int ret;
> +
> + length = strlen(name) + 1;
> +
> + while (1) {
> + unsigned int argsz = sizeof(struct vfio_dev_property) + length;
> + property = realloc(property, argsz);
By my read, realloc() doesn't give zero'd memory, so property->length is
uninitialized here.
> + property->argsz = argsz;
> + property->type = type;
> + strcpy((char *) property->data, name);
> +
> + ret = ioctl(device, VFIO_DEVICE_GET_DEV_PROPERTY, property);
This ioctl might not exit.
> + if (length < property->length) {
Which means this compares length to random memory and potentially causes
a segfault when trying to realloc.
What types of devices are going to have VFIO_DEVICE_GET_DEV_PROPERTY and
is this appropriate for common? The error and return here leaves
something to be desired. Maybe only return for a given error.
> + length = property->length;
> + } else {
> + break;
> + }
> + }
> +
> + if (ret) {
> + g_free(property);
> + property = NULL;
> + }
> +
> + return property;
> +}
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 2f1b09c..9c649cd 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -149,6 +149,8 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as);
> void vfio_put_group(VFIOGroup *group);
> int vfio_get_device(VFIOGroup *group, const char *name,
> VFIODevice *vbasedev);
> +struct vfio_dev_property *vfio_get_dev_property(int device, const char *name,
> + unsigned int type);
>
> extern const MemoryRegionOps vfio_region_ops;
> extern const MemoryListener vfio_memory_listener;
next prev parent reply other threads:[~2015-01-12 15:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-12 13:21 [Qemu-devel] [RFC PATCH 0/4] VFIO platform: Use device properties API Baptiste Reynal
2015-01-12 13:21 ` [Qemu-devel] [RFC PATCH 1/4] linux-headers update Baptiste Reynal
2015-01-12 13:21 ` [Qemu-devel] [RFC PATCH 2/4] hw/vfio/common.c : vfio_get_dev_property Baptiste Reynal
2015-01-12 15:36 ` Alex Williamson [this message]
2015-01-12 13:21 ` [Qemu-devel] [RFC PATCH 3/4] hw/arm/sysbus-fdt: vfio device property for interrupts Baptiste Reynal
2015-01-15 15:57 ` Eric Auger
2015-01-12 13:21 ` [Qemu-devel] [RFC PATCH 4/4] hw/arm/sysbus-fdt: arm, pl330 vfio device property Baptiste Reynal
2015-01-15 16:16 ` Eric Auger
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=1421077015.6130.18.camel@redhat.com \
--to=alex.williamson@redhat.com \
--cc=b.reynal@virtualopensystems.com \
--cc=eric.auger@linaro.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=qemu-devel@nongnu.org \
--cc=tech@virtualopensystems.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;
as well as URLs for NNTP newsgroup(s).