On Sat, 2018-01-06 at 01:30 +0100, Borislav Petkov wrote: > On Fri, Jan 05, 2018 at 11:08:06AM -0600, Josh Poimboeuf wrote: > > I seem to recall that we also discussed the need for this for converting > > pvops to use alternatives, though the "why" is eluding me at the moment. > > Ok, here's something which seems to work in my VM here. I'll continue > playing with it tomorrow. Josh, if you have some example sequences for > me to try, send them my way pls. > > Anyway, here's an example: > > alternative("", "xor %%rdi, %%rdi; jmp startup_64", X86_FEATURE_K8); > > which did this: > > [    0.921013] apply_alternatives: feat: 3*32+4, old: (ffffffff81027429, len: 8), repl: (ffffffff824759d2, len: 8), pad: 8 > [    0.924002] ffffffff81027429: old_insn: 90 90 90 90 90 90 90 90 > [    0.928003] ffffffff824759d2: rpl_insn: 48 31 ff e9 26 a6 b8 fe > [    0.930212] process_jumps: repl[0]: 0x48 > [    0.932002] process_jumps: insn len: 3 > [    0.932814] process_jumps: repl[0]: 0xe9 > [    0.934003] recompute_jump: o_dspl: 0xfeb8a626 > [    0.934914] recompute_jump: target RIP: ffffffff81000000, new_displ: 0xfffd8bd7 > [    0.936001] recompute_jump: final displ: 0xfffd8bd2, JMP 0xffffffff81000000 > [    0.937240] process_jumps: insn len: 5 > [    0.938053] ffffffff81027429: final_insn: e9 d2 8b fd ff a6 b8 fe > > Apparently our insn decoder is smart enough to parse the insn and get > its length, so I can use that. It jumps over the first 3-byte XOR and > than massaged the following 5-byte jump. Thanks. From code inspection, I couldn't see that it was smart enough *not* to process a relative jump in the 'altinstr' section which was jumping to a target *within* that same altinstr section, and thus didn't need to be touched at all. Does this work? alternative("", "xor %%rdi, %%rdi; jmp 2f; 2: jmp startup_64", X86_FEATURE_K8);