[Reproducible-commits] [dpkg] 16/25: s-s-d: Cope with bogus OpenVZ kernels that prepend the " (deleted)" marker

Holger Levsen holger at layer-acht.org
Tue May 3 08:43:55 UTC 2016


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to annotated tag 1.16.16
in repository dpkg.

commit 8449a3081b48cd37d86d4e0a905824478817a639
Author: Guillem Jover <guillem at debian.org>
Date:   Wed May 14 04:27:31 2014 +0200

    s-s-d: Cope with bogus OpenVZ kernels that prepend the " (deleted)" marker
    
    Cherry picked from commit b766dca91159da611c6340dea347f4ef00159768.
    
    There are OpenVZ Linux kernels that instead of appending, prepend the
    deleted marker, making the exec check fail to match. Add a workaround
    so that those systems do not get affected.
    
    This will still be affecting any other userland tool that checks the
    /proc/PID/exe symlink, and might end up helping this behaviour to get
    entrenched, but better this than the getting strange system failures.
    
    Closes: #731530
---
 debian/changelog          |  3 +++
 utils/start-stop-daemon.c | 16 ++++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 472c608..5e64b36 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -19,6 +19,9 @@ dpkg (1.16.15+nmu1) UNRELEASED; urgency=low
     Although this should not have security implications as the buffer is
     surrounded by two arrays (so those catch accesses even if the stack
     grows up or down), and we are compiling with -fstack-protector anyway.
+  * Add a workaround to start-stop-daemon for bogus OpenVZ Linux kernels that
+    prepend, instead of appending, the " (deleted)" marker in /proc/PID/exe.
+    Closes: #731530
 
   [ Updated scripts translations ]
   * Fix typos in German (Helge Kreutzmann)
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 11afbaf..132d814 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -1022,6 +1022,7 @@ pid_is_exec(pid_t pid, const struct stat *esb)
 {
 	char lname[32];
 	char lcontents[_POSIX_PATH_MAX + 1];
+	char *filename;
 	const char deleted[] = " (deleted)";
 	int nread;
 	struct stat sb;
@@ -1031,11 +1032,18 @@ pid_is_exec(pid_t pid, const struct stat *esb)
 	if (nread == -1)
 		return false;
 
-	lcontents[nread] = '\0';
-	if (strcmp(lcontents + nread - strlen(deleted), deleted) == 0)
-		lcontents[nread - strlen(deleted)] = '\0';
+	filename = lcontents;
+	filename[nread] = '\0';
 
-	if (stat(lcontents, &sb) != 0)
+	/* OpenVZ kernels contain a bogus patch that instead of appending,
+	 * prepends the deleted marker. Workaround those. Otherwise handle
+	 * the normal appended marker. */
+	if (strncmp(filename, deleted, strlen(deleted)) == 0)
+		filename += strlen(deleted);
+	else if (strcmp(filename + nread - strlen(deleted), deleted) == 0)
+		filename[nread - strlen(deleted)] = '\0';
+
+	if (stat(filename, &sb) != 0)
 		return false;
 
 	return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list