-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix two issues detected by Valgrind #34462
Fix two issues detected by Valgrind #34462
Conversation
When I have used Valgrind to investigate a memory corruption issue recently, I've noticed that it has also reported two cases when a conditional jump was using an uninitialized variable as one of the inputs to the condition. This change fixes these.
@janvorli I tried running |
@@ -1539,6 +1539,8 @@ Thread::Thread() | |||
m_DeserializationTracker = NULL; | |||
|
|||
m_currentPrepareCodeConfig = nullptr; | |||
|
|||
memset(dangerousObjRefs, 0, sizeof(dangerousObjRefs)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be under debug ifdef?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it does. I have not noticed that it is a debug build only thing.
It actually fails relatively early with .NET Core 5, but it worked fine with .NET Core 3.1. |
@tmds this is the Valgrind failure with .NET Core 5 I was getting:
This looks like a bug in Valgrind, as there is a valid IRET instruction with REX.W prefix. |
With: valgrind -v --tool=memcheck --leak-check=full --show-reachable=yes \
--num-callers=40 --log-file=dotnet-valgrind.log \
dotnet5 new console
==112569== ERROR SUMMARY: 1819 errors from 170 contexts (suppressed: 0 from 0)
|
On Fedora 31 with .NET 3.1 I get:
@janvorli what version of valgrind are you using? And does it still work with .NET Core 3.1? |
I was using the default valgrind package on Ubuntu 16.04, which is version 3.11.0. However, I have tested it just on an app reproducing the write behind allocated memory issue. So it is possible that more things would trouble it if it went through different code paths. |
Where are these superfluous REX.W prefixes coming from? Do we generate them, or is it something that clang generates? |
One comes from RtlRestoreContext here:
I don't know where the other stems from. |
Thanks. The prefix on |
@jkotas the other one - the JMP with extra REX.W prefix seems to be coming from the JIT or a code that runtime generates. |
Is there a way to dump the disassembly before the offending JMP? Hopefully, we will be able to guess where it came from. |
@jkotas there is a way to run valgrind in a mode where one can attach a debugger externally, so I'll give it a try. |
@jkotas, I can see that the jump that it complains on is: So it comes from
It is used here: runtime/src/coreclr/src/vm/i386/stublinkerx86.cpp Lines 5974 to 5978 in 42183b1
|
When I have used Valgrind to investigate a memory corruption issue recently,
I've noticed that it has also reported two cases when a conditional jump
was using an uninitialized variable as one of the inputs to the condition.
This change fixes these.