Skip to content

Commit 7dff88a

Browse files
committed
Revert "jailer: Use O_NOFOLLOW for cgroup and netns file operations"
This reverts commit ce2a467. It turns out users do want to legitimately use symlinks in these paths. Commit 72340ca ("docs: Clarify that all jailer inputs must be trusted") updated documentation to make it clear that all jailer inputs are always considered trusted anyway, so this revert is not a regression. Signed-off-by: Ilias Stamatis <ilstam@amazon.com>
1 parent 4a2183a commit 7dff88a

2 files changed

Lines changed: 4 additions & 23 deletions

File tree

src/jailer/src/env.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,8 @@ impl Env {
519519

520520
fn join_netns(path: &str) -> Result<(), JailerError> {
521521
// The fd backing the file will be automatically dropped at the end of the scope
522-
let netns = OpenOptions::new()
523-
.read(true)
524-
.custom_flags(libc::O_NOFOLLOW)
525-
.open(path)
526-
.map_err(|err| JailerError::FileOpen(PathBuf::from(path), err))?;
522+
let netns =
523+
File::open(path).map_err(|err| JailerError::FileOpen(PathBuf::from(path), err))?;
527524

528525
// SAFETY: Safe because we are passing valid parameters.
529526
SyscallReturnCode(unsafe { libc::setns(netns.as_raw_fd(), libc::CLONE_NEWNET) })

src/jailer/src/main.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
use std::ffi::{CString, NulError, OsString};
55
use std::fmt::{Debug, Display};
6-
use std::fs::OpenOptions;
7-
use std::io::Read;
8-
use std::os::unix::fs::OpenOptionsExt;
96
use std::path::{Path, PathBuf};
107
use std::{env as p_env, fs, io};
118

@@ -243,25 +240,12 @@ where
243240
T: AsRef<Path> + Debug,
244241
V: Display + Debug,
245242
{
246-
let mut file = OpenOptions::new()
247-
.write(true)
248-
.create(true)
249-
.truncate(true)
250-
.custom_flags(libc::O_NOFOLLOW)
251-
.open(file_path.as_ref())
252-
.map_err(|err| JailerError::Write(PathBuf::from(file_path.as_ref()), err))?;
253-
io::Write::write_all(&mut file, format!("{}\n", value).as_bytes())
243+
fs::write(file_path, format!("{}\n", value))
254244
.map_err(|err| JailerError::Write(PathBuf::from(file_path.as_ref()), err))
255245
}
256246

257247
pub fn readln_special<T: AsRef<Path> + Debug>(file_path: &T) -> Result<String, JailerError> {
258-
let mut file = OpenOptions::new()
259-
.read(true)
260-
.custom_flags(libc::O_NOFOLLOW)
261-
.open(file_path.as_ref())
262-
.map_err(|err| JailerError::ReadToString(PathBuf::from(file_path.as_ref()), err))?;
263-
let mut line = String::new();
264-
file.read_to_string(&mut line)
248+
let mut line = fs::read_to_string(file_path)
265249
.map_err(|err| JailerError::ReadToString(PathBuf::from(file_path.as_ref()), err))?;
266250

267251
// Remove the newline character at the end (if any).

0 commit comments

Comments
 (0)