diff --git a/devices/device_unix.go b/devices/device_unix.go index bd401d3b..58c5c9ae 100644 --- a/devices/device_unix.go +++ b/devices/device_unix.go @@ -100,7 +100,8 @@ func GetDevices(path string) ([]*config.Device, error) { switch f.Name() { // ".lxc" & ".lxd-mounts" added to address https://github.com/lxc/lxd/issues/2825 // ".udev" added to address https://github.com/opencontainers/runc/issues/2093 - case "pts", "shm", "fd", "mqueue", ".lxc", ".lxd-mounts", ".udev": + // ".incus-mounts" added to address https://github.com/moby/sys/issues/260 + case "pts", "shm", "fd", "mqueue", ".lxc", ".lxd-mounts", ".udev", ".incus-mounts": continue default: sub, err := GetDevices(filepath.Join(path, f.Name())) diff --git a/devices/device_unix_test.go b/devices/device_unix_test.go index 262671c0..1bbee973 100644 --- a/devices/device_unix_test.go +++ b/devices/device_unix_test.go @@ -26,6 +26,7 @@ import ( "errors" "io/fs" "os" + "path/filepath" "runtime" "testing" @@ -120,3 +121,44 @@ func TestHostDevicesAllValid(t *testing.T) { } } } + +type namedDir struct { + name string +} + +func (d namedDir) Name() string { return d.name } +func (d namedDir) IsDir() bool { return true } +func (d namedDir) Type() fs.FileMode { return fs.ModeDir } +func (d namedDir) Info() (fs.FileInfo, error) { return nil, errors.New("unused") } + +func TestGetDevicesSkipsIncusMounts(t *testing.T) { + t.Cleanup(cleanupTest) + + for _, tc := range []struct { + name string + wantErr bool + }{ + {name: ".incus-mounts"}, + {name: "private", wantErr: true}, + } { + t.Run(tc.name, func(t *testing.T) { + osReadDir = func(dirname string) ([]fs.DirEntry, error) { + if filepath.Base(dirname) == tc.name { + return nil, os.ErrPermission + } + return []fs.DirEntry{namedDir{name: tc.name}}, nil + } + + _, err := GetDevices("/dev") + if tc.wantErr { + if !errors.Is(err, os.ErrPermission) { + t.Fatalf("got %v, want permission", err) + } + return + } + if err != nil { + t.Fatalf("GetDevices: %v", err) + } + }) + } +}