-
Notifications
You must be signed in to change notification settings - Fork 7
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
Allow controlling Landlock ABI versions #41
Closed
+113
−20
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8063fc0
Allow controlling Landlock ABI versions
cd-work a3f4cdd
Remove unused pub export
cd-work 7bc2d4c
Use latest landlock ABI for `add_exception`
cd-work 73894af
Add test for FS_TRUNCATE
cd-work 597a934
Refine truncate test
cd-work 6c92295
Require V2 landlock version
cd-work d50b852
WIP
cd-work aad0bef
Switch to fixed max ABI
cd-work 38af74a
Fix code formatting
cd-work File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,56 @@ | ||
#[rustfmt::skip] | ||
#[cfg(target_os = "linux")] | ||
use { | ||
std::ffi::CString, | ||
std::fs, | ||
|
||
birdcage::linux::LANDLOCK_ABI, | ||
birdcage::{Birdcage, Exception, Sandbox}, | ||
tempfile::NamedTempFile, | ||
}; | ||
|
||
#[cfg(target_os = "linux")] | ||
fn main() { | ||
// Create files with non-zero length. | ||
let input = "truncate this"; | ||
let public_file = NamedTempFile::new().unwrap(); | ||
let public_path = public_file.path(); | ||
fs::write(public_path, input).unwrap(); | ||
let private_file = NamedTempFile::new().unwrap(); | ||
let private_path = private_file.path(); | ||
fs::write(private_path, input).unwrap(); | ||
|
||
// Enable our sandbox. | ||
let mut birdcage = match Birdcage::new_with_version(LANDLOCK_ABI::V3) { | ||
Ok(birdcage) => birdcage, | ||
// Skip this test if LANDLOCK_ABI::V3 is not supported. | ||
Err(_) => return, | ||
}; | ||
birdcage.add_exception(Exception::Write(public_path.into())).unwrap(); | ||
birdcage.add_exception(Exception::Read(public_path.into())).unwrap(); | ||
birdcage.add_exception(Exception::Read(private_path.into())).unwrap(); | ||
birdcage.lock().unwrap(); | ||
|
||
// Allow truncating public file. | ||
let path_str = public_path.to_string_lossy().to_string(); | ||
let c_path = CString::new(path_str).unwrap(); | ||
let result = unsafe { libc::truncate(c_path.as_ptr(), 0) }; | ||
assert_eq!(result, 0); | ||
|
||
// Ensure the file is empty. | ||
let content = fs::read_to_string(public_path).unwrap(); | ||
assert_eq!(content, String::new()); | ||
|
||
// Prevent truncating private file. | ||
let path_str = private_path.to_string_lossy().to_string(); | ||
let c_path = CString::new(path_str).unwrap(); | ||
let result = unsafe { libc::truncate(c_path.as_ptr(), 0) }; | ||
assert_eq!(result, -1); | ||
|
||
// Ensure the file is NOT empty. | ||
let content = fs::read_to_string(private_path).unwrap(); | ||
assert_eq!(content, String::from(input)); | ||
} | ||
|
||
#[cfg(not(target_os = "linux"))] | ||
fn main() {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not merge until a new landlock version is released.