All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Mika Penttilä" <mika.penttila@nextfour.com>
To: Scott Bauer <sbauer@eng.utah.edu>, linux-kernel@vger.kernel.org
Cc: kernel-hardening@lists.openwall.com, x86@kernel.org,
	ak@linux.intel.com, luto@amacapital.net, mingo@redhat.com,
	tglx@linutronix.de, Abhiram Balasubramanian <abhiram@cs.utah.edu>
Subject: [kernel-hardening] Re: [PATCHv2 2/2] x86: SROP mitigation: implement signal cookies
Date: Sun, 7 Feb 2016 08:35:50 +0200	[thread overview]
Message-ID: <56B6E5C6.4090209@nextfour.com> (raw)
In-Reply-To: <1454801964-50385-3-git-send-email-sbauer@eng.utah.edu>

Hi,


On 07.02.2016 01:39, Scott Bauer wrote:
> This patch adds SROP mitigation logic to the x86 signal delivery
> and sigreturn code. The cookie is placed in the unused alignment
> space above the saved FP state, if it exists. If there is no FP
> state to save then the cookie is placed in the alignment space above
> the sigframe.
>
> Cc: Abhiram Balasubramanian <abhiram@cs.utah.edu>
> Signed-off-by: Scott Bauer <sbauer@eng.utah.edu>
> ---
>  arch/x86/ia32/ia32_signal.c        | 63 +++++++++++++++++++++++++---
>  arch/x86/include/asm/fpu/signal.h  |  1 +
>  arch/x86/include/asm/sighandling.h |  5 ++-
>  arch/x86/kernel/fpu/signal.c       | 10 +++++
>  arch/x86/kernel/signal.c           | 86 +++++++++++++++++++++++++++++++++-----
>  5 files changed, 146 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
> index 0552884..2751f47 100644
> --- a/arch/x86/ia32/ia32_signal.c
> +++ b/arch/x86/ia32/ia32_signal.c
> @@ -68,7 +68,8 @@
>  }
>  
>  static int ia32_restore_sigcontext(struct pt_regs *regs,
> -				   struct sigcontext_32 __user *sc)
> +				   struct sigcontext_32 __user *sc,
> +				   void __user **user_cookie)
>  {
>  	unsigned int tmpflags, err = 0;
>  	void __user *buf;
> @@ -105,6 +106,16 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
>  		buf = compat_ptr(tmp);
>  	} get_user_catch(err);
>  
> +	/*
> +	 * If there is fp state get cookie from the top of the fp state,
> +	 * else get it from the top of the sig frame.
> +	 */
> +
> +	if (tmp != 0)
> +		*user_cookie = compat_ptr(tmp + fpu__getsize(1));
> +	else
> +		*user_cookie = NULL;
> +
>  	err |= fpu__restore_sig(buf, 1);
>  
>  	force_iret();
> @@ -117,6 +128,7 @@ asmlinkage long sys32_sigreturn(void)
>  	struct pt_regs *regs = current_pt_regs();
>  	struct sigframe_ia32 __user *frame = (struct sigframe_ia32 __user *)(regs->sp-8);
>  	sigset_t set;
> +	void __user *user_cookie;
>  
>  	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
>  		goto badframe;
> @@ -129,8 +141,15 @@ asmlinkage long sys32_sigreturn(void)
>  
>  	set_current_blocked(&set);
>  
> -	if (ia32_restore_sigcontext(regs, &frame->sc))
> +	if (ia32_restore_sigcontext(regs, &frame->sc, &user_cookie))
> +		goto badframe;
> +
> +	if (user_cookie == NULL)
> +		user_cookie = compat_ptr((regs->sp - 8) + sizeof(*frame));
> +
> +	if (verify_clear_sigcookie(user_cookie))
>  		goto badframe;
> +
>  	return regs->ax;
>  
>  badframe:
> @@ -142,6 +161,7 @@ asmlinkage long sys32_rt_sigreturn(void)
>  {
>  	struct pt_regs *regs = current_pt_regs();
>  	struct rt_sigframe_ia32 __user *frame;
> +	void __user *user_cookie;
>  	sigset_t set;
>  
>  	frame = (struct rt_sigframe_ia32 __user *)(regs->sp - 4);
> @@ -153,7 +173,13 @@ asmlinkage long sys32_rt_sigreturn(void)
>  
>  	set_current_blocked(&set);
>  
> -	if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext))
> +	if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &user_cookie))
> +		goto badframe;
> +
> +	if (user_cookie == NULL)
> +		user_cookie = (void __user *)((regs->sp - 4) + sizeof(*frame));
regs->sp is already restored so you should use frame instead.

--Mika

WARNING: multiple messages have this Message-ID (diff)
From: "Mika Penttilä" <mika.penttila@nextfour.com>
To: Scott Bauer <sbauer@eng.utah.edu>, <linux-kernel@vger.kernel.org>
Cc: <kernel-hardening@lists.openwall.com>, <x86@kernel.org>,
	<ak@linux.intel.com>, <luto@amacapital.net>, <mingo@redhat.com>,
	<tglx@linutronix.de>,
	Abhiram Balasubramanian <abhiram@cs.utah.edu>
Subject: Re: [PATCHv2 2/2] x86: SROP mitigation: implement signal cookies
Date: Sun, 7 Feb 2016 08:35:50 +0200	[thread overview]
Message-ID: <56B6E5C6.4090209@nextfour.com> (raw)
In-Reply-To: <1454801964-50385-3-git-send-email-sbauer@eng.utah.edu>

Hi,


On 07.02.2016 01:39, Scott Bauer wrote:
> This patch adds SROP mitigation logic to the x86 signal delivery
> and sigreturn code. The cookie is placed in the unused alignment
> space above the saved FP state, if it exists. If there is no FP
> state to save then the cookie is placed in the alignment space above
> the sigframe.
>
> Cc: Abhiram Balasubramanian <abhiram@cs.utah.edu>
> Signed-off-by: Scott Bauer <sbauer@eng.utah.edu>
> ---
>  arch/x86/ia32/ia32_signal.c        | 63 +++++++++++++++++++++++++---
>  arch/x86/include/asm/fpu/signal.h  |  1 +
>  arch/x86/include/asm/sighandling.h |  5 ++-
>  arch/x86/kernel/fpu/signal.c       | 10 +++++
>  arch/x86/kernel/signal.c           | 86 +++++++++++++++++++++++++++++++++-----
>  5 files changed, 146 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
> index 0552884..2751f47 100644
> --- a/arch/x86/ia32/ia32_signal.c
> +++ b/arch/x86/ia32/ia32_signal.c
> @@ -68,7 +68,8 @@
>  }
>  
>  static int ia32_restore_sigcontext(struct pt_regs *regs,
> -				   struct sigcontext_32 __user *sc)
> +				   struct sigcontext_32 __user *sc,
> +				   void __user **user_cookie)
>  {
>  	unsigned int tmpflags, err = 0;
>  	void __user *buf;
> @@ -105,6 +106,16 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
>  		buf = compat_ptr(tmp);
>  	} get_user_catch(err);
>  
> +	/*
> +	 * If there is fp state get cookie from the top of the fp state,
> +	 * else get it from the top of the sig frame.
> +	 */
> +
> +	if (tmp != 0)
> +		*user_cookie = compat_ptr(tmp + fpu__getsize(1));
> +	else
> +		*user_cookie = NULL;
> +
>  	err |= fpu__restore_sig(buf, 1);
>  
>  	force_iret();
> @@ -117,6 +128,7 @@ asmlinkage long sys32_sigreturn(void)
>  	struct pt_regs *regs = current_pt_regs();
>  	struct sigframe_ia32 __user *frame = (struct sigframe_ia32 __user *)(regs->sp-8);
>  	sigset_t set;
> +	void __user *user_cookie;
>  
>  	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
>  		goto badframe;
> @@ -129,8 +141,15 @@ asmlinkage long sys32_sigreturn(void)
>  
>  	set_current_blocked(&set);
>  
> -	if (ia32_restore_sigcontext(regs, &frame->sc))
> +	if (ia32_restore_sigcontext(regs, &frame->sc, &user_cookie))
> +		goto badframe;
> +
> +	if (user_cookie == NULL)
> +		user_cookie = compat_ptr((regs->sp - 8) + sizeof(*frame));
> +
> +	if (verify_clear_sigcookie(user_cookie))
>  		goto badframe;
> +
>  	return regs->ax;
>  
>  badframe:
> @@ -142,6 +161,7 @@ asmlinkage long sys32_rt_sigreturn(void)
>  {
>  	struct pt_regs *regs = current_pt_regs();
>  	struct rt_sigframe_ia32 __user *frame;
> +	void __user *user_cookie;
>  	sigset_t set;
>  
>  	frame = (struct rt_sigframe_ia32 __user *)(regs->sp - 4);
> @@ -153,7 +173,13 @@ asmlinkage long sys32_rt_sigreturn(void)
>  
>  	set_current_blocked(&set);
>  
> -	if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext))
> +	if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &user_cookie))
> +		goto badframe;
> +
> +	if (user_cookie == NULL)
> +		user_cookie = (void __user *)((regs->sp - 4) + sizeof(*frame));
regs->sp is already restored so you should use frame instead.

--Mika

  reply	other threads:[~2016-02-07  6:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-06 23:39 [kernel-hardening] [PATCHv2 0/2] SROP Mitigation: Signal cookies Scott Bauer
2016-02-06 23:39 ` Scott Bauer
2016-02-06 23:39 ` [kernel-hardening] [PATCHv2 1/2] SROP Mitigation: Architecture independent code for signal cookies Scott Bauer
2016-02-06 23:39   ` Scott Bauer
2016-02-06 23:39 ` [kernel-hardening] [PATCHv2 2/2] x86: SROP mitigation: implement " Scott Bauer
2016-02-06 23:39   ` Scott Bauer
2016-02-07  6:35   ` Mika Penttilä [this message]
2016-02-07  6:35     ` Mika Penttilä
2016-02-07  8:10     ` [kernel-hardening] " Scotty Bauer
2016-02-07  8:10       ` Scotty Bauer
2016-02-08 21:50       ` [kernel-hardening] " Andy Lutomirski
2016-02-08 21:50         ` Andy Lutomirski
2016-02-08 23:17         ` [kernel-hardening] " Scotty Bauer
2016-02-08 23:17           ` Scotty Bauer
2016-02-09  5:51           ` [kernel-hardening] " Andy Lutomirski
2016-02-09  5:51             ` Andy Lutomirski
2016-02-09 20:45         ` [kernel-hardening] " Andi Kleen
2016-02-09 20:45           ` Andi Kleen

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=56B6E5C6.4090209@nextfour.com \
    --to=mika.penttila@nextfour.com \
    --cc=abhiram@cs.utah.edu \
    --cc=ak@linux.intel.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@redhat.com \
    --cc=sbauer@eng.utah.edu \
    --cc=tglx@linutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.