forked from riscvarchive/riscv-glibc
-
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
Open
jaidTw
wants to merge
14
commits into
master
Choose a base branch
from
enable-cfi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f21e2fd
riscv: Add --enable-cfi option for controlling cfi features
jaidTw 5acf662
riscv/cfi: Setup necessary options for enable-cfi option
jaidTw ac19c6f
riscv: Add GNU property definitions for RISC-V CFI
jaidTw 0ad9ba6
riscv: Adjust assembly routines to support landing pad
jaidTw 8ba3774
riscv: Introduce feature variables for holding RISC-V GNU properties
jaidTw cdb3443
riscv/cfi: Add prctl definitions for RISC-V CFI
jaidTw c1fd3e2
riscv/cfi: Enable CFI on static binaries
jaidTw 6ecacc7
riscv/cfi: Enable CFI on dynamic binaries
jaidTw a1fadb3
riscv/cfi: introduce tunables for CFI features
jaidTw 004a8c0
riscv/cfi: Adjust setjmp/longjmp for shadow stack to work
jaidTw cfcaead
riscv/cfi: Support locking/disabling CFI and move OS depedent code
jaidTw 4e52273
riscv/cfi: Store shadow stack information in TLS and ucontext_t
jaidTw 8e44a6a
riscv/cfi: Add __allocate_shadow_stack for mapping new shadow stack
jaidTw 9b3bf3a
riscv/cfi: Support ucontext under CFI
jaidTw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| /* Initialize CPU feature data. | ||
| This file is part of the GNU C Library. | ||
| Copyright (C) 2025 Free Software Foundation, Inc. | ||
|
|
||
| The GNU C Library is free software; you can redistribute it and/or | ||
| modify it under the terms of the GNU Lesser General Public | ||
| License as published by the Free Software Foundation; either | ||
| version 2.1 of the License, or (at your option) any later version. | ||
|
|
||
| The GNU C Library is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| Lesser General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Lesser General Public | ||
| License along with the GNU C Library; if not, see | ||
| <https://www.gnu.org/licenses/>. */ | ||
|
|
||
| #ifndef _CPU_FEATURES_RISCV_H | ||
| #define _CPU_FEATURES_RISCV_H | ||
|
|
||
| # define TUNABLE_NAMESPACE cpu | ||
| # include <cpu-tunables.c> | ||
|
|
||
| # ifdef __riscv_landing_pad | ||
| extern void TUNABLE_CALLBACK (set_riscv_cfi_lp) (tunable_val_t *) | ||
| attribute_hidden; | ||
| # endif | ||
| # ifdef __riscv_shadow_stack | ||
| extern void TUNABLE_CALLBACK (set_riscv_cfi_ss) (tunable_val_t *) | ||
| attribute_hidden; | ||
| # endif | ||
|
|
||
| static inline void | ||
| init_cpu_features (void) | ||
| { | ||
| # ifdef __riscv_landing_pad | ||
| TUNABLE_GET (riscv_cfi_lp, tunable_val_t *, | ||
| TUNABLE_CALLBACK (set_riscv_cfi_lp)); | ||
| # endif | ||
| # ifdef __riscv_shadow_stack | ||
| TUNABLE_GET (riscv_cfi_ss, tunable_val_t *, | ||
| TUNABLE_CALLBACK (set_riscv_cfi_ss)); | ||
| # endif | ||
| } | ||
| #endif /* _CPU_FEATURES_RISCV_H */ |
This file contains hidden or 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,50 @@ | ||
| /* RISC-V CPU feature tuning. | ||
| This file is part of the GNU C Library. | ||
| Copyright (C) 2025 Free Software Foundation, Inc. | ||
|
|
||
| The GNU C Library is free software; you can redistribute it and/or | ||
| modify it under the terms of the GNU Lesser General Public | ||
| License as published by the Free Software Foundation; either | ||
| version 2.1 of the License, or (at your option) any later version. | ||
|
|
||
| The GNU C Library is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| Lesser General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Lesser General Public | ||
| License along with the GNU C Library; if not, see | ||
| <https://www.gnu.org/licenses/>. */ | ||
|
|
||
| #define TUNABLE_NAMESPACE cpu | ||
| #include <elf/dl-tunables.h> | ||
| #include <dl-tunables-parse.h> | ||
| #include <ldsodefs.h> | ||
|
|
||
| #ifdef __riscv_landing_pad | ||
| attribute_hidden | ||
| void | ||
| TUNABLE_CALLBACK (set_riscv_cfi_lp) (tunable_val_t *valp) | ||
| { | ||
| if (tunable_strcmp_cte (valp, "permissive")) | ||
| GL(dl_riscv_feature_control).lp = cfi_permissive; | ||
| else if (tunable_strcmp_cte (valp, "off")) | ||
| GL(dl_riscv_feature_control).lp = cfi_always_off; | ||
| else | ||
| GL(dl_riscv_feature_control).lp = cfi_always_on; | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef __riscv_shadow_stack | ||
| attribute_hidden | ||
| void | ||
| TUNABLE_CALLBACK (set_riscv_cfi_ss) (tunable_val_t *valp) | ||
| { | ||
| if (tunable_strcmp_cte (valp, "permissive")) | ||
| GL(dl_riscv_feature_control).ss = cfi_permissive; | ||
| else if (tunable_strcmp_cte (valp, "off")) | ||
| GL(dl_riscv_feature_control).ss = cfi_always_off; | ||
| else | ||
| GL(dl_riscv_feature_control).ss = cfi_always_on; | ||
| } | ||
| #endif |
This file contains hidden or 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,4 @@ | ||
| /* crti.S is empty because .init_array/.fini_array are used exclusively. | ||
| Include sysdep.h to define gnu property if necessary. */ | ||
|
|
||
| #include <sysdep.h> |
This file contains hidden or 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,4 @@ | ||
| /* crtn.S is empty because .init_array/.fini_array are used exclusively. | ||
| Include sysdep.h to define gnu property if necessary. */ | ||
|
|
||
| #include <sysdep.h> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.