[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aNVx9vlgi8t81V6Y@arm.com>
Date: Thu, 25 Sep 2025 17:46:46 +0100
From: Catalin Marinas <catalin.marinas@....com>
To: Mark Brown <broonie@...nel.org>
Cc: Will Deacon <will@...nel.org>, Christian Brauner <brauner@...nel.org>,
Adhemerval Zanella Netto <adhemerval.zanella@...aro.org>,
Shuah Khan <shuah@...nel.org>,
Rick Edgecombe <rick.p.edgecombe@...el.com>,
Deepak Gupta <debug@...osinc.com>,
Wilco Dijkstra <wilco.dijkstra@....com>,
Carlos O'Donell <codonell@...hat.com>,
Florian Weimer <fweimer@...hat.com>, Szabolcs Nagy <nsz@...t70.net>,
Rich Felker <dalias@...c.org>, libc-alpha@...rceware.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org
Subject: Re: [PATCH RFC 1/3] arm64/gcs: Support reuse of GCS for exited
threads
On Sun, Sep 21, 2025 at 02:21:35PM +0100, Mark Brown wrote:
> diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c
> index fd1d5a6655de..4649c2b107a7 100644
> --- a/arch/arm64/mm/gcs.c
> +++ b/arch/arm64/mm/gcs.c
> @@ -199,14 +199,37 @@ void gcs_set_el0_mode(struct task_struct *task)
>
> void gcs_free(struct task_struct *task)
> {
> + unsigned long __user *cap_ptr;
> + unsigned long cap_val;
> + int ret;
> +
> if (!system_supports_gcs())
> return;
>
> if (!task->mm || task->mm != current->mm)
> return;
> - if (task->thread.gcs_base)
> + if (task->thread.gcs_base) {
> vm_munmap(task->thread.gcs_base, task->thread.gcs_size);
> + } else if (task == current &&
> + task->thread.gcs_el0_mode & PR_SHADOW_STACK_EXIT_TOKEN) {
I checked the code paths leading here and task is always current. But
better to keep the test in case the core code ever changes.
> + cap_ptr = (unsigned long __user *)read_sysreg_s(SYS_GCSPR_EL0);
> + cap_ptr--;
> + cap_val = GCS_CAP(cap_ptr);
> +
> + /*
> + * We can't do anything constructive if this fails,
> + * and the thread might be exiting due to being in a
> + * bad state anyway.
> + */
> + put_user_gcs(cap_val, cap_ptr, &ret);
> +
> + /*
> + * Ensure the new cap is ordered before standard
> + * memory accesses to the same location.
> + */
> + gcsb_dsync();
> + }
The only downside is that, if the thread did not unwind properly, we
don't write the token where it was initially. We could save the token
address from clone3() and restore it there instead.
--
Catalin
Powered by blists - more mailing lists