yahoo/monitr

pthread_setname_np privilege error on Linux after a setuid() call

evantorrie opened this issue · 1 comments

pthread_setname_np is implemented in glibc with two different code paths.

When called on a target thread other than the current thread, it attempts to write to /proc/self/task/<taskid>/comm. However, when a process calls setuid/seteuid, the proc entries underneath remain owned by the pre-setuid userid unless the Linux kernel tunable /proc/sys/fs/suid_dumpable is set to 1.

As a result, we see repeated failures and perror errors from this call to pthread_setname_np in our error log where we start node as root and then lower privileges by calling setuid() prior to calling require("monitr").

On the other hand, when pthread_setname_np is called by a thread on itself, it uses a different code path which makes a syscall to prctl. So suggested fix is to change the location where pthread_setname_np is called to be inside the monitr thread itself, rather than inside the v8 thread.