Skip to content

Commit c839707

Browse files
pb8oShadowCurse
authored andcommitted
chore(jailer): drop code supporting Linux 4.14
Remove code to support Linux 4.14. Firecracker/Jailer will only work with kernel 5.10 and above. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 80ff4a1 commit c839707

File tree

2 files changed

+3
-49
lines changed

2 files changed

+3
-49
lines changed

src/cpu-template-helper/src/fingerprint/dump.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ pub fn dump(vmm: Arc<Mutex<Vmm>>) -> Result<Fingerprint, FingerprintDumpError> {
3131
"/sys/devices/system/cpu/cpu0/regs/identification/revidr_el1",
3232
)?,
3333
bios_version: read_sysfs_file("/sys/devices/virtual/dmi/id/bios_version")?,
34-
// TODO: Replace this with `read_sysfs_file("/sys/devices/virtual/dmi/id/bios_release")`
35-
// after the end of kernel 4.14 support.
36-
// https://github.com/firecracker-microvm/firecracker/issues/3677
37-
bios_revision: run_shell_command(
38-
"set -o pipefail && dmidecode -t bios | grep \"BIOS Revision\" | cut -d':' -f2 | tr \
39-
-d ' \\n'",
40-
)?,
34+
bios_revision: read_sysfs_file("/sys/devices/virtual/dmi/id/bios_release")?,
4135
guest_cpu_config: crate::template::dump::dump(vmm)?,
4236
})
4337
}

src/jailer/src/main.rs

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

44
use std::ffi::{CString, NulError, OsString};
55
use std::fmt::{Debug, Display};
6-
use std::os::unix::prelude::AsRawFd;
76
use std::path::{Path, PathBuf};
87
use std::{env as p_env, fs, io};
98

@@ -261,44 +260,10 @@ fn close_fds_by_close_range() -> Result<(), JailerError> {
261260
.map_err(JailerError::CloseRange)
262261
}
263262

264-
fn close_fds_by_reading_proc() -> Result<(), JailerError> {
265-
// Calling this method means that close_range failed (we might be on kernel < 5.9).
266-
// We can't use std::fs::ReadDir here as under the hood we need access to the dirfd in order to
267-
// not close it twice
268-
let path = "/proc/self/fd";
269-
let mut dir = nix::dir::Dir::open(
270-
path,
271-
nix::fcntl::OFlag::O_DIRECTORY | nix::fcntl::OFlag::O_NOATIME,
272-
nix::sys::stat::Mode::empty(),
273-
)
274-
.map_err(|e| JailerError::DirOpen(path.to_string(), e.to_string()))?;
275-
276-
let dirfd = dir.as_raw_fd();
277-
let mut c = dir.iter();
278-
279-
while let Some(Ok(path)) = c.next() {
280-
let file_name = path.file_name();
281-
let fd_str = file_name.to_str().map_err(JailerError::UTF8Parsing)?;
282-
283-
// If the entry is an INT entry, we go ahead and we treat it as an FD identifier.
284-
if let Ok(fd) = fd_str.parse::<i32>() {
285-
if fd > 2 && fd != dirfd {
286-
// SAFETY: Safe because close() cannot fail when passed a valid parameter.
287-
unsafe { libc::close(fd) };
288-
}
289-
}
290-
}
291-
Ok(())
292-
}
293-
294263
// Closes all FDs other than 0 (STDIN), 1 (STDOUT) and 2 (STDERR)
295264
fn close_inherited_fds() -> Result<(), JailerError> {
296-
// The approach we take here is to firstly try to use the close_range syscall
297-
// which is available on kernels > 5.9.
298-
// We then fallback to using /proc/sef/fd to close open fds.
299-
if close_fds_by_close_range().is_err() {
300-
close_fds_by_reading_proc()?;
301-
}
265+
// We use the close_range syscall which is available on kernels > 5.9.
266+
close_fds_by_close_range()?;
302267
Ok(())
303268
}
304269

@@ -439,11 +404,6 @@ mod tests {
439404
}
440405
}
441406

442-
#[test]
443-
fn test_fds_proc() {
444-
run_close_fds_test(close_fds_by_reading_proc);
445-
}
446-
447407
#[test]
448408
fn test_sanitize_process() {
449409
run_close_fds_test(sanitize_process);

0 commit comments

Comments
 (0)