From: "Nicholas Piggin" <npiggin@gmail.com>
To: "Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Michael Ellerman" <mpe@ellerman.id.au>
Cc: <linux-kernel@vger.kernel.org>, <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH 4/4] powerpc/kuap: Make disabling KUAP at boottime optional
Date: Tue, 06 Jun 2023 19:27:03 +1000 [thread overview]
Message-ID: <CT5GKZN6D21R.3US3D2GZWGLS2@wheely> (raw)
In-Reply-To: <8d5438da7174ecb32e1c28cdb49987648df6ef15.1685963081.git.christophe.leroy@csgroup.eu>
On Mon Jun 5, 2023 at 9:04 PM AEST, Christophe Leroy wrote:
> It is possible to disable KUAP at boottime with 'nosmap' parameter.
>
> That is implemented with jump_label hence adds a 'nop' in front
> of each open/close of userspace access.
>
> From a security point of view it makes sence to disallow disabling
> KUAP. And on processors like the 8xx where 'nop' is not seamless,
> it saves a few cycles.
>
> So add a CONFIG item to make it optionnal.
I love counting cycles, but a CONFIG option for one nop... I think
you have me beat.
Is that sustainable? What if instead of the static branch you patched in
nops to the lock/unlock asm? AFAIKS there does not look like much (any?)
C code in the kuap enabled branches.
Thanks,
Nick
>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> arch/powerpc/include/asm/kup.h | 2 +-
> arch/powerpc/mm/init-common.c | 3 +++
> arch/powerpc/platforms/Kconfig.cputype | 10 ++++++++++
> 3 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h
> index 74b7f4cee2ed..f3280169aeec 100644
> --- a/arch/powerpc/include/asm/kup.h
> +++ b/arch/powerpc/include/asm/kup.h
> @@ -53,7 +53,7 @@ extern struct static_key_false disable_kuap_key;
>
> static __always_inline bool kuap_is_disabled(void)
> {
> - return static_branch_unlikely(&disable_kuap_key);
> + return IS_ENABLED(CONFIG_PPC_KUAP_BOOTTIME) && static_branch_unlikely(&disable_kuap_key);
> }
> #endif
> #else
> diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
> index 74e140b1efef..994ee58f0092 100644
> --- a/arch/powerpc/mm/init-common.c
> +++ b/arch/powerpc/mm/init-common.c
> @@ -48,6 +48,9 @@ early_param("nosmep", parse_nosmep);
>
> static int __init parse_nosmap(char *p)
> {
> + if (!IS_ENABLED(CONFIG_PPC_KUAP_BOOTTIME))
> + return 0;
> +
> disable_kuap = true;
> pr_warn("Disabling Kernel Userspace Access Protection\n");
> return 0;
> diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
> index 45fd975ef521..f75c2d5cd182 100644
> --- a/arch/powerpc/platforms/Kconfig.cputype
> +++ b/arch/powerpc/platforms/Kconfig.cputype
> @@ -502,6 +502,16 @@ config PPC_KUAP
>
> If you're unsure, say Y.
>
> +config PPC_KUAP_BOOTTIME
> + bool "Allow disabling Kernel Userspace Access Protection at boottime"
> + depends on PPC_KUAP
> + default y
> + help
> + Allow the user to disable Kernel Userspace Access Protection (KUAP)
> + at boot time using 'nosmap' kernel parameter.
> +
> + If you're unsure, say Y.
> +
> config PPC_KUAP_DEBUG
> bool "Extra debugging for Kernel Userspace Access Protection"
> depends on PPC_KUAP
> --
> 2.40.1
next prev parent reply other threads:[~2023-06-06 9:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-05 11:04 [PATCH 1/4] powerpc/kuap: Avoid unnecessary reads of MD_AP Christophe Leroy
2023-06-05 11:04 ` [PATCH 2/4] powerpc/kuap: Avoid useless jump_label on empty function Christophe Leroy
2023-06-06 9:12 ` Nicholas Piggin
2023-06-05 11:04 ` [PATCH 3/4] powerpc/kuap: Refactor static branch for disabling kuap Christophe Leroy
2023-06-06 9:16 ` Nicholas Piggin
2023-06-22 6:08 ` Christophe Leroy
2023-06-05 11:04 ` [PATCH 4/4] powerpc/kuap: Make disabling KUAP at boottime optional Christophe Leroy
2023-06-06 9:27 ` Nicholas Piggin [this message]
2023-06-22 6:20 ` Christophe Leroy
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=CT5GKZN6D21R.3US3D2GZWGLS2@wheely \
--to=npiggin@gmail.com \
--cc=christophe.leroy@csgroup.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
/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