This is an archive of the discontinued LLVM Phabricator instance.

[asan] Don't raise false alarm to recv/recvfrom when MSG_TRUNC is present.
ClosedPublic

Authored by m.ostapenko on May 16 2016, 2:55 AM.

Details

Summary

Currenty ASan checks the return value of real recv/recvfrom to see if the written bytes fit in the buffer. That works fine most of time. However, there is an exception: (from the RECV(2) man page)

MSG_TRUNC (since Linux 2.2)
    ... return the real length of the packet or datagram, even when it was longer than the passed buffer. ...

Some programs combine MSG_TRUNC, MSG_PEEK and a single-byte buffer to peek the incoming data size without reading (much of) them. In this case, the return value is usually longer than what's been written and ASan raises a false alarm here. To avoid such false positive reports, we can use min(res, len) in COMMON_INTERCEPTOR_WRITE_RANGE checks.

Diff Detail

Repository
rL LLVM

Event Timeline

m.ostapenko retitled this revision from to [asan] Don't raise false alarm to recv/recvfrom when MSG_TRUNC is present..
m.ostapenko updated this object.
m.ostapenko added reviewers: kcc, dvyukov, eugenis.
m.ostapenko set the repository for this revision to rL LLVM.
m.ostapenko added subscribers: llvm-commits, laszio, ygribov.
kcc edited edge metadata.May 16 2016, 10:34 AM

Code change LG, please move the test to the common dir.

test/asan/TestCases/Linux/recv_msg_trunc.cc
1 ↗(On Diff #57325)

Can you move this test to test/sanitizer_common/TestCases/Linux ?
And please verify that it fails there w/o your fix.

m.ostapenko edited edge metadata.

Moved testcase to test/sanitizer_common/TestCases/Linux and verified that it passes with patch and fails without it.

kcc accepted this revision.May 16 2016, 11:16 AM
kcc edited edge metadata.

LGTM, thanks!

This revision is now accepted and ready to land.May 16 2016, 11:16 AM
This revision was automatically updated to reflect the committed changes.