All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/hvm: Correct hvm_ioreq_server_alloc_rangesets() failure path
@ 2014-06-04 11:00 Andrew Cooper
  2014-06-04 11:30 ` Paul Durrant
  2014-06-04 12:22 ` Jan Beulich
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Cooper @ 2014-06-04 11:00 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Paul Durrant, Keir Fraser, Jan Beulich

Coverity-ID: 1220092 "Unsigned compare against 0"
Coverity-ID: 1220093 "Out-of-bounds read"

Both of these are cased by the the while() loop in the fail path, which
results in an infinite loop and memory corruption from rangeset_destroy().

Move hvm_ioreq_server_free_rangesets() up and use it for cleanup on the
failure path.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>
CC: Paul Durrant <paul.durrant@citrix.com>
---
 xen/arch/x86/hvm/hvm.c |   27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 4f993f4..1f13329 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -824,6 +824,18 @@ static void hvm_ioreq_server_unmap_pages(struct hvm_ioreq_server *s,
     }
 }
 
+static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s,
+                                            bool_t is_default)
+{
+    unsigned int i;
+
+    if ( is_default )
+        return;
+
+    for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
+        rangeset_destroy(s->range[i]);
+}
+
 static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s, 
                                             bool_t is_default)
 {
@@ -861,24 +873,11 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
     return 0;
 
  fail:
-    while ( --i >= 0 )
-        rangeset_destroy(s->range[i]);
+    hvm_ioreq_server_free_rangesets(s, 0);
 
     return rc;
 }
 
-static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s, 
-                                            bool_t is_default)
-{
-    unsigned int i;
-
-    if ( is_default )
-        return;
-
-    for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
-        rangeset_destroy(s->range[i]);
-}
-
 static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s,
                                     bool_t is_default)
 {
-- 
1.7.10.4

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

* Re: [PATCH] x86/hvm: Correct hvm_ioreq_server_alloc_rangesets() failure path
  2014-06-04 11:00 [PATCH] x86/hvm: Correct hvm_ioreq_server_alloc_rangesets() failure path Andrew Cooper
@ 2014-06-04 11:30 ` Paul Durrant
  2014-06-04 12:22 ` Jan Beulich
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Durrant @ 2014-06-04 11:30 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Keir (Xen.org), Jan Beulich

> -----Original Message-----
> From: Andrew Cooper [mailto:andrew.cooper3@citrix.com]
> Sent: 04 June 2014 12:01
> To: Xen-devel
> Cc: Andrew Cooper; Keir (Xen.org); Jan Beulich; Paul Durrant
> Subject: [PATCH] x86/hvm: Correct hvm_ioreq_server_alloc_rangesets()
> failure path
> 
> Coverity-ID: 1220092 "Unsigned compare against 0"
> Coverity-ID: 1220093 "Out-of-bounds read"
> 
> Both of these are cased by the the while() loop in the fail path, which
> results in an infinite loop and memory corruption from rangeset_destroy().
> 
> Move hvm_ioreq_server_free_rangesets() up and use it for cleanup on the
> failure path.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Keir Fraser <keir@xen.org>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Paul Durrant <paul.durrant@citrix.com>

Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

> ---
>  xen/arch/x86/hvm/hvm.c |   27 +++++++++++++--------------
>  1 file changed, 13 insertions(+), 14 deletions(-)
> 
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index 4f993f4..1f13329 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -824,6 +824,18 @@ static void hvm_ioreq_server_unmap_pages(struct
> hvm_ioreq_server *s,
>      }
>  }
> 
> +static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s,
> +                                            bool_t is_default)
> +{
> +    unsigned int i;
> +
> +    if ( is_default )
> +        return;
> +
> +    for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
> +        rangeset_destroy(s->range[i]);
> +}
> +
>  static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
>                                              bool_t is_default)
>  {
> @@ -861,24 +873,11 @@ static int hvm_ioreq_server_alloc_rangesets(struct
> hvm_ioreq_server *s,
>      return 0;
> 
>   fail:
> -    while ( --i >= 0 )
> -        rangeset_destroy(s->range[i]);
> +    hvm_ioreq_server_free_rangesets(s, 0);
> 
>      return rc;
>  }
> 
> -static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s,
> -                                            bool_t is_default)
> -{
> -    unsigned int i;
> -
> -    if ( is_default )
> -        return;
> -
> -    for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
> -        rangeset_destroy(s->range[i]);
> -}
> -
>  static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s,
>                                      bool_t is_default)
>  {
> --
> 1.7.10.4

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

* Re: [PATCH] x86/hvm: Correct hvm_ioreq_server_alloc_rangesets() failure path
  2014-06-04 11:00 [PATCH] x86/hvm: Correct hvm_ioreq_server_alloc_rangesets() failure path Andrew Cooper
  2014-06-04 11:30 ` Paul Durrant
@ 2014-06-04 12:22 ` Jan Beulich
  2014-06-04 12:25   ` Andrew Cooper
  1 sibling, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2014-06-04 12:22 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Paul Durrant, Keir Fraser, Xen-devel

>>> On 04.06.14 at 13:00, <andrew.cooper3@citrix.com> wrote:
> Coverity-ID: 1220092 "Unsigned compare against 0"
> Coverity-ID: 1220093 "Out-of-bounds read"
> 
> Both of these are cased by the the while() loop in the fail path, which
> results in an infinite loop and memory corruption from rangeset_destroy().
> 
> Move hvm_ioreq_server_free_rangesets() up and use it for cleanup on the
> failure path.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Since you and Paul appear to agree to fix it that way, it'll go in as is,
but ...

> @@ -861,24 +873,11 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
>      return 0;
>  
>   fail:
> -    while ( --i >= 0 )

... the one line equivalent fix would have been to use while ( i-- ).

Jan

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

* Re: [PATCH] x86/hvm: Correct hvm_ioreq_server_alloc_rangesets() failure path
  2014-06-04 12:22 ` Jan Beulich
@ 2014-06-04 12:25   ` Andrew Cooper
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Cooper @ 2014-06-04 12:25 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Paul Durrant, Keir Fraser, Xen-devel

On 04/06/14 13:22, Jan Beulich wrote:
>
>> @@ -861,24 +873,11 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
>>      return 0;
>>  
>>   fail:
>> -    while ( --i >= 0 )
> ... the one line equivalent fix would have been to use while ( i-- ).
>
> Jan

I was considering the possible case where alloc/free_rangesets() gain
further moving parts, although I guess is probably unlikely.

~Andrew

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

end of thread, other threads:[~2014-06-04 12:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-04 11:00 [PATCH] x86/hvm: Correct hvm_ioreq_server_alloc_rangesets() failure path Andrew Cooper
2014-06-04 11:30 ` Paul Durrant
2014-06-04 12:22 ` Jan Beulich
2014-06-04 12:25   ` Andrew Cooper

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.