Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove faulty statfs hooks in Go apps #3054

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
4 changes: 2 additions & 2 deletions mirrord/layer/src/file/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@

/// 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 @@ -919,10 +919,10 @@
})
.unwrap_or_bypass_with(|_| FN_FSTATFS(fd, out_stat))
}

Check warning on line 922 in mirrord/layer/src/file/hooks.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/mirrord/mirrord/mirrord/layer/src/file/hooks.rs
/// Hook for `libc::statfs`.
#[hook_guard_fn]
pub(crate) unsafe extern "C" fn statfs_detour(
unsafe extern "C" fn statfs_detour(
raw_path: *const c_char,
out_stat: *mut statfs,
) -> c_int {
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
Loading