Skip to content

Commit 6092a4b

Browse files
committed
fix some file mode bits missing when doing mount syscall
Signed-off-by: lifubang <[email protected]>
1 parent dbe8434 commit 6092a4b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

libcontainer/mount_linux.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package libcontainer
22

33
import (
4+
"io/fs"
45
"strconv"
56

67
"golang.org/x/sys/unix"
@@ -103,3 +104,20 @@ func unmount(target string, flags int) error {
103104
}
104105
return nil
105106
}
107+
108+
// syscallMode returns the syscall-specific mode bits from Go's portable mode bits.
109+
// Copy from https://cs.opensource.google/go/go/+/refs/tags/go1.20.7:src/os/file_posix.go;l=61-75
110+
func syscallMode(i fs.FileMode) (o uint32) {
111+
o |= uint32(i.Perm())
112+
if i&fs.ModeSetuid != 0 {
113+
o |= unix.S_ISUID
114+
}
115+
if i&fs.ModeSetgid != 0 {
116+
o |= unix.S_ISGID
117+
}
118+
if i&fs.ModeSticky != 0 {
119+
o |= unix.S_ISVTX
120+
}
121+
// No mapping for Go's ModeTemporary (plan9 only).
122+
return
123+
}

libcontainer/rootfs_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
462462
return err
463463
}
464464
} else {
465-
dt := fmt.Sprintf("mode=%04o", stat.Mode())
465+
dt := fmt.Sprintf("mode=%04o", syscallMode(stat.Mode()))
466466
if m.Data != "" {
467467
dt = dt + "," + m.Data
468468
}

0 commit comments

Comments
 (0)