From: Michael Ellerman <patch-notifications@ellerman.id.au>
To: John Sperbeck <jsperbeck@google.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
linuxppc-dev@lists.ozlabs.org
Cc: John Sperbeck <jsperbeck@google.com>
Subject: Re: powerpc/mm: restore SEGV_ACCERR for segv on mapped region
Date: Thu, 4 Jan 2018 00:16:54 +1100 (AEDT) [thread overview]
Message-ID: <3zBWft73J4z9s81@ozlabs.org> (raw)
In-Reply-To: <20180101052458.132027-1-jsperbeck@google.com>
On Mon, 2018-01-01 at 05:24:58 UTC, John Sperbeck wrote:
> A recent refactoring of the powerpc page fault handler caused
> access to protected memory regions to indicate SEGV_MAPERR instead
> of the traditional SEGV_ACCERR in the si_code field of a user-space
> signal handler. This can confuse debug libraries that temporarily
> change the protection of memory regions, and expect to use
> SEGV_ACCERR as an indication to restore access to a region.
>
> This change restores the previous behavior. The following program
> exhibits the issue:
>
> $ ./repro read || echo "FAILED"
> $ ./repro write || echo "FAILED"
> $ ./repro exec || echo "FAILED"
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
> #include <signal.h>
> #include <sys/mman.h>
> #include <assert.h>
>
> static void segv_handler(int n, siginfo_t *info, void *arg) {
> _exit(info->si_code == SEGV_ACCERR ? 0 : 1);
> }
>
> int main(int argc, char **argv)
> {
> void *p = NULL;
> struct sigaction act = {
> .sa_sigaction = segv_handler,
> .sa_flags = SA_SIGINFO,
> };
>
> assert(argc == 2);
> p = mmap(NULL, getpagesize(),
> (strcmp(argv[1], "write") == 0) ? PROT_READ : 0,
> MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
> assert(p != MAP_FAILED);
>
> assert(sigaction(SIGSEGV, &act, NULL) == 0);
> if (strcmp(argv[1], "read") == 0)
> printf("%c", *(unsigned char *)p);
> else if (strcmp(argv[1], "write") == 0)
> *(unsigned char *)p = 0;
> else if (strcmp(argv[1], "exec") == 0)
> ((void (*)(void))p)();
> return 1; /* failed to generate SEGV */
> }
>
> Signed-off-by: John Sperbeck <jsperbeck@google.com>
> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/ecb101aed86156ec7cd71e5dca668e
cheers
prev parent reply other threads:[~2018-01-03 13:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-01 5:24 [PATCH] powerpc/mm: restore SEGV_ACCERR for segv on mapped region John Sperbeck
2018-01-01 20:55 ` Benjamin Herrenschmidt
2018-01-03 13:16 ` Michael Ellerman [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=3zBWft73J4z9s81@ozlabs.org \
--to=patch-notifications@ellerman.id.au \
--cc=benh@kernel.crashing.org \
--cc=jsperbeck@google.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=paulus@samba.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).