From 68e39c2e472fc6302092093abdfd7edcfeaf53c6 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Mon, 3 Jun 2019 15:43:56 +0200 Subject: [PATCH] Startup Checks: Improved the pidfile check: Do not just check for existing PID but also check executable filename --- docs/changes.txt | 1 + src/pidfile.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 711e1407d..d11b9d156 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -56,6 +56,7 @@ ## Improvements ## +- Startup Checks: Improved the pidfile check: Do not just check for existing PID but also check executable filename - Cracking bcrypt and Password Safe v2: Use a feedback from the OpenCL runtime to dynamically find out optimal thread count - Bitcoin Wallet: Be more user friendly by allowing a larger data range for ckey and public_key - Building: Updated BUILD.md diff --git a/src/pidfile.c b/src/pidfile.c index 8654d41a8..a366d48ae 100644 --- a/src/pidfile.c +++ b/src/pidfile.c @@ -72,17 +72,46 @@ static int check_running_process (hashcat_ctx_t *hashcat_ctx) char *pidbin; - hc_asprintf (&pidbin, "/proc/%u/cmdline", pd->pid); + hc_asprintf (&pidbin, "/proc/%u/exe", pd->pid); if (hc_path_exist (pidbin) == true) { - event_log_error (hashcat_ctx, "Already an instance running on pid %u", pd->pid); + // pid info + + char *pidexe = (char *) hcmalloc (HCBUFSIZ_TINY); + + const ssize_t pidexe_len = readlink (pidbin, pidexe, HCBUFSIZ_TINY - 1); + + pidexe[pidexe_len] = 0; + + // self info + + char *selfexe = (char *) hcmalloc (HCBUFSIZ_TINY); + + const ssize_t selfexe_len = readlink ("/proc/self/exe", selfexe, HCBUFSIZ_TINY - 1); + + selfexe[selfexe_len] = 0; + + // compare + + const int r = strncmp (pidexe, selfexe, selfexe_len); + + if (r == 0) + { + event_log_error (hashcat_ctx, "Already an instance '%s' running on pid %u", pidexe, pd->pid); + } + + hcfree (selfexe); + + hcfree (pidexe); hcfree (pd); hcfree (pidbin); - return -1; + if (r == 0) return -1; + + return 0; } hcfree (pidbin);