Skip to contentSkip to conversation

x86/compat: correct SMEP/SMAP NOPs patching

PATCH In review Jan Beulich 3 participants 4 messages May 25, 2016 – May 27, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/compat: correct SMEP/SMAP NOPs patching

Correct the number of single byte NOPs we want to be replaced in case neither SMEP nor SMAP are available.

Also simplify the expression adding these NOPs - at that location . equals .Lcr4_orig, and removing that part of the expression fixes a bogus ".space or fill with negative value, ignored" warning by very old gas (which actually is what made me look at those constructs again).

xen/arch/x86/x86_64/compat/entry.S +3 -2
@@ -175,7 +175,7 @@ compat_bad_hypercall:
 ENTRY(compat_restore_all_guest)
         ASSERT_INTERRUPTS_DISABLED
 .Lcr4_orig:
-        .skip (.Lcr4_alt_end - .Lcr4_alt) - (. - .Lcr4_orig), 0x90
+        .skip .Lcr4_alt_end - .Lcr4_alt, 0x90
 .Lcr4_orig_end:
         .pushsection .altinstr_replacement, "ax"
 .Lcr4_alt:
@@ -200,7 +200,8 @@ ENTRY(compat_restore_all_guest)
         jne   1b
 .Lcr4_alt_end:
         .section .altinstructions, "a"
-        altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, 12, 0
+        altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, \
+                             (.Lcr4_orig_end - .Lcr4_orig), 0
         altinstruction_entry .Lcr4_orig, .Lcr4_alt, X86_FEATURE_SMEP, \
                              (.Lcr4_orig_end - .Lcr4_orig), \
                              (.Lcr4_alt_end - .Lcr4_alt)

x86/compat: correct SMEP/SMAP NOPs patching

Correct the number of single byte NOPs we want to be replaced in case neither SMEP nor SMAP are available.

Also simplify the expression adding these NOPs - at that location . equals .Lcr4_orig, and removing that part of the expression fixes a bogus ".space or fill with negative value, ignored" warning by very old gas (which actually is what made me look at those constructs again).

xen/arch/x86/x86_64/compat/entry.S +3 -2
@@ -175,7 +175,7 @@ compat_bad_hypercall:
 ENTRY(compat_restore_all_guest)
         ASSERT_INTERRUPTS_DISABLED
 .Lcr4_orig:
-        .skip (.Lcr4_alt_end - .Lcr4_alt) - (. - .Lcr4_orig), 0x90
+        .skip .Lcr4_alt_end - .Lcr4_alt, 0x90
 .Lcr4_orig_end:
         .pushsection .altinstr_replacement, "ax"
 .Lcr4_alt:
@@ -200,7 +200,8 @@ ENTRY(compat_restore_all_guest)
         jne   1b
 .Lcr4_alt_end:
         .section .altinstructions, "a"
-        altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, 12, 0
+        altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, \
+                             (.Lcr4_orig_end - .Lcr4_orig), 0
         altinstruction_entry .Lcr4_orig, .Lcr4_alt, X86_FEATURE_SMEP, \
                              (.Lcr4_orig_end - .Lcr4_orig), \
                              (.Lcr4_alt_end - .Lcr4_alt)

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

Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Jan Beulich

Correct the number of single byte NOPs we want to be replaced in case neither SMEP nor SMAP are available.

Also simplify the expression adding these NOPs - at that location . equals .Lcr4_orig, and removing that part of the expression fixes a bogus ".space or fill with negative value, ignored" warning by very old gas (which actually is what made me look at those constructs again).

xen/arch/x86/x86_64/compat/entry.S +1 -1
@@ -175,7 +175,7 @@ compat_bad_hypercall:
 ENTRY(compat_restore_all_guest)
         ASSERT_INTERRUPTS_DISABLED
 .Lcr4_orig:
-        .skip (.Lcr4_alt_end - .Lcr4_alt) - (. - .Lcr4_orig), 0x90
+        .skip .Lcr4_alt_end - .Lcr4_alt, 0x90
 .Lcr4_orig_end:
         .pushsection .altinstr_replacement, "ax"
 .Lcr4_alt:

xen/arch/x86/x86_64/compat/entry.S ENTRY(compat_restore_all_guest) · line 207

Quoted 9 lines
xen/arch/x86/x86_64/compat/entry.S +2 -1
@@ -200,7 +200,8 @@ ENTRY(compat_restore_all_guest)
         jne   1b
 .Lcr4_alt_end:
         .section .altinstructions, "a"
-        altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, 12, 0
+        altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, \
+                             (.Lcr4_orig_end - .Lcr4_orig), 0
         altinstruction_entry .Lcr4_orig, .Lcr4_alt, X86_FEATURE_SMEP, \
                              (.Lcr4_orig_end - .Lcr4_orig), \
                              (.Lcr4_alt_end - .Lcr4_alt)

FWIW:

And subject to review from Andrew:

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

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich

Correct the number of single byte NOPs we want to be replaced in case neither SMEP nor SMAP are available.

Also simplify the expression adding these NOPs - at that location . equals .Lcr4_orig, and removing that part of the expression fixes a bogus ".space or fill with negative value, ignored" warning by very old gas (which actually is what made me look at those constructs again).

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

#3 lore raw
In reply to Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 25.05.16 at 17:00, <[email protected]> wrote:

Correct the number of single byte NOPs we want to be replaced in case neither SMEP nor SMAP are available.

Also simplify the expression adding these NOPs - at that location . equals .Lcr4_orig, and removing that part of the expression fixes a bogus ".space or fill with negative value, ignored" warning by very old gas (which actually is what made me look at those constructs again).

That gas is behaving really strangely: For one, this morning the warning now also appears with the patch in place. I'm sure it wasn't there Wednesday night. Further, warning or not, the generated code is wrong (no NOPs getting inserted at all, obviously resulting in the BUG_ON(a->replacementlen > a->instrlen) in apply_alternatives_nocheck() to trigger during boot). And finally, generated code is right (and the warning gone) when having gas produce a listing via -a. In that case, however, it errors on the four .rept in the hypercall (argument) tables, so we also can't easily use that as a workaround. .list / .nolist don't alter behavior for either of the two issues.

I've tried to find some other workaround, but I'm now willing to give up, as there are clearly more useful things to do. We may want / need to consider raising the bar for which binutils versions we support building with.

Jan

Quoted 17 lines
xen/arch/x86/x86_64/compat/entry.S +1 -2
@@ -175,7 +175,7 @@ compat_bad_hypercall:
 ENTRY(compat_restore_all_guest)
         ASSERT_INTERRUPTS_DISABLED
 .Lcr4_orig:
-        .skip (.Lcr4_alt_end - .Lcr4_alt) - (. - .Lcr4_orig), 0x90
+        .skip .Lcr4_alt_end - .Lcr4_alt, 0x90
 .Lcr4_orig_end:
         .pushsection .altinstr_replacement, "ax"
 .Lcr4_alt:
@@ -200,7 +200,8 @@ ENTRY(compat_restore_all_guest)
         jne   1b
 .Lcr4_alt_end:
         .section .altinstructions, "a"
-        altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, 12, 

0

xen/arch/x86/x86_64/compat/entry.S ENTRY(compat_restore_all_guest) · line 207

Quoted 5 lines
xen/arch/x86/x86_64/compat/entry.S +2 -0
+        altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, \
+                             (.Lcr4_orig_end - .Lcr4_orig), 0
         altinstruction_entry .Lcr4_orig, .Lcr4_alt, X86_FEATURE_SMEP, \
                              (.Lcr4_orig_end - .Lcr4_orig), \
                              (.Lcr4_alt_end - .Lcr4_alt)

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