From: Andrew Cooper <Andrew.Cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Roger Pau Monne <roger.pau@citrix.com>, Wei Liu <wl@xen.org>,
Xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v2 3/7] x86/altcall: Optimise away endbr64 instruction where possible
Date: Mon, 14 Feb 2022 16:03:47 +0000 [thread overview]
Message-ID: <c053423d-e06f-b349-34bc-9509dc44bcd7@citrix.com> (raw)
In-Reply-To: <adbd9ee8-46c5-9696-c3eb-3e18b2d60684@suse.com>
On 14/02/2022 13:51, Jan Beulich wrote:
> On 14.02.2022 14:31, Andrew Cooper wrote:
>> On 14/02/2022 13:06, Jan Beulich wrote:
>>> On 14.02.2022 13:56, Andrew Cooper wrote:
>>>> @@ -330,6 +333,41 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
>>>> add_nops(buf + a->repl_len, total_len - a->repl_len);
>>>> text_poke(orig, buf, total_len);
>>>> }
>>>> +
>>>> + /*
>>>> + * Clobber endbr64 instructions now that altcall has finished optimising
>>>> + * all indirect branches to direct ones.
>>>> + */
>>>> + if ( force && cpu_has_xen_ibt )
>>>> + {
>>>> + void *const *val;
>>>> + unsigned int clobbered = 0;
>>>> +
>>>> + /*
>>>> + * This is some minor structure (ab)use. We walk the entire contents
>>>> + * of .init.{ro,}data.cf_clobber as if it were an array of pointers.
>>>> + *
>>>> + * If the pointer points into .text, and at an endbr64 instruction,
>>>> + * nop out the endbr64. This causes the pointer to no longer be a
>>>> + * legal indirect branch target under CET-IBT. This is a
>>>> + * defence-in-depth measure, to reduce the options available to an
>>>> + * adversary who has managed to hijack a function pointer.
>>>> + */
>>>> + for ( val = __initdata_cf_clobber_start;
>>>> + val < __initdata_cf_clobber_end;
>>>> + val++ )
>>>> + {
>>>> + void *ptr = *val;
>>>> +
>>>> + if ( !is_kernel_text(ptr) || !is_endbr64(ptr) )
>>>> + continue;
>>>> +
>>>> + add_nops(ptr, 4);
>>> This literal 4 would be nice to have a #define next to where the ENDBR64
>>> encoding has its central place.
>> We don't have an encoding of ENDBR64 in a central place.
>>
>> The best you can probably have is
>>
>> #define ENDBR64_LEN 4
>>
>> in endbr.h ?
> Perhaps. That's not in this series nor in staging already, so it's a little
> hard to check. By "central place" I really meant is_enbr64() if that's the
> only place where the encoding actually appears.
endbr.h is the header which contains is_endbr64(), and deliberately does
not contain the raw encoding.
>
>>>> --- a/xen/arch/x86/xen.lds.S
>>>> +++ b/xen/arch/x86/xen.lds.S
>>>> @@ -221,6 +221,12 @@ SECTIONS
>>>> *(.initcall1.init)
>>>> __initcall_end = .;
>>>>
>>>> + . = ALIGN(POINTER_ALIGN);
>>>> + __initdata_cf_clobber_start = .;
>>>> + *(.init.data.cf_clobber)
>>>> + *(.init.rodata.cf_clobber)
>>>> + __initdata_cf_clobber_end = .;
>>>> +
>>>> *(.init.data)
>>>> *(.init.data.rel)
>>>> *(.init.data.rel.*)
>>> With r/o data ahead and r/w data following, may I suggest to flip the
>>> order of the two section specifiers you add?
>> I don't follow. This is all initdata which is merged together into a
>> single section.
>>
>> The only reason const data is split out in the first place is to appease
>> the toolchains, not because it makes a difference.
> It's marginal, I agree, but it would still seem more clean to me if all
> (pseudo) r/o init data lived side by side.
I still don't understand what you're asking.
There is no such thing as actually read-only init data.
Wherever the .init.rodata goes in here, it's bounded by .init.data.
~Andrew
next prev parent reply other threads:[~2022-02-14 16:04 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-14 12:56 [PATCH v2 0/7] x86: Further harden function pointers Andrew Cooper
2022-02-14 12:56 ` [PATCH v2 1/7] xen/altcall: Use __ro_after_init now that it exists Andrew Cooper
2022-02-14 12:59 ` Jan Beulich
2022-02-14 12:56 ` [PATCH v2 2/7] x86/altcall: Check and optimise altcall targets Andrew Cooper
2022-02-14 12:56 ` [PATCH v2 3/7] x86/altcall: Optimise away endbr64 instruction where possible Andrew Cooper
2022-02-14 13:06 ` Jan Beulich
2022-02-14 13:31 ` Andrew Cooper
2022-02-14 13:51 ` Jan Beulich
2022-02-14 16:03 ` Andrew Cooper [this message]
2022-02-14 16:16 ` Jan Beulich
2022-03-01 11:59 ` Jan Beulich
2022-03-01 14:51 ` Andrew Cooper
2022-03-01 14:58 ` Jan Beulich
2022-02-14 12:56 ` [PATCH v2 4/7] xsm: Use __initconst_cf_clobber for xsm_ops Andrew Cooper
2022-02-14 12:56 ` [PATCH v2 5/7] x86/hvm: Use __initdata_cf_clobber for hvm_funcs Andrew Cooper
2022-02-14 13:10 ` Jan Beulich
2022-02-14 13:35 ` Andrew Cooper
2022-02-14 16:39 ` Andrew Cooper
2022-02-14 16:45 ` Jan Beulich
2022-02-14 12:56 ` [PATCH v2 6/7] x86/ucode: Use altcall, and __initconst_cf_clobber Andrew Cooper
2022-02-14 13:13 ` Jan Beulich
2022-02-14 12:56 ` [PATCH v2 7/7] x86/vpmu: Harden indirect branches Andrew Cooper
2022-02-14 13:14 ` Jan Beulich
2022-02-21 18:03 ` [PATCH v2.1 8/7] x86/IOMMU: Use altcall, and __initconst_cf_clobber Andrew Cooper
2022-02-22 9:29 ` Jan Beulich
2022-02-22 10:54 ` Andrew Cooper
2022-02-22 11:02 ` Andrew Cooper
2022-02-22 11:06 ` Jan Beulich
2022-02-22 11:34 ` Andrew Cooper
2022-02-22 11:04 ` Jan Beulich
2022-02-22 11:47 ` [PATCH v2.2 " Andrew Cooper
2022-02-22 12:10 ` Jan Beulich
2022-02-25 8:24 ` Jan Beulich
2022-03-01 14:58 ` Andrew Cooper
2022-03-02 8:10 ` Jan Beulich
2022-03-02 10:12 ` Andrew Cooper
2022-03-02 10:34 ` Jan Beulich
2022-03-02 13:39 ` Andrew Cooper
2022-03-02 19:57 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c053423d-e06f-b349-34bc-9509dc44bcd7@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.