Skip to contentSkip to conversation

xen: re-add type checking to {,__}copy_from_guest_offset()

PATCH In review Jan Beulich 3 participants 3 messages Jun 24, 2024 – Jun 25, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: re-add type checking to {,__}copy_from_guest_offset()

When re-working them to avoid UB on guest address calculations, I failed to add explicit type checks in exchange for the implicit ones that until then had happened in assignments that were there anyway.

Fixes 43d5c5d5f70b ("xen: avoid UB in guest handle arithmetic")
xen/include/xen/guest_access.h +2 -0
@@ -86,6 +86,7 @@
 #define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
     unsigned long s_ = (unsigned long)(hnd).p;          \
     typeof(*(ptr)) *_d = (ptr);                         \
+    (void)((hnd).p == _d);                              \
     raw_copy_from_guest(_d,                             \
                         (const void *)(s_ + (off) * sizeof(*_d)), \
                         (nr) * sizeof(*_d));            \
@@ -140,6 +141,7 @@
 #define __copy_from_guest_offset(ptr, hnd, off, nr) ({          \
     unsigned long s_ = (unsigned long)(hnd).p;                  \
     typeof(*(ptr)) *_d = (ptr);                                 \
+    (void)((hnd).p == _d);                                      \
     __raw_copy_from_guest(_d,                                   \
                           (const void *)(s_ + (off) * sizeof(*_d)), \
                           (nr) * sizeof(*_d));                  \
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jan Beulich

When re-working them to avoid UB on guest address calculations, I failed to add explicit type checks in exchange for the implicit ones that until then had happened in assignments that were there anyway.

Fixes 43d5c5d5f70b ("xen: avoid UB in guest handle arithmetic")
#2 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich

When re-working them to avoid UB on guest address calculations, I failed
to add explicit type checks in exchange for the implicit ones that until
then had happened in assignments that were there anyway.

Fixes 43d5c5d5f70b ("xen: avoid UB in guest handle arithmetic")

~ Oleksii