-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Thread names are not always valid UTF-8 #123495
Comments
Ooph, yeah. I messed up there by only upholding that it was a
That indeed would be great. |
I'm actually thinking it might be better to just do a straight up revert. Hm. |
If it's not immediately dawning on us, I think we should revert it and figure out the correct behavior later, yes. |
This reverts rust-lang#121666 due to rust-lang#123495
Ok, I put up a revert PR. |
…ngjubilee Revert "Use OS thread name by default" This reverts rust-lang#121666 (Use the OS thread name by default if `THREAD_INFO` has not been initialized) due to rust-lang#123495 (Thread names are not always valid UTF-8). It's not a direct revert because there have been other changes since that PR.
…ngjubilee Revert "Use OS thread name by default" This reverts rust-lang#121666 (Use the OS thread name by default if `THREAD_INFO` has not been initialized) due to rust-lang#123495 (Thread names are not always valid UTF-8). It's not a direct revert because there have been other changes since that PR.
Rollup merge of rust-lang#123505 - ChrisDenton:revert-121666, r=workingjubilee Revert "Use OS thread name by default" This reverts rust-lang#121666 (Use the OS thread name by default if `THREAD_INFO` has not been initialized) due to rust-lang#123495 (Thread names are not always valid UTF-8). It's not a direct revert because there have been other changes since that PR.
This reverts rust-lang#121666 due to rust-lang#123495 This has already been done on master but beta needs something that will backport cleanly.
This reverts rust-lang#121666 due to rust-lang#123495 This has already been done on master but beta needs something that will backport cleanly. (cherry picked from commit 081ad85)
Thread
(or wellInner
) has the following invariant:rust/library/std/src/thread/mod.rs
Line 1252 in d009f60
and relies on it for soundness:
rust/library/std/src/thread/mod.rs
Line 1413 in d009f60
Starting with #121666, this invariant can be broken, because the native thread names are not required to be UTF-8. So for example, this code is unsound:
(run with miri and
--target x86_64-unknown-linux-gnu
)This can even be exploited in entirely safe code. On platforms with key-based thread locals, the
Thread
handle is initialized with the system thread name when accessed in TLS destructors. On all UNIXes except macOS, the main thread name is the name of the program. So if you spawn a program with a bad name on these platforms (e.g. Illumos), callingthread::current().name()
will cause UB.We can fix this by checking the thread name in
Thread::new
, and not using it if it is bad. In the long-term, a function likeos_name
might be nice and perhaps fix some other issues as well.CC @ChrisDenton
The text was updated successfully, but these errors were encountered: