From: Sean Christopherson <seanjc@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Dave Hansen <dave.hansen@intel.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org, keescook@chromium.org
Subject: Re: [PATCH] x86/mm: Refuse W^X violations
Date: Thu, 25 Aug 2022 17:18:13 +0000 [thread overview]
Message-ID: <Yweu1dvkJ8aV+C+T@google.com> (raw)
In-Reply-To: <YwdpwykpV9RB+4tL@worktop.programming.kicks-ass.net>
On Thu, Aug 25, 2022, Peter Zijlstra wrote:
>
> x86 has STRICT_*_RWX, but not even a warning when someone violates it.
>
> Add this warning and fully refuse the transition.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
> index 1abd5438f126..9e9bef3f36b3 100644
> --- a/arch/x86/mm/pat/set_memory.c
> +++ b/arch/x86/mm/pat/set_memory.c
> @@ -579,6 +579,30 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long start,
> return __pgprot(pgprot_val(prot) & ~forbidden);
> }
>
> +/*
> + * Validate and enforce strict W^X semantics.
> + */
> +static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long start,
> + unsigned long pfn, unsigned long npg)
> +{
> + unsigned long end;
> +
I think this needs
if (!(__supported_pte_mask & _PAGE_NX))
return new;
to play nice with non-PAE 32-bit kernels.
> + if (!((pgprot_val(old) ^ pgprot_val(new)) & (_PAGE_RW | _PAGE_NX)))
> + return new;
> +
> + if ((pgprot_val(new) & (_PAGE_RW | _PAGE_NX)) != _PAGE_RW)
> + return new;
> +
> + end = start + npg * PAGE_SIZE - 1;
> + WARN(1, "CPA refuse W^X violation: %016llx -> %016llx range: 0x%016lx - 0x%016lx PFN %lx\n",
WARN_ONCE() to avoid eternal spam if something does go sideways?
> + (unsigned long long)pgprot_val(old),
> + (unsigned long long)pgprot_val(new),
> + start, end, pfn);
> +
> + /* refuse the transition into WX */
> + return old;
> +}
next prev parent reply other threads:[~2022-08-25 17:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-25 12:23 [PATCH] x86/mm: Refuse W^X violations Peter Zijlstra
2022-08-25 17:18 ` Sean Christopherson [this message]
2022-08-25 17:38 ` Dave Hansen
2022-08-25 18:16 ` Kees Cook
2022-08-25 19:42 ` 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=Yweu1dvkJ8aV+C+T@google.com \
--to=seanjc@google.com \
--cc=dave.hansen@intel.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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 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.