Skip to contentSkip to conversation

nfs-utils: Do not drop privileges if running as non-root user

PATCH In review [email protected] 2 participants 2 messages Nov 4, 2025 – Nov 19, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs-utils: Do not drop privileges if running as non-root user

From: Peter Schwenke <[email protected]>

If sm-notify is not running root and is running
as the owner of the state directory, it is not
necessary to drop privileges.

The patch checks if the current user is the owner of the state directory.

In the case of a ha-callout, the ha-callout will, more than likely, be running as rpcuser - or similar. That means the sm-notify program can not be called from the ha-callout.

nsm_drop_privileges() is also called by statd. However, that will fail for a number of reasons such as not being able to create the PID file etc. So, this patch should not cause any issues for statd. statd will still need to be started as root.

Without this patch capabalities such as cap_setpcap, cap_setgid, cap_net_bind_service=ep need to be set. Clearly, that is an ugly hack and best avoided.

---
 support/nsm/file.c        | 11 +++++++++++
 utils/statd/sm-notify.man | 10 +++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
support/nsm/file.c +11 -0
index 5ec801c3..1e97b5b6 100644
@@ -394,6 +394,7 @@ _Bool
 nsm_drop_privileges(const int pidfd)
 {
 	struct stat st;
+	uid_t uid;
 
 	(void)umask(S_IRWXO);
 
@@ -408,6 +409,16 @@ nsm_drop_privileges(const int pidfd)
 		return false;
 	}
 
+	/*
+	 * Check if we are running as non-root user and we are the owner of
+	 * the monitor directory.  Then there is no reason to drop privileges
+	 * and change groups etc.
+	 */
+	uid = getuid();
+	if (uid != 0 && uid == st.st_uid) {
+		return true;
+	}
+
 	if (!prune_bounding_set())
 		return false;
 
utils/statd/sm-notify.man +9 -1
index addf5d3c..2e82c683 100644
@@ -275,7 +275,7 @@ section is
 .SH SECURITY
 The
 .B sm-notify
-command must be started as root to acquire privileges needed
+command is, generally, started as root to acquire privileges needed
 to access the state information database.
 It drops root privileges
 as soon as it starts up to reduce the risk of a privilege escalation attack.
@@ -290,6 +290,14 @@ chooses, simply use
 .BR chown (1)
 to set the owner of
 the state directory.
+.PP
+The
+.B sm-notify
+command can also be started by the user ID that owns the state directory.
+That is useful for the situation when it is called from an rpc-stat
+ha-callout program that is already running as the
+non-privileged user.  The non-root user will not have the capabilities
+to drop the root privileges as described above.
 .SH ADDITIONAL NOTES
 Lock recovery after a reboot is critical to maintaining data integrity
 and preventing unnecessary application hangs.
Signature · 1 line
2.39.5
#1 lore raw
Quoted 18 lines · On 11/3/25 11:34 PM, [email protected] wrote:

From: Peter Schwenke <[email protected]>

If sm-notify is not running root and is running
as the owner of the state directory, it is not
necessary to drop privileges.

The patch checks if the current user is the owner of the state directory.

In the case of a ha-callout, the ha-callout will, more than likely, be running as rpcuser - or similar. That means the sm-notify program can not be called from the ha-callout.

nsm_drop_privileges() is also called by statd. However, that will fail for a number of reasons such as not being able to create the PID file etc. So, this patch should not cause any issues for statd. statd will still need to be started as root.

Quoted 6 lines

Without this patch capabalities such as cap_setpcap, cap_setgid, cap_net_bind_service=ep need to be set. Clearly, that is an ugly hack and best avoided.

Committed... (tag: nfs-utils-2-8-5-rc1)

steved.> ---

Quoted 61 lines
  support/nsm/file.c        | 11 +++++++++++
  utils/statd/sm-notify.man | 10 +++++++++-
  2 files changed, 20 insertions(+), 1 deletion(-)
support/nsm/file.c +11 -0
index 5ec801c3..1e97b5b6 100644
@@ -394,6 +394,7 @@ _Bool
  nsm_drop_privileges(const int pidfd)
  {
  	struct stat st;
+	uid_t uid;
 
  	(void)umask(S_IRWXO);
 
@@ -408,6 +409,16 @@ nsm_drop_privileges(const int pidfd)
  		return false;
  	}
 
+	/*
+	 * Check if we are running as non-root user and we are the owner of
+	 * the monitor directory.  Then there is no reason to drop privileges
+	 * and change groups etc.
+	 */
+	uid = getuid();
+	if (uid != 0 && uid == st.st_uid) {
+		return true;
+	}
+
  	if (!prune_bounding_set())
  		return false;
 
utils/statd/sm-notify.man +9 -1
index addf5d3c..2e82c683 100644
@@ -275,7 +275,7 @@ section is
  .SH SECURITY
  The
  .B sm-notify
-command must be started as root to acquire privileges needed
+command is, generally, started as root to acquire privileges needed
  to access the state information database.
  It drops root privileges
  as soon as it starts up to reduce the risk of a privilege escalation attack.
@@ -290,6 +290,14 @@ chooses, simply use
  .BR chown (1)
  to set the owner of
  the state directory.
+.PP
+The
+.B sm-notify
+command can also be started by the user ID that owns the state directory.
+That is useful for the situation when it is called from an rpc-stat
+ha-callout program that is already running as the
+non-privileged user.  The non-root user will not have the capabilities
+to drop the root privileges as described above.
  .SH ADDITIONAL NOTES
  Lock recovery after a reboot is critical to maintaining data integrity
  and preventing unnecessary application hangs.