nfs-utils: Do not drop privileges if running as non-root user
Subsystems (2)
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
@@ -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
@@ -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
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.Signed-off-by Peter Schwenke <[email protected]>Signed-off-by Peter Schwenke <[email protected]>
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@@ -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@@ -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.