Skip to contentSkip to conversation

x86/mm: Fix Coverity issues 1373105 and 1373106

PATCH In review Razvan Cojocaru 3 participants 5 messages Sep 21, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/mm: Fix Coverity issues 1373105 and 1373106

Added missing error checks in p2m_set_mem_access_multi().

---
Changes since V1:
- Returning -EFAULT instead of -EINVAL.
- Replaced stray TAB with spaces.

---
 xen/arch/x86/mm/p2m.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
xen/arch/x86/mm/p2m.c +6 -2
index b16e563..9526fff 100644
@@ -1936,8 +1936,12 @@ long p2m_set_mem_access_multi(struct domain *d,
         uint8_t access;
         uint64_t gfn_l;
 
-        copy_from_guest_offset(&gfn_l, pfn_list, start, 1);
-        copy_from_guest_offset(&access, access_list, start, 1);
+        if ( copy_from_guest_offset(&gfn_l, pfn_list, start, 1) ||
+             copy_from_guest_offset(&access, access_list, start, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
 
         if ( !xenmem_access_to_p2m_access(p2m, access, &a) )
         {
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 17 lines · Razvan Cojocaru

Added missing error checks in p2m_set_mem_access_multi().

---
Changes since V1:
- Returning -EFAULT instead of -EINVAL.
- Replaced stray TAB with spaces.

---
 xen/arch/x86/mm/p2m.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
xen/arch/x86/mm/p2m.c +0 -0
index b16e563..9526fff 100644
@@ -1936,8 +1936,12 @@ long p2m_set_mem_access_multi(struct domain *d,
         uint8_t access;

xen/arch/x86/mm/p2m.c long p2m_set_mem_access_multi(struct domain *d, · line 1944

Quoted 10 lines
xen/arch/x86/mm/p2m.c +6 -2
         uint64_t gfn_l;
 
-        copy_from_guest_offset(&gfn_l, pfn_list, start, 1);
-        copy_from_guest_offset(&access, access_list, start, 1);
+        if ( copy_from_guest_offset(&gfn_l, pfn_list, start, 1) ||
+             copy_from_guest_offset(&access, access_list, start, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }

This will return EFAULT even if it has managed to successfully handle some of the pfn/access pairs. It looks like this is sort of typical (the handful of places I could find that had copy_from_guest* inside a loop followed a similar form).

So:

I'll check this in.

-George

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

#2 lore raw
In reply to Razvan Cojocaru
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 21.09.16 at 14:41, <[email protected]> wrote:

Added missing error checks in p2m_set_mem_access_multi().

I think the patch subject should say what is being changed/fixed, and the two Coverity IDs should be listed here instead. Otherwise someone looking over just the patch titles will have no idea what this is actually about. If I end up committing this, I'll take the liberty to do adjustments.

Jan

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

#3 lore raw
Quoted 8 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 21.09.16 at 14:41, <[email protected]> wrote:

Added missing error checks in p2m_set_mem_access_multi().

I think the patch subject should say what is being changed/fixed, and the two Coverity IDs should be listed here instead. Otherwise someone looking over just the patch titles will have no idea what this is actually about. If I end up committing this, I'll take the liberty to do adjustments.

I said I'd commit it, so how about:

x86/mm: Add missing copy_from_user error checks in p2m_set_access_multi

-George

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

#4 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.09.16 at 14:55, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 21.09.16 at 14:41, <[email protected]> wrote:

Added missing error checks in p2m_set_mem_access_multi().

I think the patch subject should say what is being changed/fixed, and the two Coverity IDs should be listed here instead. Otherwise someone looking over just the patch titles will have no idea what this is actually about. If I end up committing this, I'll take the liberty to do adjustments.

Quoted 3 lines

I said I'd commit it, so how about:

x86/mm: Add missing copy_from_user error checks in p2m_set_access_multi

Sound good.

Jan

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