From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "x86@kernel.org" <x86@kernel.org>,
"ivanrwcm25@gmail.com" <ivanrwcm25@gmail.com>,
"tglx@kernel.org" <tglx@kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"bp@alien8.de" <bp@alien8.de>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
Cc: "brauner@kernel.org" <brauner@kernel.org>,
"sammiee5311@gmail.com" <sammiee5311@gmail.com>,
"lirongqing@baidu.com" <lirongqing@baidu.com>,
"hpa@zytor.com" <hpa@zytor.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"shuah@kernel.org" <shuah@kernel.org>,
"Mehta, Sohil" <sohil.mehta@intel.com>,
"nik.borisov@suse.com" <nik.borisov@suse.com>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH 1/2] x86/shstk: free shadow stack when copy_thread() fails
Date: Wed, 21 Oct 2026 19:26:46 +0000 [thread overview]
Message-ID: <948b6b86c6b00199fc7c36779d131ac75d92db63.camel@intel.com> (raw)
In-Reply-To: <20261015023147.519257-2-ivanrwcm25@gmail.com>
By inspection the bug looks real to me.
On Wed, 2026-10-14 at 23:31 -0300, Iván Ezequiel Rodriguez wrote:
> diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
> index 346c438ac880..be840652d055 100644
> --- a/arch/x86/kernel/process.c
> +++ b/arch/x86/kernel/process.c
> @@ -265,11 +265,19 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
> /* Set a new TLS for the child thread? */
> if (clone_flags & CLONE_SETTLS)
> ret = set_new_tls(p, tls);
> + if (ret) {
Having the error check happen even if !CLONE_SETTLS makes it not clear that this
condition could only happen that way. I'd maybe nest the check inside, like is
done in several cases in in copy_process(). Like (untested):
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 346c438ac8801..e40f83a02fdb1 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -176,7 +176,7 @@ int copy_thread(struct task_struct *p, const struct
kernel_clone_args *args)
struct fork_frame *fork_frame;
struct pt_regs *childregs;
unsigned long new_ssp;
- int ret = 0;
+ int ret;
childregs = task_pt_regs(p);
fork_frame = container_of(childregs, struct fork_frame, regs);
@@ -263,13 +263,19 @@ int copy_thread(struct task_struct *p, const struct
kernel_clone_args *args)
}
/* Set a new TLS for the child thread? */
- if (clone_flags & CLONE_SETTLS)
+ if (clone_flags & CLONE_SETTLS) {
ret = set_new_tls(p, tls);
+ if (ret)
+ goto shstk_free;
+ }
- if (!ret && unlikely(test_tsk_thread_flag(current, TIF_IO_BITMAP)))
+ if (unlikely(test_tsk_thread_flag(current, TIF_IO_BITMAP)))
io_bitmap_share(p);
return ret;
+shstk_free:
+ shstk_free(p);
+ return ret;
}
static void pkru_flush_thread(void)
> + /*
> + * copy_process() skips exit_thread() when copy_thread()
> + * fails. Free the shadow stack mapped before this error.
> + */
I'm not in favor of this comment. It is describing behavior far away. And the
idea that you cleanup what you allocated in on a later error condition is a
pretty common pattern. I tried to write something and nothing seems non-obvious.
Maybe just drop it.
> + shstk_free(p);
> + return ret;
> + }
>
> - if (!ret && unlikely(test_tsk_thread_flag(current, TIF_IO_BITMAP)))
> + if (unlikely(test_tsk_thread_flag(current, TIF_IO_BITMAP)))
> io_bitmap_share(p);
>
> - return ret;
> + return 0;
> }
next prev parent reply other threads:[~2026-10-21 19:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 2:31 [PATCH 0/2] x86/shstk: don't leak a shadow stack when clone TLS fails Iván Ezequiel Rodriguez
2026-10-15 2:31 ` [PATCH 1/2] x86/shstk: free shadow stack when copy_thread() fails Iván Ezequiel Rodriguez
2026-10-21 19:26 ` Edgecombe, Rick P [this message]
2026-10-15 2:31 ` [PATCH 2/2] selftests/x86: shadow stack must survive a bad TLS 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=948b6b86c6b00199fc7c36779d131ac75d92db63.camel@intel.com \
--to=rick.p.edgecombe@intel.com \
--cc=bp@alien8.de \
--cc=brauner@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=ivanrwcm25@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lirongqing@baidu.com \
--cc=mingo@redhat.com \
--cc=nik.borisov@suse.com \
--cc=sammiee5311@gmail.com \
--cc=shuah@kernel.org \
--cc=sohil.mehta@intel.com \
--cc=tglx@kernel.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 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®