Skip to contentSkip to conversation

x86: fix bug_line()

PATCH In review Jan Beulich 2 participants 2 messages Oct 11, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: fix bug_line()

Due to the packing into a bit field together with a relocated field, the computation can overflow when the relocated field ends up getting a negative value stored. Hence it isn't sufficient to correct the value by 1 in this case, but we also need to mask the result to the width of the original bit field.

xen/include/asm-x86/bug.h +4 -2
@@ -15,9 +15,11 @@ struct bug_frame {
 
 #define bug_loc(b) ((const void *)(b) + (b)->loc_disp)
 #define bug_ptr(b) ((const void *)(b) + (b)->ptr_disp)
-#define bug_line(b) ((((b)->line_hi + ((b)->loc_disp < 0)) <<                \
+#define bug_line(b) (((((b)->line_hi + ((b)->loc_disp < 0)) &                \
+                       ((1 << BUG_LINE_HI_WIDTH) - 1)) <<                    \
                       BUG_LINE_LO_WIDTH) +                                   \
-                     (b)->line_lo + ((b)->ptr_disp < 0))
+                     (((b)->line_lo + ((b)->ptr_disp < 0)) &                 \
+                      ((1 << BUG_LINE_LO_WIDTH) - 1)))
 #define bug_msg(b) ((const char *)(b) + (b)->msg_disp[1])
 
 #define BUGFRAME_run_fn 0

x86: fix bug_line()

Due to the packing into a bit field together with a relocated field, the computation can overflow when the relocated field ends up getting a negative value stored. Hence it isn't sufficient to correct the value by 1 in this case, but we also need to mask the result to the width of the original bit field.

xen/include/asm-x86/bug.h +4 -2
@@ -15,9 +15,11 @@ struct bug_frame {
 
 #define bug_loc(b) ((const void *)(b) + (b)->loc_disp)
 #define bug_ptr(b) ((const void *)(b) + (b)->ptr_disp)
-#define bug_line(b) ((((b)->line_hi + ((b)->loc_disp < 0)) <<                \
+#define bug_line(b) (((((b)->line_hi + ((b)->loc_disp < 0)) &                \
+                       ((1 << BUG_LINE_HI_WIDTH) - 1)) <<                    \
                       BUG_LINE_LO_WIDTH) +                                   \
-                     (b)->line_lo + ((b)->ptr_disp < 0))
+                     (((b)->line_lo + ((b)->ptr_disp < 0)) &                 \
+                      ((1 << BUG_LINE_LO_WIDTH) - 1)))
 #define bug_msg(b) ((const char *)(b) + (b)->msg_disp[1])
 
 #define BUGFRAME_run_fn 0

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

Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

Due to the packing into a bit field together with a relocated field, the computation can overflow when the relocated field ends up getting a negative value stored. Hence it isn't sufficient to correct the value by 1 in this case, but we also need to mask the result to the width of the original bit field.

Quoted 24 lines
xen/include/asm-x86/bug.h +3 -2
@@ -15,9 +15,11 @@ struct bug_frame {
 
 #define bug_loc(b) ((const void *)(b) + (b)->loc_disp)
 #define bug_ptr(b) ((const void *)(b) + (b)->ptr_disp)
-#define bug_line(b) ((((b)->line_hi + ((b)->loc_disp < 0)) <<
 \
+#define bug_line(b) (((((b)->line_hi + ((b)->loc_disp < 0)) &
 \
+                       ((1 << BUG_LINE_HI_WIDTH) - 1)) <<
 \
                       BUG_LINE_LO_WIDTH) +
 \
-                     (b)->line_lo + ((b)->ptr_disp < 0))
+                     (((b)->line_lo + ((b)->ptr_disp < 0)) &

\
+ ((1 << BUG_LINE_LO_WIDTH) - 1)))
#define bug_msg(b) ((const char *)(b) + (b)->msg_disp[1])

#define BUGFRAME_run_fn 0