diff options
author | Weimin Pan <weimin.pan@oracle.com> | 2017-08-23 10:57:37 +0200 |
---|---|---|
committer | Jose E. Marchesi <jose.marchesi@oracle.com> | 2017-08-23 10:57:37 +0200 |
commit | 58afddc6c7c5eaacdb68cdc3cacd0f76a3d01490 (patch) | |
tree | f930d2376581ff96b671a185dbe7c1c2164d8c26 /gdb/testsuite | |
parent | 98973784dc4775dbce3470b0933d1cb13f8c5a87 (diff) | |
download | gdb-58afddc6c7c5eaacdb68cdc3cacd0f76a3d01490.zip gdb-58afddc6c7c5eaacdb68cdc3cacd0f76a3d01490.tar.gz gdb-58afddc6c7c5eaacdb68cdc3cacd0f76a3d01490.tar.bz2 |
gdb: SPARC ADI support
The M7 processor supports an Application Data Integrity (ADI) feature
that detects invalid data accesses. When software allocates data, it
chooses a 4-bit version number, sets the version in the upper 4 bits
of the 64-bit pointer to that data, and stores the 4-bit version in
every cacheline of the object. Hardware saves the latter in spare
bits in the cache and memory hierarchy. On each load and store, the
processor compares the upper 4 VA (virtual address) bits to the
cacheline's version. If there is a mismatch, the processor generates a
version mismatch trap which can be either precise or disrupting. The
trap is an error condition which the kernel delivers to the process as
a SIGSEGV signal.
The upper 4 bits of the VA represent a version and are not part of the
true address. The processor clears these bits and sign extends bit 59
to generate the true address.
Note that 32-bit applications cannot use ADI.
This patch adds ADI support in gdb which allows the user to examine
current version tags and assign new version tags in the program. It
also catches and reports precise or disrupting memory corruption
traps.
gdb/ChangeLog:
2017-08-07 Weimin Pan <weimin.pan@oracle.com>
* sparc64-tdep.h: (adi_normalize_address): New export.
* sparc-nat.h: (open_adi_tag_fd): New export.
* sparc64-linux-nat.c: (open_adi_tag_fd): New function.
* sparc64-linux-tdep.c:
(SEGV_ACCADI, SEGV_ADIDERR, SEGV_ADIPERR) New defines.
(sparc64_linux_handle_segmentation_fault): New function.
(sparc64_linux_init_abi): Register
sparc64_linux_handle_segmentation_fault
* sparc64-tdep.c: Include cli-utils.h,gdbcmd.h,auxv.h.
(sparc64_addr_bits_remove): New function.
(sparc64_init_abi): Register sparc64_addr_bits_remove.
(MAX_PROC_NAME_SIZE): New macro.
(AT_ADI_BLKSZ, AT_ADI_NBITS, AT_ADI_UEONADI) New defines.
(sparc64adilist): New variable.
(adi_proc_list): New variable.
(find_adi_info): New function.
(add_adi_info): New function.
(get_adi_info_proc): New function.
(get_adi_info): New function.
(info_adi_command): New function.
(read_maps_entry): New function.
(adi_available): New function.
(adi_normalize_address): New function.
(adi_align_address): New function.
(adi_convert_byte_count): New function.
(adi_tag_fd): New function.
(adi_is_addr_mapped): New function.
(adi_read_versions): New function.
(adi_write_versions): New function.
(adi_print_versions): New function.
(do_examine): New function.
(do_assign): New function.
(adi_examine_command): New function.
(adi_assign_command): New function.
(_initialize_sparc64_adi_tdep): New function.
gdb/doc/ChangeLog:
2017-08-07 Weimin Pan <weimin.pan@oracle.com>
* gdb.texinfo (Architectures): Add new Sparc64 section to document
ADI support.
* NEWS: Add "adi examine" and "adi assign" commands.
gdb/testsuite/ChangeLog:
2017-08-07 Weimin Pan <weimin.pan@oracle.com>
* gdb.arch/sparc64-adi.exp: New file.
* gdb.arch/sparc64-adi.c: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.arch/sparc64-adi.c | 145 | ||||
-rw-r--r-- | gdb/testsuite/gdb.arch/sparc64-adi.exp | 53 |
3 files changed, 203 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d2ccd84..5581e5a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-07 Weimin Pan <weimin.pan@oracle.com> + + * gdb.arch/sparc64-adi.exp: New file. + * gdb.arch/sparc64-adi.c: New file. + 2017-08-22 Pedro Alves <palves@redhat.com> * gdb.cp/overload.exp (line_range_pattern): New procedure. diff --git a/gdb/testsuite/gdb.arch/sparc64-adi.c b/gdb/testsuite/gdb.arch/sparc64-adi.c new file mode 100644 index 0000000..704fe26 --- /dev/null +++ b/gdb/testsuite/gdb.arch/sparc64-adi.c @@ -0,0 +1,145 @@ +/* Application Data Integrity (ADI) test in sparc64. + + Copyright 2017 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <pthread.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> +#include <sys/errno.h> +#include <sys/utsname.h> +#include <sys/param.h> +#include <malloc.h> +#include <string.h> +#include <signal.h> +#include <sys/shm.h> +#include <errno.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <poll.h> +#include <setjmp.h> +#include "adi.h" + +#define ONEKB 1024 +#define PAT 0xdeadbeaf + +#define MAPSIZE 8192 +#define SHMSIZE 102400 +#ifndef PROT_ADI +#define PROT_ADI 0x10 +#endif + +static int +memory_fill (char *addr, size_t size, int pattern) +{ + long *aligned_addr = (long *) addr; + long i; + for (i = 0; i < size / sizeof (long); i += ONEKB) + { + *aligned_addr = pattern; + aligned_addr = aligned_addr + ONEKB; + } + return (0); +} + +int main () +{ + char *haddr; + caddr_t vaddr; + int version; + + /* Test ISM. */ + int shmid = shmget (IPC_PRIVATE, SHMSIZE, IPC_CREAT | 0666); + if (shmid == -1) + exit(1); + char *shmaddr = (char *)shmat (shmid, NULL, 0x666 | SHM_RND); + if (shmaddr == (char *)-1) + { + shmctl (shmid, IPC_RMID, NULL); + exit(1); + } + /* Enable ADI on ISM segment. */ + if (mprotect (shmaddr, SHMSIZE, PROT_READ|PROT_WRITE|PROT_ADI)) + { + perror ("mprotect failed"); + goto err_out; + } + if (memory_fill (shmaddr, SHMSIZE, PAT) != 0) /* line breakpoint here */ + { + exit(1); + } + adi_clr_version (shmaddr, SHMSIZE); + caddr_t vshmaddr = adi_set_version (shmaddr, SHMSIZE, 0x8); + if (vshmaddr == 0) + exit(1); + /* Test mmap. */ + int fd = open ("/dev/zero", O_RDWR); + if (fd < 0) + exit(1); + char *maddr = (char *)mmap (NULL, MAPSIZE, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fd, 0); + if (maddr == (char *)-1) + exit(1); + /* Enable ADI. */ + if (mprotect (shmaddr, MAPSIZE, PROT_READ|PROT_WRITE|PROT_ADI)) + { + perror ("mprotect failed"); + goto err_out; + + } + if (memory_fill (maddr, MAPSIZE, PAT) != 0) + exit(1); + caddr_t vmaddr = adi_set_version (maddr, MAPSIZE, 0x8); + + /* Test heap. */ + haddr = (char*) memalign (MAPSIZE, MAPSIZE); + /* Enable ADI. */ + if (mprotect (shmaddr, MAPSIZE, PROT_READ|PROT_WRITE|PROT_ADI)) + { + perror ("mprotect failed"); + goto err_out; + } + + if (memory_fill (haddr, MAPSIZE, PAT) != 0) + exit(1); + adi_clr_version (haddr, MAPSIZE); + /* Set some ADP version number. */ + caddr_t vaddr1, vaddr2, vaddr3, vaddr4; + vaddr = adi_set_version (haddr, 64*2, 0x8); + vaddr1 = adi_set_version (haddr+64*2, 64*2, 0x9); + vaddr2 = adi_clr_version (haddr+64*4, 64*2); + vaddr3 = adi_set_version (haddr+64*6, 64*2, 0xa); + vaddr4 = adi_set_version (haddr+64*8, 64*10, 0x3); + if (vaddr == 0) + exit(1); + char *versioned_p = vaddr; + *versioned_p = 'a'; + char *uvp = haddr; // unversioned pointer + *uvp = 'b'; // version mismatch trap + + return (0); +err_out: + if (shmdt ((const void *)shmaddr) != 0) + perror ("Detach failure"); + shmctl (shmid, IPC_RMID, NULL); + exit (1); +} diff --git a/gdb/testsuite/gdb.arch/sparc64-adi.exp b/gdb/testsuite/gdb.arch/sparc64-adi.exp new file mode 100644 index 0000000..410bcf9 --- /dev/null +++ b/gdb/testsuite/gdb.arch/sparc64-adi.exp @@ -0,0 +1,53 @@ +# Copyright 2017 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This file is part of the gdb testsuite. + +# Basic tests of examining/assigning ADI version tags, and reporting +# precise mismatch. + +if ![istarget "sparc64*-*-linux*"] then { + verbose "Skipping sparc64 ADI test." + return 0 +} + +standard_testfile + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ + [list debug libs=-ladi]] } { + return -1 +} + +if ![runto_main] then { + untested "could not run to main" + return -1 +} + +gdb_test "break [gdb_get_line_number "line breakpoint here"]" \ + "Breakpoint .* at .*${srcfile}.*" \ + "set line breakpoint in main" +gdb_continue_to_breakpoint "continue to line breakpoint in main" + +########################################## +set newadi "7" +gdb_test "adi x shmaddr" "${hex}00:\t0" "examine ADI" +gdb_test_no_output "adi a/100 shmaddr=${newadi}" "assign ADI" +gdb_test "adi x/100 shmaddr" "${hex}00:\t${newadi} ${newadi}" \ + "examine new ADI" +gdb_test_no_output "adi a/100 shmaddr=0x0" "reset ADI" +gdb_test "continue" \ + [multi_line "Program received signal SIGSEGV, Segmentation fault.*" \ + "ADI precise mismatch while accessing address $hex.*" ] \ + "continue to sigsegv" |