John Sperbeck
49b52457e1
powerpc/mm: Fix SEGV on mapped region to return SEGV_ACCERR
...
commit ecb101aed86156ec7cd71e5dca668e09146e6994 upstream.
The recent refactoring of the powerpc page fault handler in commit
c3350602e876 ("powerpc/mm: Make bad_area* helper functions") 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 commit 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 */
}
Fixes: c3350602e876 ("powerpc/mm: Make bad_area* helper functions")
Signed-off-by: John Sperbeck <jsperbeck@google.com>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
[mpe: Add commit references in change log]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-01-10 09:31:21 +01:00
..
2017-11-02 10:04:46 -07:00
2018-01-10 09:31:21 +01:00
2017-12-25 14:26:33 +01:00
2017-12-29 17:53:48 +01:00
2017-12-20 10:10:34 +01:00
2017-11-02 11:20:11 +01:00
2017-11-02 11:19:54 +01:00
2017-11-02 11:20:11 +01:00
2017-11-02 11:19:54 +01:00
2017-11-02 11:20:11 +01:00
2017-11-05 12:14:50 -08:00
2017-11-02 11:20:11 +01:00
2017-12-10 13:40:39 +01:00
2017-11-02 11:20:11 +01:00
2017-11-02 11:20:11 +01:00
2017-12-17 15:07:59 +01:00
2017-11-02 11:20:11 +01:00
2017-11-02 11:20:11 +01:00
2017-11-02 11:20:11 +01:00
2017-12-29 17:53:47 +01:00
2018-01-10 09:31:21 +01:00
2017-12-25 14:26:31 +01:00
2017-11-02 11:19:54 +01:00
2017-11-02 11:20:11 +01:00
2018-01-02 20:31:13 +01:00
2017-12-17 15:07:59 +01:00
2017-12-29 17:53:43 +01:00
2017-12-29 17:53:43 +01:00
2018-01-10 09:31:20 +01:00
2017-11-02 11:20:11 +01:00
2017-12-10 13:40:40 +01:00