Tweak disable_debugger_attachment a little

Don't warn when we have no implementation of this function (since it's
on-by-default); reformat the changes entry; fix an overlong line.
This commit is contained in:
Nick Mathewson
2011-11-24 23:39:44 -05:00
parent 68114ca52c
commit 3508de3cd6
2 changed files with 32 additions and 22 deletions
+19 -11
View File
@@ -40,19 +40,19 @@
#include <shlobj.h>
#endif
#include "procmon.h"
/* From main.c */
extern int quiet_level;
/* Includes for the process attaching prevention */
#if defined(HAVE_SYS_PRCTL_H) && defined(__linux__)
#include <sys/prctl.h>
#include <sys/prctl.h>
#elif defined(__APPLE__)
#include <sys/types.h>
#include <sys/ptrace.h>
#endif
#include "procmon.h"
/* From main.c */
extern int quiet_level;
/** Enumeration of types which option values can take */
typedef enum config_type_t {
CONFIG_TYPE_STRING = 0, /**< An arbitrary string. */
@@ -703,25 +703,33 @@ get_dirportfrontpage(void)
* attach to the Tor process.
*/
/** Attempt to disable debugger attachment. */
static int tor_disable_debugger_attach(void) {
int r;
static int
tor_disable_debugger_attach(void)
{
int r, attempted;
r = -1;
attempted = 0;
log_debug(LD_CONFIG,
"Attemping to disable debugger attachment to Tor for unprivileged users.");
"Attemping to disable debugger attachment to Tor for "
"unprivileged users.");
#if defined(__linux__) && defined(HAVE_SYS_PRCTL_H) && defined(HAVE_PRCTL)
#ifdef PR_SET_DUMPABLE
attempted = 1;
r = prctl(PR_SET_DUMPABLE, 0);
#endif
#endif
#if defined(__APPLE__) && defined(PT_DENY_ATTACH)
r = ptrace(PT_DENY_ATTACH, 0, 0, 0);
if (r < 0) {
attempted = 1;
r = ptrace(PT_DENY_ATTACH, 0, 0, 0);
}
#endif
// XXX: TODO - Mac OS X has dtrace and this may be disabled - implement it here
// XXX: TODO - Windows probably has something similar - implement it here
if (r == 0) {
log_debug(LD_CONFIG,"Debugger attachment disabled for unprivileged users.");
} else {
} else if (attempted) {
log_warn(LD_CONFIG, "Unable to disable ptrace attach: %s",
strerror(errno));
}