This is an archive of the discontinued LLVM Phabricator instance.

[DFSan] Add pthread and other functions to ABI list.
ClosedPublic

Authored by morehouse on Dec 8 2020, 12:09 PM.

Details

Summary

The non-pthread functions are all clear discard functions.

Some of the pthread ones could clear shadow, but aren't worth writing
custom wrappers for. I can't think of any reasonable scenario where we
would pass tainted memory to these pthread functions.

Diff Detail

Event Timeline

morehouse requested review of this revision.Dec 8 2020, 12:09 PM
morehouse created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2020, 12:09 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
compiler-rt/lib/dfsan/done_abilist.txt
99

https://screenshot.googleplex.com/7FRxwMRnWiJPqWg says the output pointed by the pointer could be depending on its input content? but I am not sure since I've never used it.
Would a custom wrapper be better?

116

create?

261

If it returns pthread_attr_setaffinity_np's input, the flow is discarded.
Maybe both these setter and getters are custom.

morehouse marked an inline comment as done.Dec 8 2020, 12:44 PM
morehouse added inline comments.
compiler-rt/lib/dfsan/done_abilist.txt
99

The source code in glibc is https://code.woboq.org/userspace/glibc/sysdeps/unix/sysv/linux/cmsg_nxthdr.c.html.

It returns a pointer at some offset from the input parameter cmsg, without writing any data. Since no data is written, I figure discard is sufficient.

If we want to get really strict, we can use a custom wrapper to combine labels for every single field accessed from mhdr and cmsg, but maybe it's overkill.

116
261

This is true. The question is whether it's worth tracking that flow or not.

My argument for why it's not worth it:

  • It seems rare that we would need to track flow through pthread_attr_ts.
  • The definition of pthread_attr_t is an implementation detail of the pthread library not exposed in the public API. So it could easily change in different versions. Any custom wrapper would require maintenance burden to be kept up-to-date with the latest pthread library.
stephan.yichao.zhao added inline comments.
compiler-rt/lib/dfsan/done_abilist.txt
261

Thank you for the explanation.

Does DFSan pass have an opportunity to visit the functions during compilation?
It can create the summary automatically by analyzing its code.
But I guess it does not...

This revision is now accepted and ready to land.Dec 8 2020, 1:27 PM
morehouse marked an inline comment as done.Dec 8 2020, 1:41 PM
morehouse added inline comments.
compiler-rt/lib/dfsan/done_abilist.txt
261

I wish it did. Both glibc and pthreads are precompiled on the system, which means we have to use the ABI list for all their functions. Even if we could compile glibc with DFSan, it has a lot of assembly code we would still need to use the ABI list for.

llvm-libc may help when it is more complete.

This revision was landed with ongoing or failed builds.Dec 8 2020, 1:56 PM
This revision was automatically updated to reflect the committed changes.