-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed not passing file open mode on bypass (Go+Linux) (#2865)
* Passing mode on bypass * Added integration test * Changelog * Style fixed in test app * Updated test doc * Fix lints in test * Use va_list in openat_detour * Fixed param type * pass mode as c_int to fix macos x64
- Loading branch information
Showing
7 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed a bug where file mode was ignored when Go applications were creating local files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module open_go | ||
|
||
go 1.23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"io/fs" | ||
_ "net" // to assert dynamic linking | ||
"os" | ||
) | ||
|
||
func main() { | ||
var path string | ||
var flags int | ||
var mode uint | ||
|
||
flag.StringVar(&path, "p", "/tmp/testfile", "Path to the file") | ||
flag.IntVar(&flags, "f", os.O_RDONLY, "Flags to use when opening the file (as raw integer)") | ||
flag.UintVar(&mode, "m", 0444, "Mode to use when opening the file (as raw integer)") | ||
flag.Parse() | ||
|
||
fd, err := os.OpenFile(path, flags, fs.FileMode(mode)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fd.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#![cfg(target_os = "linux")] | ||
#![feature(assert_matches)] | ||
#![warn(clippy::indexing_slicing)] | ||
|
||
use std::{os::unix::fs::PermissionsExt, path::Path, time::Duration}; | ||
|
||
use rand::{thread_rng, Rng}; | ||
use rstest::rstest; | ||
|
||
mod common; | ||
|
||
pub use common::*; | ||
|
||
/// Verify that issue [#2614](https://github.com/metalbear-co/mirrord/issues/2614) is fixed | ||
/// and the file open mode is honoured on bypass. | ||
#[rstest] | ||
#[tokio::test] | ||
#[timeout(Duration::from_secs(60))] | ||
async fn test_issue2614(dylib_path: &Path) { | ||
let tmpdir = tempfile::tempdir().unwrap(); | ||
let file_path = tmpdir | ||
.path() | ||
.join(format!("testfile-{}", thread_rng().gen::<u64>(),)); | ||
let application = Application::Go23Open { | ||
path: file_path.to_str().unwrap().into(), | ||
flags: libc::O_CREAT | libc::O_RDWR, | ||
mode: libc::S_IRUSR | libc::S_IRGRP | libc::S_IROTH, | ||
}; | ||
let (mut test_process, mut intproxy) = application | ||
.start_process_with_layer(dylib_path, vec![("MIRRORD_FILE_MODE", "local")], None) | ||
.await; | ||
|
||
let message = intproxy.try_recv().await; | ||
assert!( | ||
message.is_none(), | ||
"received an unexpected message: {message:?}" | ||
); | ||
test_process.wait_assert_success().await; | ||
|
||
let permissions = tokio::fs::metadata(file_path).await.unwrap().permissions(); | ||
assert_eq!( | ||
permissions.mode() & 0b111111111, | ||
libc::S_IRUSR | libc::S_IRGRP | libc::S_IROTH, | ||
"test app created file with unexpected permissions" | ||
) | ||
} |