You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It turns out that an inner static is only generated once. Hence if you have a generic function and the static somehow takes the generic type into account, the static will have the same address for all instantiations. Turns out this is a soundness problem with TLS:
$ rust run foo.rs
warning: no debug symbols in executable (-arch x86_64)
0x3ff0000000000000
1
Notably, the inner static foo has the same address each time the function foo is instantiated, hence k1 and k2 are the same value, so the first local_data::get is actually printing the hex representation of 1f.
Naturally this allows arbitrary coercion of types via TLS in safe code, this is a definite soundness issue.
You can't declare inner functions with the type parameters declared in outer functions, so perhaps the same rule should apply to statics as well? If not, then this is a codegen problem.
The text was updated successfully, but these errors were encountered:
Add lint recommending using `std::iter::once` and `std::iter::empty`
```
changelog: [`iter_once`]: add new lint
changelog: [`iter_empty`]: add new lint
```
fixesrust-lang#9186
- \[ ] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
The lint doesn't really follow the naming conventions. I don't have any better idea so I'm open to suggestions.
It turns out that an inner static is only generated once. Hence if you have a generic function and the static somehow takes the generic type into account, the static will have the same address for all instantiations. Turns out this is a soundness problem with TLS:
Notably, the inner static
foo
has the same address each time the functionfoo
is instantiated, hencek1
andk2
are the same value, so the firstlocal_data::get
is actually printing the hex representation of1f
.Naturally this allows arbitrary coercion of types via TLS in safe code, this is a definite soundness issue.
You can't declare inner functions with the type parameters declared in outer functions, so perhaps the same rule should apply to statics as well? If not, then this is a codegen problem.
The text was updated successfully, but these errors were encountered: