Skip to content

Commit 5409730

Browse files
author
Peter Zijlstra
committed
x86/static_call: Fix __static_call_fixup()
Christian reported spurious module load crashes after some of Song's module memory layout patches. Turns out that if the very last instruction on the very last page of the module is a 'JMP __x86_return_thunk' then __static_call_fixup() will trip a fault and die. And while the module rework made this slightly more likely to happen, it's always been possible. Fixes: ee88d36 ("x86,static_call: Use alternative RET encoding") Reported-by: Christian Bricart <christian@bricart.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Josh Poimboeuf <jpoimboe@kernel.org> Link: https://lkml.kernel.org/r/20230816104419.GA982867@hirez.programming.kicks-ass.net
1 parent dbf4600 commit 5409730

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

arch/x86/kernel/static_call.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ EXPORT_SYMBOL_GPL(arch_static_call_transform);
186186
*/
187187
bool __static_call_fixup(void *tramp, u8 op, void *dest)
188188
{
189+
unsigned long addr = (unsigned long)tramp;
190+
/*
191+
* Not all .return_sites are a static_call trampoline (most are not).
192+
* Check if the 3 bytes after the return are still kernel text, if not,
193+
* then this definitely is not a trampoline and we need not worry
194+
* further.
195+
*
196+
* This avoids the memcmp() below tripping over pagefaults etc..
197+
*/
198+
if (((addr >> PAGE_SHIFT) != ((addr + 7) >> PAGE_SHIFT)) &&
199+
!kernel_text_address(addr + 7))
200+
return false;
201+
189202
if (memcmp(tramp+5, tramp_ud, 3)) {
190203
/* Not a trampoline site, not our problem. */
191204
return false;

0 commit comments

Comments
 (0)