microsoft / microsoft/injectorppforrust

Check target function size to avoid undefined behavior

Open
#95 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.