lkml.org 
[lkml]   [2023]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v4 2/5] x86/alternative: add indirect call patching
From
On 14.11.23 13:37, Borislav Petkov wrote:
> On Mon, Oct 30, 2023 at 03:25:05PM +0100, Juergen Gross wrote:
>> + * Rewrite the "call BUG_func" replacement to point to the target of the
>> + * indirect pv_ops call "call *disp(%ip)".
>> + */
>> +static int alt_replace_call(u8 *instr, u8 *insn_buff, struct alt_instr *a)
>> +{
>> + void *target, *bug = &BUG_func;
>> +
>> + if (a->replacementlen != 5 || insn_buff[0] != CALL_INSN_OPCODE) {
>> + pr_err("Alternative: ALT_FLAG_CALL set for a non-call replacement instruction\n");
>
> No need for the printk prefix.

Okay.

>
>> + pr_err(" Ignoring the flag for the instruction at %pS (%px)\n", instr, instr);
>
> No ignoring - BUG

Okay.

>
>> + return 5;
>> + }
>> +
>> + if (a->instrlen != 6 || instr[0] != 0xff || instr[1] != 0x15) {
>> + pr_err("Alternative: ALT_FLAG_CALL set for unrecognized indirect call\n");
>> + pr_err(" Not replacing the instruction at %pS (%px)\n", instr, instr);
>> + return -1;
>
> Ditto.

Okay.

>
>> + }
>> +
>> +#ifdef CONFIG_X86_64
>> + /* ff 15 00 00 00 00 call *0x0(%rip) */
>> + target = *(void **)(instr + a->instrlen + *(s32 *)(instr + 2));
>> +#else
>> + /* ff 15 00 00 00 00 call *0x0 */
>> + target = *(void **)(*(s32 *)(instr + 2));
>> +#endif
>> + if (!target)
>> + target = bug;
>> +
>> + /* (BUG_func - .) + (target - BUG_func) := target - . */
>> + *(s32 *)(insn_buff + 1) += target - bug;
>
> If I squint hard enough, this looks like it is replacing one call with
> another. We have a C macro alternative_call() which does exactly that.
> Why can't you define an asm version ALTERNATIVE_CALL and use it
> instead of using adding a new flag? We have 16 possible ones in total.

It is replacing an _indirect_ call with a _direct_ one, taking the call target
from the pointer used by the indirect call.


Juergen
[unhandled content-type:application/pgp-keys][unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2023-11-20 13:59    [W:0.093 / U:1.384 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site