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

Improve "file names that don't exist" case explanation #77

Open
n0toose opened this issue Nov 2, 2024 · 0 comments
Open

Improve "file names that don't exist" case explanation #77

n0toose opened this issue Nov 2, 2024 · 0 comments

Comments

@n0toose
Copy link

n0toose commented Nov 2, 2024

The documentation mentions a case of "file names that don’t exist". This got me thinking. Is it possible to whitelist a specific "path", despite no file (and therefore, no file descriptor) for a regular path to be created, without giving R/W permissions to the parent folder? (For example, so as to create a log.txt file in the current working directory, without the process being able to inspect anything else in the current working directory apart from the log?)

pub const LANDLOCK_ACCESS_FS_MAKE_REG: u32 = 256;

MakeReg = uapi::LANDLOCK_ACCESS_FS_MAKE_REG as u64,

| MakeReg

Derived from the examples:

pub fn initialize_landlock() -> Result<RestrictionStatus, LandlockRestrictError> {
	let abi = ABI::V5;
	let access_all: landlock::BitFlags<AccessFs, u64> = AccessFs::from_all(abi);
	let access_read: landlock::BitFlags<AccessFs, u64> = AccessFs::from_read(abi);

	Ok(Ruleset::default()
		.handle_access(access_all)?
		.create()?
		.add_rules(
			WHITELISTED_PATHS
				.get()
				.unwrap()
				.as_slice()
				.iter()
				.map::<Result<_, LandlockRestrictError>, _>(|p| {
					Ok(PathBeneath::new(PathFd::new(p)?, access_all))
				}),
		)?
		.restrict_self()?)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant