From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: bp@suse.de, tglx@linutronix.de, mingo@kernel.org,
luto@kernel.org, x86@kernel.org
Cc: len.brown@intel.com, dave.hansen@intel.com, hjl.tools@gmail.com,
Dave.Martin@arm.com, jannh@google.com, mpe@ellerman.id.au,
tony.luck@intel.com, ravi.v.shankar@intel.com,
libc-alpha@sourceware.org, linux-arch@vger.kernel.org,
linux-api@vger.kernel.org, linux-kernel@vger.kernel.org,
chang.seok.bae@intel.com
Subject: [PATCH v3 3/4] x86/signal: Prevent an alternate stack overflow before a signal delivery
Date: Tue, 22 Dec 2020 17:53:11 -0800 [thread overview]
Message-ID: <20201223015312.4882-4-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20201223015312.4882-1-chang.seok.bae@intel.com>
The kernel pushes data on the userspace stack when entering a signal. If
using a sigaltstack(), the kernel precisely knows the user stack size.
When the kernel knows that the user stack is too small, avoid the overflow
and do an immediate SIGSEGV instead.
This overflow is known to occur on systems with large XSAVE state. The
effort to increase the size typically used for altstacks reduces the
frequency of these overflows, but this approach is still useful for legacy
binaries.
Suggested-by: Jann Horn <jannh@google.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Reviewed-by: Len Brown <len.brown@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
---
Changes from v2:
* Simplified the implementation (Jann Horn)
---
arch/x86/kernel/signal.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 761d856f8ef7..91056a940271 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -242,7 +242,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
unsigned long math_size = 0;
unsigned long sp = regs->sp;
unsigned long buf_fx = 0;
- int onsigstack = on_sig_stack(sp);
+ bool onsigstack = on_sig_stack(sp);
int ret;
/* redzone */
@@ -251,8 +251,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
/* This is the X/Open sanctioned signal stack switching. */
if (ka->sa.sa_flags & SA_ONSTACK) {
- if (sas_ss_flags(sp) == 0)
+ if (sas_ss_flags(sp) == 0) {
sp = current->sas_ss_sp + current->sas_ss_size;
+ /* On the alternate signal stack */
+ onsigstack = true;
+ }
} else if (IS_ENABLED(CONFIG_X86_32) &&
!onsigstack &&
regs->ss != __USER_DS &&
--
2.17.1
next prev parent reply other threads:[~2020-12-23 1:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-23 1:53 [PATCH v3 0/4] x86: Improve Minimum Alternate Stack Size Chang S. Bae
2020-12-23 1:53 ` [PATCH v3 1/4] x86/signal: Introduce helpers to get the maximum signal frame size Chang S. Bae
2020-12-23 1:53 ` [PATCH v3 2/4] x86/elf: Support a new ELF aux vector AT_MINSIGSTKSZ Chang S. Bae
2020-12-23 1:53 ` Chang S. Bae [this message]
2020-12-23 6:55 ` [PATCH v3 3/4] x86/signal: Prevent an alternate stack overflow before a signal delivery Jann Horn
2021-01-08 18:09 ` Borislav Petkov
2020-12-23 1:53 ` [PATCH v3 4/4] selftest/x86/signal: Include test cases for validating sigaltstack Chang S. Bae
2021-01-08 18:07 ` Borislav Petkov
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=20201223015312.4882-4-chang.seok.bae@intel.com \
--to=chang.seok.bae@intel.com \
--cc=Dave.Martin@arm.com \
--cc=bp@suse.de \
--cc=dave.hansen@intel.com \
--cc=hjl.tools@gmail.com \
--cc=jannh@google.com \
--cc=len.brown@intel.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=ravi.v.shankar@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--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;
as well as URLs for NNTP newsgroup(s).