mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libct: skip mount for duplicate masked paths
Co-authored-by: Davanum Srinivas <davanum@gmail.com> Refactored-by: lifubang <lifubang@acmcoder.com> Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
@@ -1346,6 +1346,7 @@ func maskPaths(paths []string, mountLabel string) error {
|
||||
procSelfFd, closer := utils.ProcThreadSelf("fd/")
|
||||
defer closer()
|
||||
|
||||
maskedPaths := make(map[string]struct{})
|
||||
for _, path := range paths {
|
||||
// Open the target path; skip if it doesn't exist.
|
||||
dstFh, err := os.OpenFile(path, unix.O_PATH|unix.O_CLOEXEC, 0)
|
||||
@@ -1360,6 +1361,14 @@ func maskPaths(paths []string, mountLabel string) error {
|
||||
dstFh.Close()
|
||||
return fmt.Errorf("can't mask path %q: %w", path, err)
|
||||
}
|
||||
// skip duplicate masked paths.
|
||||
cleanPath := pathrs.LexicallyCleanPath(path)
|
||||
if _, ok := maskedPaths[cleanPath]; ok {
|
||||
dstFh.Close()
|
||||
continue
|
||||
}
|
||||
maskedPaths[cleanPath] = struct{}{}
|
||||
|
||||
var dstType string
|
||||
if st.IsDir() {
|
||||
// Destination is a directory: bind mount a ro tmpfs over it.
|
||||
|
||||
Reference in New Issue
Block a user