This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Make atos stdin a non-tty pipe to make sure it's not stuck waiting for user input
ClosedPublic

Authored by kubamracek on Nov 29 2016, 4:31 PM.

Details

Summary

On macOS, we often symbolicate using atos (when llvm-symbolizer is not found). The current way we invoke atos involves creating a pseudo-terminal to make sure atos doesn't buffer its output. This however also makes atos think that it's stdin is interactive and in some error situations it will ask the user to enter some input instead of just printing out an error message. For example, when Developer Mode isn't enabled on a machine, atos cannot examine processes, and it will ask the user to enter an administrator's password, which will make the sanitized process get stuck. This patch only connects the pseudo-terminal to the stdout of atos, and uses a regular pipe as its stdin.

I'm not adding a testcase, because to reproduce the problem you have to disable Developer Mode on your machine, which is not something that can be done as a lit test. But if your machine has Developer Mode disabled, you will already get test failures of other tests.

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek updated this revision to Diff 79669.Nov 29 2016, 4:31 PM
kubamracek retitled this revision from to [sanitizer] Make atos stdin a non-tty pipe to make sure it's not stuck waiting for user input.
kubamracek updated this object.
kubamracek set the repository for this revision to rL LLVM.
kubamracek added a project: Restricted Project.
kubamracek added a subscriber: llvm-commits.
zaks.anna edited edge metadata.Dec 1 2016, 10:52 PM

LGTM

lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
187 ↗(On Diff #79669)

This might be a bit more readable:

`// infd[0] is the child's reading end.
close(infd[1]);`

`// Setup stdin to serve as the infd pipe.
close(STDIN_FILENO);
CHECK_GE(dup2(infd[0], STDIN_FILENO), 0);
close(infd[0]);`

zaks.anna accepted this revision.Dec 2 2016, 9:50 AM
zaks.anna edited edge metadata.

Other than the nit, this looks good!

This revision is now accepted and ready to land.Dec 2 2016, 9:50 AM
filcab edited edge metadata.Dec 2 2016, 9:50 AM

LGTM

lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
114 ↗(On Diff #79669)

Maybe extract the 5 to be a constant?
Also, why 5? It looks to me that 4 should be enough (I was planning on 3, which would make a bigger difference, but then noticed you want two pairs):
worst case: 0, 1, and 2 are closed.
pipe() creates 0, 1 <- Not good, keep trying
pipe() creates 2, X <- Not good, keep trying
pipe() creates Y, X <- ok, since 0, 1, and 2 are already taken by previous pipes.
pipe() creates A, B <- ok

189 ↗(On Diff #79669)

dup2 will close STDIN_FILENO by itself. No need to close it first.

filcab added a comment.Dec 2 2016, 9:51 AM

Nevermind the CreateTwoHighNumberedPipes comment. I tried deleting but couldn't. I saw you're just moving code around, so let's not refactor it now.

This revision was automatically updated to reflect the committed changes.