Skip to content

Commit fa52df9

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

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
@@ -698,7 +698,7 @@ next:
698698
return nil, err
699699
}
700700
if d.FileMode != nil {
701-
filemode = *d.FileMode
701+
filemode = *d.FileMode &^ unix.S_IFMT
702702
}
703703
device := &devices.Device{
704704
Rule: devices.Rule{

0 commit comments

Comments
 (0)