From e458d6674cb8934c7158c272788b886dbe04ed5e Mon Sep 17 00:00:00 2001 From: Luke Craig Date: Tue, 31 Mar 2026 15:41:47 -0400 Subject: [PATCH] gen_portal_tramp: unconditional pads with nops --- scripts/gen_portal_tramp.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/scripts/gen_portal_tramp.py b/scripts/gen_portal_tramp.py index b7df268..884215c 100644 --- a/scripts/gen_portal_tramp.py +++ b/scripts/gen_portal_tramp.py @@ -6,18 +6,11 @@ print("// Auto-generated trampoline functions\n") print("#define PORTAL_TRAMPOLINE_COUNT {0}\n".format(COUNT)) -# Conditionally apply the NOP padding only for MIPS targets to fix the kprobe branch bug. -# For all other architectures, emit an empty asm block that still embeds the unique ID -# to universally defeat Identical Code Folding (ICF). -print("#if defined(__mips__)") -print("#define TRAMP_BODY(i) asm volatile(\"nop\\n\\tnop\\n\\tnop\\n\\tnop\" : : \"i\"(i))") -print("#else") -print("#define TRAMP_BODY(i) asm volatile(\"\" : : \"i\"(i))") -print("#endif\n") - for i in range(COUNT): print(f"void portal_tramp_fn_{i:x}(void);") - print(f"void portal_tramp_fn_{i:x}(void) {{ TRAMP_BODY({i}); }}") + # Unconditionally pad with NOPs for all architectures to prevent + # kprobes from attaching to naked return/branch instructions. + print(f"void portal_tramp_fn_{i:x}(void) {{ asm volatile(\"nop\\n\\tnop\\n\\tnop\\n\\tnop\" : : \"i\"({i})); }}") print("\nvoid (*portal_tramp_table[{0}])(void) = {{".format(COUNT)) for i in range(COUNT):