All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Sami Tolvanen <samitolvanen@google.com>,
	Joao Moreira <joao@overdrivepizza.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH 4/4] x86/cfi: Add boot time hash randomization
Date: Fri, 28 Oct 2022 10:42:52 -0700	[thread overview]
Message-ID: <202210281042.D12B3A1118@keescook> (raw)
In-Reply-To: <20221027092842.765195516@infradead.org>

On Thu, Oct 27, 2022 at 11:28:16AM +0200, Peter Zijlstra wrote:
> In order to avoid known hashes (from knowing the boot image),
> randomize the CFI hashes with a per-boot random seed.
> 
> Suggested-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
>  arch/x86/kernel/alternative.c |  120 +++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 108 insertions(+), 12 deletions(-)
> 
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -711,6 +711,24 @@ enum cfi_mode {
>  };
>  
>  static enum cfi_mode cfi_mode __ro_after_init = CFI_DEFAULT;
> +static bool cfi_rand __ro_after_init = true;
> +static u32  cfi_seed __ro_after_init;
> +
> +/*
> + * Re-hash the CFI hash with a boot-time seed while making sure the result is
> + * not a valid ENDBR instruction.
> + */
> +static u32 cfi_rehash(u32 hash)
> +{
> +	hash ^= cfi_seed;
> +	while (unlikely(is_endbr(hash) || is_endbr(-hash))) {
> +		bool lsb = hash & 1;
> +		hash >>= 1;
> +		if (lsb)
> +			hash ^= 0x80200003;
> +	}
> +	return hash;
> +}

I guess this risks hash collision with existing hashes, but meeeh. I'm
glad to have the randomization. :)

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

  reply	other threads:[~2022-10-28 17:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27  9:28 [PATCH 0/4] x86/ibt: Implement FineIBT Peter Zijlstra
2022-10-27  9:28 ` [PATCH 1/4] objtool: Add --cfi to generate the .cfi_sites section Peter Zijlstra
2022-11-02  9:20   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2022-10-27  9:28 ` [PATCH 2/4] x86/ibt: Implement FineIBT Peter Zijlstra
2022-10-27 10:11   ` Peter Zijlstra
2022-10-28 17:41   ` Kees Cook
2022-11-02  9:20   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2022-10-27  9:28 ` [PATCH 3/4] x86/cfi: Boot time selection of CFI scheme Peter Zijlstra
2022-10-28 17:41   ` Kees Cook
2022-11-02  9:19   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2022-10-27  9:28 ` [PATCH 4/4] x86/cfi: Add boot time hash randomization Peter Zijlstra
2022-10-28 17:42   ` Kees Cook [this message]
2022-11-02  9:19   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2022-10-28 11:01 ` [PATCH 0/4] x86/ibt: Implement FineIBT David Laight
2022-10-28 12:03   ` Peter Zijlstra

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=202210281042.D12B3A1118@keescook \
    --to=keescook@chromium.org \
    --cc=joao@overdrivepizza.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peterz@infradead.org \
    --cc=samitolvanen@google.com \
    --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 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.