All of lore.kernel.org
 help / color / mirror / Atom feed
From: dave.martin@linaro.org (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] Ensure predictable endian state on signal handler entry
Date: Tue, 15 Feb 2011 10:37:29 +0000	[thread overview]
Message-ID: <20110215103728.GA2650@arm.com> (raw)
In-Reply-To: <20110214200222.GD31103@n2100.arm.linux.org.uk>

On Mon, Feb 14, 2011 at 08:02:22PM +0000, Russell King - ARM Linux wrote:
> Ensure a predictable endian state when entering signal handlers.  This
> avoids programs which use SETEND to momentarily switch their endian
> state from having their signal handlers entered with an unpredictable
> endian state.
> 
> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
> --
> 
>  arch/arm/kernel/signal.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
> index 907d5a6..abaf844 100644
> --- a/arch/arm/kernel/signal.c
> +++ b/arch/arm/kernel/signal.c
> @@ -474,7 +474,9 @@ setup_return(struct pt_regs *regs, struct k_sigaction *ka,
>  	unsigned long handler = (unsigned long)ka->sa.sa_handler;
>  	unsigned long retcode;
>  	int thumb = 0;
> -	unsigned long cpsr = regs->ARM_cpsr & ~PSR_f;
> +	unsigned long cpsr = regs->ARM_cpsr & ~(PSR_f | PSR_E_BIT);
> +
> +	cpsr |= PSR_ENDSTATE;
>  
>  	/*
>  	 * Maybe we need to deliver a 32-bit signal to a 26-bit task.
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Looks sensible to me.

Acked-by: Dave Martin <dave.martin@linaro.org>

Only tested it with little-endian, but it's enough to make my silly
test program not segfault.  (Without your patch, it definitely does...)

#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>

static void handler(int n)
{
	unsigned long cpsr;
#define FORMAT "handler: CPSR = 0x%08lX\n"
	char buf[sizeof FORMAT - 5 + 8];

	asm ("mrs %0, CPSR" : "=r" (cpsr));

	snprintf(buf, sizeof buf, FORMAT, cpsr);

	write(STDOUT_FILENO, buf, strlen(buf));
}

int main(void)
{
	signal(SIGINT, handler);

	asm volatile (
	"0:	setend	be\n\t"
	"	b 0b"
	);
}

Cheers
---Dave

      reply	other threads:[~2011-02-15 10:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-14 20:02 [PATCH] Ensure predictable endian state on signal handler entry Russell King - ARM Linux
2011-02-15 10:37 ` Dave Martin [this message]

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=20110215103728.GA2650@arm.com \
    --to=dave.martin@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.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.