Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,29 @@
set(SAFESTACK_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SAFESTACK_LIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(SAFESTACK_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND SAFESTACK_TEST_DEPS safestack)
# Some tests require LTO, so add a dependency on the relevant LTO plugin.
if(LLVM_ENABLE_PIC AND LLVM_BINUTILS_INCDIR)
list(APPEND SAFESTACK_TEST_DEPS
LLVMgold
)
endif()
if(APPLE)
list(APPEND SAFESTACK_TEST_DEPS
LTO
)
endif()
endif()
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
)
add_lit_testsuite(check-safestack "Running the SafeStack tests"
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${SAFESTACK_TEST_DEPS})
set_target_properties(check-safestack PROPERTIES FOLDER "Compiler-RT Misc")

View File

@ -0,0 +1,26 @@
// RUN: %clang_safestack %s -o %t
// RUN: %run %t
#include "utils.h"
// Test that loads/stores work correctly for VLAs on the unsafe stack.
int main(int argc, char **argv)
{
int i = 128;
break_optimization(&i);
char buffer[i];
// check that we can write to a buffer
for (i = 0; argv[0][i] && i < sizeof (buffer) - 1; ++i)
buffer[i] = argv[0][i];
buffer[i] = '\0';
break_optimization(buffer);
// check that we can read from a buffer
for (i = 0; argv[0][i] && i < sizeof (buffer) - 1; ++i)
if (buffer[i] != argv[0][i])
return 1;
return 0;
}

View File

@ -0,0 +1,25 @@
// RUN: %clang_safestack %s -o %t
// RUN: %run %t
#include "utils.h"
// Test that loads/stores work correctly for variables on the unsafe stack.
int main(int argc, char **argv)
{
int i;
char buffer[128];
// check that we can write to a buffer
for (i = 0; argv[0][i] && i < sizeof (buffer) - 1; ++i)
buffer[i] = argv[0][i];
buffer[i] = '\0';
break_optimization(buffer);
// check that we can read from a buffer
for (i = 0; argv[0][i] && i < sizeof (buffer) - 1; ++i)
if (buffer[i] != argv[0][i])
return 1;
return 0;
}

View File

@ -0,0 +1,38 @@
// RUN: %clang_safestack -fno-stack-protector -D_FORTIFY_SOURCE=0 -g %s -o %t.nossp
// RUN: %run %t.nossp 2>&1 | FileCheck --check-prefix=NOSSP %s
// RUN: %clang_safestack -fstack-protector-all -D_FORTIFY_SOURCE=0 -g %s -o %t.ssp
// RUN: env LIBC_FATAL_STDERR_=1 not --crash %run %t.ssp 2>&1 | \
// RUN: FileCheck -check-prefix=SSP %s
// Test stack canaries on the unsafe stack.
// REQUIRES: stable-runtime
#include <assert.h>
#include <stdio.h>
#include <string.h>
__attribute__((noinline)) void f(unsigned *y) {
char x;
char *volatile p = &x;
char *volatile q = (char *)y;
assert(p < q);
assert(q - p < 1024); // sanity
// This has technically undefined behavior, but we know the actual layout of
// the unsafe stack and this should not touch anything important.
memset(&x, 0xab, q - p + sizeof(*y));
}
int main(int argc, char **argv)
{
unsigned y;
// NOSSP: main 1
// SSP: main 1
fprintf(stderr, "main 1\n");
f(&y);
// NOSSP: main 2
// SSP-NOT: main 2
fprintf(stderr, "main 2\n");
return 0;
}

View File

@ -0,0 +1,9 @@
// RUN: %clang_safestack %s -o %t
// RUN: %run %t
// Basic smoke test for the runtime library.
int main(int argc, char **argv)
{
return 0;
}

View File

@ -0,0 +1,22 @@
# -*- Python -*-
import os
# Setup config name.
config.name = 'SafeStack'
# Setup source root.
config.test_source_root = os.path.dirname(__file__)
# Test suffixes.
config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm', '.ll', '.test']
# Add clang substitutions.
config.substitutions.append( ("%clang_nosafestack ", config.clang + " -O0 -fno-sanitize=safe-stack ") )
config.substitutions.append( ("%clang_safestack ", config.clang + " -O0 -fsanitize=safe-stack ") )
if config.lto_supported:
config.substitutions.append((r"%clang_lto_safestack ", ' '.join(config.lto_launch + [config.clang] + config.lto_flags + ['-fsanitize=safe-stack '])))
if config.host_os not in ['Linux', 'FreeBSD', 'Darwin', 'NetBSD']:
config.unsupported = True

View File

@ -0,0 +1,7 @@
@LIT_SITE_CFG_IN_HEADER@
# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
# Load tool-specific config that would do the real work.
lit_config.load_config(config, "@SAFESTACK_LIT_SOURCE_DIR@/lit.cfg")

View File

@ -0,0 +1,12 @@
// REQUIRES: lto
// RUN: %clang_lto_safestack %s -o %t
// RUN: %run %t
// Test that safe stack works with LTO.
int main() {
char c[] = "hello world";
puts(c);
return 0;
}

View File

@ -0,0 +1,29 @@
// RUN: %clang_safestack %s -o %t
// RUN: %run %t
// RUN: %clang_nosafestack -fno-stack-protector %s -o %t
// RUN: not %run %t
// Test that buffer overflows on the unsafe stack do not affect variables on the
// safe stack.
// REQUIRES: stable-runtime
__attribute__((noinline))
void fct(volatile int *buffer)
{
memset(buffer - 1, 0, 7 * sizeof(int));
}
int main(int argc, char **argv)
{
int prebuf[7];
int value1 = 42;
int buffer[5];
int value2 = 42;
int postbuf[7];
fct(prebuf + 1);
fct(postbuf + 1);
fct(buffer);
return value1 != 42 || value2 != 42;
}

View File

@ -0,0 +1,31 @@
// RUN: %clang_safestack %s -pthread -o %t
// RUN: not --crash %run %t
// Test that unsafe stacks are deallocated correctly on thread exit.
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
enum { kBufferSize = (1 << 15) };
void *t1_start(void *ptr)
{
char buffer[kBufferSize];
return buffer;
}
int main(int argc, char **argv)
{
pthread_t t1;
char *buffer = NULL;
if (pthread_create(&t1, NULL, t1_start, NULL))
abort();
if (pthread_join(t1, &buffer))
abort();
// should segfault here
memset(buffer, 0, kBufferSize);
return 0;
}

View File

@ -0,0 +1,42 @@
// RUN: %clang_safestack %s -pthread -o %t
// RUN: %run %t
// XFAIL: darwin
// Test that pthreads receive their own unsafe stack.
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "utils.h"
static int ptr_test = 42;
void *t1_start(void *ptr)
{
if (ptr != &ptr_test)
abort();
// safe stack
int val = ptr_test * 5;
// unsafe stack
char buffer[8096]; // two pages
memset(buffer, val, sizeof (buffer));
break_optimization(buffer);
return ptr;
}
int main(int argc, char **argv)
{
pthread_t t1;
void *ptr = NULL;
if (pthread_create(&t1, NULL, t1_start, &ptr_test))
abort();
if (pthread_join(t1, &ptr))
abort();
if (ptr != &ptr_test)
abort();
return 0;
}

View File

@ -0,0 +1,8 @@
#ifndef UTILS_H
#define UTILS_H
static inline void break_optimization(void *arg) {
__asm__ __volatile__("" : : "r" (arg) : "memory");
}
#endif