-
Notifications
You must be signed in to change notification settings - Fork 4
Support RISC-V Control Flow Integrity Extensions #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
kito-cheng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rename most variable about lp to lp_unlabeled since we will have lp_func_sig in future.
25abf21 to
78c1733
Compare
7fae5b2 to
b752f71
Compare
| This tunable is specific to aarch64. | ||
| @end deftp | ||
|
|
||
| @deftp Tunable glibc.cpu.riscv_cfi_lp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @deftp Tunable glibc.cpu.riscv_cfi_lp | |
| @deftp Tunable glibc.cpu.riscv_cfi_unlabeled_lp |
|
|
||
| struct dl_riscv_feature_control | ||
| { | ||
| enum dl_riscv_cfi_control lp : 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| enum dl_riscv_cfi_control lp : 2; | |
| enum dl_riscv_cfi_control unlabeled_lp : 2; |
6cb15b3 to
fbbc3b0
Compare
33dc279 to
337c0b3
Compare
0a049e1 to
6d561c5
Compare
Co-authored-by: Hau Hsu <[email protected]>
Add GNU properties used by RISC-V CFI extensions (zicfilp/zicfiss)
Landing pads, instructions for setting the label value as well as alignment directives are inserted at where they should be. Frame offsets for floating point registers in _dl_runtime_resolve are also adjusted because now t2 has to be saved onto the stack. Co-authored-by: Hau Hsu <[email protected]> Co-authored-by: Kito Cheng <[email protected]>
Member l_riscv_feature_1_and is added to struct link_map, which stores the feature_1_and property information for each object. New global _dl_riscv_feature_1 will be used to store what features are finally enabled for this process.
These operations are for setting/retrieving/locking the status of the landing pad and the shadow stack extensions.
For static binaries, CFI are enabled inside ARCH_SETUP_TLS, with a macro to enable the shadow stack to prevent underflowing the shadow stack on return, and with a function _dl_cfi_setup_features to enable landing pad. It scans backward of the program header to find the PT_GNU_PROPERTY note first, then enable CFI features corresponding to the feature bits. Co-authored-by: Deepak Gupta <[email protected]>
For dynamic binaries, CFI features are parsed from GNU properties, store in to GLRO(dl_riscv_feature_1) and later enabled in RTLD_START. Co-authored-by: Deepak Gupta <[email protected]>
dl_riscv_feature_control is a structure with each member represents a feature configuration. At this time it's only used by CFI features. Each cfi feature is a 2-bit enum, which could be [on|off|permissive], these values decide whether a new legacy object should be blocked while loaded dynamically, and could be controled by glibc tunables.
Since longjmp to a previous setjmp'ed state could change the stack frame and involves stack frame unwinding, shadow stacks is also required to be unwinded. The unwinding is implemented according to the zicfiss spec by increasing the ssp by a page size (4K) at most, to prevent from accidentally point to another legal shadow stack page after the adjustment.
Switching between different ucontexts involves two cases, one is both sharing a same shadow stack, which requires a unwinding, and the other is both using a different shadow stack, which require a stack switch using shadow stack restore token. By storing shadow stack in ucontext_t and TLS, we can tell the difference and perform the following action.
This patch adds support for shadow stack and landing pad to the ucontext library, shadow stack switches are protected by a shadow stack restore token which will be validated during the switch. Co-authored-by: Nia Su <[email protected]>
No description provided.