@@ -659,7 +659,19 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
659659
660660#define EMIT_LFENCE () EMIT3(0x0F, 0xAE, 0xE8)
661661
662- static void emit_indirect_jump (u8 * * pprog , int reg , u8 * ip )
662+ static void __emit_indirect_jump (u8 * * pprog , int reg , bool ereg )
663+ {
664+ u8 * prog = * pprog ;
665+
666+ if (ereg )
667+ EMIT1 (0x41 );
668+
669+ EMIT2 (0xFF , 0xE0 + reg );
670+
671+ * pprog = prog ;
672+ }
673+
674+ static void emit_indirect_jump (u8 * * pprog , int reg , bool ereg , u8 * ip )
663675{
664676 u8 * prog = * pprog ;
665677
@@ -668,15 +680,15 @@ static void emit_indirect_jump(u8 **pprog, int reg, u8 *ip)
668680 emit_jump (& prog , its_static_thunk (reg ), ip );
669681 } else if (cpu_feature_enabled (X86_FEATURE_RETPOLINE_LFENCE )) {
670682 EMIT_LFENCE ();
671- EMIT2 ( 0xFF , 0xE0 + reg );
683+ __emit_indirect_jump ( pprog , reg , ereg );
672684 } else if (cpu_feature_enabled (X86_FEATURE_RETPOLINE )) {
673685 OPTIMIZER_HIDE_VAR (reg );
674686 if (cpu_feature_enabled (X86_FEATURE_CALL_DEPTH ))
675- emit_jump (& prog , & __x86_indirect_jump_thunk_array [reg ], ip );
687+ emit_jump (& prog , & __x86_indirect_jump_thunk_array [reg + 8 * ereg ], ip );
676688 else
677- emit_jump (& prog , & __x86_indirect_thunk_array [reg ], ip );
689+ emit_jump (& prog , & __x86_indirect_thunk_array [reg + 8 * ereg ], ip );
678690 } else {
679- EMIT2 ( 0xFF , 0xE0 + reg ); /* jmp *%\reg */
691+ __emit_indirect_jump ( pprog , reg , ereg );
680692 if (IS_ENABLED (CONFIG_MITIGATION_RETPOLINE ) || IS_ENABLED (CONFIG_MITIGATION_SLS ))
681693 EMIT1 (0xCC ); /* int3 */
682694 }
@@ -796,7 +808,7 @@ static void emit_bpf_tail_call_indirect(struct bpf_prog *bpf_prog,
796808 * rdi == ctx (1st arg)
797809 * rcx == prog->bpf_func + X86_TAIL_CALL_OFFSET
798810 */
799- emit_indirect_jump (& prog , 1 /* rcx */ , ip + (prog - start ));
811+ emit_indirect_jump (& prog , 1 /* rcx */ , false, ip + (prog - start ));
800812
801813 /* out: */
802814 ctx -> tail_call_indirect_label = prog - start ;
@@ -3442,7 +3454,7 @@ static int emit_bpf_dispatcher(u8 **pprog, int a, int b, s64 *progs, u8 *image,
34423454 if (err )
34433455 return err ;
34443456
3445- emit_indirect_jump (& prog , 2 /* rdx */ , image + (prog - buf ));
3457+ emit_indirect_jump (& prog , 2 /* rdx */ , false, image + (prog - buf ));
34463458
34473459 * pprog = prog ;
34483460 return 0 ;
0 commit comments