rust-lang / jobserver-rs

Apache License 2.0
69 stars 40 forks source link

unix: Check that file descriptors obtained from `--jobserver-auth=R,W` actually refer to a pipe #27

Closed petrochenkov closed 3 years ago

petrochenkov commented 4 years ago

cargo and rustc (and other tools using jobserver) will fail with a "failed to acquire jobserver token: early EOF on jobserver pipe" error in the next scenario reported in https://github.com/rust-lang/rust/issues/46981#issuecomment-681090839 as ICE in rustc:

jobserver could be more resilient in the face of garbage descriptors if it checked not only that the descriptors are valid, but also that they actually refer to a pipe rather than random unrelated files.

alexcrichton commented 4 years ago

Currently there's a check that the fd is at leaset least a valid file descriptor, and adding another check there that it's a pipe makes sense to me!

petrochenkov commented 4 years ago

Sigh, the is_pipe logic was implemented originally, but then replaced with is_valid_fd in https://github.com/alexcrichton/jobserver-rs/pull/6. cc @ishitatsuyuki

ishitatsuyuki commented 4 years ago

I'm totally OK with reverting that change, as I have found that a socket wouldn't be any useful for jobservers.

It does make me wonder that make has the same checking logic but doesn't get affected. Not sure what's going on, but maybe submake gets some special treatment?

petrochenkov commented 4 years ago

@ishitatsuyuki Submake does get a special treatment, because the jobserver pipe is still open for it, so submake can inherit it. I'll try to check what happens if nested make gets garbage (but open) descriptors and tries to read from them, from source code it looks like it should fail with a fatal error, similarly to cargo.

petrochenkov commented 3 years ago

Ok, I think it's better to be consistent with make and keep the current behavior, so I'll close this issue.

However, what needs to be done is a better diagnostic in the erroneous cases.

To do this the jobserver crate needs to produce slightly more detailed error types from from_env and acquire than it does now. I'll try to prototype these improvements for rustc and make a PR.