LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: "H. Peter Anvin" <hpa@zytor.com>, Andi Kleen <andi@firstfloor.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Andy Lutomirski <luto@amacapital.net>
Subject: [PATCH 1/2] x86_64,signal: Save and restore SS in signal frames
Date: Fri, 11 Jul 2014 09:29:22 -0700 [thread overview]
Message-ID: <d8865f151f1b0abed2df6a3ba545f4cd8b1e873f.1405095200.git.luto@amacapital.net> (raw)
In-Reply-To: <cover.1405095200.git.luto@amacapital.net>
In-Reply-To: <cover.1405095200.git.luto@amacapital.net>
The comment in the signal code says that apps can save/restore other
segments on their own. It's true that apps can *save* SS on their
own, but there's no way for apps to restore it: SYSCALL effectively
resets SS to __USER_DS, so any value that user code tries to load
into SS gets lost on entry to sigreturn.
This recycles two padding bytes in the segment selector area for SS.
I suspect that 64-bit programs that try to run 16-bit code and uses
signals will have a lot of trouble without this.
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
---
arch/x86/include/asm/sigcontext.h | 2 +-
arch/x86/include/uapi/asm/sigcontext.h | 2 +-
arch/x86/kernel/signal.c | 8 +-------
3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/sigcontext.h b/arch/x86/include/asm/sigcontext.h
index 9dfce4e..f910cdc 100644
--- a/arch/x86/include/asm/sigcontext.h
+++ b/arch/x86/include/asm/sigcontext.h
@@ -59,7 +59,7 @@ struct sigcontext {
unsigned short cs;
unsigned short gs;
unsigned short fs;
- unsigned short __pad0;
+ unsigned short ss;
unsigned long err;
unsigned long trapno;
unsigned long oldmask;
diff --git a/arch/x86/include/uapi/asm/sigcontext.h b/arch/x86/include/uapi/asm/sigcontext.h
index d8b9f90..076b11f 100644
--- a/arch/x86/include/uapi/asm/sigcontext.h
+++ b/arch/x86/include/uapi/asm/sigcontext.h
@@ -179,7 +179,7 @@ struct sigcontext {
__u16 cs;
__u16 gs;
__u16 fs;
- __u16 __pad0;
+ __u16 ss;
__u64 err;
__u64 trapno;
__u64 oldmask;
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 2851d63..08d7a9e 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -94,15 +94,8 @@ int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
COPY(r15);
#endif /* CONFIG_X86_64 */
-#ifdef CONFIG_X86_32
COPY_SEG_CPL3(cs);
COPY_SEG_CPL3(ss);
-#else /* !CONFIG_X86_32 */
- /* Kernel saves and restores only the CS segment register on signals,
- * which is the bare minimum needed to allow mixed 32/64-bit code.
- * App's signal handler can save/restore other segments if needed. */
- COPY_SEG_CPL3(cs);
-#endif /* CONFIG_X86_32 */
get_user_ex(tmpflags, &sc->flags);
regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
@@ -164,6 +157,7 @@ int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
put_user_ex(regs->cs, &sc->cs);
put_user_ex(0, &sc->gs);
put_user_ex(0, &sc->fs);
+ put_user_ex(regs->ss, &sc->ss);
#endif /* CONFIG_X86_32 */
put_user_ex(fpstate, &sc->fpstate);
--
1.9.3
next prev parent reply other threads:[~2014-07-11 16:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-11 16:29 [PATCH 0/2] x86_64,signal: Fix the set of saved segment registers Andy Lutomirski
2014-07-11 16:29 ` Andy Lutomirski [this message]
2015-03-09 20:15 ` [PATCH 1/2] x86_64,signal: Save and restore SS in signal frames Andy Lutomirski
2014-07-11 16:29 ` [PATCH 2/2] x86_64,signal: Remove 'fs' and 'gs' from sigcontext Andy Lutomirski
2014-07-11 18:12 ` Andi Kleen
2014-07-11 18:39 ` Andy Lutomirski
2014-07-12 2:09 ` H. Peter Anvin
2014-07-12 2:04 ` H. Peter Anvin
2014-07-12 2:21 ` Linus Torvalds
2014-07-12 2:26 ` H. Peter Anvin
2014-07-12 8:39 ` Andy Lutomirski
2014-07-12 18:37 ` Andi Kleen
2014-07-12 18:40 ` H. Peter Anvin
2014-07-12 18:52 ` Andi Kleen
2014-07-12 21:17 ` Andy Lutomirski
2014-07-18 1:13 ` Andy Lutomirski
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=d8865f151f1b0abed2df6a3ba545f4cd8b1e873f.1405095200.git.luto@amacapital.net \
--to=luto@amacapital.net \
--cc=andi@firstfloor.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
--cc=x86@kernel.org \
--subject='Re: [PATCH 1/2] x86_64,signal: Save and restore SS in signal frames' \
/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
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).