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 check of statx and handle EPERM #65685

Merged
merged 2 commits into from
Oct 25, 2019
Merged

Conversation

oxalica
Copy link
Contributor

@oxalica oxalica commented Oct 22, 2019

Should fix #65662

#65662 (comment)

I think a reasonable solution might be to do something like try to stat AT_CWD initially and if that fails with EPERM or ENOSYS we disable the syscall entirely, otherwise it's cached as always good to use.

r? @alexcrichton

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2019
@lnicola
Copy link
Member

lnicola commented Oct 22, 2019

I suppose a micro-optimization would be to only do the AT_CWD check if it fails for the argument, but maybe it's not worth it.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks great to me, thanks again for helping to handle this @oxalica!

.err()
.and_then(|e| e.raw_os_error());
// `seccomp` will emit `EPERM` on denied syscall.
// See: https://github.com/rust-lang/rust/issues/65662
Copy link
Member

Choose a reason for hiding this comment

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

Could this expand the comment inline to explain why EPERM is handled specially and why we attempt to stat a "known good" location, along with the pitfalls of this could still return a false negative?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... along with the pitfalls of this could still return a false negative?

Will it? The manual said it never returns EPERM. So it should be the only case.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps! I've come to not trust man pages on errors though, they basically never describe the exhaustive set of errors, only some possible ones.

src/libstd/sys/unix/fs.rs Outdated Show resolved Hide resolved
_ => {
let mut buf: libc::statx = mem::zeroed();
if let Err(err) = cvt(statx(fd, path, flags, mask, &mut buf)) {
return Some(Err(err));
Copy link
Member

Choose a reason for hiding this comment

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

Although not part of this PR, it might be nice to change this to return io::Result<Option<FileAttr>> to use ? here instead of if let

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, Ok(None) for "unavailable" seems weird to me...
Option<Result<T>> is for the syscall may be unavailable, or available with a result.

Changing the type does not simplify much more code. Instead, we need an extra ? after every calls below.

src/libstd/sys/unix/fs.rs Outdated Show resolved Hide resolved
@rust-highfive
Copy link
Collaborator

Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-22T19:53:44.6812391Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-10-22T19:53:44.7000920Z ##[command]git config gc.auto 0
2019-10-22T19:53:44.7081513Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-10-22T19:53:44.7140390Z ##[command]git config --get-all http.proxy
2019-10-22T19:53:45.5040678Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65685/merge:refs/remotes/pull/65685/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@alexcrichton
Copy link
Member

@bors: r+

Looks good to me!

@bors
Copy link
Contributor

bors commented Oct 22, 2019

📌 Commit 10f1bc7 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Oct 22, 2019

🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 22, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 25, 2019
Fix check of `statx` and handle EPERM

Should fix rust-lang#65662

rust-lang#65662 (comment)
> I think a reasonable solution might be to do something like try to stat AT_CWD initially and if that fails with EPERM or ENOSYS we disable the syscall entirely, otherwise it's cached as always good to use.

r? @alexcrichton
Centril added a commit to Centril/rust that referenced this pull request Oct 25, 2019
Fix check of `statx` and handle EPERM

Should fix rust-lang#65662

rust-lang#65662 (comment)
> I think a reasonable solution might be to do something like try to stat AT_CWD initially and if that fails with EPERM or ENOSYS we disable the syscall entirely, otherwise it's cached as always good to use.

r? @alexcrichton
bors added a commit that referenced this pull request Oct 25, 2019
Rollup of 9 pull requests

Successful merges:

 - #64639 (Stabilize `#[non_exhaustive]` (RFC 2008))
 - #65074 (Fix the start/end byte positions in the compiler JSON output)
 - #65315 (Intern place projection)
 - #65685 (Fix check of `statx` and handle EPERM)
 - #65731 (Prevent unnecessary allocation in PathBuf::set_extension.)
 - #65740 (Fix default "disable-shortcuts" feature value)
 - #65787 (move panictry! to where it is used.)
 - #65789 (move Attribute::with_desugared_doc to librustdoc)
 - #65790 (move report_invalid_macro_expansion_item to item.rs)

Failed merges:

r? @ghost
@bors bors merged commit 10f1bc7 into rust-lang:master Oct 25, 2019
@oxalica oxalica deleted the statx-eperm branch January 1, 2020 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler doesn't work when using Docker
5 participants