From: Ian Kent <raven@themaw.net>
To: autofs mailing list <autofs@vger.kernel.org>
Subject: [PATCH 19/19] autofs-5.1.3 - also check flag file exe name
Date: Wed, 02 Aug 2017 10:18:48 +0800 [thread overview]
Message-ID: <150164032851.6106.8506180973364684004.stgit@pluto.themaw.net> (raw)
In-Reply-To: <150164013844.6106.10264212633586462386.stgit@pluto.themaw.net>
automount(8) uses a flag file if it needs to check for multiple
invocations of itself at startup.
The check to see if a flag file is owned by an existing automount(8)
process can return a false positive because it doesn't also check the
name of the executable of the given pid.
Signed-off-by: Ian Kent <raven@themaw.net>
Reported-by: Doron Cohen <doron@weka.io>
---
CHANGELOG | 1 +
daemon/flag.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/CHANGELOG b/CHANGELOG
index af8b099c..1b5c69ee 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -17,6 +17,7 @@ xx/xx/2017 autofs-5.1.4
- add some more debug logging to get_nfs_info().
- add some more debug logging to get_supported_ver_and_cost().
- fix ipv6 proto option handling.
+- also check flag file exe name.
24/05/2017 autofs-5.1.3
=======================
diff --git a/daemon/flag.c b/daemon/flag.c
index db9a4bde..99f26847 100644
--- a/daemon/flag.c
+++ b/daemon/flag.c
@@ -33,12 +33,43 @@
#define MAX_PIDSIZE 20
#define FLAG_FILE AUTOFS_FLAG_DIR "/autofs-running"
+#define EXE_SELF "/proc/self/exe"
+#define EXE_PID "/proc/%u/exe"
+
/* Flag for already existing flag file. */
static int we_created_flagfile = 0;
/* file descriptor of flag file */
static int fd = -1;
+static int check_pid_exe_name(pid_t pid)
+{
+ char self_name[PATH_MAX + 1];
+ char pid_name[PATH_MAX + 1];
+ char exe_pid[MAX_PIDSIZE + 1];
+ int len, ret = 0;
+
+ len = readlink(EXE_SELF, self_name, PATH_MAX);
+ if (len == -1 || len == PATH_MAX)
+ goto out;
+ else
+ self_name[len] = 0;
+
+ len = snprintf(exe_pid, MAX_PIDSIZE, EXE_PID, pid);
+ if (len >= MAX_PIDSIZE)
+ goto out;
+
+ len = readlink(exe_pid, pid_name, PATH_MAX);
+ if (len == -1 || len == PATH_MAX)
+ goto out;
+ else
+ pid_name[len] = 0;
+
+ ret = !strcmp(self_name, pid_name);
+out:
+ return ret;
+}
+
static int flag_is_owned(int fd)
{
int pid = 0, tries = 3;
@@ -83,6 +114,10 @@ static int flag_is_owned(int fd)
*/
if (ret == -1 && errno == ESRCH)
return 0;
+
+ /* If there is a process check if it is automount */
+ if (!check_pid_exe_name(pid))
+ return 0;
} else {
/*
* Odd, no pid in file - so what should we do?
--
To unsubscribe from this list: send the line "unsubscribe autofs" in
prev parent reply other threads:[~2017-08-02 2:18 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-02 2:17 [PATCH 00/19] Current autofs patch queue Ian Kent
2017-08-02 2:17 ` [PATCH 01/19] autofs-5.1.3 - fix spec file url Ian Kent
2017-08-02 2:17 ` [PATCH 02/19] autofs-5.1.3 - fix unset tsd group name handling Ian Kent
2017-08-02 2:17 ` [PATCH 03/19] autofs-5.1.3 - Add -c option when calling /bin/umount - if supported Ian Kent
2017-08-02 2:17 ` [PATCH 04/19] autofs-5.1.3 - remove some redundant rpc library code Ian Kent
2017-08-02 2:17 ` [PATCH 05/19] autofs-5.1.3 - add port parameter to rpc_ping() Ian Kent
2017-08-02 2:17 ` [PATCH 06/19] autofs-5.1.3 - dont probe NFSv2 by default Ian Kent
2017-08-02 2:17 ` [PATCH 07/19] autofs-5.1.3 - add version parameter to rpc_ping() Ian Kent
2017-08-02 2:17 ` [PATCH 08/19] autofs-5.1.3 - fix typo in autofs config file comments Ian Kent
2017-08-02 2:17 ` [PATCH 09/19] autofs-5.1.3 - fix typos in autofs man pages Ian Kent
2017-08-02 2:17 ` [PATCH 10/19] autofs-5.1.3 - use pkg-config to search for libtirpc to fix cross-compilation Ian Kent
2017-08-02 2:18 ` [PATCH 11/19] autofs-5.1.3 - fix incorrect status return in get_nfs_info() Ian Kent
2017-08-02 2:18 ` [PATCH 12/19] autofs-5.1.3 - fix a couple of compiler warnings Ian Kent
2017-08-02 2:18 ` [PATCH 13/19] autofs-5.1.3 - set systemd KillMode to process Ian Kent
2017-08-02 2:18 ` [PATCH 14/19] autofs-5.1.3 - fix mount.nfs blocks on first mount Ian Kent
2017-08-02 2:18 ` [PATCH 15/19] autofs-5.1.3 - fix some man page problems Ian Kent
2017-08-02 2:18 ` [PATCH 16/19] autofs-5.1.3 - add some more debug logging to get_nfs_info() Ian Kent
2017-08-02 2:18 ` [PATCH 17/19] autofs-5.1.3 - add some more debug logging to get_supported_ver_and_cost() Ian Kent
2017-08-02 2:18 ` [PATCH 18/19] autofs-5.1.3 - fix ipv6 proto option handling Ian Kent
2017-08-02 2:18 ` Ian Kent [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=150164032851.6106.8506180973364684004.stgit@pluto.themaw.net \
--to=raven@themaw.net \
--cc=autofs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).