Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcontainer: fix the file mode of the device #2804

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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