Skip to content

Commit

Permalink
Merge pull request #2804 from Iceber/filemode
Browse files Browse the repository at this point in the history
libcontainer: fix the file mode of the device
  • Loading branch information
kolyshkin authored Feb 22, 2021
2 parents f245a1d + fa52df9 commit ee06c70
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion libcontainer/devices/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
Permissions: Permissions(permissions),
},
Path: path,
FileMode: os.FileMode(mode),
FileMode: os.FileMode(mode &^ unix.S_IFMT),
Uid: stat.Uid,
Gid: stat.Gid,
}, nil
Expand Down
11 changes: 1 addition & 10 deletions libcontainer/devices/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,13 @@ func TestHostDevicesAllValid(t *testing.T) {
if device.Major == 0 {
t.Errorf("device entry %+v has zero major number", device)
}
// Devices should only have file modes that correspond to their type.
var expectedType os.FileMode
switch device.Type {
case BlockDevice:
expectedType = unix.S_IFBLK
case CharDevice:
expectedType = unix.S_IFCHR
case BlockDevice, CharDevice:
case FifoDevice:
t.Logf("fifo devices shouldn't show up from HostDevices")
fallthrough
default:
t.Errorf("device entry %+v has unexpected type %v", device, device.Type)
}
gotType := device.FileMode & unix.S_IFMT
if expectedType != gotType {
t.Errorf("device entry %+v has mismatched types (expected %#x, got %#x)", device, expectedType, gotType)
}
}
}
2 changes: 1 addition & 1 deletion libcontainer/specconv/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ next:
return nil, err
}
if d.FileMode != nil {
filemode = *d.FileMode
filemode = *d.FileMode &^ unix.S_IFMT
}
device := &devices.Device{
Rule: devices.Rule{
Expand Down

0 comments on commit ee06c70

Please sign in to comment.