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

Fix rights checks across the codebase. #770

Merged
merged 2 commits into from
Jan 9, 2020

Conversation

marmistrz
Copy link
Contributor

See the commit messages for a detailed description.

Obsoletes and closes #618. It was easier to manually port the commit than to fight merge conflicts and I didn't want to invalidate the discussions in that PR.

cc @kubkon @sunfishcode @peterhuene

@peterhuene peterhuene added wasi:impl Issues pertaining to WASI implementation in Wasmtime wasi:tests Issues pertaining to WASI tests in Wasmtime labels Jan 7, 2020
Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

LGTM but let's get the other requested reviewers eyes on it. Thanks!

Copy link
Member

@kubkon kubkon left a comment

Choose a reason for hiding this comment

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

LGTM! Just a couple of minor nits.

Do you guys think it would useful to add an assertion in each testcase that the (main) tested syscall fails without the required rights as expected? It's a loose thought that I don't intend we address in this PR, but perhaps we could in a subsequent PR.

};
// Since we no longer have the right to fd_read, trying to read a file
// should be an error.
wasi::fd_read(fd, &[iovec]).expect_err("reading bytes from file should fail");
Copy link
Member

Choose a reason for hiding this comment

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

Could you also test for the returned error value here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean that I should assert that the error code is precisely ENOTCAPABLE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 64 to 67
assert!(
wasi::fd_fdstat_set_rights(fd, new_base, new_inheriting).is_ok(),
"dropping fd rights",
);
}
Copy link
Member

Choose a reason for hiding this comment

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

You could probably make it a little clearer by using an expect rather than assert on Ok :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but then there will be no line info displayed in case of a panic. (I know that I'm using expect in other places but it's worth discussing)

Copy link
Member

Choose a reason for hiding this comment

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

Apropos of this: rust-lang/rust#67887 just landed, so this issue should go away once that makes its way to stable rust :-).

Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

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

This looks good to me too. Thanks for seeing this all the way through!

@@ -157,6 +157,10 @@ impl FdEntry {
) -> Result<()> {
if !self.rights_base & rights_base != 0 || !self.rights_inheriting & rights_inheriting != 0
{
log::trace!(
" | validate_rights failed: required: rights_base = {}, rights_inheriting = {}; actual: rights_base = {}, rights_inheriting = {}",
Copy link
Member

Choose a reason for hiding this comment

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

Can you log the rights as hex (#:x)? Also, would it make sense to log those rights which were required but not present, so that it's easy to see at a glance why a capability check failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@marmistrz marmistrz force-pushed the read-vuln2 branch 5 times, most recently from c44a861 to 9a2940b Compare January 9, 2020 16:09
* Fix path_open granting more rights than requested
* Add missing rights checks in: fd_fdstat_set_flags, fd_filestat_get, poll_oneoff
* Fix `open_scratch_directory` not requesting any rights.
* Properly request needed rights in various tests
* Add some extra trace-level logging
* Remove a no-op restriction of rights to the ones returned by
  `determine_type_rights`. It was redundant, because `FdEntry:from`
  internally also called `determine_type_rights` and only dropped some of them.
@sunfishcode sunfishcode merged commit f7f10c1 into bytecodealliance:master Jan 9, 2020
@sunfishcode
Copy link
Member

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi:impl Issues pertaining to WASI implementation in Wasmtime wasi:tests Issues pertaining to WASI tests in Wasmtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants