This is an archive of the discontinued LLVM Phabricator instance.

[dfsan] Handle more uninstrumented functions
Needs ReviewPublic

Authored by gbalats on Jul 22 2021, 8:02 PM.

Details

Diff Detail

Event Timeline

gbalats requested review of this revision.Jul 22 2021, 8:02 PM
gbalats created this revision.
Herald added a subscriber: Restricted Project. · View Herald TranscriptJul 22 2021, 8:02 PM
compiler-rt/lib/dfsan/done_abilist.txt
76

Is this discard?

https://man7.org/linux/man-pages/man3/isatty.3.html

isatty() returns 1 if fd is an open file descriptor referring to a terminal; otherwise 0 is returned, and errno is set to indicate the error.

This sounds like the return value has no direct dependency on fd.

159

This one probably needs a custom wrapper.

Here is an mac os implementation.
We can see

fp->_file = fd;

So we need to propagate fd's label to fp's _file field. It would be great to find a linux implementation to confirm this.

163

From this uncommon implementation, the return value may depend on the contents the input pointer refers to.

Other APIs in this change may have similar dependency. I suggest we could check their implementation a bit more.

gbalats marked an inline comment as done.Jul 23 2021, 12:38 PM
gbalats added inline comments.
compiler-rt/lib/dfsan/done_abilist.txt
76

isatty(3) is a library function and is usually implemented by calling tcgetattr(3) and checking its return value.

Not sure if there might be a direct dependency, because it depends on tcgetattr's implementation. In any case, I wouldn't think file descriptors will have non-zero labels in practice so it probably doesn't make a lot of difference. I could still change it to discard, if you want.

159

Yeah, this is the one I was most unsure about. However, FILE* is an opaque struct. Do you think a custom wrapper that simply copied the file descriptor argument's label to the return label would suffice?

163

I think marking this discard is consistent with other wrappers. E.g., if you look at __dfsw_fgets (or other IO-related functions) it doesn't do anything with its stream_label nor does it propagate it to its output. Since fgetc has only a single stream argument, its implementation would basically just zero out the return label which iiuc is equivalent to marking it discard.

compiler-rt/lib/dfsan/done_abilist.txt
159

This is how other sanitizers define their interceptors for fdopen. It seems that we do not take FILE* as opaque. We can refer to this file for other wrappers too.