-
Notifications
You must be signed in to change notification settings - Fork 1
Full clone support for both x86_64 and RISC-V #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
144 commits
Select commit
Hold shift + click to select a range
b46d41c
major changes due to difference between RISC-V and x64. Updated versi…
402a337
Trampoline doesn't prematurely clobber used registers anymore
3efb0e3
sp value changes now keep it 16-byte boundary aligned
ce40f2f
Now instruction following ecall must not use ra as operand to be able…
0a206ab
context and its references are now coherent with RISC-V and stack lay…
1ca3f27
Assembly files now follow the correct logic. Clone should now be hand…
d1cb7a8
pattern1 work in progress
07af378
code cleanup
b5499cc
pointer small fix
8b4ce8d
small pointer fix and added prototype of a function
d6572cc
small fix, code cleanup and disabled CMake PERFORM_STYLE_CHECKS and T…
463eafa
Created one more simple test
8390aad
deleted SYS_vfork references and substituted SYS_open with SYS_openat
165b36d
Correctly patching 490 out of 492 ecall in libc. To do: debug return …
db7244f
ECALL can now be successfully patched even with just 6 overwritable b…
3164838
added simple openat interception test
dc0bde7
Commented out useless debug_dump calls
fc2c796
changed two flags and corrected link_directories
eed7bdd
added trampoline creation in 6 byte patch case
8a51ff9
updated .gitignore and one assembly test
2db363e
test/CMakeLists.txt test push
a864c32
restored original version of test/CMakeLists.txt
76e7e5c
Fixed relocation bug and fixed bug for leaves procedure; now returni…
SilenceDesigner dbb4538
added some tests
SilenceDesigner 0f6f411
some more tests
SilenceDesigner 2f88c94
corrected some more tests
SilenceDesigner 93ec711
example.c test corrected
SilenceDesigner 8962c5c
c.nop placement bug solved
SilenceDesigner 3e7d0e5
Cleaning arch-specific dependencies
GlassOfWhiskey 2fa201b
temporary registers are now saved and restored as expected by libc
SilenceDesigner 02eb5fb
t5 is now correctly preserved across the interception
SilenceDesigner 951a8d8
Use of in following instruction is no more forbidding, added C.JR ca…
SilenceDesigner ca2581a
Library is now architecture independent. It works on both x86_64 and …
2874db5
Solved some warnings
971ab4b
Solved last warning
a8e6c3b
Corrected comment to RISC-V specific files
3a9f3d7
Made architecture indepentent
279be19
Added missing syscall formats
808c090
Fixed and enabled perl coding style check
9b0ae57
Removed unused flag
f220d8e
Disabling perl style check again
db3308f
Commented lines cleanup
eb98da3
Removed unused patcher.c from arch-independent directory
70f43e6
Started writing arch-specific READMEs
b8e9877
Updated READMEs and CMakeLists.txt builds test and examples just if a…
9314b64
Restored original x64 test
71b38aa
Updated READMEs
SilenceDesigner 1f3f035
Corrected copyright headers
SilenceDesigner f9cee3f
Removed executable in test
SilenceDesigner 384830a
Updated REAME.md
SilenceDesigner 4a97559
Restored vfork handling in intercept_routine
d3a00ba
Corrected copyright notes
0ff4b72
Cleaned up commented lines, placed TRAMPOLINE_SIZE definition here back
519c6fb
Smarter definition of macros and boolean flags depending on the targe…
6007fe6
Refined arch-dependant definition
2ec36ea
Refined arch-dependant definition
cce5d53
Cleaned up unnecessary inclusions and fixed copyright notes
a1da724
Updated team roles
e1186a1
SARGS definition are now dependant on SYS_* macro definition instead …
367e7df
Added simple brk test
1319a0f
Added statx test
64eac89
Made write and openat tests assertive
97670a8
Corrected openat_test
a795f91
Fixed clone() handling
311633c
Added clone test
4c73235
Comment, formatting
9100592
modified .gitignore
163a11b
Created a temporary folder for RISC-V testing
SilenceDesigner 5f55f0c
Added Makefile
SilenceDesigner e747d2d
All tests are updated
SilenceDesigner 66eddc8
Reformatting
SilenceDesigner 58500df
Switched to mkdirat since mkdir is not defined on RISC-V
SilenceDesigner 64423d9
Reinforced clone test
SilenceDesigner 7249ac2
Corrected relative paths
SilenceDesigner f411c56
Corrected clone test
SilenceDesigner aca8415
Updated READMEs
66554ab
Solved relative inclusions
5e5434b
Comments cleanup
fe44157
Ditched clone test as clone handling is WIP
3ef8a80
Corrected one instruction
74b0471
Updated test/riscv/Makefile
SilenceDesigner d569ae8
Clone handling with NULL arg1
890c794
Fixed unhandled ecall case context restoring
SilenceDesigner 95232d2
Refined clone_test
SilenceDesigner ebfaac8
Added fork test
13be19c
Capstone 5.0.6 is now automatically fetched and compiled
3e8695c
fix: linking x64 tests and capstone
bf3a719
update: cmake minimum required version is now 3.10
SilenceDesigner 623aa84
Bump capstone project came_minimum_required
marcoSanti 30be91c
update: post_clone for stack space sharing clone is called from norma…
SilenceDesigner c2dee0f
update: capstone compilation, clone full support
91b673d
chore: syntax correction
e0fdaac
calling same post_clone routine both from C routine and ASM wrapper
61004fe
code cleanup
91d9d52
solving minor issues with pmem tests
SilenceDesigner aac467f
updated original pmem x64 tests to work with newer glibc versions
f63d4c3
updated CI pipeline to run on Ubuntu 22
0436c23
fine-tuned fstat logging
SilenceDesigner 218287c
tailored tests to work on different glibc versions
SilenceDesigner 4495eae
rearranged riscv tests in dedicated directory
SilenceDesigner 339e822
updated riscv test directory
SilenceDesigner 4744756
test list order is now consistent
SilenceDesigner 06876b0
Merge branch 'master' into riscv-dev
SilenceDesigner d1bfc3d
refined trampoline allocation
SilenceDesigner bfae1e3
Update README.md
SilenceDesigner e94f6c8
Update README.md
SilenceDesigner 66d954f
Specified referenced capstone version
SilenceDesigner d5d5bd6
rearranged arch-specific tests
SilenceDesigner 96d012b
Now building tests on both x86_64 and riscv
SilenceDesigner 3dd50f0
optional inclusion of arch_prctl
SilenceDesigner dbe5686
optional inclusion of sys/io.h
SilenceDesigner 9750686
optional inclusion of system calls not defined on RISCV
SilenceDesigner 4f99e4f
moved vfork test to x86_64 tests directory
SilenceDesigner 63d7d67
Test suite is built with cmake on both x86_64 and RISC-V
SilenceDesigner 7f32061
solved unused variables warnings
SilenceDesigner ed4bd5e
added -Wno-unused-result for tests
SilenceDesigner ff4fe29
added -Wno-unused-variable for test
SilenceDesigner e4a1321
fine-tuning for cmake-independent execution
SilenceDesigner 185d3f7
excluded generic test generated files and directories
SilenceDesigner f38bb29
Updated tests description
732fc31
removed lines added by github merge
fb6c8fd
poll and ppoll test logging fine-tuning
8e54554
faccessat test logging fixed
107221f
dup2/dup3 logging test discrepancy solved
eb3713c
replaced token with where just letters can be present
77fd75a
revert token substitution
489606b
Created different log match files for each arch
10755aa
Fine-tuned riscv syscall format logging match file
51e070c
create_module format declaration is now optional
cafd156
typo fix
15a38d8
fixed accpt4 expetations
8bcc45e
fixed accept4 expectations
3a369aa
typo fix
5ac4f55
typo fix
c1f160c
Full test suite passed with glibc 2.39 on x64
SilenceDesigner df43ff0
Updated riscv syscall_format_log match file
SilenceDesigner ea36858
typo fix
SilenceDesigner 962291d
Fixed semctl args expectations
SilenceDesigner d5d316b
typo fix
SilenceDesigner 170fd6c
fixed renameat2 log expectations
SilenceDesigner 09c0637
fixed renameat2 log expectations
SilenceDesigner 132ae5d
added delete_module and quotactl to log match file
SilenceDesigner cfece63
fixed epoll_create log expectation
SilenceDesigner 9271486
fixed inotify_init log expectation
SilenceDesigner 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,24 @@ | ||
| # syscall_intercept | ||
|
|
||
|
|
||
| [//]: # ([](https://travis-ci.org/pmem/syscall_intercept)) | ||
|
|
||
| [//]: # ([](https://codecov.io/gh/pmem/syscall_intercept)) | ||
|
|
||
| [//]: # ([](https://scan.coverity.com/projects/syscall_intercept)) | ||
|
|
||
| This repository contains a multi-architecture porting of [syscall_intercept](https://github.com/pmem/syscall_intercept) working on both x86_64 and RISC-V | ||
| This repository contains a multi-architecture porting of [syscall_intercept](https://github.com/pmem/syscall_intercept) working on both **x86_64** and **RISC-V**. | ||
| Full-featured support for **aarch64** (ARM64) is in progress. | ||
|
|
||
| [](https://opensource.org/licenses/BSD-3-Clause) | ||
| # Dependencies # | ||
|
|
||
|
|
||
| ## Runtime dependencies ## | ||
|
|
||
| * libcapstone -- the disassembly engine used under the hood | ||
| (RISC-V support requires version **5.0** or higher, while apt installs version 4.0.2 by default, as february 2025). | ||
| Compiling capstone by hand will require setting [CMakeLists.txt](CMakeLists.txt#L109) accordingly | ||
| Since a manual installation of Capstone could not be automatically detected while compiling syscall_intercept, we ensured that libcapstone v5.0.6 is **automatically compiled** from source during the syscall_intercept cmake execution. | ||
|
|
||
| ## Build dependencies ## | ||
|
|
||
|
|
@@ -56,20 +60,14 @@ There is an install target. For now, all it does, is cp. | |
| make install | ||
| ``` | ||
|
|
||
| Testing on **x86_64**: | ||
| Running test suite: | ||
| ```shell | ||
| make test | ||
| ``` | ||
|
|
||
| Testing on **RISC-V**:\ | ||
| Go to `syscall_intercept/test/riscv/`, then | ||
| ```shell | ||
| make | ||
| make test | ||
| ``` | ||
|
|
||
| # Synopsis # | ||
|
|
||
|
|
||
| ```c | ||
| #include <libsyscall_intercept_hook_point.h> | ||
| ``` | ||
|
|
@@ -188,6 +186,7 @@ ls: reading directory '.': Operation not supported | |
|
|
||
| # Under the hood: # | ||
|
|
||
|
|
||
| ##### Assumptions: ##### | ||
| In order to handle syscalls in user space, the library relies | ||
| on the following assumptions: | ||
|
|
@@ -311,20 +310,20 @@ aa20a: bltu a5,a0,aa262 <__open+0xaa> | aa20a: bltu a5,a0,aa262 <__ope | |
| ``` | ||
|
|
||
| # Limitations: # | ||
|
|
||
|
|
||
| * Only Linux is supported | ||
| * Only x86\_64 and RISC-V are supported | ||
| * Only tested with glibc, although perhaps it works | ||
| with some other libc implementations as well | ||
| * RISC-V version assumes `$t6` is not used as base pointer or as source | ||
| register without being reinitialized after an `ecall` and before the ending of | ||
| a function - tested with glibc 2.35, 2.37 and 2.39 | ||
| * :warning: **Clone** is not fully handled on **RISC-V**. Whereas in x86_64 | ||
| version it is possible to define post-clone hook functions for both the | ||
| parent and child threads, on RISC-V it is only possible to define a pre-clone | ||
| hook function therefore providing a similar interception to every other system | ||
| calls. An example is present in [intercept_sys_clone.c](test/riscv/src/intercept_sys_clone.c) | ||
| a function. While this assumption involves heuristics, this choice was tested | ||
| on different glibc version, i.e. 2.35, 2.37 and 2.39, and on different kernel | ||
| implementations manifesting a consistent and working behaviour. | ||
|
|
||
| # Debugging: # | ||
|
|
||
| Besides logging, the most important factor during debugging is to make | ||
| sure the system calls in the debugger are not intercepted. To achieve this, use | ||
| the INTERCEPT_HOOK_CMDLINE_FILTER variable described above. | ||
|
|
@@ -340,7 +339,8 @@ process itself. | |
|
|
||
| # RISC-V porting # | ||
|
|
||
| Ottavio Monticelli <[email protected]> (Maintainer) \ | ||
|
|
||
| Ottavio Monticelli <[email protected]> (Maintainer) \ | ||
| Marco Edoardo Santimaria <[email protected]> (Maintainer) \ | ||
| Marco Aldinucci <[email protected]> (Maintainer and Principal Investigator) \ | ||
| Iacopo Colonnelli <[email protected]> (Maintainer and Principal Investigator) | ||
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,15 @@ | ||
| cmake_minimum_required(VERSION 3.10) | ||
| project(capstone) | ||
| include(FetchContent) | ||
|
|
||
| ##################################### | ||
| # Import external project from git | ||
| ##################################### | ||
| FetchContent_Declare(capstone | ||
| GIT_REPOSITORY https://github.com/capstone-engine/capstone.git | ||
| # the following git tag refers to capstone version 5.0.6 | ||
| GIT_TAG accf4df62f1fba6f92cae692985d27063552601c | ||
| ) | ||
|
|
||
| FetchContent_MakeAvailable(capstone) | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.