Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

fixed VirtualMemoryLogging::logRecords overflow with negative indexing #27907

Closed
wants to merge 1 commit into from

Conversation

tqinli
Copy link

@tqinli tqinli commented Nov 21, 2019

when VirtualMemoryLogging::recordNumber increments from LONG_MAX,
it became negative number, and the result of i % MaxRecords became
a number from -127 to 0.

When that happens we will ovewrite CRITICAL_SECTION virtual_critsec
which are stored in bss right before logRecords with garbage data.
Then most likely the process will have a GC hang with one or more
GC threads stuck trying to enter or leave critical section.

The fix is to ensure ULONG value are passed to modulo operation.

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for tracking this issue down and fixing it!

src/pal/src/map/virtual.cpp Outdated Show resolved Hide resolved
@tqinli tqinli force-pushed the fix_vmlogging_underflow branch 2 times, most recently from 5938f5e to 8281f09 Compare November 21, 2019 21:26
@tqinli tqinli changed the title fixed VirtualMemoryLogging::logRecords underflow fixed VirtualMemoryLogging::logRecords overflow with negative indexing Nov 21, 2019
src/pal/src/map/virtual.cpp Outdated Show resolved Hide resolved
@@ -137,7 +137,9 @@ namespace VirtualMemoryLogging
IN LPVOID returnedAddress,
IN BOOL result)
{
LONG i = InterlockedIncrement(&recordNumber) - 1;
ULONG i = InterlockedIncrement((LONG *)&recordNumber) - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please put cast to ULONG before the InterlockedIncrement too? Clang is probably ok with it, but some people spent quite an effort trying to keep the codebase buildable with GCC too and it is picky on these.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix this

when VirtualMemoryLogging::recordNumber increments from LONG_MAX,
it became negative number, and the result of i % MaxRecords became
a number from -127 to 0.

When that happens we will ovewrite CRITICAL_SECTION virtual_critsec
which are stored in bss right before logRecords with garbage data.
Then most likely the process will have a GC hang with one or more
GC threads stuck trying to enter or leave critical section.

The fix is to ensure ULONG value are passed to modulo operation.
@tqinli tqinli force-pushed the fix_vmlogging_underflow branch from 8281f09 to c7fee2b Compare November 22, 2019 00:06
Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@janvorli janvorli added the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Nov 22, 2019
@janvorli
Copy link
Member

@tqinli the PR will need to be ported and merged into the new runtime repo once it is open (should happen soon). This repo is closed for new PRs.

@tqinli
Copy link
Author

tqinli commented Nov 22, 2019

@janvorli thanks for letting me know. yeah, I will port and re-send once the new repo is set up. thanks for your help!

@janvorli
Copy link
Member

@tqinli the dotnet/runtime repo is open now, could you please port your change to it?

@tqinli
Copy link
Author

tqinli commented Nov 26, 2019

thanks for letting me know. Yeah I will work on this today and send the new one

@maryamariyan
Copy link
Member

Thank you for your contribution. As announced in #27549 the dotnet/runtime repository will be used going forward for changes to this code base. Closing this PR as no more changes will be accepted into master for this repository. If you’d like to continue working on this change please move it to dotnet/runtime.

@tqinli tqinli deleted the fix_vmlogging_underflow branch June 4, 2020 00:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
* NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants