microsoft / microsoft/injectorppforrust
Check target function size to avoid undefined behavior
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 404
- Forks
- 19
- Avg merge
- 23h 57m
- Merged PRs (30d)
- 1
Description
The size of target function to fake could be less than the patching size. Patching such function could cause undefined behavior at runtime.
One option is checking the size of the target function before performing patching. Panic if the function size is smaller than the required patching size.
For example, aarch64 has a hard coded size. This could cause undefined behavior if the function to fake is smaller.
fn replace_function_with_other_function(
src: FuncPtrInternal,
target: FuncPtrInternal,
) -> PatchGuard {
const PATCH_SIZE: usize = 12;
const JIT_SIZE: usize = 20;
let original_bytes = unsafe { read_bytes(src.as_ptr() as *mut u8, PATCH_SIZE) };
let jit_memory = allocate_jit_memory(&src, JIT_SIZE);
generate_will_execute_jit_code_abs(jit_memory, target.as_ptr());
apply_branch_patch(src, jit_memory, JIT_SIZE, &original_bytes)
}
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 with src/injector_core/patch_arm64.rs and the replace_function_with_other_function entry point shown in the issue. Trace how the hard-coded patch size is used before applying a branch patch, then inspect related architecture-specific patching code. Done means undersized target functions are detected before patching and the behavior is covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100