Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prctl(PR_SET_PTRACER) not implemented #3053

Closed
zeux opened this issue Mar 26, 2018 · 5 comments
Closed

prctl(PR_SET_PTRACER) not implemented #3053

zeux opened this issue Mar 26, 2018 · 5 comments

Comments

@zeux
Copy link

zeux commented Mar 26, 2018

LeakSanitizer (which is part of address sanitizer) creates a thread and tries to call prctl(PR_SET_PTRACER) on it which results in EINVAL:

clone(child_stack=0x7f09634f0ff0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_UNTRACED) = 595
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
getpid()                                = 594
prctl(PR_SET_PTRACER, 595)              = -1 EINVAL (Invalid argument)

You can reproduce this by compiling a "Hello, world" program with -fsanitize=address and running it:

$ echo 'int main() { printf("Hello, world!"); return 0; }' >hello.c
$ gcc -fsanitize=address hello.c -o hello
hello.c: In function ‘main’:
hello.c:1:14: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
 int main() { printf("Hello, world!"); return 0; }
              ^~~~~~
hello.c:1:14: warning: incompatible implicit declaration of built-in function ‘printf’
hello.c:1:14: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
$ ./hello
==1070==LeakSanitizer has encountered a fatal error.
==1070==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
==1070==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)

Setting /proc/sys/kernel/yama/ptrace_scope to 0 works around the issue.

@zeux zeux mentioned this issue Mar 26, 2018
@WSLUser
Copy link

WSLUser commented Jul 27, 2018

Fixed in Build 17723 (Fast Ring) per Release Notes.

@zeux
Copy link
Author

zeux commented Oct 3, 2018

This is probably fixed in 1809 (17763.1). The reason why I say "probably" is that:

  • During normal operation, LeakSanitizer now doesn't output any errors.
  • When the program has a memory leak, LeakSanitizer doesn't output any errors but the program exits with return code 1. I suspect based on strace output that LeakSanitizer might be printing the error stack etc. to some handle but the writes might be failing. I'm not sure how to analyze this behavior myself - but I can file another bug with new repro steps?..

@zeux
Copy link
Author

zeux commented Oct 3, 2018

Specifically the output is now as follows...

prctl(PR_SET_PTRACER, 467)              = 0
futex(0x7ffff8e66960, FUTEX_WAKE, 1)    = 1
wait4(467, NULL, __WALL, NULL)          = -1 ECHILD (No child processes)
munmap(0x7fc5323f0000, 2101248)         = 0
getpid()                                = 466
write(2, "==466==LeakSanitizer has encountered a fatal error.\n", 52) = -1 EBADF (Bad file descriptor)
write(2, "ReportFile::Write() can't output requested buffer!\n", 51) = -1 EBADF (Bad file descriptor)
exit_group(1)                           = ?
+++ exited with 1 +++

Now, LeakSanitizer did say that it doesn't work with strace so I'm not sure if I can trust this output - as in, I can't be sure that without strace the behavior of LeakSanitizer diverges. But the exit code matches the behavior without strace so it might be the same issue. Could it be that the implementation of PR_SET_PTRACER is incomplete somehow? It looks like wait4 doesn't work on the process that is set as a tracer.

@therealkenc
Copy link
Collaborator

I'm not sure how to analyze this behavior myself - but I can file another bug with new repro steps?..

That makes sense. The EINVAL in the OP is addressed and this is going to get a 'fixed' tag when 1809 ships even if LeakSanitizer is still not in a happy place. Spawn a new issue so this one doesn't go full Schrödinger.

@zeux
Copy link
Author

zeux commented Oct 3, 2018

Sounds good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants