Skip to content

Commit 58978b4

Browse files
Brian GerstIngo Molnar
authored andcommitted
x86/entry/64: Use TASK_SIZE_MAX for canonical RIP test
Using shifts to determine if an address is canonical is difficult for the compiler to optimize when the virtual address width is variable (LA57 feature) without using inline assembly. Instead, compare RIP against TASK_SIZE_MAX. The only user executable address outside of that range is the deprecated vsyscall page, which can fall back to using IRET. Signed-off-by: Brian Gerst <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Uros Bizjak <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ca282b4 commit 58978b4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/x86/entry/common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ __visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr)
110110
* in kernel space. This essentially lets the user take over
111111
* the kernel, since userspace controls RSP.
112112
*
113-
* Change top bits to match the most significant bit (47th or 56th bit
114-
* depending on paging mode) in the address.
113+
* TASK_SIZE_MAX covers all user-accessible addresses other than
114+
* the deprecated vsyscall page.
115115
*/
116-
if (unlikely(!__is_canonical_address(regs->ip, __VIRTUAL_MASK_SHIFT + 1)))
116+
if (unlikely(regs->ip >= TASK_SIZE_MAX))
117117
return false;
118118

119119
/*

0 commit comments

Comments
 (0)