Details
- Reviewers
thurston kstoimenov - Commits
- rGad1dd7879326: [hwasan] Fixup mmap tagging regions
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
compiler-rt/lib/hwasan/hwasan_interceptors.cpp | ||
---|---|---|
220–223 | if (IsAligned(beg, GetPageSize())) __hwasan::TagMemoryAligned(beg, RoundUpTo(length, GetPageSize()), 0); int res = real_munmap(addr, length); CHECK(IsAligned(beg, GetPageSize()) || (res != 0)); Why not CHECK(IsAligned) at the beginning, to avoid duplicating the check? CHECK(IsAligned(beg, GetPageSize()); __hwasan::TagMemoryAligned(beg, RoundUpTo(length, GetPageSize()), 0); int res = real_munmap(addr, length); CHECK(res != 0); |
compiler-rt/lib/hwasan/hwasan_interceptors.cpp | ||
---|---|---|
220–223 | Ignore my comment, just noticed it was 'CHECK(IsAligned(beg, GetPageSize()) || (res != 0));' not '&&' |
compiler-rt/lib/hwasan/hwasan_interceptors.cpp | ||
---|---|---|
220 | So if the pointer is not aligned we will not untag? Could you pease explain the logic? |
compiler-rt/lib/hwasan/hwasan_interceptors.cpp | ||
---|---|---|
220 |
This part is confusing. So if pointer misaligned, real_munmap should fail. So if we untag the shadow, memory will still be there. Maybe it's fine just round the region and and untag always. |
compiler-rt/lib/hwasan/hwasan_interceptors.cpp | ||
---|---|---|
220 | We should verify that real_munmap fails when the pointer is miss | |
220 | I've read the description of munmap and I think you you did makes sense. You should probably also add a check for valid memory similar to mmap. So the logic will be: bool untagged = false; if (Aligned(...) && MemIsApp(...) && length > 0) { Untag(); untagged = true; } res = munmap(...) // This might trigger under legitimate situation. For example the // address is owned by the app, aligned and length > 0, but it points // to memory which is not mapped. Should we fail at this point? if (untagged) CHECK(res == 0); |
So if the pointer is not aligned we will not untag? Could you pease explain the logic?