]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
xen/blkif: Avoid double access to src->nr_segments
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 18 Dec 2015 15:44:58 +0000 (15:44 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 18 Dec 2015 15:52:06 +0000 (15:52 +0000)
src is stored in shared memory and src->nr_segments is dereferenced
twice at the end of the function.  If a compiler decides to compile this
into two separate memory accesses then the size limitation could be
bypassed.

Fix it by removing the double access to src->nr_segments.

This is part of XSA-155.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
hw/xen_blkif.h

index c0f4136228817d9976531ab28e7099395c19d1e0..24188f40b271619dd73de516b4b9bec3377fcaca 100644 (file)
@@ -79,8 +79,10 @@ static inline void blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_reque
        dst->handle = src->handle;
        dst->id = src->id;
        dst->sector_number = src->sector_number;
-       if (n > src->nr_segments)
-               n = src->nr_segments;
+       /* prevent the compiler from optimizing the code and using src->nr_segments instead */
+       barrier();
+       if (n > dst->nr_segments)
+               n = dst->nr_segments;
        for (i = 0; i < n; i++)
                dst->seg[i] = src->seg[i];
 }
@@ -94,8 +96,10 @@ static inline void blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_reque
        dst->handle = src->handle;
        dst->id = src->id;
        dst->sector_number = src->sector_number;
-       if (n > src->nr_segments)
-               n = src->nr_segments;
+       /* prevent the compiler from optimizing the code and using src->nr_segments instead */
+       barrier();
+       if (n > dst->nr_segments)
+               n = dst->nr_segments;
        for (i = 0; i < n; i++)
                dst->seg[i] = src->seg[i];
 }