mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: "Iván Ezequiel Rodriguez" <ivanrwcm25@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Mark Rutland <mark.rutland@arm.com>,
	Deepak Gupta <debug@rivosinc.com>,
	Alexandre Ghiti <alex@ghiti.fr>,
	Albert Ou <aou@eecs.berkeley.edu>, Shuah Khan <shuah@kernel.org>,
	Christian Brauner <brauner@kernel.org>,
	James Morse <james.morse@arm.com>,
	Yury Khrustalev <yury.khrustalev@arm.com>,
	Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
	Samuel Holland <samuel.holland@sifive.com>,
	Zong Li <zong.li@sifive.com>,
	Charlie Jenkins <thecharlesjenkins@gmail.com>,
	Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>,
	Zishun Yi <vulab@iscas.ac.cn>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/4] arm64/gcs: release GCS on failed fork
Date: Tue, 20 Oct 2026 13:05:11 +0100	[thread overview]
Message-ID: <atdY90gcVwbHu2sc@sirena.co.uk> (raw)
In-Reply-To: <2539f61f79a6053e2a33a1d1ae9df09013c04bd8.1792179433.git.ivanrwcm25@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1894 bytes --]

On Fri, Oct 16, 2026 at 04:46:00PM -0300, Iván Ezequiel Rodriguez wrote:

> Select HAVE_EXIT_THREAD and free the child's GCS from
> exit_thread(). gcs_free() already ignores a cleared base and a
> different mm, so the usual exit path (deactivate_mm() then this) is
> a no-op the second time. copy_thread_gcs() zeros the inherited
> tracking before a user-thread allocation, so an allocation error
> still skips exit_thread() with nothing to unmap.

This makes sense and mirrors the handling on x86 which had an existing
exit_thread().  There was a lot of pain finding the right places to hook
in here, there's far too many routes through this code :/ .

> A kthread copies the caller's GCS fields via arch_dup_task_struct().
> kernel_thread() uses CLONE_VM, so during a failed copy_process()
> the child still shares the caller's mm and gcs_free()'s mm check
> does not save us. Clear the inherited tracking as part of kthread
> setup.

I'm not spotting an equivalent path on x86, it's entirely possible I'm
missing something here but if I'm not then I expect they need the same
fix?  They use a similar memcpy() for the arch data and I'm not seeing a
reset anywhere.

> @@ -503,6 +513,17 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
>  
>  		p->thread.cpu_context.x19 = (unsigned long)args->fn;
>  		p->thread.cpu_context.x20 = (unsigned long)args->fn_arg;
> +#ifdef CONFIG_ARM64_GCS
> +		/*
> +		 * kernel_thread() uses CLONE_VM, so a failed
> +		 * copy_process() still shares the caller's mm.
> +		 * Inherited GCS tracking would then look like a
> +		 * child mapping to gcs_free().
> +		 */
> +		p->thread.gcs_base = 0;
> +		p->thread.gcs_size = 0;
> +		p->thread.gcspr_el0 = 0;
> +#endif

I think it'd be a bit more idiomatic to have a function to reset the GCS
state that gets an empty stub with !CONFIG_GCS 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-10-20 12:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 19:45 [PATCH 0/4] arm64, riscv: release shadow stacks " Iván Ezequiel Rodriguez
2026-10-16 19:46 ` [PATCH 1/4] arm64/gcs: release GCS " Iván Ezequiel Rodriguez
2026-10-20 12:05   ` Mark Brown [this message]
2026-10-16 19:46 ` [PATCH 2/4] riscv/shstk: release shadow stack " Iván Ezequiel Rodriguez
2026-10-16 19:46 ` [PATCH 3/4] selftests/arm64: GCS must not leak on a failed clone3 Iván Ezequiel Rodriguez
2026-10-20 15:16   ` Mark Brown
2026-10-16 19:46 ` [PATCH 4/4] selftests/riscv: shadow stack " Iván Ezequiel Rodriguez

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=atdY90gcVwbHu2sc@sirena.co.uk \
    --to=broonie@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=brauner@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=debug@rivosinc.com \
    --cc=ivanrwcm25@gmail.com \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=palmer@dabbelt.com \
    --cc=peterz@infradead.org \
    --cc=pjw@kernel.org \
    --cc=samuel.holland@sifive.com \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tan.shaopeng@jp.fujitsu.com \
    --cc=thecharlesjenkins@gmail.com \
    --cc=thiago.bauermann@linaro.org \
    --cc=vulab@iscas.ac.cn \
    --cc=will@kernel.org \
    --cc=yury.khrustalev@arm.com \
    --cc=zong.li@sifive.com \
    /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

all inboxes | Powered by JetHome®