Skip to content

Commit 0641452

Browse files
committed
libcontainer: fix the file mode of the device
Signed-off-by: Iceber Gu <[email protected]>
1 parent 9f13653 commit 0641452

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

libcontainer/devices/devices.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
5454
Permissions: Permissions(permissions),
5555
},
5656
Path: path,
57-
FileMode: os.FileMode(mode),
57+
FileMode: os.FileMode(mode &^ unix.S_IFMT),
5858
Uid: stat.Uid,
5959
Gid: stat.Gid,
6060
}, nil

libcontainer/devices/devices_test.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,13 @@ func TestHostDevicesAllValid(t *testing.T) {
8282
if device.Major == 0 {
8383
t.Errorf("device entry %+v has zero major number", device)
8484
}
85-
// Devices should only have file modes that correspond to their type.
86-
var expectedType os.FileMode
8785
switch device.Type {
88-
case BlockDevice:
89-
expectedType = unix.S_IFBLK
90-
case CharDevice:
91-
expectedType = unix.S_IFCHR
86+
case BlockDevice, CharDevice:
9287
case FifoDevice:
9388
t.Logf("fifo devices shouldn't show up from HostDevices")
9489
fallthrough
9590
default:
9691
t.Errorf("device entry %+v has unexpected type %v", device, device.Type)
9792
}
98-
gotType := device.FileMode & unix.S_IFMT
99-
if expectedType != gotType {
100-
t.Errorf("device entry %+v has mismatched types (expected %#x, got %#x)", device, expectedType, gotType)
101-
}
10293
}
10394
}

libcontainer/specconv/spec_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ next:
707707
Minor: d.Minor,
708708
},
709709
Path: d.Path,
710-
FileMode: filemode,
710+
FileMode: filemode &^ unix.S_IFMT,
711711
Uid: uid,
712712
Gid: gid,
713713
}

0 commit comments

Comments
 (0)