This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Support v2 and v3 capabilities
ClosedPublic

Authored by iii on Feb 9 2023, 8:25 AM.

Details

Summary

capget() and capset() may read or write more than one cap_user_data_t,
depending on the version field of cap_user_header_t. Currently the
code assumes it's just one, so MSan complains if an application uses
version 2 or 3, where two cap_user_data_ts are used.

Parse the header in order to determine the number of cap_user_data_ts.
Also add a test.

Diff Detail

Event Timeline

iii created this revision.Feb 9 2023, 8:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2023, 8:25 AM
Herald added a subscriber: Enna1. · View Herald Transcript
iii requested review of this revision.Feb 9 2023, 8:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2023, 8:25 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
iii updated this revision to Diff 496237.Feb 9 2023, 2:15 PM
  • Do not define the constants, the kernel provides them since v2.6.
  • Rewrite the test in C.
iii edited the summary of this revision. (Show Details)Feb 9 2023, 2:16 PM
glider added a subscriber: glider.Feb 23 2023, 8:07 AM

LGTM with a nit.

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
252

Do we want to do anything in the case of incorrect version?

compiler-rt/test/sanitizer_common/TestCases/Linux/cap.c
36

If we do, can you please add a test case for it?

iii added inline comments.Feb 23 2023, 3:17 PM
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
252

I used 1 here in order to keep the old sanitizer behavior, but, come to think of it, it doesn't really make sense: if a buggy program passes a bad version, we don't want to unpoison the buffer. There can be new versions added in the future too, but this code would have to be updated in order to support them anyway.

So I'll change this to 0 and think of a way to test this.

iii updated this revision to Diff 500004.Feb 23 2023, 4:08 PM
iii edited the summary of this revision. (Show Details)
  • Do not touch memory if the version is incorrect.
  • Test this.
iii marked 2 inline comments as done.Feb 23 2023, 4:08 PM
vitalybuka accepted this revision.Feb 23 2023, 10:57 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
5762–5768
5780

same

This revision is now accepted and ready to land.Feb 23 2023, 10:57 PM
iii updated this revision to Diff 500137.Feb 24 2023, 4:06 AM
  • Compute datasz only when necessary.
This revision was landed with ongoing or failed builds.Feb 24 2023, 5:12 AM
This revision was automatically updated to reflect the committed changes.