From 607a892f2e3e6e19109bf51969f0e459483aaa7c Mon Sep 17 00:00:00 2001 From: "fupan.lfp" Date: Wed, 6 Jan 2021 16:05:49 +0800 Subject: [PATCH] rustjail: fix the issue of bind mount /dev In case the container rootfs's /dev was overrided by binding mount from another directory, then there's no need to create the default devices nodes and symlinks in /dev. Fixes: #692 Signed-off-by: fupan.lfp --- src/agent/rustjail/src/mount.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/agent/rustjail/src/mount.rs b/src/agent/rustjail/src/mount.rs index 1942fcc5b8..5f4c9e26d3 100644 --- a/src/agent/rustjail/src/mount.rs +++ b/src/agent/rustjail/src/mount.rs @@ -185,6 +185,7 @@ pub fn init_rootfs( None::<&str>, )?; + let mut bind_mount_dev = false; for m in &spec.mounts { let (mut flags, data) = parse_mount(&m); if !m.destination.starts_with("/") || m.destination.contains("..") { @@ -198,6 +199,9 @@ pub fn init_rootfs( mount_cgroups(cfd_log, &m, rootfs, flags, &data, cpath, mounts)?; } else { if m.destination == "/dev" { + if m.r#type == "bind" { + bind_mount_dev = true; + } flags &= !MsFlags::MS_RDONLY; } @@ -239,9 +243,14 @@ pub fn init_rootfs( let olddir = unistd::getcwd()?; unistd::chdir(rootfs)?; - default_symlinks()?; - create_devices(&linux.devices, bind_device)?; - ensure_ptmx()?; + // in case the /dev directory was binded mount from guest, + // then there's no need to create devices nodes and symlinks + // in /dev. + if !bind_mount_dev { + default_symlinks()?; + create_devices(&linux.devices, bind_device)?; + ensure_ptmx()?; + } unistd::chdir(&olddir)?;