[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9ccdcff2-90f9-47da-9aea-46cffe7fae85@suse.com>
Date: Tue, 14 Nov 2023 13:56:37 +0100
From: Juergen Gross <jgross@...e.com>
To: Borislav Petkov <bp@...en8.de>
Cc: linux-kernel@...r.kernel.org, x86@...nel.org,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>,
Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH v4 2/5] x86/alternative: add indirect call patching
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
Download attachment "OpenPGP_0xB0DE9DD628BF132F.asc" of type "application/pgp-keys" (3099 bytes)
Download attachment "OpenPGP_signature.asc" of type "application/pgp-signature" (496 bytes)
Powered by blists - more mailing lists