[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <877clney35.fsf@linaro.org>
Date: Sat, 09 Dec 2023 20:49:02 -0300
From: Thiago Jung Bauermann <thiago.bauermann@...aro.org>
To: Mark Brown <broonie@...nel.org>
Cc: Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
Jonathan Corbet <corbet@....net>,
Andrew Morton <akpm@...ux-foundation.org>,
Marc Zyngier <maz@...nel.org>,
Oliver Upton <oliver.upton@...ux.dev>,
James Morse <james.morse@....com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Arnd Bergmann <arnd@...db.de>, Oleg Nesterov <oleg@...hat.com>,
Eric Biederman <ebiederm@...ssion.com>,
Kees Cook <keescook@...omium.org>,
Shuah Khan <shuah@...nel.org>,
"Rick P. Edgecombe" <rick.p.edgecombe@...el.com>,
Deepak Gupta <debug@...osinc.com>,
Ard Biesheuvel <ardb@...nel.org>,
Szabolcs Nagy <Szabolcs.Nagy@....com>,
"H.J. Lu" <hjl.tools@...il.com>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Florian Weimer <fweimer@...hat.com>,
Christian Brauner <brauner@...nel.org>,
linux-arm-kernel@...ts.infradead.org, linux-doc@...r.kernel.org,
kvmarm@...ts.linux.dev, linux-fsdevel@...r.kernel.org,
linux-arch@...r.kernel.org, linux-mm@...ck.org,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-riscv@...ts.infradead.org
Subject: Re: [PATCH v7 26/39] arm64/ptrace: Expose GCS via ptrace and core
files
Mark Brown <broonie@...nel.org> writes:
> Provide a new register type NT_ARM_GCS reporting the current GCS mode
> and pointer for EL0. Due to the interactions with allocation and
> deallocation of Guarded Control Stacks we do not permit any changes to
> the GCS mode via ptrace, only GCSPR_EL0 may be changed.
The code allows disabling GCS. Is that unintended?
> Signed-off-by: Mark Brown <broonie@...nel.org>
> ---
> arch/arm64/include/uapi/asm/ptrace.h | 8 +++++
> arch/arm64/kernel/ptrace.c | 59 ++++++++++++++++++++++++++++++++++++
> include/uapi/linux/elf.h | 1 +
> 3 files changed, 68 insertions(+)
>
> diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h
> index 7fa2f7036aa7..0f39ba4f3efd 100644
> --- a/arch/arm64/include/uapi/asm/ptrace.h
> +++ b/arch/arm64/include/uapi/asm/ptrace.h
> @@ -324,6 +324,14 @@ struct user_za_header {
> #define ZA_PT_SIZE(vq) \
> (ZA_PT_ZA_OFFSET + ZA_PT_ZA_SIZE(vq))
>
> +/* GCS state (NT_ARM_GCS) */
> +
> +struct user_gcs {
> + __u64 features_enabled;
> + __u64 features_locked;
> + __u64 gcspr_el0;
> +};
If there's a reserved field in sigframe's gcs_context, isn't it worth it
to have a reserved field here as well?
> +
> #endif /* __ASSEMBLY__ */
>
> #endif /* _UAPI__ASM_PTRACE_H */
> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
> index 20d7ef82de90..f15b8e33561e 100644
> --- a/arch/arm64/kernel/ptrace.c
> +++ b/arch/arm64/kernel/ptrace.c
> @@ -33,6 +33,7 @@
> #include <asm/cpufeature.h>
> #include <asm/debug-monitors.h>
> #include <asm/fpsimd.h>
> +#include <asm/gcs.h>
> #include <asm/mte.h>
> #include <asm/pointer_auth.h>
> #include <asm/stacktrace.h>
> @@ -1409,6 +1410,51 @@ static int tagged_addr_ctrl_set(struct task_struct *target, const struct
> }
> #endif
>
> +#ifdef CONFIG_ARM64_GCS
> +static int gcs_get(struct task_struct *target,
> + const struct user_regset *regset,
> + struct membuf to)
> +{
> + struct user_gcs user_gcs;
> +
> + if (target == current)
> + gcs_preserve_current_state();
> +
> + user_gcs.features_enabled = target->thread.gcs_el0_mode;
> + user_gcs.features_locked = target->thread.gcs_el0_locked;
> + user_gcs.gcspr_el0 = target->thread.gcspr_el0;
> +
> + return membuf_write(&to, &user_gcs, sizeof(user_gcs));
> +}
> +
> +static int gcs_set(struct task_struct *target, const struct
> + user_regset *regset, unsigned int pos,
> + unsigned int count, const void *kbuf, const
> + void __user *ubuf)
> +{
> + int ret;
> + struct user_gcs user_gcs;
> +
> + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &user_gcs, 0, -1);
> + if (ret)
> + return ret;
> +
> + if (user_gcs.features_enabled & ~PR_SHADOW_STACK_SUPPORTED_STATUS_MASK)
> + return -EINVAL;
> +
> + /* Do not allow enable via ptrace */
> + if ((user_gcs.features_enabled & PR_SHADOW_STACK_ENABLE) &&
> + !!(target->thread.gcs_el0_mode & PR_SHADOW_STACK_ENABLE))
There should be only one '!' above.
Though contrary to the patch description, this code allows disabling
GCS. Shouldn't we require that
(user_gcs.features_enabled & PR_SHADOW_STACK_ENABLE) ==
(target->thread.gcs_el0_mode & PR_SHADOW_STACK_ENABLE)
? That would ensure that the GCS mode can't be changed.
> + return -EBUSY;
> +
> + target->thread.gcs_el0_mode = user_gcs.features_enabled;
> + target->thread.gcs_el0_locked = user_gcs.features_locked;
> + target->thread.gcspr_el0 = user_gcs.gcspr_el0;
> +
> + return 0;
> +}
> +#endif
--
Thiago
Powered by blists - more mailing lists