linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfio: fix vfio_info_cap_add/shift
@ 2016-11-21  6:21 Eric Auger
  2016-11-21 18:52 ` David Hildenbrand
  2016-11-21 20:37 ` Alex Williamson
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Auger @ 2016-11-21  6:21 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, alex.williamson, linux-kernel, kvm

Capability header next field is an offset relative to the start of
the INFO buffer. tmp->next is assigned the proper value but iterations
implemented in vfio_info_cap_add and vfio_info_cap_shift use next
as an offset between the headers. When coping with multiple capabilities
this leads to an Oops.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 drivers/vfio/vfio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index d1d70e0..1e838d1 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -1763,7 +1763,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps,
 	header->version = version;
 
 	/* Add to the end of the capability chain */
-	for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next)
+	for (tmp = buf; tmp->next; tmp = buf + tmp->next)
 		; /* nothing */
 
 	tmp->next = caps->size;
@@ -1776,8 +1776,9 @@ EXPORT_SYMBOL_GPL(vfio_info_cap_add);
 void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset)
 {
 	struct vfio_info_cap_header *tmp;
+	void *buf = (void *)caps->buf;
 
-	for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset)
+	for (tmp = buf; tmp->next; tmp = buf + tmp->next - offset)
 		tmp->next += offset;
 }
 EXPORT_SYMBOL_GPL(vfio_info_cap_shift);
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] vfio: fix vfio_info_cap_add/shift
  2016-11-21  6:21 [PATCH] vfio: fix vfio_info_cap_add/shift Eric Auger
@ 2016-11-21 18:52 ` David Hildenbrand
  2016-11-21 20:37 ` Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2016-11-21 18:52 UTC (permalink / raw)
  To: Eric Auger, eric.auger.pro, alex.williamson, linux-kernel, kvm

Am 21.11.2016 um 07:21 schrieb Eric Auger:
> Capability header next field is an offset relative to the start of
> the INFO buffer. tmp->next is assigned the proper value but iterations
> implemented in vfio_info_cap_add and vfio_info_cap_shift use next
> as an offset between the headers. When coping with multiple capabilities
> this leads to an Oops.
>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
> ---
>  drivers/vfio/vfio.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index d1d70e0..1e838d1 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -1763,7 +1763,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps,
>  	header->version = version;
>
>  	/* Add to the end of the capability chain */
> -	for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next)
> +	for (tmp = buf; tmp->next; tmp = buf + tmp->next)
>  		; /* nothing */
>

Looks sane to me, tmp->next is always set to the old size, which 
corresponds to the offset from the start of the buffer.

>  	tmp->next = caps->size;
> @@ -1776,8 +1776,9 @@ EXPORT_SYMBOL_GPL(vfio_info_cap_add);
>  void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset)
>  {
>  	struct vfio_info_cap_header *tmp;
> +	void *buf = (void *)caps->buf;
>
> -	for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset)
> +	for (tmp = buf; tmp->next; tmp = buf + tmp->next - offset)
>  		tmp->next += offset;


Reviewed-by: David Hildenbrand <david@redhat.com>

-- 

David

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] vfio: fix vfio_info_cap_add/shift
  2016-11-21  6:21 [PATCH] vfio: fix vfio_info_cap_add/shift Eric Auger
  2016-11-21 18:52 ` David Hildenbrand
@ 2016-11-21 20:37 ` Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2016-11-21 20:37 UTC (permalink / raw)
  To: Eric Auger; +Cc: eric.auger.pro, linux-kernel, kvm, David Hildenbrand

On Mon, 21 Nov 2016 07:21:02 +0100
Eric Auger <eric.auger@redhat.com> wrote:

> Capability header next field is an offset relative to the start of
> the INFO buffer. tmp->next is assigned the proper value but iterations
> implemented in vfio_info_cap_add and vfio_info_cap_shift use next
> as an offset between the headers. When coping with multiple capabilities
> this leads to an Oops.
> 
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
> ---
>  drivers/vfio/vfio.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index d1d70e0..1e838d1 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -1763,7 +1763,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps,
>  	header->version = version;
>  
>  	/* Add to the end of the capability chain */
> -	for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next)
> +	for (tmp = buf; tmp->next; tmp = buf + tmp->next)
>  		; /* nothing */
>  
>  	tmp->next = caps->size;
> @@ -1776,8 +1776,9 @@ EXPORT_SYMBOL_GPL(vfio_info_cap_add);
>  void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset)
>  {
>  	struct vfio_info_cap_header *tmp;
> +	void *buf = (void *)caps->buf;
>  
> -	for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset)
> +	for (tmp = buf; tmp->next; tmp = buf + tmp->next - offset)
>  		tmp->next += offset;
>  }
>  EXPORT_SYMBOL_GPL(vfio_info_cap_shift);

Thanks, good to get this fixed before we start getting multiple entries
in the chain and expose it via mdev.  For that same reason I also don't
see that this needs any sort of stable backport as the existing code
works for the single entries in the tree.  Applied to next branch for
4.10 with David's R-b.  Thanks,

Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-21 20:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-21  6:21 [PATCH] vfio: fix vfio_info_cap_add/shift Eric Auger
2016-11-21 18:52 ` David Hildenbrand
2016-11-21 20:37 ` Alex Williamson

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).