All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: David Vrabel <david.vrabel@citrix.com>
Cc: Frediano Ziglio <frediano.ziglio@citrix.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	"stable@kernel.org" <stable@kernel.org>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH] xen/x86: don't corrupt %eip when returning from a signal handler
Date: Wed, 17 Oct 2012 12:48:36 +0100	[thread overview]
Message-ID: <507E9B14.1040601@citrix.com> (raw)
In-Reply-To: <1350474150-3990-1-git-send-email-david.vrabel@citrix.com>

On 17/10/12 12:42, 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 following test program shows the bug.  It will receive the signal
when in the infinite loop and return to the preceeding int 3 instruction.

Big thanks to Frediano for producing the test program and the majority
of the effort in tracking down this bug.

David

8<--------------------------
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <assert.h>
#include <sys/time.h>

static void handler(int sig)
{
	static unsigned count = 0;
	if (++count == 60 * 1000)
		exit(0);
}

int main(void)
{
	struct sigaction act;

	// set signal
	sigfillset(&act.sa_mask);
	act.sa_flags = 0;
	act.sa_handler = handler;

	int err = sigaction(SIGALRM, &act, NULL);
	assert(!err);

	// set timer
	struct itimerval ival = { { 0, 1000 }, { 0, 1000 } };
	err = setitimer(ITIMER_REAL, &ival, NULL);
	assert(!err);

#if !defined(__x86_64__) && !defined(__i386__)
# error This code work only on Intel architecture!
#endif

	// wait for a core !!
	asm(
#ifdef __x86_64__
"	mov	$-513, %rax\n"
#else
"	mov	$-513, %eax\n"
#endif
"	jmp	infinite\n"
"	int	$3\n"
"	int	$3\n"
"	int	$3\n"
"	int	$3\n"
"infinite:\n"
"	jmp	infinite\n"
);

	return 0;
}

  reply	other threads:[~2012-10-17 11:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-17 11:42 [PATCH] xen/x86: don't corrupt %eip when returning from a signal handler David Vrabel
2012-10-17 11:48 ` David Vrabel [this message]
2012-10-17 11:52 ` Ian Campbell
2012-10-17 12:07 ` Jan Beulich
2012-10-17 12:19   ` David Vrabel
2012-10-17 12:28     ` 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=507E9B14.1040601@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=frediano.ziglio@citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=stable@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 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.