-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
gcc: Improve security #22216
base: master
Are you sure you want to change the base?
gcc: Improve security #22216
Conversation
38785be
to
c4d0ae8
Compare
Nit: packages that are linked statically don't need to be in |
@mati865 Yes that's 100% correct. I have removed those dependencies from compiler packages, leaving only libwinpthread on gcc-libs. |
3353630
to
8ea5886
Compare
do that for lto-plugin, too. |
b478bab
to
a8fc69f
Compare
It should be fine now. All programs, as well as liblto_plugin.dll, now reference only system DLLs. |
Wouldn't calling And why is gcc special here, doesn't this affect everything? |
It only affects
In reality gcc.exe is not affected. https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-unpackaged-apps:
gcc.exe and libgcc_s_seh-1.dll are in the same directory, so when this DLL is loaded by gcc.exe it has priority 7, which trumps always everything else - even system DLLs. But if cc1.exe is spawned by gcc.exe, it can't find libgcc_s_seh-1.dll in 'the folder from which the application loaded', which is later found in PATH according to rule 12. Then the risk is if there's a DLL with the same name in 'the current folder', it will take precedence over 12. |
ah, unfortunate.. the docs are confusing..
ah, right, thanks Doing some more searching, would https://learn.microsoft.com/en-us/cpp/build/reference/dependentloadflag?view=msvc-170 help in theory? i.e. |
There does not seem to be support in GNU LD? |
yes, also not in mingw lld I think, though it's in lld llvm/llvm-project#71537 I was just wondering if (1) this would help in this case (2) and if yes we can ask upstreams to add support. Not saying that we should wait on new upstream features, it would just be nice to know that we can remove static linking again one day. |
LLD supports
Definitely. It would be good to have.
I am not familiar with binutils; after a quick glance I suspect relevant code is in 'bfd/peXXigen.c' around where the TLS directory is set. |
Adding it to LLD should be trivial, just like llvm/llvm-project@276283d Currently it should work if you pass |
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. I'm not sure about the name as ld.bfd doesn't support it (yet?). There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. I'm not sure about the name as ld.bfd doesn't support it (yet?). There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
The language-specific compilers (cc1, cc1plus, lto-wrapper, etc.) are not in PATH, but in '<prefix>/lib/gcc/<triplet>/<version>'. When these compilers are invoked by GCC, they prefer DLLs in the working directory to those in PATH [1], which allows, for example, an untrusted source repo to create libgmp-10.dll in the working directory, which will get picked by cc1plus, resulting in arbitrary code execution. These programs shall be linked against all dependencies statically. After this change they depend on only GCC runtime libraries. [1] https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-security Signed-off-by: LIU Hao <[email protected]>
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. I'm not sure about the name as ld.bfd doesn't support it (yet?). There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. I'm not sure about the name as ld.bfd doesn't support it (yet?). There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. I'm not sure about the name as ld.bfd doesn't support it (yet?). There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. ld.bfd doesn't support it, yet at least, but if they later add support for something similar, hopefully they’d agree to the same option name. There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. ld.bfd doesn't support it, yet at least, but if they later add support for something similar, hopefully they’d agree to the same option name. There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. ld.bfd doesn't support it, yet at least, but if they later add support for something similar, hopefully they’d agree to the same option name. There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
Implement MSVC's `/DEPENDENTLOADFLAG` as `--dependent-load-flag` and forward it to COFF. ld.bfd doesn't support it, yet at least, but if they later add support for something similar, hopefully they’d agree to the same option name. There is no solid need for it yet, but it's being considered: msys2/MINGW-packages#22216 (comment)
gcc: Improve security
The language-specific compilers (cc1, cc1plus, lto-wrapper, etc.) are not in
PATH, but in '/lib/gcc//'. When these compilers are
invoked by GCC, they prefer DLLs in the working directory to those in PATH [1],
which allows, for example, an untrusted source repo to create libgmp-10.dll in
the working directory, which will get picked by cc1plus, resulting in arbitrary
code execution.
These programs shall be linked against all dependencies statically.
[1] https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-security
Signed-off-by: LIU Hao [email protected]