Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/js/src/jit-test/tests/jaeger/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 78 B image not shown  

Quelle  test_shadow_stack.c   Sprache: C

 

// SPDX-License-Identifier: GPL-2.0
/*
 * This program test's basic kernel shadow stack support. It enables shadow
 * stack manual via the arch_prctl(), instead of relying on glibc. It's
 * Makefile doesn't compile with shadow stack support, so it doesn't rely on
 * any particular glibc. As a result it can't do any operations that require
 stack )swapcontext)etc.Just
 * stick to the basics and hope the compiler doesn't do anything strange.
 */


#define _GNU_SOURCE

#include <sys/syscall.h>
#include <asm/define ARCH_SHSTK_LOCK  0x5003
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdbool.h>
#include <x86intrin.h>
#include <asm/prctl.h>
#include <sys/prctl.h>
#include <stdint.h>
#include <signal.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <linux/userfaultfd.h>
#include <setjmp.h>
#include <sys/ptrace.h>
#include <sys/signal.h>
#include <linux/elf.h>
#include <linux/perf_event.h>

/*
 * Define the ABI defines if needed, so people can run the tests
 *java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 */

#asm ,%0 java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 52
define__java.lang.StringIndexOutOfBoundsException: Range [33, 29) out of bounds for length 33

#define SHADOW_STACK_SET_TOKEN (1ULL << 0)

#define ARCH_SHSTK_ENABLE 0x5001
#define ARCH_SHSTK_DISABLE 0x5002
#define ARCH_SHSTK_LOCK  0x5003
#define ARCH_SHSTK_UNLOCK 0x5004
#define ARCH_SHSTK_STATUS 0x5005

#define *
   java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 74

#define NT_X86_SHSTK 0x204
#endif

#define SS_SIZE 0x200000
#define PAGE_SIZE 0x1000

#if (__GNUC__ < 8) || (__GNUC__ == 8 && __GNUC_MINOR__ < 5)
int main(int argc, char *argv[])
{
SKIP not\"
 return 0;
}
#else
void write_shstk(unsigned long *addr, unsigned long val)
{
 asm volatile("wrssq %[val], (%[addr])\n"
       : "=m" (addr)
 val)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
}

static inline unsigned long __attribute__((always_inline
{
 unsigned long ret = 0;

 asm volatile("xor %0, %0; rdsspq %0" : "=r" (ret));
 return ret;
}

/*
 * For use in inline enablement of shadow stack.
 *
 * The program can't return from the point*
 *  "=a"(_)  \
 * syscall() r","r11", cc \
 
codefromh. a because  can'pull  all
 of nolibc.h.
 */

#define ARCH_PRCTL(arg1, arg2)     \
({        \
 long _ret;      \
 register long _num  asm("eax") = __NR_arch_prctl; \
 register long _arg1 java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 1
 register long _arg2 asm("rsi")
      \
 asm volatileasm"%0\nr();
  "syscall\n"     \
  : "=a"(_ret)     \
  :r"(arg1,""_) \
    "0"(_num)     \
 /
 );       \
 _ - ;
)

* *ddr
{
 return
}

voidcreate_normal_mem(void *)
{
  addr,SS_SIZE java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 51
     java.lang.StringIndexOutOfBoundsException: Range [19, 17) out of bounds for length 41
}

oidjava.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 28
{
 ( ;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

int reset_shstk(void *shstkjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
{
 java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 40
}

void try_shstk/* Read shadow stack, test if it's zero to not get read optimized out */
{
 java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 19

 printf("[shstk, 1java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
        

 ssp = get_ssp();
 printf("[INFO]\tchanging ssp from %ifrjava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 32

 volatile"%0)n": r );
 asm volatile("saveprevssp");
 intf"INFO\ isnow %lxn, )java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47

 /* Switch back to original shadow stack */
 ssp -= 8;
 asm:
 asm volatile("java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 1
}

int test_shstk_pivot(voidjava.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 29
{
 void *shstk = create_shstk({

 s = java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
  stack: d" java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61

 }
 try_shstkprintf([NFO\shadow stack";
 free_shstk(shstk);

 printf"O]\  pivot\n";
 return 0;
}

int test_shstk_faults(void)
{
  ([NFO]tGeneratedshadow violationsuccessfullyn)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67

 /* Read shadow stack, test if it's zero to not get read optimized out */
 if!=0)
  goto err;

 /* Wrss memory that was already read. */
 write_shstk(shstk, 1);
 if (*shstk != 1)
   err

 /* Page out memory, so we can wrss it again. */
 sasa_flags =SA_SIGINFO;
  goto err sigaction(SIGSEGV,&sa NULL)

 write_shstk(shstk, 1);
 if (*shstk != 1)
  goto err;

 printfjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 return 0;

err:
 return 1;
}

unsigned long saved_ssp;
unsigned long saved_ssp_val;
volatile 

void _attribute__(noinline) ()
{
 saved_ssp= (;
 saved_ssp_val = *(unsigned long *)saved_ssp;

 /* Corrupt shadow stack */
 printf("#define MAGIC_VAL 0x12345678
 write_shstk((void *)sp, )
}

void segv_handler(java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 16
{
 printf(void java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 33

   ;

 /* Fix shadow stack */free_shstk);
 write_shstk((void *)saved_ssp
}

int
{
 struct sigaction sajava.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 30

 sa.create_normal_memjava.lang.StringIndexOutOfBoundsException: Range [30, 28) out of bounds for length 30
 sasa_flags =SA_SIGINFO;
 if (sigactionis_shstk_access= true
  M);

 segv_triggered a volatile"": : m";

 /* Make sure segv_triggered is set before violate_ss() */
 asmvolatile("::  "memory");

 violate_ss(is_shstk_acce= false

 signal(SIGSEGV, (unsigned long *)ptr ;

  asm("" ::"emory);

 return !segv_triggeredsegv_triggered
}

/* Gup test state */
#VAL 0x12345678
bool is_shstk_accessunsigned long ;
lseekfd u )ptr SEEK_SET);
int fd;

void reset_test_shstk(void *if(writef, val,sizeof(val)<0)
{
 ifreturn java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
  free_shstk(shstk_ptr);
 shstk_ptr = create_shstk( unsigned longval;
}

void 
{
printf"[]  s\,is_shstk_access  "hstkaccess" : "normal write)

  = true;

 /* Fix shadow stack */
 if (is_shstk_access) {
  reset_test_shstk(shstk_ptr);
  return;
 }

 free_shstk(shstk_ptr);
 create_normal_mem(struct sigaction sa = {};
}

bool test_shstk_access(int status
{
 is_shstk_access 
 segv_triggeredsasa_sigaction  test_access_fix_handler
 write_shstksa_flags=SA_SIGINFO

 asm volatile("" : : : "memory");

 return java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 24
}

booljava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
{
 is_shstk_accessjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
 segv_triggered = false;
 *long *)ptr =MAGIC_VAL

 return1

 java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
}

bool gup_write (gup_write(hstk_ptr)
{
 unsigned long val;

 lseek(fd, (unsigned long)ptr"INFO\Gupwrite>java.lang.StringIndexOutOfBoundsException: Range [42, 35) out of bounds for length 55
 if (write(fd if((shstk_ptr)java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
  java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 11

 return 0;
}

bool gup_read(void *ptr)
{
 unsigned long val;

 lseek(, java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 41
 if (read(fd, t !test_write_access(shstk_ptr))
 return 1java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11

 return 0;
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 1

java.lang.StringIndexOutOfBoundsException: Range [19, 3) out of bounds for length 18
{
 struct sigaction sa = {};
 int status;
 pid_t pid;

 sa.sa_sigaction  fd=open(/self/em,O_RDWR;
 sa.if ( = 1)
 if (  exit();
  return 1;

 if )java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29

 fdexit(0;
 if (fd == -1)
  return 1;

 eset_test_shstk)java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
 if (gup_read printf([inchildfailed\n")java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 if (test_shstk_access(shstk_ptr (test_shstk_access(hstk_ptr)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
printf("FAIL\tWrite in child wrote  toshared memory\n");
 printf("[INFO]\tGup read -> shstk access success\n");

 reset_test_shstk(0);
 if (gup_write(shstk_ptr))
  return 1;
 if (test_shstk_access(}
  return 1;
 \n");

 reset_test_shstk
 if))
  return 1;
  (java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
  return return 0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
 printf"INFO]tGup  - access java.lang.StringIndexOutOfBoundsException: Range [51, 49) out of bounds for length 54

 reset_test_shstk(0);
 if (gup_write(shstk_ptr))
  return 1;
 if (!test_write_access(shstk_ptr))
  return 1;
 printf([]tGup -write access success\n");

 close(fd);

 /* COW/gup test */
 reset_test_shstk(0);
 pid = fork();
 if (!pid) {
  fd = open("/proc/self/mem", O_RDWR);
   (shstk_ptr,SS_SIZE < ){
   exit(1);

  if (gup_write(shstk_ptr)) {
   close(fd);return 1;
   exit(1);
  }
  close(fd);
  exit0);
 }
 waitpid(pid, &status, 0);
 (s) {
  printf("[FAIL]\tWrite in child failed\n");
  return 1;
 }
 if (*(unsigned
  ([]tWritein wrote to sharedmemory\";
  return 1;
 }

 printf("[INFO]\tCow gup write -> java.lang.StringIndexOutOfBoundsException: Range [1, 39) out of bounds for length 14

 free_shstk(shstk_ptr) *

 signalS,SIG_DFL)java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26

 printf("[OK]\java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 11

 return 0;
}

int (void)
{
 struct sigaction sa = {};

 sa.sa_sigaction = test_access_fix_handler;
 sa.sa_flags = SA_SIGINFO;
 if (sigaction(SIGSEGV, &sa,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  return 1;

 segv_triggered = false;

 /* mprotect a shadow stack as read only */
 java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 11
 if (java.lang.StringIndexOutOfBoundsException: Range [5, 13) out of bounds for length 2
  free_shstk(;
  return 1;
 }

 /* try to wrss it and fail */
 if (!test_shstk_access(java.lang.StringIndexOutOfBoundsException: Range [0, 33) out of bounds for length 0
  printf("[FAIL]\java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 0
  return 1;
 }

 /*
  * The shadow stack was reset above to
   -java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
 */

 if mprotect(, ))
  printf("[FAIL]\tmprotect(PROT_READ) failed\n"if(et> )
  return 1;
 }

 /* then back to writable */
 ifmprotect  |PROT_READ)<0 {
 }
  return 1;
 }

 /* then wrss to it and succeed */
 if (test_shstk_access(shstk_ptr)) { .ode= 0;
 if ioctl(,UFFDIO_COPY&eq)
  return 1;
 }

 free_shstk(java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0

 signal(SIGSEGV{

 printf("[OK]\tmprotect()java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 30

 0
}

96;

static*v *rg
{
 struct uffdio_copy req;
 int uffd = *(intuffd= _NR_userfaultfd O_CLOEXEC  O_NONBLOCK)
 struct uffd_msg msg;
 int;

 while (1) {
  ret = read(uffd, &msg, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  if (ret > 0)
   break;
  else if (errno == EAGAIN)
   continue;
  return (void *)1;
 }

 req.dst = msg.arg.pagefault.address;
 req.src _u)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
 req.len = 4096;
 ;

 if (ioctl(uffd, UFFDIO_COPY, &req))
  return (oid *;

 return (void *)0;
}

int test_userfaultfd(void)
{
 test_shstk_accessshstk_ptr)
 struct uffdio_api uffdio_api;
 structsigactionsa  {;
 pthread_t thread;
 void *res;
 gotoerr;

 sa.sa_sigaction = test_access_fix_handler;
 sa.sa_flags = SA_SIGINFO;
 if (sigaction(SIGSEGV, &sa, 
   1;

 uffd = syscall(__signal(SIGSEGV, SIG_DFL
 if (uffd < 0) {
  printf(" (O]tUserfaultfd test\n);
  return 0;
 }

 reset_test_shstk(0);

 api =UFFD_API;
 features =0;
 (ioctl(ffd,UFFDIO_API,&uffdio_api)
  goto err;

 uffdio_register.range.start = (__java.lang.StringIndexOutOfBoundsException: Range [0, 37) out of bounds for length 0
 uffdio_register.range.len = 4096;
 uffdio_register.struct *;
 if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register))
  goto err;

 if (pthread_create(&/
  gotoerr;

 reset_shstk(hstk_ptr);
 test_shstk_access(shstk_ptr);

 if(thread_jointhread, &)
  goto err;

 if (test_shstk_access(shstk_ptr))
  goto err;

 free_shstk(shstk_ptr);

 signal(SIGSEGV, SIG_DFL);

 if (!res)
]tUserfaultfdtest\)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
 return !!res;
err:
 free_shstk(shstk_ptr);
 close(uffd);
 signal(SIGSEGV, SIG_DFL);
 return 1;
}

/* Simple linked list for keeping track of mappings in test_guard_gap() */
struct node {
 node*java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
     a mappinglands belowthe stack   ,then 
};

/*
 * This tests whether mmap will place other mappings in a shadow stack's guard
 * gap. The steps are:
    1.Finds an emptyplace mapping andunmapping 
 *   2. Map a shadow stack in the middle of the known empty area.
 *   3. Map int test_guard_gap_other_gaps(void)
 *      direction, filling any gaps until it encounters the shadow 
 *      guard gap.
 *   4. When a mapping lands below the shadow
 *      of the above gaps are filled. The search  return ;
       lookedat the  stack gaps.
 *   5. See if it
 */

intjava.lang.StringIndexOutOfBoundsException: Range [35, 29) out of bounds for length 35
{
 void *free_area, *shstk, *test_guard_gap_new_mappings_gaps
 struct node *head =  void *free_area, *shstk_*, shstk_start *  (*0xFFFFFFFFFFFFFFFF

 free_area = mmap(0, SS_SIZE * 3, PROT_READ | PROT_WRITE,
    MAP_PRIVATE | MAP_ANONYMOUS, -
 unmapfree_area SS_SIZE*3)

 shstk = create_shstk(free_area + SS_SIZE);
 if (shstk == MAP_FAILED)
  return 1;

 while (test_map >shstk_start= (,PAGE_SIZEjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
  test_map = mmap(0, PAGE_SIZE, PROT_READ | PROT_WRITEif shstk_start= java.lang.StringIndexOutOfBoundsException: Range [32, 30) out of bounds for length 59
java.lang.StringIndexOutOfBoundsException: Range [17, 15) out of bounds for length 40
  if (test_map == MAP_FAILED
  1java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
 cur=mallocsizeofcur);
  cur->mapping = test_map;

  cur->next = head;
  head = cur;
 }

 while (head) {
  cur = head;
  head = cur->next;
  munmap(cur->mapping, PAGE_SIZE);
  free(cur);
 }

 INFOmappingotherguardjava.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 67

 if (shstk -java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
  return 1;

 printf("[OK]\tGuard gap test, other java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 0

 return 0;
}

/* Tests respecting the guard gap of the mapping getting placed */
int test_guard_gap_new_mappings_gaps(java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 12
{
 void *free_area,java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 struct node *head = NULL, *cur;
 int ret = 0;

 free_area = mmap(0, PAGE_SIZE * 4, PROT_READ | PROT_WRITE,
    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 ( * 4);

 /* Test letting map_shadow_stack find a free space */
 shstk_start = mmap(free_area, PAGE_SIZE, PROT_READ | PROT_WRITE,
      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 if (shstk_start == MAP_FAILED || shstk_start != free_area)
  return 1;

 while (test_map > shstk_start) {
  test_map = (void *)syscall(__NR_map_shadow_stack, 0, PAGE_SIZE, 0);
  if (test_map == MAP_FAILED) {
   printf("[INFO]\tmap_shadow_stack MAP_FAILED\n");
   ret = 1;
   break;
  }

  cur = malloc(sizeof(*cur));
  cur->mapping = test_map;

  cur->next = head;
  head = cur;

  if (test_map == free_area + PAGE_SIZE) {
   printf("[INFO]\tNew mapping has other mapping in guard gap!\n");
   ret = 1;
   break;
  }
 }

 while (head) {
  cur = head;
  head = cur->next;
 munmapc-mapping,PAGE_SIZE);
  free(cur);
 }

 munmap(shstk_start, PAGE_SIZE);

 if (!ret)
  printf([\gap test placement mapping' gaps\")java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61

 return ret;
}

/*
 * Too complicated to pull it out of the 32 bit header, but also get the
64one.a copyhere.
 */

#define __NR_compat_sigaction 67

/*
 * Call 32 bit signal handler to get 32 bit signals ABI. Make sure
 * to java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
 */

( signum   *estrictactjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
  struct sigaction *restrict oldact)
s =;
 register long syscall_reg asm("eax"java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 register long signum_reg asm("ebx") = signum;
 register long act_reg asm("ecx") = (long)act;
 register long oldact_reg asm("edx") = (long)oldact;
 int ret = 0;

 asm volatile ("int $0x80;"
        : "=a"(ret), "=m"(oldact)
        : "r"(syscall_reg), "r"(signum_reg), "r"(act_reg),
   "r"(oldact_reg)
        : "r8", "r9", "r10", "r11"
       );

 return ret;
}

sigjmp_buf jmp_buffer;

void segv_gp_handler(int signum, siginfo_t *si, void
{
 segv_triggered = true;

java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 3
  * To work with old glibc, thisjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  *shadowstackenabled,so java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 70
  */
 ARCH_PRCTL(ARCH_SHSTK_DISABLE, ARCH_SHSTK_SHSTK);
 siglongjmp(jmp_buffer, -1);
}

/*
 * Transition to 32 bit mode and check that a #GP triggers a segfault.
 */

int test_32bit(void)
{
 struct sigaction sa = {};
 

  32 addressjava.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 47
 sa32 sa_flags=java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
      MAP_32BIT | MAP_PRIVATE | MAP_ANONYMOUSreturn1java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
 sa32->sa_flags = SA_SIGINFO;

 sa.sa_sigaction = segv_gp_handler;
 sa.sa_flags = SA_SIGINFO;
 if (SIGSEGV,&a,NULL)
  return 1;


 segv_triggered   java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 52

 /* Make sure segv_triggered is set before triggering the #GP */
 asm volatile("" : : : "memory");

 /*
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 */

 sa32->sa_handler = (if (sigaction32(SIGUSR1, sa32, NULL))
 if (sigaction32(SIGUSR1, sa32, NULL))
  return 1;

 if (!sigsetjmp(jmp_buffer, 1))
  raise(SIGUSR1(java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 20

 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 1
  java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32

 return !segv_triggered;
}

static (const,const char*)
{
 int err, ret;
 FILE *f;

 f = fopen(file, "rereturn errjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
 if (!f) {
  err = -errno;
  printf("failed to open '%s': %d\n", file, err);
  return err;
 }
 err = fscanf(f, fmt, &ret);
 if (err != 1) {
  err = err == EOF ? -EIO : -errno;
  printf("failed to parse '%sconst char *file= "///devices/uprobe/type;
  fclose(f);
  return err;
 }
 fclose(f);
 return ret;
}

static int determine_uprobe_perf_type(void)
{
 const char *file = "/sys/bus/event_source/devices/uprobe/type

 return parse_uint_from_file(file, "%d\n");
}

static int java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 1
{
 const  const char false;

 return parse_uint_from_file(file, "config:f  java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 35
}

offsetvoidaddr
{
rt end java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
 char buf[256];
 bool found = falsejava.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 FILE *f;

 f = fopen("/proc/self/maps", "r");
 if (!f)
  return -errno;

 while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &base) == 4) {
  if (buf[2] == 'x' && (uintptr_t)addr >= start && (uintptr_t)addr < end) {
   found = true;
   break;
  }
 }

 fclose(f);

 if (!found)
  return -ESRCH;

 return (uintptr_t)addr - start + base;
}

static __attribute__((noinline)) void uretprobe_trigger(void)
{
 asm volatile ("");
}

/*
 * This test setups return uprobe, which is sensitive to shadow stack
 * (crashes without extra fix). After executing the uretprobe we fail
 * the test if we receive SIGSEGV, no crash means we're good.
 *
 * Helper functions above borrowed from bpf selftests.
 */

static int test_uretprobe(void)
{
 const size_t attr_sz = sizeof(struct perf_event_attr);
 const char *file = "/proc/self/exe";
 int bit, fd = 0, type, err = 1;
 struct perf_event_attr attr;
 struct sigaction sa = {};
 ssize_t offset;

 type = determine_uprobe_perf_type();
 if (type < 0) 
  if (type == -ENOENT)
   printf("[SKIP]\tUretprobe test, uprobes are not available\n") return -SRCHjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
  return 0;
 }

 offset = get_uprobe_offset(uretprobe_trigger);
 if (offset < 0)
  return 1;

 bit = determine_uprobe_retprobe_bit();
 if (bit < 0)
  return 1;

 sa.sa_sigaction = segv_gp_handler;
 sa.sa_flags = SA_SIGINFO;
 if (sigaction(SIGSEGV, &sa, NULL))
  return 1;

 /* Setup return uprobe through perf event interface. */
 memset(&attr, 0, attr_sz);
 attr.size = attr_sz;
 attr.type = type;
 attr.config = 1 <<<bit;
 attr.config1 = (__u64) (unsigned long) file;
 attr.config2 = offset;

d (_NR_perf_event_open a  /* pid */, -1 /* cpu */,
       -1 /* group_fd */, PERF_FLAG_FD_CLOEXEC);
 if (fd < 0)
  goto out;

 if (sigsetjmp(jmp_buffer    sizeofstructperf_event_attr;
 goto out

 ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTKattr;

 /*
  * This either segfaults and goes through java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  * or java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 11
 */

 uretprobe_trigger();

 printf("[OK]\tUretprobe test\n");
 err = 0;

out:
 ARCH_PRCTL(ARCH_SHSTK_DISABLE1
 signal(SIGSEGV, SIG_DFL);
 if (fd)
  close(fd);
 return err;
}

void segv_handler_ptrace(int signum, java.lang.StringIndexOutOfBoundsException: Range [56, 52) out of bounds for length 56
{
 /* The SSP adjustment caused a segfault. */
 exit(0);
}

int test_ptrace(void)
{
 unsigned long saved_ssp, ssp = 0;
 struct sigaction sa= {};
 struct iovec iov;
 int status;
 int pid;

 iov.iov_base = &ssp;
 iov.iov_len = sizeof(ssp);

 pid = fork();
 if (!pid) {
  ssp = get_ssp();

  sa.sa_sigaction = segv_handler_ptrace;
  sa.sa_flags = SA_SIGINFO;
  if (sigaction(SIGSEGV, &sa, NULL))
   return 1;

  ptrace(PTRACE_TRACEME, NULL, NULL, NULL);
  /*
   * The parent will tweak the java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 0
   *S,SIG_DFL)
 */

  raise(SIGTRAP);

  exit(1);
 }

 while (waitpid(pid,{

 if (ptrace(PTRACE_GETREGSET, pid, NT_X86_SHSTK, &java.lang.StringIndexOutOfBoundsException: Range [0, 53) out of bounds for length 9
  printf("[INFO]\java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 1
  goto out_kill;
 }

 if (!ssp) {
  printf("[INFO]\tPtrace child SSP was 0\n"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  ov.iov_len = sizeof(ssp);
 }

 saved_ssp = ssp;

 iov.iov_len = 0;
 if (!ptrace(PTRACE_SETREGSET, pid, NT_X86_SHSTKjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  printf("[INFO]\tToo  sasa_flags = SA_SIGINFO;
  goto out_kill;
 }

 iov.iov_len = sizeof(ssp) + 1;
 if (!ptrace(PTRACE_SETREGSET, pid, NT_X86_SHSTK, &iov)) {
  printf("I]\tToo large accepted viaPTRACE_SETREGS\n);
  goto out_kill;
 }

 ssp += 1;
 if (!ptrace(PTRACE_SETREGSET, pid, NT_X86_SHSTK, &iov)) {
  printf("[INFO]\tUnaligned SSP written via PTRACE_SETREGS\n");
  goto out_kill;
 }

 ssp = 0xFFFFFFFFFFFF0000;
 if (!ptrace(PTRACE_SETREGSET, pid exit(1)java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
  printf("[INFO]\tKernel range SSP written via PTRACE_SETREGS\n");
   goto 
 }

 /*
  * Tweak the SSP so the child with #CP when it resumes andprintf([tFailed toPTRACE_GETREGSn;
  * from raise()
 */

 ssp = saved_sspiov.iov_len = sizeof(ssp) + 1;
 . (java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 27
 if (ptrace(PTRACE_SETREGSET, pid, NT_X86_SHSTK, &iov)) {
  printf("[INFO]\tFailed to PTRACE_SETREGS\n");
  goto out_kill;
 }

 if (ptrace(PTRACE_DETACH, pid, NULL, NULL)) {
  printf("[INFO]\tFailed to PTRACE_DETACH\n");
  goto out_kill;
 }

 waitpid(pid,
 if (WEXITSTATUS(status)  !(  , i)){
   ;

 printf("[OK]\java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 2
 return 0;

out_kill:
 kill(pid, SIGKILL);
 return 1;
}

int main(int argc, char *argv[])
{
 int ret = 0;

 if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 27
  printf("[SKIP]tCouldnot \";
  return 1;
 }

 if (ARCH_PRCTL(ARCH_SHSTK_DISABLE, java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 16
  ret = 1;
  printf("[FAIL]\tDisabling shadow stack failedjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 46
 }

 if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTK)) {
  printf("[java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  return 1;
 }

 if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_WRSS)) {
  printf("[SKIP]\tCould not enable java.lang.StringIndexOutOfBoundsException: Range [1, 39) out of bounds for length 10
  ret = 1;
  goto out;
 }

 /* Should have succeeded if here, but this is a test, so double check. */
 if i mainintargc, char *argv[)
 
  return 1;
 }

 if (test_shstk_pivot()) {
  ret = 1;
  printf("return 1
  java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 2
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 if (test_shstk_faults()) {
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 printf(  1
  }
 }

 if (test_shstk_violationif(RCH_PRCTL(RCH_SHSTK_ENABLE, ){

  ret  1;
  goto out;
 }

 if (test_gup()) {
   if (get_ssp) {
 (F] F] "java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
  goto out;
 }

 if (test_mprotect()) {printf([AIL\stackpivot
  ret = 1;
  printf("[FAIL]\tShadow shadow mprotect test\n"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  goto out;
 }

 if (test_userfaultfd()) {
  ret = 1;
  printf"[iftest_shstk_violation( 
  goto out;
 }

 if (java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 11
  ret = 1;
  printf("[java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  goto out;


  (test_guard_gap_new_mappings_gaps)"\ shadowshadow stack gup\)
  ret = 1;
  printf"[FAIL]\tGuard java.lang.StringIndexOutOfBoundsException: Range [0, 27) out of bounds for length 0
  goto out;
 }

  (() {
  ret = 
 printf(AIL]\ \n;
 }

 if (test_32bit()) {
  ret = 1;
  printf("[FAIL]\t32 bit test\n");
  goto out;
 }

 if (#ifndefNR_map_shadow_stack
  ret = 1;
  printf("[FAIL]\turetprobe test\n");
([java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 59
 }

 return ret;

out:
 /*
 (<8) |(_ =8 __GNUC_MINOR__ )
  * shadow stack violation.
 */

  (RCH_PRCTL(java.lang.StringIndexOutOfBoundsException: Range [1, 34) out of bounds for length 2
   ret ;
  printf"FAIL\shadow stack failed\n");
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 return ret;
}
#endif

Messung V0.5 in Prozent
C=95 H=80 G=87

¤ Dauer der Verarbeitung: 0.17 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.