You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Linux madvise() advice values incorrectly combined via bitwise OR in GCToOSInterface::VirtualReset #126950
As part of our (@neiljohari and @andyblox) investigation into GC heap corruption we discovered that VirtualReset in gcenv.unix.cpp combines MADV_FREE and MADV_DONTDUMP via bitwise OR and passes the result to a single madvise() call. madvise() takes a single advice constant, not a bitmask. The combined value is either rejected or misinterpreted by the kernel.
This change was made here: #95643 in an effort to reduce the number of
syscalls (#87173)
Note that VirtualReserveInner in the same file correctly uses a standalone madvise(pRetVal, size, MADV_DONTDUMP) call.
Expected behavior
VirtualReset should apply MADV_FREE and MADV_DONTDUMP independently via separate madvise() calls.
Actual behavior
The combined value 24 is passed as a single advice:
Kernel < 5.18: 24 is unrecognized, madvise() returns EINVAL. Neither advice takes effect. (We were able to confirm this with Ubuntu 22 + Kernel 5.15)
Kernel >= 5.18: 24 matches MADV_DONTNEED_LOCKED, which immediately discards pages (including locked pages) — different semantics from both MADV_FREE and MADV_DONTDUMP.
This also has the side effect of dropping MADV_DONTDUMP which will lead to extra pages being included in dumps.
This is very eye opening! I know your research was done on Linux + glibc, however, I was wondering if you believed it was plausible that this behavior would have cascading effects on unix-like systems?
For context, I was having issues with cross-platform sys calls between Linux 6.X + glibc and Darwin 22.X + libc, that I suspect may be caused by this implementation flaw.
This is very eye opening! I know your research was done on Linux + glibc, however, I was wondering if you believed it was plausible that this behavior would have cascading effects on unix-like systems?
For context, I was having issues with cross-platform sys calls between Linux 6.X + glibc and Darwin 22.X + libc, that I suspect may be caused by this implementation flaw.
Quite possibly, as the code paths are the same for Linux/Unix and variants (although they differ based on some predefines such as HAVE_MADV_FREE etc)
Activity
dotnet-policy-service commentedon Apr 15, 2026
Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Apr 15, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/gc
See info in area-owners.md if you want to be subscribed.
janvorli commentedon Apr 15, 2026
Oh, @BenV thank you for finding this! I was convinced that these were flags.
BenV commentedon Apr 15, 2026
No problem at all, it took us a while to spot this as well, especially since calls like
mmapdo use flags 😆Static-Codes commentedon Apr 15, 2026
This is very eye opening! I know your research was done on Linux + glibc, however, I was wondering if you believed it was plausible that this behavior would have cascading effects on unix-like systems?
For context, I was having issues with cross-platform sys calls between Linux 6.X + glibc and Darwin 22.X + libc, that I suspect may be caused by this implementation flaw.
BenV commentedon Apr 15, 2026
Quite possibly, as the code paths are the same for Linux/Unix and variants (although they differ based on some predefines such as
HAVE_MADV_FREEetc)Static-Codes commentedon Apr 15, 2026
This is great to know for future reference!
Thank you for your research and also the prompt reply!