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

validate: enhance linux devices validation #297

Merged

Conversation

Mashimiao
Copy link

@Mashimiao Mashimiao commented Dec 30, 2016

duplicated device path is invalid
duplicated major:minor is not recommended

Signed-off-by: Ma Shimiao mashimiao.fnst@cn.fujitsu.com

@wking
Copy link
Contributor

wking commented Jan 3, 2017 via email

@Mashimiao
Copy link
Author

Mashimiao commented Jan 4, 2017 via email

@Mashimiao Mashimiao force-pushed the validate-enhance-devices-validation branch from 9ce30fb to 109462a Compare January 4, 2017 02:46
@mrunalp
Copy link
Contributor

mrunalp commented Jan 4, 2017

@Mashimiao I think it should be clarified in the spec first.

@wking
Copy link
Contributor

wking commented Jan 4, 2017 via email

@Mashimiao
Copy link
Author

Try to fix runtime-spec at 647

@Mashimiao
Copy link
Author

@wking @mrunalp @hqhq @liangchenye
As spec has been fixed, I think we can continue reviewing this PR.

devList[device.Path] = true
}
devId := fmt.Sprintf("%d:%d", device.Major, device.Minor)
if existId, exists := typeList[device.Type]; exists && existId == devId {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeList can also be a map[string]bool (used as a set, so the value doesn't matter). devId should be the typeList key and contain the type as well (normalizing u -> c).

@Mashimiao
Copy link
Author

Mashimiao commented Jan 13, 2017 via email

@wking
Copy link
Contributor

wking commented Jan 13, 2017

u and c are synonyms.

@Mashimiao Mashimiao force-pushed the validate-enhance-devices-validation branch from cc3f4be to 02bb004 Compare January 13, 2017 05:17
@Mashimiao
Copy link
Author

Mashimiao commented Jan 13, 2017 via email

} else {
devId = fmt.Sprintf("%s:%d:%d", device.Type, device.Major, device.Minor)
}
if _, exists := devList[devId]; exists {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you're using devList with two types of keys: device.Path and devId. While the risk of collision is low, I'd rather have two separate maps (devPaths and devIds?) just to be safe.

@Mashimiao Mashimiao force-pushed the validate-enhance-devices-validation branch from 02bb004 to d1b9a5d Compare January 13, 2017 05:32
@Mashimiao
Copy link
Author

Mashimiao commented Jan 13, 2017 via email

msgs = append(msgs, fmt.Sprintf("device %s is duplicated", device.Path))
} else {
devList[device.Path] = true
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it applies to

If a [file][file.1] already exists at path that does not match the requested device, the runtime MUST generate an error.

correctly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As duplicated devices make no sense, unmatched device is not allowed, no matter what they are, if the path is duplicated, tell user this is not valid I think it's acceptable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if path is not duplicated, but the path already exists in container filesystem and does not match the requested device?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really a problem. updated. PTAL

@Mashimiao Mashimiao force-pushed the validate-enhance-devices-validation branch from d1b9a5d to b473c76 Compare February 9, 2017 09:56
msgs = append(msgs, err.Error())
} else {
msgs = append(msgs, fmt.Sprintf("%s already exists in filesystem", device.Path))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a [file][file.1] already exists at path that does not match the requested device, the runtime MUST generate an error.

I think it means if the specified path exists in container filesystem, and it matches the requested device (same type, major and minor), that should be taken as valid case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wking @hqhq I think SPEC does not clearly rule Mounts should be applied first or Devices should be applied fist. And from runc's code, Mounts are applied first.
Then, there will be a problem. If we want to create device /dev/test, and though a unmatched /dev/test already exists in filesystem, mount may bind a valid /dev/test as we wanted.
I think we'd better just validate duplicate device problem and skip unmatched device problem
How do you think about it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think SPEC does not clearly rule Mounts should be applied first or Devices should be applied fist. And from runc's code, Mounts are applied first.

It's implementation details which spec should not define, as long as we define device path to be path in container, implementations would have to mount first.

If we want to create device /dev/test, and though a unmatched /dev/test already exists in filesystem, mount may bind a valid /dev/test as we wanted.

Bind mount would cover what already in the filesystem, I think that's intentional, device check doesn't have to care about what mounts have done, but what we have at that moment in the filesystem when we do validation.

duplicated device path is invalid
duplicated type and major:minor is not recommended

Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
@Mashimiao
Copy link
Author

Mashimiao commented Feb 13, 2017 via email

@hqhq
Copy link
Contributor

hqhq commented Feb 13, 2017

With mounts, the bundle may can be run well and it's a valid bundle.
But we would say it's invalid.

We really don't have much to do if mounts are gonna mess container filesystem, or are you suggesting we remove If a [file][file.1] already exists at path that does not match the requested device, the runtime MUST generate an error. from spec?

@Mashimiao Mashimiao force-pushed the validate-enhance-devices-validation branch from b473c76 to 11481b1 Compare February 14, 2017 01:20
@Mashimiao
Copy link
Author

Mashimiao commented Feb 14, 2017 via email

Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
@Mashimiao Mashimiao force-pushed the validate-enhance-devices-validation branch from 11481b1 to 119353e Compare February 14, 2017 01:24
@Mashimiao Mashimiao modified the milestone: 0.6 Apr 11, 2017
@Mashimiao
Copy link
Author

ping @opencontainers/runtime-tools-maintainers

}

if _, exists := typeList[devID]; exists {
logrus.Warnf("type:%s, major:%d and minor:%d for linux devices is duplicated", device.Type, device.Major, device.Minor)
Copy link
Contributor

@wking wking Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good reason to bring in the RFC 2119 errors from #354. But if you'd rather leave it alone until someone else adds it to the validate command, that's fine too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many other places need it, let's leave it for a follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, RFC2119 erros could come in the following PRs.

@liangchenye
Copy link
Member

liangchenye commented Aug 8, 2017

LGTM

Approved with PullApprove

1 similar comment
@zhouhao3
Copy link

zhouhao3 commented Aug 14, 2017

LGTM

Approved with PullApprove

@zhouhao3 zhouhao3 merged commit bcf89dd into opencontainers:master Aug 14, 2017
@Mashimiao Mashimiao removed this from the v0.6.0 milestone Sep 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants