This is an archive of the discontinued LLVM Phabricator instance.

sanitizer_common: fix crashes in parsing of memory profiles
ClosedPublic

Authored by dvyukov on Oct 29 2021, 2:48 AM.

Details

Summary

ParseUnixMemoryProfile assumes well-formed input with \n at the end, etc.
It can over-read the input and crash on basically every line
in the case of malformed input.
ReadFileToBuffer has cap the max file size (64MB) and returns
truncated contents if the file is larger. Thus even if kernel behaves,
ParseUnixMemoryProfile crashes on too large /proc/self/smaps.
Fix input over-reading in ParseUnixMemoryProfile.

Depends on D112792.

Diff Detail

Event Timeline

dvyukov requested review of this revision.Oct 29 2021, 2:48 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2021, 2:48 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
melver accepted this revision.Oct 29 2021, 3:34 AM
melver added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp
163

why is the (char*) cast needed? smaps is already a char*.

171

s/well-format/well-formed/ ?

compiler-rt/lib/sanitizer_common/tests/sanitizer_procmaps_test.cpp
126

Just normal lambda function instead

This revision is now accepted and ready to land.Oct 29 2021, 3:34 AM
dvyukov updated this revision to Diff 383314.Oct 29 2021, 4:59 AM
dvyukov marked 3 inline comments as done.

adderessed comments

This revision was landed with ongoing or failed builds.Oct 29 2021, 5:03 AM
This revision was automatically updated to reflect the committed changes.

I suspect this broke the Mac build bot: https://green.lab.llvm.org/green/job/clang-stage1-RA/25101/console

Can you please take a look and revert if the fix would take a while?

Hi Jan,

I am looking into this. Thanks for the report.