linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <n.borisov.lkml@gmail.com>
To: Nikolay Borisov <nik.borisov@suse.com>, x86@kernel.org
Cc: pawan.kumar.gupta@linux.intel.com, peterz@infradead.org,
	linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com
Subject: Re: [PATCH] x86/its: Always return a writable page for dynamic thunks
Date: Wed, 4 Jun 2025 15:18:36 +0300	[thread overview]
Message-ID: <67be78c8-d276-4edc-a101-51f168e200da@gmail.com> (raw)
In-Reply-To: <20250604104715.700149-1-nik.borisov@suse.com>



On 6/4/25 13:47, Nikolay Borisov wrote:
> its_alloc unconditionally allocates and return a ROX page, but setting
> it RW is predicated on its_mod being set. This can cause a #GP on the
> memset in its_allocate_thunk() if its_mod is not set.
> 
> Since the function always returns a page, ensure it's always set
> writable so it can be initialized properly.
> 
> Fixes: 872df34d7c51 ("x86/its: Use dynamic thunks for indirect branches")
> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
> ---
>   arch/x86/kernel/alternative.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index ecfe7b497cad..191e909636a5 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -199,6 +199,8 @@ static void *its_alloc(void)
>   	if (!page)
>   		return NULL;
>   
> +	execmem_make_temp_rw(page, PAGE_SIZE);
> +
>   #ifdef CONFIG_MODULES
>   	if (its_mod) {
>   		void *tmp = krealloc(its_mod->its_page_array,
> @@ -210,7 +212,6 @@ static void *its_alloc(void)
>   		its_mod->its_page_array = tmp;
>   		its_mod->its_page_array[its_mod->its_num_pages++] = page;
>   
> -		execmem_make_temp_rw(page, PAGE_SIZE);
>   	}
>   #endif /* CONFIG_MODULES */
>   

Ok, this actually works in the upstream kernel thanks to 
d6d1e3e6580ca35071ad474381f053cbf1fb6414 meaning at the time retpolines 
are processed the execmem cache is actually writable...

      parent reply	other threads:[~2025-06-04 12:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04 10:47 [PATCH] x86/its: Always return a writable page for dynamic thunks Nikolay Borisov
2025-06-04 10:54 ` Nikolay Borisov
2025-06-04 12:18 ` Nikolay Borisov [this message]

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=67be78c8-d276-4edc-a101-51f168e200da@gmail.com \
    --to=n.borisov.lkml@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nik.borisov@suse.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).