Skip to contentSkip to conversation

x86/domctl: remove impossible condition in XEN_DOMCTL_getpageframeinfo3

PATCH Superseded Olaf Hering 3 participants 4 messages Mar 9, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/domctl: remove impossible condition in XEN_DOMCTL_getpageframeinfo3

The value of num is always the same as domctl->u.getpageframeinfo3.num, it was assigned just a few lines before.

---
 xen/arch/x86/domctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/domctl.c +1 -2
index 8fbbf3aeb3..46d288a490 100644
@@ -421,8 +421,7 @@ long arch_do_domctl(
         /* Games to allow this code block to handle a compat guest. */
         void __user *guest_handle = domctl->u.getpageframeinfo3.array.p;
 
-        if ( unlikely(num > 1024) ||
-             unlikely(num != domctl->u.getpageframeinfo3.num) )
+        if ( unlikely(num > 1024) )
         {
             ret = -E2BIG;
             break;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw
Quoted 4 lines · Olaf Hering

The value of num is always the same as domctl->u.getpageframeinfo3.num, it was assigned just a few lines before.

This isn't dead code.  It is a truncation check.

~Andrew

Quoted 9 lines
---
 xen/arch/x86/domctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/domctl.c +0 -0
index 8fbbf3aeb3..46d288a490 100644

xen/arch/x86/domctl.c long arch_do_domctl( · line 427

Quoted 9 lines
xen/arch/x86/domctl.c +1 -2
@@ -421,8 +421,7 @@ long arch_do_domctl(
         /* Games to allow this code block to handle a compat guest. */
         void __user *guest_handle = domctl->u.getpageframeinfo3.array.p;
 
-        if ( unlikely(num > 1024) ||
-             unlikely(num != domctl->u.getpageframeinfo3.num) )
+        if ( unlikely(num > 1024) )
         {
             ret = -E2BIG;
             break;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 7 lines · Andrew Cooper
Quoted 4 lines · Olaf Hering

The value of num is always the same as domctl->u.getpageframeinfo3.num, it was assigned just a few lines before.

This isn't dead code.  It is a truncation check.

How can this happen, other than num being a 32bit type? Perhaps the type of num should match the type of i?

Olaf

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Olaf Hering
Quoted 4 lines · Olaf Hering

The value of num is always the same as domctl->u.getpageframeinfo3.num, it was assigned just a few lines before.

It is still useful. The field in getpageframeinfo3 is uint64_aligned_t while here num is just unsigned int. The check makes sure no truncation happens.

Quoted 19 lines
---
 xen/arch/x86/domctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/domctl.c +1 -2
index 8fbbf3aeb3..46d288a490 100644
@@ -421,8 +421,7 @@ long arch_do_domctl(
         /* Games to allow this code block to handle a compat guest. */
         void __user *guest_handle = domctl->u.getpageframeinfo3.array.p;
 
-        if ( unlikely(num > 1024) ||
-             unlikely(num != domctl->u.getpageframeinfo3.num) )
+        if ( unlikely(num > 1024) )
         {
             ret = -E2BIG;
             break;
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel