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

from_env causes io-unsafety in child processes #64

Open
the8472 opened this issue Dec 25, 2023 · 4 comments
Open

from_env causes io-unsafety in child processes #64

the8472 opened this issue Dec 25, 2023 · 4 comments

Comments

@the8472
Copy link
Member

the8472 commented Dec 25, 2023

(copied from rust-lang/rust#113730 (comment))

These lines seem questionable:

jobserver-rs/src/unix.rs

Lines 152 to 153 in b4bc5db

drop(set_cloexec(read, true));
drop(set_cloexec(write, true));

They lead the fds not being available to child processes by default (unless reverted by Client::configure) but from_env_ext() does not remove the environment variables. Which means child processes are instructed to access file descriptor numbers for jobserver communication that aren't open anymore and may have been reopened to point to other files. This seems like a violation of IO-safety (rust-lang/rust#116059 (comment)).

Either cloexec shouldn't be set or the environment variables should also be removed and only be added back via configure.

@NobodyXu
Copy link
Contributor

NobodyXu commented Dec 26, 2023

I think removing the env arg makes sense?

Since if you create a new jobserver, its fd is cloexec and there's no jobserver env setup.

@petrochenkov
Copy link
Contributor

I suspect that in a typical case you do want to pass the created or inherited jobserver to children processes.

In all cases caught by rust-lang/rust#113730 the right solution was to pass the jobserver further (except one case when it didn't matter much).

@petrochenkov
Copy link
Contributor

#65 is a draft PR that reverses the current behavior - jobserver is inherited by default, but the inheritance can be disabled by explicitly calling a method.

@NobodyXu
Copy link
Contributor

NobodyXu commented Mar 2, 2024

I think the best way to fix this is to use named fifo instead of annoymous pipe.

Passing pipe by fd also shares its file description, meaning whenever one process sets O_NONBLOCK it affects all the other processes.

I've got bitten by this the hard way in cc

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

No branches or pull requests

3 participants