microsoft / microsoft/injectorppforrust
Potential security issue by disabling W^X in the original function and the jit memory
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 404
- Forks
- 19
- Avg merge
- 23h 57m
- Merged PRs (30d)
- 1
Description
For functions in the memory, we usually have W^X protection to avoid buffer overflow attacking.
In the patch_function, it disabled the W^X first to be able to inject code to the original function address:
pub(crate) unsafe fn patch_function(func: *mut u8, patch: &[u8]) {
make_memory_writable_and_executable(func); // <--------- HERE
inject_asm_code(patch, func);
}
Should we consider doing it like this:
- Change the memory page to Writable only (or Writable and Executable)
- Inject the code.
- Change the memory page to Executable only.
This idea also applies to the allocate_jit_memory.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating patch_function and allocate_jit_memory, then inspect how make_memory_writable_and_executable and inject_asm_code manage page permissions. Done means the injection flow is preserved while writable and executable permissions are not left enabled together longer than necessary, with the behavior verified by the relevant existing checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100