Skip to content

Commit

Permalink
go_env hook: use a different stack for the hook execution (#309)
Browse files Browse the repository at this point in the history
* go_env hook: use a different stack for the hook execution
  • Loading branch information
aviramha authored Aug 31, 2022
1 parent 7d9624a commit 10fdf1c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

### Fixed
- mirrord-layer: Go environment variables crash - run Go env setup in a different stack (should fix [#292](https://github.com/metalbear-co/mirrord/issues/292))

### Changed
- mirrord-layer: Add `#![feature(let_chains)]` to `lib.rs` to support new compiler version.

## 2.10.1
### Fixed
- CI:Release - Fix typo that broke the build
Expand Down
72 changes: 48 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mirrord-layer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ regex = "1"
errno = "0.2"
async-trait = "0.1"
socket2 = "0.4"
stacker = "0.1"

[lib]
crate_type = ["cdylib"]
Expand Down
18 changes: 10 additions & 8 deletions mirrord-layer/src/go_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ fn make_argv() -> Vec<*mut c_char> {

#[hook_fn]
unsafe extern "C" fn goenvs_unix_detour() {
trace!("hook goenvs_unix");
let modules = frida_gum::Module::enumerate_modules();
let binary = &modules.first().unwrap().name;
if let Some(argv) = frida_gum::Module::find_symbol_by_name(binary, "runtime.argv") {
let mut new_argv = ManuallyDrop::new(make_argv());
let argv_ptr: *mut *mut *mut i8 = argv.0.cast();
std::ptr::replace(argv_ptr, new_argv.as_mut_ptr());
}
stacker::grow(32 * 1024 * 1024, || {
trace!("hook goenvs_unix");
let modules = frida_gum::Module::enumerate_modules();
let binary = &modules.first().unwrap().name;
if let Some(argv) = frida_gum::Module::find_symbol_by_name(binary, "runtime.argv") {
let mut new_argv = ManuallyDrop::new(make_argv());
let argv_ptr: *mut *mut *mut i8 = argv.0.cast();
std::ptr::replace(argv_ptr, new_argv.as_mut_ptr());
}
});
FN_GOENVS_UNIX();
}

Expand Down
1 change: 1 addition & 0 deletions mirrord-layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![feature(naked_functions)]
#![feature(result_flattening)]
#![feature(io_error_uncategorized)]
#![feature(let_chains)]

use std::{
collections::{HashSet, VecDeque},
Expand Down

0 comments on commit 10fdf1c

Please sign in to comment.