diff mbox

x86/traps: replace ASSERT() checking array bounds

Message ID 582056A0020000780011C962@prv-mh.provo.novell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Beulich Nov. 7, 2016, 9:25 a.m. UTC
Avoid out of bounds accesses on non-debug builds.

Coverity ID: 1055744

Signed-off-by: Jan Beulich <jbeulich@suse.com>
x86/traps: replace ASSERT() checking array bounds

Avoid out of bounds accesses on non-debug builds.

Coverity ID: 1055744

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -3764,7 +3764,11 @@ void async_exception_cleanup(struct vcpu
             if ( (curr->async_exception_mask ^
                   curr->async_exception_state(trap).old_mask) == (1 << trap) )
                 break;
-    ASSERT(trap <= VCPU_TRAP_LAST);
+    if ( unlikely(trap > VCPU_TRAP_LAST) )
+    {
+        ASSERT_UNREACHABLE();
+        return;
+    }
 
     /* Restore previous asynchronous exception mask. */
     curr->async_exception_mask = curr->async_exception_state(trap).old_mask;

Comments

Andrew Cooper Nov. 7, 2016, 10:22 a.m. UTC | #1
On 07/11/16 09:25, Jan Beulich wrote:
> Avoid out of bounds accesses on non-debug builds.
>
> Coverity ID: 1055744
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

>
> --- a/xen/arch/x86/traps.c
> +++ b/xen/arch/x86/traps.c
> @@ -3764,7 +3764,11 @@ void async_exception_cleanup(struct vcpu
>              if ( (curr->async_exception_mask ^
>                    curr->async_exception_state(trap).old_mask) == (1 << trap) )
>                  break;
> -    ASSERT(trap <= VCPU_TRAP_LAST);
> +    if ( unlikely(trap > VCPU_TRAP_LAST) )
> +    {
> +        ASSERT_UNREACHABLE();
> +        return;
> +    }
>  
>      /* Restore previous asynchronous exception mask. */
>      curr->async_exception_mask = curr->async_exception_state(trap).old_mask;
>
>
>
Wei Liu Nov. 7, 2016, 10:41 a.m. UTC | #2
On Mon, Nov 07, 2016 at 10:22:56AM +0000, Andrew Cooper wrote:
> On 07/11/16 09:25, Jan Beulich wrote:
> > Avoid out of bounds accesses on non-debug builds.
> >
> > Coverity ID: 1055744
> >
> > Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> 

Release-acked-by: Wei Liu <wei.liu2@citrix.com>
diff mbox

Patch

--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -3764,7 +3764,11 @@  void async_exception_cleanup(struct vcpu
             if ( (curr->async_exception_mask ^
                   curr->async_exception_state(trap).old_mask) == (1 << trap) )
                 break;
-    ASSERT(trap <= VCPU_TRAP_LAST);
+    if ( unlikely(trap > VCPU_TRAP_LAST) )
+    {
+        ASSERT_UNREACHABLE();
+        return;
+    }
 
     /* Restore previous asynchronous exception mask. */
     curr->async_exception_mask = curr->async_exception_state(trap).old_mask;