forked from openenclave/openenclave
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2388: Mark oe_setjmp and setjmp as returns_twice r=jhand2 a=jhand2 The function setjmp in libc has a behavior known as "returns twice". This means that setjmp returns from normal control flow, but can also return via another method. The `longjmp` function resets a saved register state and jumps to the instruction immediately after a call to `setjmp`, which is functionally equivalent to a return from `setjmp`. clang 8 and 9 have a feature called Speculative Load Hardening, which is designed to mitigate some vulnerabilities in speculative execution. One such mitigation is to check for a return address in the "red zone" of the stack (a range of the stack below %rsp) to ensure proper control flow. You can read more [here](https://llvm.org/docs/SpeculativeLoadHardening.html#indirect-call-branch-and-return-predicates). Clang cannot apply these mitigations to functions with nonstandard control flow (like returns_twice) but in OE clang does not know that setjmp and oe_setjmp have this havavior. This PR adds annotations to these functions. Because it updates a 3rdparty library (musl) a .patch file is also included that can be applied to future versions of musl. It also changes oe_setjmp and oe_longjmp to use straight assembly rather than inline assembly in C files. This ensures that the stack is not improperly modified by compiler generated instructions. It also removes the need to compile setjmp and longjmp with specific optimization. Fixes openenclave#2386 Co-authored-by: Jordan Hand <[email protected]> Co-authored-by: Jordan Hand <[email protected]>
- Loading branch information
Showing
9 changed files
with
81 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Open Enclave SDK contributors. | ||
// Licensed under the MIT License. | ||
|
||
#ifndef _SETJMP_H | ||
#define _SETJMP_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <features.h> | ||
|
||
#include <bits/setjmp.h> | ||
|
||
typedef struct __jmp_buf_tag { | ||
__jmp_buf __jb; | ||
unsigned long __fl; | ||
unsigned long __ss[128/sizeof(long)]; | ||
} jmp_buf[1]; | ||
|
||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
|| defined(_BSD_SOURCE) | ||
typedef jmp_buf sigjmp_buf; | ||
int sigsetjmp (sigjmp_buf, int) __attribute__((returns_twice)); | ||
_Noreturn void siglongjmp (sigjmp_buf, int); | ||
#endif | ||
|
||
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
|| defined(_BSD_SOURCE) | ||
int _setjmp (jmp_buf) __attribute__((returns_twice)); | ||
_Noreturn void _longjmp (jmp_buf, int); | ||
#endif | ||
|
||
int setjmp (jmp_buf) __attribute__((returns_twice)); | ||
_Noreturn void longjmp (jmp_buf, int); | ||
|
||
#define setjmp setjmp | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters