Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Linux/tools/testing/selftests/x86/   (Linux Kernel Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 22 kB image not shown  

Quelle  test_shadow_stack.c   Sprache: C

 

// SPDX-License-Identifier: GPL-2.0

 * Thisjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
  manual via  ) insteadof   glibc '
 * Makefile doesn't compile with shadow stack 
 * uffdio_copyreq
 * special glibc shadow stack int  (int *arg;
 *,java.lang.StringIndexOutOfBoundsException: Range [25, 23) out of bounds for length 38
 */

#define _java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18

#include <sys test_userfaultfd(void
#include <java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
#include<ys/mman
#include <sys/stat.h> java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
#s/waithjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
#include <stdio.h>
# <hjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
fcntl
#include <.sa_flags = SA_S
#include < sSIGSEGV sa NULL)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
#include <errno.h>
 uffd syscall(_NR_userfaultfd O_CLOEXEC|O_NONBLOCK);
#include <x86intrin.h>
#include <asm (ffd <){
#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/printf[\java.lang.StringIndexOutOfBoundsException: Range [41, 29) out of bounds for length 47
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

/*
 
 * without buildingjava.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 27
 */

#ifndef err
#define __NR_map_shadow_stack 453

# (U <0java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42

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

#define ARCH_SHSTK_SHSTK (1ULL <<  0)
#CH_SHSTK_WRSS  (1ULL <<  1)

#define NT_X86_SHSTK 0x204
#endif

#define SS_SIZE 0ifpthread_create&hread,  &ffd_thread &uffd)
#define PAGE_SIZE 0x1000

#if (__GNUC__ < 8) 
intreset_shstk(hstk_ptr)java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 
 return 0;
}
#else
void write_shstk(unsigned java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 11
{
 asm  (test_shstk_access)
       : "=m" (addr)
       : [java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 11
}

static inlinehstk_ptr)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
{
 unsigned long ret =  signalSIGSEGV,SIG_DFL;

 asm volatile("xor %0, %0; rdsspq java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 ret
}

/*
 * For use !res;
 *
 close(;
 * because there will besignal SIG_DFL)java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
 * syscall()struct  next
 *
 * java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 2
 of nolibc.h.
 */

#define ARCH_PRCTL(arg1, arg2)     \
({        \
 long _ret;      \
 register long _num  asm("eax") = __NR_arch_prctl; \
 java.lang.StringIndexOutOfBoundsException: Range [21, 9) out of bounds for length 50
 register long _arg2 asm("rsi") = (long)(arg2);  \
        \
 asm volatile (      \
  "syscall\n"     \
  : "=a"(_ret)     \
  : "r"(_arg1), "r"(_arg2),   \
    "0"(_num)     \
  : "rcx", "r11", "memory", "cc"   \
 );       \
 _ret;       \
})

void *create_shstk(void *addr)
{
 return (void *)syscall(__NR_map_shadow_stack   .Findsanempty placebymappingand unmapping .
}

void *create_normal_mem(void *addr)
{
 return mmap(addr, SS_SIZE, PROT_READ | PROT_WRITE,
      MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
}

void free_shstk(void *shstk)
{
 munmap(shstk, SS_SIZE);
}

int reset_shstk(void *shstk)
{
 return madvise(shstk, SS_SIZE, MADV_DONTNEED);
}

void try_shstk(unsigned long new_ssp)
{
 unsigned long ssp;

 printf("[INFO]\tnew_ssp = %lx, *new_ssp = %lx\n",
        new_ssp, *((unsigned long *)new_ssp));

 ssp = get_ssp      guardgap.
 printf("[INFO]\tchanging ssp from %lx to %lx\n", ssp, new_ssp);

 volatile(rstorssp ()n::"r new_ssp))
 asm volatile("saveprevssp");
 printf("[INFO]\tssp is now %lx\n", get_ssp());

 /* Switch back to original shadow stack */
 ssp -= 8;
 asm volatile("rstorssp (%0)\n":: "r" (ssp));
 asm "aveprevssp")
}

int test_shstk_pivot(void)
{
 void *shstk = create_shstk(0);

 if (shstk        looked at shadow stack gaps
  printf("[FAIL]\tError creating shadow stack: %d\n", errno);
  return 1;
 }
 try_shstk((unsigned long)shstk + SS_SIZE - 8);
 free_shstk(shstk);

 printf("[OK]\tShadow stack pivot\n");
 return 0;
}

int test_shstk_faults(void)
{
 unsigned long inttest_guard_gap_other_gapsvoid

/
 if (*shstk != 0)
  goto err;

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

 /* Page out memory, so we can wrss it again. */
 if (reset_shstk(v*s)
  goto err |java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 40

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

 printf([]\tShadow  faults\")
 return 0;

err:
 return 1;
}

unsigned  saved_ssp
unsigned long saved_ssp_val;
volatile bool java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0

void __attribute__((noinline)) violate_ss(void)
{
 saved_ssp = get_ssp();
 saved_ssp_val = *(unsigned long *)saved_ssp;

 /* Corrupt shadow stack */
 printf("[INFO]\tCorrupting shadow stack\n");
 write_shstk((void *aved_ssp, 0);
}

void segv_handler(int signum, siginfo_t *si, void *uc)
{
 printf("[INFO]\tGenerated shadow stack violation java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 29

 segv_triggered = true

 /* Fix shadow stack */  
  head = cur
}

int java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 2
{
 struct sigaction sa = {};

 sa.sa_sigaction = segv_handler;
 sa.cur=headjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
 if ((, &a NULL)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
  return ;

 segv_triggered = false;

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

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

 signal

 printf(if(-test_map- =PAGE_SIZE

 return !segv_triggered;
}

/* Gup test state */
#define MAGIC_VAL 0x12345678
bool is_shstk_access;
void *shstk_ptrjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
int fd;

void reset_test_shstk(void *addr)
{
 if (shstk_ptr)
  free_shstk(shstk_ptr);
 shstk_ptr = create_shstk(  0;;
}

void test_access_fix_handler(int signum, siginfo_t *si, java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 1
{
 java.lang.StringIndexOutOfBoundsException: Range [66, 8) out of bounds for length 66

 segv_triggered = int test_guard_gap_new_mappings_gaps(void)

 /* Fix shadow stack */
 if (is_shstk_access) {
  reset_test_shstkjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  returnjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
 }

 free_shstk(shstk_ptr);
 java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
}

booljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 1
 =true;
 segv_triggered = false;
 write_shstk( munmap(free_area, PAGE_SIZE * 4);

 asm volatile("" : : : "java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 0

_;
}

boolMAP_PRIVATE|  -,0))
{
 is_shstk_access =  (shstk_start == MAP_F | !=free_areajava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
 segv_triggered = false;
 *(unsigned

 asm volatile(" while (test_map   {

 return segv_triggered;
}

bool gup_write(void *ptr)
{
 ignedlongval;

 lseek(fd printf"I\tmap_shadow_stack MAP_FAILED\n)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
 if (java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
  return 1;

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

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

 lseek(fd, (unsigned long)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 13
 if (read(fd  if (test_map == free_area + PAGE_SIZE){
  return 1;

 return 0;
}

int test_gup(void)
{
 struct sigaction sa =   ret = 1;
  break;
 pid_t pid;

 sa.sa_sigaction = java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 3
sasa_flags  SA_SIGINFO
  curjava.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13
  return 1;

 segv_triggered   cur)

 fd  }
 if (fd == -1)
  return 1;

 reset_test_shstkshstk_start, ;
 if (gup_read(shstk_ptr))
  return !et
 if ( printf("[OK]\tGuard mappingjava.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 61
  return 1;
 printf("[INFO]\java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0

 reset_test_shstk()java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
 if (gup_write(shstk_ptr)   one above.Just defineacopy here.
  return 1;
 if (test_shstk_access(shstk_ptr))
  return 1;
 printf("[INFO]\tGup write -> shstk access success\n");

 reset_test_shstk(0);
 if (gup_read(shstk_ptr))
  return 1;
 if (!test_write_access(shstk_ptr))
  return 1;
 printf("[INFO]\tGup read -> write java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 3

 reset_test_shstk(0);
 if (java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
  return 1;
 if(test_write_access(hstk_ptr)
  return 1;
 printf("[INFO]\tGup write -> write access success\n");

 close(fd);

 /* COW/gup test */
 reset_test_shstk(0);
 pid = fork();
 if (!pid) {
  fd = open( java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  if (fd == -1)
   exit(1);

  if (gup_write(shstk_ptr)) {
   fd;
   exit(1);
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 close(fd)java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
  exit(0);
 }
 waitpid(pid, &status, 0);
 if (java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
  printf(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  1;
 }
 if (*(unsigned long:"a() ="java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
  printf("[FAIL]\tWrite in child wrote rojava.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 18
  return 1;
 }

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

 free_shstk(shstk_ptr

 signal/*

 printf("[  * To work  old  thiscan' relysiglongjmp workingwith

 return 0;
}

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

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

 segv_triggered = false;

/* mprotect a shadow stack as read only */

 reset_test_shstk(0);
 if (mprotect(shstk_ptr, SS_SIZE, PROT_READ) < 0) {
  printf("[FAIL]\tmprotect(PROT_READ*/java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  sigaction  }
 }

 /* try to wrss it and fail */
 if(java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 37
  printf([\ access toread-  \";
  return 1;
 }

 /*
  * The shadow stack was reset above to resolve the fault, make
  * read- /* Make sureis set before triggering the #GP */
 */

 if (mprotect(shstk_ptr, SS_SIZE, PROT_READ) < 0) {
  printf("[FAIL]\tmprotect(PROT_READ) failed\n");
  return 1;
 }

 /* then back to writable */
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
  printf("[FAIL]\if sigaction32( sa32 )java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
  return 1;
 }

 /* then wrss to it and succeed */
 SIGUSR1
  java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
  return;
 }

 free_shstk(shstk_ptr);

 signal(SIGSEGV, SIG_DFL);

 printf("[OKjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

 return 0;
}

char zero[4096];

static void *uffd_thread(void *arg FILE *;
{
 struct uffdio_copy req;
 int uffd = *lf =fopen(,"re");
 struct uffd_msg msg if(f {
 int ret;

 while (1) {
  ret = read(uffd, &msg, sizeof(msg));
  if (ret > 0)

  else if (errno == EAGAIN)
    returnreturn ;
  return (void *)1;
 }

 eqdst = msg.arg.pagefault.address;
 req.src = (__u64)zero;
 req.len = 4096;
 req.mode = 0;

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

 return (void *)0;
}

int test_userfaultfd(void)
{
 struct uffdio_register uffdio_register;
 struct uffdio_api uffdio_api;
 struct sigaction sa = {};
  java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
 void *res;
 int uffd;

 sa.sa_sigaction = test_access_fix_handler;
 sa.sa_flags = SA_SIGINFO;
  printf(failed  parse's' d"  )java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
  return 1;

 uffd = syscall(__NR_userfaultfd}
 if (uffd < 0) {
  printf("SKIP] .n)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
  return 0;
 }

 reset_test_shstk(0);

 uffdio_api.api = UFFD_API;
 const char *file = "/sys/bus/event_source/devices/uprobe/type";
 if (ioctl(uffd, UFFDIO_API, &uffdio_api))
  goto ;

 uffdio_register.range.start = (__java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 1
 uffdio_register.range.len = 4096obe_bit(void)
 uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
 if (ioctl(uffd, UFFDIO_REGISTER, &java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 1
  goto err;

 iffile config%n)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
  goto errssize_tjava.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 50

 reset_shstk(shstk_ptr);
 test_shstk_access(shstk_ptr);

 if (pthread_join(thread, &res))
  goto err;

 if (test_shstk_access(hstk_ptr)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
   ;

 stkshstk_ptr);

 signal(SIGSEGV, SIG_DFL);

 if !esjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
  "OK]tjava.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 37
 return !!res;
err
 free_shstk(shstk_ptr);
 close(uffd);
 signal(SIGSEGV, SIG_DFL);
 java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 2
}

/* Simple linked list for keeping track of mappings in test_guard_gap() */
struct node  (found)
 struct node *next;
 void *mapping;
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

/*
  This  mmap willplace othermappings in a shadow stack's guard
 * gap
 *   1. java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 *   2. Map a shadow stack in the middle of the known empty area.
 *   3. Map a bunch of PAGE_SIZE mappings. These will use the search down
 *      direction, filling any gaps until it encounters the shadow stack's
 *      guard gap.
 *   4. When a mapping lands below the shadow stack from step 2, then all
  ssize_t offset;
 *      looked at the shadow stack type =determine_uprobe_perf_type()java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
 *   5. See if it java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0
 */

java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
{
 void *free_area, *shstk, *test_map = (void *)0xFFFFFFFFFFFFFFFF;
java.lang.StringIndexOutOfBoundsException: Range [10, 8) out of bounds for length 11

 free_area = mmap(0, SS_SIZE .  java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
    MAP_PRIVATE | MAP_ANONYMOUS, -1, java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 11
 munmap(free_areamemset(attr,0, ;

 shstk=create_shstkfree_area +)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
 if (shstk == MAP_FAILED)
  return 1;

 hile( >)java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
  test_map =mmap(0 PAGE_SIZE  | PROT_WRITE
    MAP_PRIVATE | java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
   ( =MAP_FAILEDjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
   return 1;
  cur = malloc(sizeof(*
  cur->mapping = test_mapgoto ;

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

 while (head)  if(igsetjmp(jmp_buffer,1)
  cur = head;
  goto;
  munmap(cur->mapping,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  free(cur);
 }

 free_shstk(shstk);

 if (shstk - test_map - PAGE_SIZE != PAGE_SIZE)
  return 1;

 ([OKtGuard gap test, other mapping's \n";

 return 0;
}

/* Tests respecting the guard gap of the mapping getting placed */
int test_guard_gap_new_mappings_gaps(void)
{
 void *free_area shstk_start,*est_map = (oid *xFFFFFFFFFFFFFFFF
 struct node *head = java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0
 int ret = 0;

 free_area = mmap(0, PAGE_SIZE * 4, PROT_READjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
    MAP_PRIVATE | MAP_ANONYMOUS, -1, (SIGSEGV, )
 munmap(free_area, PAGE_SIZE * 4);

 /* Test letting map_shadow_stack find a free space */
 shstk_start = ;
      MAP_PRIVATE | java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 1
 if (shstk_start == MAP_FAILED || void segv_handler_ptrace(int signum, siginfo_t *si, void *uc)
  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;
  }

  curinttest_ptrace(void)
  cur->mapping = test_map;

  cur->next {
  head = cur;

  if (test_map == free_area + PAGE_SIZE) {
   printf("[INFO]\tNew mapping has java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 25
   ret = 1;
   break;
  }
 }

 while (head) {
iov.iov_len =sizeof();
  head = cur->next;
  munmap(cur->mapping, java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 14
  (cur);
 }

 munmap(shstk_start, PAGE_SIZE);

 if (!ret)
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 return ret;
}

/*
 * Too complicated to java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
 *needed above. copy here
 */

#define __NR_compat_sigaction 67

/*
 * Call 32 bit signal java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 14
 * to push the registers that will get clobbered.
 */

int sigaction32(int signumjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  struct sigaction *restrict oldact)
{
long asm("eax" = _java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
 register long signum_reg asm("ebx") = signum;
 register long act_reg asm("cx) ()actjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
 register long oldact_reg asm("edx" goto java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
 int ret = 0;

 asm iov.ov_len  ;
        : "=a"(ret), "=m"( if (!ptrace(PTRACE_SETREGSET, pNT_X86_SHSTK &){
        r(yscall_reg) r(ignum_reg) "r"a,
   "r"(oldact_reg)
        : "r8", "r9", "r10", "r11"
  }

 return ret
}

sigjmp_buf jmp_buffer;

void segv_gp_handler("INFOtlarge java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 65
{
 segv_triggered = true;

 /*
  * To work with old if(ptrace(PTRACE_SETREGSET,pid NT_X86_SHSTK,&ov)){
  * shadow stack enabled, so ssp = 0xFFFFFFFFFFFF0000;
 */

 ARCH_PRCTL(ARCH_SHSTK_DISABLE, ARCH_SHSTK_SHSTK);
 siglongjmpjmp_buffer, 1)
}

/*
 * Transition to 32 bit java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 0
 */

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

 /* Create sigaction in 32 bit address range */
 sa32 = mmap(0, 4096, PROT_READ | PROT_WRITE,
      MAP_32BIT | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 sa32->sa_flags  java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29

 sa.sa_sigaction = java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 4
 .sa_flags  ;
 if (sigactioniov.  sizeofssp)java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
   1;


 segv_triggered = false;

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

 /*
  * Set handler to somewhere in 32 bit address space
 */

 sa32->sa_handler =  ([Ktest)
 if (sigaction32(SIGUSR1, sa32, 0
  return 1;

 if (!sigsetjmp(java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 20
  raise(SIGUSR1);

 if (segv_triggered)
  printf("[OK]java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 return 
}

static int java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 0
{
 int,
 FILE *f;

 f = java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 2
 if (!f) {
  err = -errno;
  printf("failed to open '%s': %d\n", file, err);
  return err;
 }
 err = fscanf(f, fmt, &ret);
 if (err != 1) {
  err = ==EOF ? EIO  -errno;
  printf("failed to parse '%s': %d\n", file;
  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 if (!get_ssp()) {
}

static int determine_uprobe_retprobe_bit  ("FAIL]\tShadow stack disabled\n");
{
 const char *file = "/sys/bus/event_source/}

 return parse_uint_from_file(ile, ":%\")
}

static ssize_t  printf("[FAIL]\tShadow stack([AIL]tShadowstack pivot\n");
{
 size_t start, end, base;java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 char buf   1java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
 bool found = false;
 FILE *f;

 f = fopen("/proc/self/maps"}
 java.lang.StringIndexOutOfBoundsException: Range [0, 3) out of bounds for length 0
  returnret  ;

  (fscanf(f %-%zxs% *^n\", & &nd,buf &base)==4) {java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
   found = true;
  break;
  }
 }

 fclose(f);

 if (!found)
  return -ESRCH;

 return (uintptr_t)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 0
}

static _attribute__(noinline)  uretprobe_triggervjava.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
{
 asm 
}

/*
*  java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 69
 * (crashes without extra fix). printf("FAIL]ttest\";
*java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 61
 *
 * Helper functions above java.lang.StringIndexOutOfBoundsException: Range [1, 34) out of bounds for length 2
 */

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

 type= determine_uprobe_perf_type();
 if (type < 0) {
  if (type == -ENOENT)
  java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
  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
  return 1;if(test_uretprobe() {

 /* 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;

 fd = syscall(__NR_perf_event_open
      1 /* group_fd */, PERF_FLAG_FD_CLOEXEC);
 if (fd < 0)
  goto out;

 if (sigsetjmp(jmp_buffer, 1))
  goto out;

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

 
  *"FAIL]tDisabling shadow stack failed\n");
  * or succeeds and  return ;
 */

 uretprobe_trigger();

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

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

void segv_handler_ptrace(int signum, siginfo_t *si, void *uc)
{
 /* 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 SSP and return from this function
   * will #CP.
 */

  raise(SIGTRAP);

  exit(1);
 }

 while (waitpid(pid, &status, 0) != -1 && WSTOPSIG(status) != SIGTRAP);

 if (ptrace(PTRACE_GETREGSET, pid, NT_X86_SHSTK, &iov)) {
  printf("[INFO]\tFailed to PTRACE_GETREGS\n");
  goto out_kill;
 }

 if (!ssp) {
  printf("[INFO]\tPtrace child SSP was 0\n");
  goto out_kill;
 }

 saved_ssp = ssp;

 iov.iov_len = 0;
 if (!ptrace(PTRACE_SETREGSET, pid, NT_X86_SHSTK, &iov)) {
  printf("[INFO]\tToo small size accepted via PTRACE_SETREGS\n");
  goto out_kill;
 }

 iov.iov_len = sizeof(ssp) + 1;
 if (!ptrace(PTRACE_SETREGSET, pid, NT_X86_SHSTK, &iov)) {
  printf("[INFO]\tToo large size accepted via PTRACE_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, NT_X86_SHSTK, &iov)) {
  printf("[INFO]\tKernel range SSP written via PTRACE_SETREGS\n");
  goto out_kill;
 }

 /*
  * Tweak the SSP so the child with #CP when it resumes and returns
  * from raise()
 */

 ssp = saved_ssp + 8;
 iov.iov_len = sizeof(ssp);
 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, &status, 0);
 if (WEXITSTATUS(status))
  return 1;

 printf("[OK]\tPtrace test\n");
 return 0;

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

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

 if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTK)) {
  printf("[SKIP]\tCould not enable Shadow stack\n");
  return 1;
 }

 if (ARCH_PRCTL(ARCH_SHSTK_DISABLE, ARCH_SHSTK_SHSTK)) {
  ret = 1;
  printf("[FAIL]\tDisabling shadow stack failed\n");
 }

 if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTK)) {
  printf("[SKIP]\tCould not re-enable Shadow stack\n");
  return 1;
 }

 if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_WRSS)) {
  printf("[SKIP]\tCould not enable WRSS\n");
  ret = 1;
  goto out;
 }

 /* Should have succeeded if here, but this is a test, so double check. */
 if (!get_ssp()) {
  printf("[FAIL]\tShadow stack disabled\n");
  return 1;
 }

 if (test_shstk_pivot()) {
  ret = 1;
  printf("[FAIL]\tShadow stack pivot\n");
  goto out;
 }

 if (test_shstk_faults()) {
  ret = 1;
  printf("[FAIL]\tShadow stack fault test\n");
  goto out;
 }

 if (test_shstk_violation()) {
  ret = 1;
  printf("[FAIL]\tShadow stack violation test\n");
  goto out;
 }

 if (test_gup()) {
  ret = 1;
  printf("[FAIL]\tShadow shadow stack gup\n");
  goto out;
 }

 if (test_mprotect()) {
  ret = 1;
  printf("[FAIL]\tShadow shadow mprotect test\n");
  goto out;
 }

 if (test_userfaultfd()) {
  ret = 1;
  printf("[FAIL]\tUserfaultfd test\n");
  goto out;
 }

 if (test_guard_gap_other_gaps()) {
  ret = 1;
  printf("[FAIL]\tGuard gap test, other mappings' gaps\n");
  goto out;
 }

 if (test_guard_gap_new_mappings_gaps()) {
  ret = 1;
  printf("[FAIL]\tGuard gap test, placement mapping's gaps\n");
  goto out;
 }

 if (test_ptrace()) {
  ret = 1;
  printf("[FAIL]\tptrace test\n");
 }

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

 if (test_uretprobe()) {
  ret = 1;
  printf("[FAIL]\turetprobe test\n");
  goto out;
 }

 return ret;

out:
 /*
  * Disable shadow stack before the function returns, or there will be a
  * shadow stack violation.
 */

 if (ARCH_PRCTL(ARCH_SHSTK_DISABLE, ARCH_SHSTK_SHSTK)) {
  ret = 1;
  printf("[FAIL]\tDisabling shadow stack failed\n");
 }

 return ret;
}
#endif

Messung V0.5 in Prozent
C=96 H=78 G=87

¤ Dauer der Verarbeitung: 0.17 Sekunden  (vorverarbeitet am  2026-10-12) ¤

*© 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.