Skip to content

Commit f4eebb1

Browse files
[cexec] Bind mount existing sources:
Instead of creating new mounts from special filesystems for the chroot, we bind mount the existing locations for /dev, /sys, /proc. Creating a new mount point using devtmpfs is not recommended as it can cause issues and conflicts with /dev. Especially when we created the devtmpfs mount point as read only. This caused the host system's /dev to change to read only as well. Signed-off-by: Jacob Weinstock <[email protected]>
1 parent 6861e4a commit f4eebb1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cexec/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,24 @@ func chroot(path string) (func() error, error) {
225225

226226
// mountSpecialDirs ensures that /dev /proc /sys /etc/resolv.conf exist in the chroot.
227227
func (s settings) mountSpecialDirs(path string) error {
228+
if path == "" {
229+
return errors.New("mount path cannot be empty")
230+
}
228231
// Mount dev
229232
dev := filepath.Join(path, "dev")
230-
if err := syscall.Mount("none", dev, "devtmpfs", syscall.MS_RDONLY, ""); err != nil {
233+
if err := syscall.Mount("/dev", dev, "", syscall.MS_BIND, ""); err != nil {
231234
return fmt.Errorf("couldn't mount /dev to %v: %w", dev, err)
232235
}
233236

234237
// Mount proc
235238
proc := filepath.Join(path, "proc")
236-
if err := syscall.Mount("none", proc, "proc", syscall.MS_RDONLY, ""); err != nil {
239+
if err := syscall.Mount("/proc", proc, "", syscall.MS_BIND, ""); err != nil {
237240
return fmt.Errorf("couldn't mount /proc to %v: %w", proc, err)
238241
}
239242

240243
// Mount sys
241244
sys := filepath.Join(path, "sys")
242-
if err := syscall.Mount("none", sys, "sysfs", syscall.MS_RDONLY, ""); err != nil {
245+
if err := syscall.Mount("/sys", sys, "", syscall.MS_BIND, ""); err != nil {
243246
return fmt.Errorf("couldn't mount /sys to %v: %w", sys, err)
244247
}
245248

0 commit comments

Comments
 (0)