Skip to content

Commit

Permalink
Remove faulty statfs hooks in Go apps (#3054)
Browse files Browse the repository at this point in the history
* Removed statfs/fstatfs hooks in Go apps

* format
  • Loading branch information
Razz4780 authored Feb 3, 2025
1 parent d5c9170 commit c745d5b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
1 change: 1 addition & 0 deletions changelog.d/+statfs-go-hook.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed faulty `statfs` hook for Go applications.
7 changes: 2 additions & 5 deletions mirrord/layer/src/file/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ unsafe extern "C" fn fstatat_detour(

/// Hook for `libc::fstatfs`.
#[hook_guard_fn]
pub(crate) unsafe extern "C" fn fstatfs_detour(fd: c_int, out_stat: *mut statfs) -> c_int {
unsafe extern "C" fn fstatfs_detour(fd: c_int, out_stat: *mut statfs) -> c_int {
if out_stat.is_null() {
return HookError::BadPointer.into();
}
Expand All @@ -922,10 +922,7 @@ pub(crate) unsafe extern "C" fn fstatfs_detour(fd: c_int, out_stat: *mut statfs)

/// Hook for `libc::statfs`.
#[hook_guard_fn]
pub(crate) unsafe extern "C" fn statfs_detour(
raw_path: *const c_char,
out_stat: *mut statfs,
) -> c_int {
unsafe extern "C" fn statfs_detour(raw_path: *const c_char, out_stat: *mut statfs) -> c_int {
if out_stat.is_null() {
return HookError::BadPointer.into();
}
Expand Down
6 changes: 4 additions & 2 deletions mirrord/layer/src/go/linux_x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ unsafe extern "C" fn c_abi_syscall_handler(
faccessat_detour(param1 as _, param2 as _, param3 as _, 0) as i64
}
libc::SYS_fstat => fstat_detour(param1 as _, param2 as _) as i64,
libc::SYS_statfs => statfs_detour(param1 as _, param2 as _) as i64,
libc::SYS_fstatfs => fstatfs_detour(param1 as _, param2 as _) as i64,
// Currently disabled due to a [bug](https://github.com/metalbear-co/mirrord/issues/3044).
// libc::SYS_statfs => statfs_detour(param1 as _, param2 as _) as i64,
// Currently disabled due to a [bug](https://github.com/metalbear-co/mirrord/issues/3044).
// libc::SYS_fstatfs => fstatfs_detour(param1 as _, param2 as _) as i64,
libc::SYS_getdents64 => getdents64_detour(param1 as _, param2 as _, param3 as _) as i64,
#[cfg(all(target_os = "linux", not(target_arch = "aarch64")))]
libc::SYS_mkdir => mkdir_detour(param1 as _, param2 as _) as i64,
Expand Down
6 changes: 4 additions & 2 deletions mirrord/layer/src/go/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ unsafe extern "C" fn c_abi_syscall6_handler(
.into()
}
libc::SYS_fstat => fstat_detour(param1 as _, param2 as _) as i64,
libc::SYS_statfs => statfs_detour(param1 as _, param2 as _) as i64,
libc::SYS_fstatfs => fstatfs_detour(param1 as _, param2 as _) as i64,
// Currently disabled due to a [bug](https://github.com/metalbear-co/mirrord/issues/3044).
// libc::SYS_statfs => statfs_detour(param1 as _, param2 as _) as i64,
// Currently disabled due to a [bug](https://github.com/metalbear-co/mirrord/issues/3044).
// libc::SYS_fstatfs => fstatfs_detour(param1 as _, param2 as _) as i64,
libc::SYS_fsync => fsync_detour(param1 as _) as i64,
libc::SYS_fdatasync => fsync_detour(param1 as _) as i64,
libc::SYS_openat => {
Expand Down
22 changes: 12 additions & 10 deletions mirrord/layer/tests/apps/fileops/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ import (

func main() {
tempFile := "/tmp/test_file.txt"
fd, _ := syscall.Open(tempFile, syscall.O_CREAT|syscall.O_WRONLY, 0644)
syscall.Open(tempFile, syscall.O_CREAT|syscall.O_WRONLY, 0644)
var stat syscall.Stat_t
err := syscall.Stat(tempFile, &stat)
if err != nil {
panic(err)
}

var statfs syscall.Statfs_t
err = syscall.Statfs(tempFile, &statfs)
if err != nil {
panic(err)
}
// statfs/fstatfs hooks are currently disabled in Go apps due to a [bug](https://github.com/metalbear-co/mirrord/issues/3044).

err = syscall.Fstatfs(fd, &statfs)
if err != nil {
panic(err)
}
// var statfs syscall.Statfs_t
// err = syscall.Statfs(tempFile, &statfs)
// if err != nil {
// panic(err)
// }

// err = syscall.Fstatfs(fd, &statfs)
// if err != nil {
// panic(err)
// }
}
5 changes: 3 additions & 2 deletions mirrord/layer/tests/fileops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ async fn go_stat(
))))
.await;

intproxy.expect_statfs("/tmp/test_file.txt").await;
intproxy.expect_fstatfs(fd).await;
// statfs/fstatfs hooks are currently disabled in Go apps due to a [bug](https://github.com/metalbear-co/mirrord/issues/3044).
// intproxy.expect_statfs("/tmp/test_file.txt").await;
// intproxy.expect_fstatfs(fd).await;

test_process.wait_assert_success().await;
test_process.assert_no_error_in_stderr().await;
Expand Down

0 comments on commit c745d5b

Please sign in to comment.