Skip to contentSkip to conversation

Subject: [PATCH] Statd should always 'chdir' to its state directory.

DISCUSSION Chuck Lever 2 participants 2 messages Jul 21, 2011 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 9 lines · NeilBrown

Subject: [PATCH] Statd should always 'chdir' to its state directory.

As statd can be started by 'mount' which can sometimes be run by a normal user, the current-working-directory could be anything. In partcular it could be in a mounted filesystem. As 'statd' continues running as a daemon it could keep prevent that filesystem from being unmounted.

Quoted 5 lines

statd does currently 'chdir' to the state directory, but only if the state directory is not owned by root. This is wrong - it should check for root after the chdir, not before.

So swap the two if statements around.

Seems reasonable.

Quoted 27 lines

--
looks like this regression slipped in around January 2010 with the big libnsm clean up.

(quoted diff) +0 -1
-NB
support/nsm/file.c +0 -6
index 98b47bf..a12c753 100644
@@ -395,18 +395,18 @@ nsm_drop_privileges(const int pidfd)
 		return false;
 	}
 
-	if (st.st_uid == 0) {
-		xlog_warn("Running as root.  "
-			"chown %s to choose different user", nsm_base_dirname);
-		return true;
-	}
-
 	if (chdir(nsm_base_dirname) == -1) {
 		xlog(L_ERROR, "Failed to change working directory to %s: %m",
 				nsm_base_dirname);
 		return false;
 	}

support/nsm/file.c nsm_drop_privileges(const int pidfd) · line 412

Quoted 10 lines
support/nsm/file.c +6 -0
 
+	if (st.st_uid == 0) {
+		xlog_warn("Running as root.  "
+			"chown %s to choose different user", nsm_base_dirname);
+		return true;
+	}
+
 	/*
 	 * If the pidfile happens to reside on NFS, dropping privileges
 	 * will probably cause us to lose access, even though we are

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com

#2 lore raw
In reply to a message not in the archive
Quoted 9 lines · NeilBrown

Subject: [PATCH] Statd should always 'chdir' to its state directory.

As statd can be started by 'mount' which can sometimes be run by a normal user, the current-working-directory could be anything. In partcular it could be in a mounted filesystem. As 'statd' continues running as a daemon it could keep prevent that filesystem from being unmounted.

Quoted 7 lines

statd does currently 'chdir' to the state directory, but only if the state directory is not owned by root. This is wrong - it should check for root after the chdir, not before.

So swap the two if statements around.

Committed...

steved.

Quoted 35 lines

--
looks like this regression slipped in around January 2010 with the big libnsm clean up.

(quoted diff) +0 -1
-NB
support/nsm/file.c +6 -6
index 98b47bf..a12c753 100644
@@ -395,18 +395,18 @@ nsm_drop_privileges(const int pidfd)
 		return false;
 	}
 
-	if (st.st_uid == 0) {
-		xlog_warn("Running as root.  "
-			"chown %s to choose different user", nsm_base_dirname);
-		return true;
-	}
-
 	if (chdir(nsm_base_dirname) == -1) {
 		xlog(L_ERROR, "Failed to change working directory to %s: %m",
 				nsm_base_dirname);
 		return false;
 	}
 
+	if (st.st_uid == 0) {
+		xlog_warn("Running as root.  "
+			"chown %s to choose different user", nsm_base_dirname);
+		return true;
+	}
+
 	/*
 	 * If the pidfile happens to reside on NFS, dropping privileges
 	 * will probably cause us to lose access, even though we are