diff mbox series

[for-4.19] xen: re-add type checking to {,__}copy_from_guest_offset()

Message ID 6fc55df2-5d92-4f3f-8eb3-69bd89bfea4e@suse.com (mailing list archive)
State New, archived
Headers show
Series [for-4.19] xen: re-add type checking to {,__}copy_from_guest_offset() | expand

Commit Message

Jan Beulich June 24, 2024, 12:26 p.m. UTC
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")
Signed-off-by: Jan Beulich <jbeulich@suse.com>

Comments

Andrew Cooper June 24, 2024, 1:20 p.m. UTC | #1
On 24/06/2024 1:26 pm, Jan Beulich wrote:
> 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")
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Oleksii Kurochko June 25, 2024, 8:03 a.m. UTC | #2
On Mon, 2024-06-24 at 14:20 +0100, Andrew Cooper wrote:
> On 24/06/2024 1:26 pm, Jan Beulich wrote:
> > 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")
> > Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

Release-Acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

~ Oleksii
diff mbox series

Patch

--- a/xen/include/xen/guest_access.h
+++ b/xen/include/xen/guest_access.h
@@ -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));                  \