Skip to content

Commit c41981d

Browse files
committed
overlay: scope ID map contiguity check to mountProgram
The contiguity of ID mappings is a requirement for fuse-overlayfs, do not impose it for the native kernel driver. Closes: #2345 Closes: https://issues.redhat.com/browse/RHEL-94967 Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 53c5b70 commit c41981d

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

drivers/overlay/overlay.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,16 +2555,18 @@ func (d *Driver) supportsIDmappedMounts() bool {
25552555

25562556
// SupportsShifting tells whether the driver support shifting of the UIDs/GIDs to the provided mapping in an userNS
25572557
func (d *Driver) SupportsShifting(uidmap, gidmap []idtools.IDMap) bool {
2558-
if !idtools.IsContiguous(uidmap) {
2559-
return false
2560-
}
2561-
if !idtools.IsContiguous(gidmap) {
2562-
return false
2563-
}
25642558
if os.Getenv("_CONTAINERS_OVERLAY_DISABLE_IDMAP") == "yes" {
25652559
return false
25662560
}
25672561
if d.options.mountProgram != "" {
2562+
// fuse-overlayfs supports only contiguous mappings, since it performs the mapping on the
2563+
// upper layer too, to avoid https://github.com/containers/podman/issues/10272
2564+
if !idtools.IsContiguous(uidmap) {
2565+
return false
2566+
}
2567+
if !idtools.IsContiguous(gidmap) {
2568+
return false
2569+
}
25682570
return true
25692571
}
25702572
return d.supportsIDmappedMounts()

drivers/overlay/overlay_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
graphdriver "github.com/containers/storage/drivers"
1010
"github.com/containers/storage/drivers/graphtest"
1111
"github.com/containers/storage/pkg/archive"
12+
"github.com/containers/storage/pkg/idtools"
1213
"github.com/containers/storage/pkg/reexec"
1314
"github.com/stretchr/testify/assert"
1415
"github.com/stretchr/testify/require"
@@ -52,6 +53,45 @@ func TestContainersOverlayXattr(t *testing.T) {
5253
assert.Equal(t, 0o555&os.ModePerm, fi.Mode()&os.ModePerm, root)
5354
}
5455

56+
func TestSupportsShifting(t *testing.T) {
57+
contiguousMap := []idtools.IDMap{
58+
{
59+
ContainerID: 0,
60+
HostID: 1000,
61+
Size: 65536,
62+
},
63+
}
64+
nonContiguousMap := []idtools.IDMap{
65+
{
66+
ContainerID: 0,
67+
HostID: 0,
68+
Size: 1,
69+
},
70+
{
71+
ContainerID: 2,
72+
HostID: 2,
73+
Size: 1,
74+
},
75+
}
76+
77+
t.Run("no mount program", func(t *testing.T) {
78+
driver := graphtest.GetDriver(t, driverName)
79+
80+
supported := driver.SupportsShifting(nil, nil)
81+
assert.Equal(t, supported, driver.SupportsShifting(contiguousMap, contiguousMap), "contiguous map with no mount program")
82+
assert.Equal(t, supported, driver.SupportsShifting(nonContiguousMap, nonContiguousMap), "non-contiguous map with no mount program")
83+
})
84+
85+
t.Run("with mount program", func(t *testing.T) {
86+
driver := graphtest.GetDriver(t, driverName, "mount_program=/usr/bin/true")
87+
88+
assert.True(t, driver.SupportsShifting(nil, nil), "nil map with mount program")
89+
assert.True(t, driver.SupportsShifting(contiguousMap, contiguousMap), "contiguous map with mount program")
90+
// If a mount program is specified, SupportsShifting must return false
91+
assert.False(t, driver.SupportsShifting(nonContiguousMap, nonContiguousMap), "non-contiguous map with mount program")
92+
})
93+
}
94+
5595
// This avoids creating a new driver for each test if all tests are run
5696
// Make sure to put new tests between TestOverlaySetup and TestOverlayTeardown
5797
func TestOverlaySetup(t *testing.T) {

0 commit comments

Comments
 (0)