-
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
in Windows x86, the symbol name generated by raw-dylib+undecorated
are not as expected
#124958
Comments
raw-dylib+undecorated
raw-dylib+undecorated
raw-dylib+undecorated
raw-dylib+undecorated
raw-dylib+undecorated
are not as expected
Why are you using |
Normally, the import_name_type attribute should not change the symbol name. You can check the "synchronization.lib" file of the Windows SDK, the info about
Then we look at the disassembly code when using WakeByAddressSingle, and we can see that the symbol name is still __imp__WakeByAddressSingle@4. Rust's behavior is not standard, and there are security issues. In another lib file, there happens to be such a function. Because of Rust's non-standard behavior, they will have exactly the same symbol names. This makes it impossible for the linker to distinguish between them, and the linker will only use the first symbol. In the following code, will rust use the
|
cc @dpaoliello for this and #124956 |
Can you please elaborate on this? If you are linking against a malicious import library or loading a malicious DLL, then name confusion doesn't provide any benefits to the attacker: they already have arbitrary read/write/execute and can use many other tricks to force their code to be executed.
This is a fair criticism, but we'd need to make sure that using
Can you please point me to documentation for this "standard" or "rule"? Also, the intent of
It calls You have shown that Rust produces different import headers than MSVC or Clang does, but you haven't explained why this is an issue. Please remember that the goal of the If you can show an example where Rust calls a function that does not match the name per the |
@dpaoliello MS decorated-names doc is here From the documentation, we can see that raw-dylib+undecorated's symbol name rules are flawed. For example, how should the following two functions be distinguished between rust? extern "C" void __stdcall _Test()
{
}
extern "C" void __cdecl Test()
{
} |
That document describes how to decorate names, but if you use We modeled the feature on the "name type" part of the PE spec, although we implemented this in Rust instead of relying on LLVM (something that I'd be willing to change, although with caution).
I think you are misunderstanding the purpose of this feature. It is not intended to be used all the time for all imports, it is very specifically designed to import functions where the exported name isn't decorated as Rust would normally expect. So, if you can tell me how those two functions are exported, then I can tell you what Examples like this and the original one in your issue are not useful - you need to show where this feature does not meet the behavior documented in Rust's docs, not where it doesn't meet your expectations. If you believe the documented behavior is incorrect, please file an MCP with the behavior that you'd recommend. |
Triage: changing this to |
Given the issue linked directly above it seems like this is an issue, at least for Firefox. |
Working on a fix... |
If we're at it, would it make sense to mangle the symbol name using the regular rust symbol mangling too? We do this for wasm imports too ( rust/compiler/rustc_symbol_mangling/src/lib.rs Lines 191 to 204 in 749f80a
|
Set "symbol name" in raw-dylib import libraries to the decorated name `windows-rs` received a bug report that mixing raw-dylib generated and the Windows SDK import libraries was causing linker failures: <microsoft/windows-rs#3285> The root cause turned out to be rust-lang#124958, that is we are not including the decorated name in the import library and so the import name type is also not being correctly set. This change modifies the generation of import libraries to set the "symbol name" to the fully decorated name and correctly marks the import as being data vs function. Note that this also required some changes to how the symbol is named within Rust: for MSVC we now need to use the decorated name but for MinGW we still need to use partially decorated (or undecorated) name. Fixes rust-lang#124958 Passing i686 MSVC and MinGW build: <https://github.com/rust-lang/rust/actions/runs/11000433888?pr=130586> r? `@ChrisDenton`
Set "symbol name" in raw-dylib import libraries to the decorated name `windows-rs` received a bug report that mixing raw-dylib generated and the Windows SDK import libraries was causing linker failures: <microsoft/windows-rs#3285> The root cause turned out to be rust-lang#124958, that is we are not including the decorated name in the import library and so the import name type is also not being correctly set. This change modifies the generation of import libraries to set the "symbol name" to the fully decorated name and correctly marks the import as being data vs function. Note that this also required some changes to how the symbol is named within Rust: for MSVC we now need to use the decorated name but for MinGW we still need to use partially decorated (or undecorated) name. Fixes rust-lang#124958 Passing i686 MSVC and MinGW build: <https://github.com/rust-lang/rust/actions/runs/11000433888?pr=130586> r? ``@ChrisDenton``
Rollup merge of rust-lang#130586 - dpaoliello:fixrawdylib, r=wesleywiser Set "symbol name" in raw-dylib import libraries to the decorated name `windows-rs` received a bug report that mixing raw-dylib generated and the Windows SDK import libraries was causing linker failures: <microsoft/windows-rs#3285> The root cause turned out to be rust-lang#124958, that is we are not including the decorated name in the import library and so the import name type is also not being correctly set. This change modifies the generation of import libraries to set the "symbol name" to the fully decorated name and correctly marks the import as being data vs function. Note that this also required some changes to how the symbol is named within Rust: for MSVC we now need to use the decorated name but for MinGW we still need to use partially decorated (or undecorated) name. Fixes rust-lang#124958 Passing i686 MSVC and MinGW build: <https://github.com/rust-lang/rust/actions/runs/11000433888?pr=130586> r? `@ChrisDenton`
Set "symbol name" in raw-dylib import libraries to the decorated name `windows-rs` received a bug report that mixing raw-dylib generated and the Windows SDK import libraries was causing linker failures: <microsoft/windows-rs#3285> The root cause turned out to be rust-lang#124958, that is we are not including the decorated name in the import library and so the import name type is also not being correctly set. This change modifies the generation of import libraries to set the "symbol name" to the fully decorated name and correctly marks the import as being data vs function. Note that this also required some changes to how the symbol is named within Rust: for MSVC we now need to use the decorated name but for MinGW we still need to use partially decorated (or undecorated) name. Fixes rust-lang#124958 Passing i686 MSVC and MinGW build: <https://github.com/rust-lang/rust/actions/runs/11000433888?pr=130586> r? `@ChrisDenton`
I tried this code:
In WIndws x86, the symbol name that should be generated should be:
__imp__WakeByAddressSingle@4
But, the symbol name of the rust generation is:
__imp_WakeByAddressSingle
.When generating the lib, the symbol name should remain
__imp__WakeByAddressSingle@4
, just set theIMPORT_OBJECT_HEADER::NameType
property toIMPORT_NAME_UNDECORATE
. Then the linker will automatically convert the name toWakeByAddressSingle
.The text was updated successfully, but these errors were encountered: