Files
Dmitrii Kuvaiskii 3cb2112b05 [LibOS,Pal] Use GCC's stack protector in LibOS and PAL functions
GCC (and other compilers, e.g. Clang) provide a stack protector
feature to detect stack corruptions. This is achieved by storing
a 64-bit canary value on the stack frame on function entry and
verifying this value on function exit. Previously, Graphene disabled
stack protector completely. This commit enables it in LibOS and PAL
code (only if `-mstack-protector` feature is supported by compiler).

The stack protector uses a random per-thread canary stored in the
TLS/TCB of each thread. Each PAL implementation must follow the
rule that TLS/TCB is accessed via the GS register and that the offset
of canary in TLS/TCB is 0x8. Since LibOS re-uses TLS/TCB of the PAL,
there is no need for additional enabling at the LibOS layer.

Since `-mstack-protector` feature is architecture-specific, it is
currently enabled only for x86-64 (and above rules on using gs:[0x8]
to access the canary apply only to x86-64).

Co-authored-by: Isaku Yamahata <isaku.yamahata@gmail.com>
2021-01-07 05:19:14 -08:00

16 lines
399 B
C

#ifndef _LINUX_UTILS_H
#define _LINUX_UTILS_H
double get_bogomips_from_cpuinfo_buf(const char* buf);
double sanitize_bogomips_value(double);
char* get_main_exec_path(void);
int read_text_file_to_cstr(const char* path, char** out);
/* called only from GCC-emitted code; declare here to suppress GCC warn "no previous prototype" */
noreturn void __stack_chk_fail(void);
#endif // _LINUX_UTILS_H