-
Notifications
You must be signed in to change notification settings - Fork 354
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
SOS sets the invalid parameter handler in the CRT on Windows in an unsafe way #4070
Comments
I'm not actually confident that we should be using the static CRT, but it seems quite bad that we are configuring all CRT invalid paramters to run through our logic. I hit this when windbg behaved incorrectly (and that has since been fixed in the live version of Windbg), but in general this seems like a bad thing to do. |
From a security and distribution perspective, we probably shouldn't try to statically link the CRT. |
That decision was before my time (I think that's been there since early 2000s), but I do remember the reasons. The following is the history of why we made that decision, but not any defense of the behavior. :) The original author(s) of SOS hooked this API for the following reasons:
I have no objections to changing that behavior, it's the right thing to do from a security perspective. Here's two caveats that might come back to bite you that might need to be mitigated:
Hope that helps! |
@davidwrighton, this line and these lines in the SOS CMakeLists.txt seem to indicate that we do statically link the CRT into SOS.dll so the comment below on the invalid parameter hook is accurate.
I'd rather not change this if it isn't really necessary for all the reasons Lee outlined above unless for the security concerns that Juan pointed out. |
@mikem8361 When I looked into this I found that for the build of sos.dll that I was using it was linked to the dynamic CRT. I know there are various comments and possibly attempts in the CMake stuff to use the static CRT, but I found that it wasn't actually doing so. I believe that with our current codebase we should link against the static CRT, but my issue is that we are not doing so. |
Thanks David. Yes, I confirmed via dumpbin /imports sos.dll on a release build shows the dynamically linked CRT imports. I will remove the invalid parameter hook. The CMakeLists.txt stuff is very confusing. |
SOS does get built dynamically linking to the C++ CRT in release so the invalid parameter handler that gets installed affects all the code in the process. Fixes issue: dotnet#4070
SOS does get built dynamically linking to the C++ CRT in release so the invalid parameter handler that gets installed affects all the code in the process. Fixes issue: #4070
Description
In https://github.com/dotnet/diagnostics/blob/a54655ea621579a60530d8cf9d516c72ea8f23c2/src/SOS/Strike/exts.cpp#L288C12-L288C12 SOS sets the invalid parameter handler to something that will throw an exception, etc.
There is a comment there that this is safe as SOS is compiled against the static CRT. Unfortunately, this isn't the case anymore, and we now run the SOS invalid parameter handler when CRT calls from windbg itself are used. (note: it appears that the debug build of SOS is linked against a static CRT, but the release build is not).
This should be fixed by either changing to link against the static CRT or by not setting process global state.
The text was updated successfully, but these errors were encountered: