Skip to content

Commit bfeee14

Browse files
bwendlingSasha Levin
authored and
Sasha Levin
committed
x86/paravirt: add extra clobbers with ZERO_CALL_USED_REGS enabled
[ Upstream commit 8c86f29 ] The ZERO_CALL_USED_REGS feature may zero out caller-saved registers before returning. In spurious_kernel_fault(), the "pte_offset_kernel()" call results in this assembly code: .Ltmp151: #APP # ALT: oldnstr .Ltmp152: .Ltmp153: .Ltmp154: .section .discard.retpoline_safe,"",@progbits .quad .Ltmp154 .text callq *pv_ops+536(%rip) .Ltmp155: .section .parainstructions,"a",@progbits .p2align 3, 0x0 .quad .Ltmp153 .byte 67 .byte .Ltmp155-.Ltmp153 .short 1 .text .Ltmp156: # ALT: padding .zero (-(((.Ltmp157-.Ltmp158)-(.Ltmp156-.Ltmp152))>0))*((.Ltmp157-.Ltmp158)-(.Ltmp156-.Ltmp152)),144 .Ltmp159: .section .altinstructions,"a",@progbits .Ltmp160: .long .Ltmp152-.Ltmp160 .Ltmp161: .long .Ltmp158-.Ltmp161 .short 33040 .byte .Ltmp159-.Ltmp152 .byte .Ltmp157-.Ltmp158 .text .section .altinstr_replacement,"ax",@progbits # ALT: replacement 1 .Ltmp158: movq %rdi, %rax .Ltmp157: .text #NO_APP .Ltmp162: testb $-128, %dil The "testb" here is using %dil, but the %rdi register was cleared before returning from "callq *pv_ops+536(%rip)". Adding the proper constraints results in the use of a different register: movq %r11, %rdi # Similar to above. testb $-128, %r11b Link: KSPP/linux#192 Signed-off-by: Bill Wendling <[email protected]> Reported-and-tested-by: Nathan Chancellor <[email protected]> Fixes: 035f7f8 ("randstruct: Enable Clang support") Reviewed-by: Juergen Gross <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent ee4d88c commit bfeee14

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arch/x86/include/asm/paravirt_types.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,17 @@ int paravirt_disable_iospace(void);
414414
"=c" (__ecx)
415415
#define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS, "=a" (__eax)
416416

417-
/* void functions are still allowed [re]ax for scratch */
417+
/*
418+
* void functions are still allowed [re]ax for scratch.
419+
*
420+
* The ZERO_CALL_USED REGS feature may end up zeroing out callee-saved
421+
* registers. Make sure we model this with the appropriate clobbers.
422+
*/
423+
#ifdef CONFIG_ZERO_CALL_USED_REGS
424+
#define PVOP_VCALLEE_CLOBBERS "=a" (__eax), PVOP_VCALL_CLOBBERS
425+
#else
418426
#define PVOP_VCALLEE_CLOBBERS "=a" (__eax)
427+
#endif
419428
#define PVOP_CALLEE_CLOBBERS PVOP_VCALLEE_CLOBBERS
420429

421430
#define EXTRA_CLOBBERS , "r8", "r9", "r10", "r11"

0 commit comments

Comments
 (0)