From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: David Vrabel <david.vrabel@citrix.com>
Cc: Frediano Ziglio <frediano.ziglio@citrix.com>,
stable@vger.kernel.org, xen-devel@lists.xen.org
Subject: Re: [PATCHv2] xen/x86: don't corrupt %eip when returning from a signal handler
Date: Wed, 17 Oct 2012 11:02:22 -0400 [thread overview]
Message-ID: <20121017150222.GA8743@phenom.dumpdata.com> (raw)
In-Reply-To: <1350480580-4844-1-git-send-email-david.vrabel@citrix.com>
On Wed, Oct 17, 2012 at 02:29:40PM +0100, David Vrabel wrote:
> From: David Vrabel <david.vrabel@citrix.com>
>
> In 32 bit guests, if a userspace process has %eax == -ERESTARTSYS
> (-512) or -ERESTARTNOINTR (-513) when it is interrupted by an event
> /and/ the process has a pending signal then %eip (and %eax) are
> corrupted when returning to the main process after handling the
> signal. The application may then crash with SIGSEGV or a SIGILL or it
> may have subtly incorrect behaviour (depending on what instruction it
> returned to).
>
> The occurs because handle_signal() is incorrectly thinking that there
> is a system call that needs to restarted so it adjusts %eip and %eax
> to re-execute the system call instruction (even though user space had
> not done a system call).
>
> If %eax == -514 (-ERESTARTNOHAND (-514) or -ERESTART_RESTARTBLOCK
> (-516) then handle_signal() only corrupted %eax (by setting it to
> -EINTR). This may cause the application to crash or have incorrect
> behaviour.
>
> handle_signal() assumes that regs->orig_ax >= 0 means a system call so
> any kernel entry point that is not for a system call must push a
> negative value for orig_ax. For example, for physical interrupts on
> bare metal the inverse of the vector is pushed and page_fault() sets
> regs->orig_ax to -1, overwriting the hardware provided error code.
>
> xen_hypervisor_callback() was incorrectly pushing 0 for orig_ax
> instead of -1.
>
> Classic Xen kernels pushed %eax which works as %eax cannot be both
> non-negative and -RESTARTSYS (etc.), but using -1 is consistent with
> other non-system call entry points.
>
> There were similar bugs in xen_failsafe_callback(), if the fault was
> corrected and normal return path was used. 64 bit guests would push 0
> which is broken. 32 bit guests would push %eax which is safe (see
> previous paragraph), but for consistency this is also changed to -1.
>
> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
> Acked-by: Jan Beulich <JBeulich@suse.com>
> Acked-by: Ian Campbell <ian.campbell@citrix.com>
> Cc: stable@vger.kernel.org
Applied.
> ---
> arch/x86/kernel/entry_32.S | 4 ++--
> arch/x86/kernel/entry_64.S | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
> index 2c63407..6a19e66 100644
> --- a/arch/x86/kernel/entry_32.S
> +++ b/arch/x86/kernel/entry_32.S
> @@ -1042,7 +1042,7 @@ ENTRY(xen_sysenter_target)
>
> ENTRY(xen_hypervisor_callback)
> CFI_STARTPROC
> - pushl_cfi $0
> + pushl_cfi $-1 /* orig_ax = -1 => not a system call */
> SAVE_ALL
> TRACE_IRQS_OFF
>
> @@ -1078,7 +1078,7 @@ ENDPROC(xen_hypervisor_callback)
> # We distinguish between categories by maintaining a status value in EAX.
> ENTRY(xen_failsafe_callback)
> CFI_STARTPROC
> - pushl_cfi %eax
> + pushl_cfi $-1 /* orig_ax = -1 => not a system call */
> movl $1,%eax
> 1: mov 4(%esp),%ds
> 2: mov 8(%esp),%es
> diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
> index cdc790c..430b1fc 100644
> --- a/arch/x86/kernel/entry_64.S
> +++ b/arch/x86/kernel/entry_64.S
> @@ -1451,7 +1451,7 @@ ENTRY(xen_failsafe_callback)
> CFI_RESTORE r11
> addq $0x30,%rsp
> CFI_ADJUST_CFA_OFFSET -0x30
> - pushq_cfi $0
> + pushq_cfi $-1 /* orig_ax = -1 => not a system call */
> SAVE_ALL
> jmp error_exit
> CFI_ENDPROC
> --
> 1.7.2.5
next prev parent reply other threads:[~2012-10-17 15:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-17 13:29 [PATCHv2] xen/x86: don't corrupt %eip when returning from a signal handler David Vrabel
2012-10-17 15:02 ` Konrad Rzeszutek Wilk [this message]
2012-10-19 15:29 ` Jan Beulich
2012-10-19 15:44 ` David Vrabel
2012-10-19 16:03 ` Jan Beulich
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=20121017150222.GA8743@phenom.dumpdata.com \
--to=konrad.wilk@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=frediano.ziglio@citrix.com \
--cc=stable@vger.kernel.org \
--cc=xen-devel@lists.xen.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).