Implement more security stuff

- Support deterministic stacks on OpenBSD
- Support OpenBSD system call origin verification
- Fix overrun by one in chibicc string token allocator
- Get all chibicc tests passing under Address Sanitizer
This commit is contained in:
Justine Tunney 2021-02-02 20:21:06 -08:00
parent cbfd4ccd1e
commit c843243322
56 changed files with 376 additions and 245 deletions

View file

@ -21,7 +21,7 @@
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/consts/nr.h"
#include "libc/macros.h"
.real
.text.syscall
.source __FILE__
/ Terminates program abnormally.

View file

@ -95,7 +95,7 @@ static int arch_prctl$freebsd(int code, int64_t addr) {
}
}
static int arch_prctl$xnu(int code, int64_t addr) {
static textsyscall int arch_prctl$xnu(int code, int64_t addr) {
int ax;
switch (code) {
case ARCH_SET_GS:
@ -113,7 +113,7 @@ static int arch_prctl$xnu(int code, int64_t addr) {
}
}
static int arch_prctl$openbsd(int code, int64_t addr) {
static textsyscall int arch_prctl$openbsd(int code, int64_t addr) {
int64_t rax;
switch (code) {
case ARCH_GET_FS:

View file

@ -19,7 +19,7 @@
#include "libc/dce.h"
#include "libc/runtime/internal.h"
#include "libc/macros.h"
.privileged
.text.syscall
.source __FILE__
/ Terminates process, ignoring destructors and atexit() handlers.

View file

@ -28,7 +28,7 @@
#define WasImported(SLOT) \
((void *)*SLOT && *SLOT != (void *)&missingno /* see libc/crt/crt.S */)
static privileged void __print$nt(const void *data, size_t len) {
static void __print$nt(const void *data, size_t len) {
int64_t hand;
char xmm[256];
uint32_t wrote;
@ -49,7 +49,7 @@ static privileged void __print$nt(const void *data, size_t len) {
* @param len can be computed w/ tinystrlen()
* @clob nothing except flags
*/
privileged void __print(const void *data, size_t len) {
textsyscall void __print(const void *data, size_t len) {
int64_t ax, ordinal;
if (WasImported(__imp_WriteFile)) {
__print$nt(data, len);
@ -68,7 +68,7 @@ privileged void __print(const void *data, size_t len) {
}
}
privileged void __print_string(const char *s) {
void __print_string(const char *s) {
size_t n = 0;
while (s[n]) ++n;
__print(s, n);

View file

@ -29,7 +29,7 @@
/**
* Aborts program under enemy fire to avoid being taken alive.
*/
void __stack_chk_fail(void) {
textsyscall void __stack_chk_fail(void) {
size_t len;
const char *msg;
int64_t ax, cx, si;