-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
make runtime library loading safer #15040
Comments
I believe @Kimundi had some ideas here. |
Dynamic loading of non-Rust libraries can probably not be made safe in general because of missing type metadata, so I'll only talk about dynamically loaded Rust crates. Additionally, dynamically loaded crates and dynamically compiled crates (like produced by a jit compiler) both only start to exist at runtime and can get cleaned up, so I see this as an issue for any kind of native code with non- RequirementsIn an ideal world, you would have a safe way to dynamically load a library, use its symbols, and then afterwards unload the library again, likely implemented with some kind of RAAI scheme. The interface should be typesafe, which implies that communication between host executable and dynamic library can only happen through types known to both. And if should be memory safe, which implies that no dependencies on dynamically loaded code should escape the lifetime of the dynamic library. However, there are three problems that need to be solved for this to happen:
Possible solutions:
|
How about keeping track of all things related to the library and not allow unload until it is safe to do so? |
It's fundamentally impossible for runtime library loading to be safe. It can be made safer via verification of the metadata in the crate, but loading a library from a path dynamically will always be A library runs arbitrary initialization code upon loading, and nothing prevents the code from having invalid metadata or simply being memory unsafe. It would be trivial to bypass safety restrictions by outputting arbitrary code in a plugin and running it. |
Yes, of course the actual loading would be unsafe for obvious reasons, but On Tue, Oct 21, 2014 at 4:11 PM, Daniel Micay [email protected]
|
It can only be verified by a hash / signature if you load the entire thing into memory first and then somehow load it from there without touching the file again. It's never going to be appropriate to remove the |
I fail to see how dynamically loading a library manually is any more unsafe than dynamically loading a library by having it dynamically linked to from the beginning. In both cases there is a point where the compiler/usercode has to trust that the file being loaded does actually contain what is expected. |
Code trust issues aside, an operation certainly unsafe for the process image integrity is _un_loading of libraries. The problems and the per-platform variability here are such that all cross-platform programming environments I've seen that allow loading of arbitrary dynamic libraries have chosen to disable or discourage unloading. There hasn't been much demand for the feature either; memory is cheap, and in systems supporting dynamic libraries it is almost certainly virtually mapped. Being able to change parts of the program at runtime is neat, but I don't think it is compatible with what Rust is aimed to be otherwise. To be safely unloaded, a module and the program using it must ensure that none of the in-image data it adds to the process is referenced elsewhere. This extends to any dynamic libraries the module might be linked to as the single consumer in the process, because the libraries are unloaded together with it (any alternatives to this behavior are not portable to the best of my knowledge). Even if Rust provides a solution for safe code with lifetimes, I expect the issues with foreign libraries will be too numerous and hard to debug. Heaven help you if any of those libraries is in C++; implementations of language features there are not safe with regard to unloading. I think it best for everyone's sanity if the unload operation is kept unsafe, or not provided at all. This will remove the problem with soundness of |
Yeah, supporting unloading for arbitrary libraries is a tricky issue for sure. But I still think it could be made safe in controlled environments like Rust-only libraries explicitly compiled as unloadable plugins. |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#661 |
fix: Use a more obscure hasher name in derive expansion Closes rust-lang#15039
We currently have an interface for runtime library loading, using the dynamic linker, but it has the problem that it interacts poorly with name mangling and is entirely unsafe. Figure out how to make it type-safe, and preferably memory-safe too.
The text was updated successfully, but these errors were encountered: