Skip to content

Commit 2250a3f

Browse files
committed
overlay: chown()ing the upper dir: ignore EINVAL on overflow IDs
When chown()ing the upper directory to match the lower directory, if the ownership of the lower directory is the overflow UID:GID, ignore EINVAL. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent c283307 commit 2250a3f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkg/overlay/overlay_linux.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package overlay
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"path/filepath"
8+
"strconv"
79
"strings"
810
"syscall"
911

@@ -60,7 +62,22 @@ func MountWithOptions(contentDir, source, dest string, opts *Options) (mount spe
6062
}
6163
if stat, ok := st.Sys().(*syscall.Stat_t); ok {
6264
if err := os.Chown(upperDir, int(stat.Uid), int(stat.Gid)); err != nil {
63-
return mount, err
65+
if !errors.Is(err, syscall.EINVAL) {
66+
return mount, err
67+
}
68+
overflowed := false
69+
overflowUIDText, uerr := os.ReadFile("/proc/sys/kernel/overflowuid")
70+
overflowGIDText, gerr := os.ReadFile("/proc/sys/kernel/overflowgid")
71+
if uerr == nil && gerr == nil {
72+
overflowUID, uerr := strconv.Atoi(strings.TrimSpace(string(overflowUIDText)))
73+
overflowGID, gerr := strconv.Atoi(strings.TrimSpace(string(overflowGIDText)))
74+
if uerr == nil && gerr == nil && int(stat.Uid) == overflowUID && int(stat.Gid) == overflowGID {
75+
overflowed = true
76+
}
77+
}
78+
if !overflowed {
79+
return mount, err
80+
}
6481
}
6582
times := []syscall.Timespec{
6683
stat.Atim,

0 commit comments

Comments
 (0)