All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/nfs-utils] mount: run START_STATD fully as root
@ 2016-04-21 23:29 NeilBrown
  2016-04-27 17:33 ` Steve Dickson
  0 siblings, 1 reply; 2+ messages in thread
From: NeilBrown @ 2016-04-21 23:29 UTC (permalink / raw)
  To: Steve Dickson; +Cc: NFS List

[-- Attachment #1: Type: text/plain, Size: 1544 bytes --]


If a "user" mount is the first NFSv3 mount, mount.nfs will be running
setuid to root (with non-root as the real-uid) when it executes START_STATD.

start-statd is a shell script and many shells refuse to run setuid,
dropping privileges immediately.  This results in start-statd running
as an unprivileged user and so statd fails to start.

To fix this, call "setuid(0)" to set real uid to zero.  Also call "setgid(0)"
for consistency.

The behaviour of a shell can often be affected by the environment,
such as the "shell functions" that bash includes from the environment.
To avoid the user being able to pass such environment to the shell,
explicitly pass an empty environment.  The start-statd script explicitly
sets the PATH which is all it really needs.

Signed-off-by: NeilBrown <neilb@suse.com>

diff --git a/utils/mount/network.c b/utils/mount/network.c
index 7240ca7bcdc4..0d12613e86a4 100644
--- a/utils/mount/network.c
+++ b/utils/mount/network.c
@@ -795,6 +795,7 @@ int start_statd(void)
 		if (S_ISREG(stb.st_mode) && (stb.st_mode & S_IXUSR)) {
 			int cnt = STATD_TIMEOUT * 10;
 			int status = 0;
+			char * const envp[1] = { NULL };
 			const struct timespec ts = {
 				.tv_sec = 0,
 				.tv_nsec = 100000000,
@@ -802,7 +803,9 @@ int start_statd(void)
 			pid_t pid = fork();
 			switch (pid) {
 			case 0: /* child */
-				execl(START_STATD, START_STATD, NULL);
+				setgid(0);
+				setuid(0);
+				execle(START_STATD, START_STATD, NULL, envp);
 				exit(1);
 			case -1: /* error */
 				nfs_error(_("%s: fork failed: %s"),

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH/nfs-utils] mount: run START_STATD fully as root
  2016-04-21 23:29 [PATCH/nfs-utils] mount: run START_STATD fully as root NeilBrown
@ 2016-04-27 17:33 ` Steve Dickson
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Dickson @ 2016-04-27 17:33 UTC (permalink / raw)
  To: NeilBrown; +Cc: NFS List



On 04/21/2016 07:29 PM, NeilBrown wrote:
> 
> If a "user" mount is the first NFSv3 mount, mount.nfs will be running
> setuid to root (with non-root as the real-uid) when it executes START_STATD.
> 
> start-statd is a shell script and many shells refuse to run setuid,
> dropping privileges immediately.  This results in start-statd running
> as an unprivileged user and so statd fails to start.
> 
> To fix this, call "setuid(0)" to set real uid to zero.  Also call "setgid(0)"
> for consistency.
> 
> The behaviour of a shell can often be affected by the environment,
> such as the "shell functions" that bash includes from the environment.
> To avoid the user being able to pass such environment to the shell,
> explicitly pass an empty environment.  The start-statd script explicitly
> sets the PATH which is all it really needs.
> 
> Signed-off-by: NeilBrown <neilb@suse.com>
Committed... 

steved.

> 
> diff --git a/utils/mount/network.c b/utils/mount/network.c
> index 7240ca7bcdc4..0d12613e86a4 100644
> --- a/utils/mount/network.c
> +++ b/utils/mount/network.c
> @@ -795,6 +795,7 @@ int start_statd(void)
>  		if (S_ISREG(stb.st_mode) && (stb.st_mode & S_IXUSR)) {
>  			int cnt = STATD_TIMEOUT * 10;
>  			int status = 0;
> +			char * const envp[1] = { NULL };
>  			const struct timespec ts = {
>  				.tv_sec = 0,
>  				.tv_nsec = 100000000,
> @@ -802,7 +803,9 @@ int start_statd(void)
>  			pid_t pid = fork();
>  			switch (pid) {
>  			case 0: /* child */
> -				execl(START_STATD, START_STATD, NULL);
> +				setgid(0);
> +				setuid(0);
> +				execle(START_STATD, START_STATD, NULL, envp);
>  				exit(1);
>  			case -1: /* error */
>  				nfs_error(_("%s: fork failed: %s"),
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-04-27 17:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-21 23:29 [PATCH/nfs-utils] mount: run START_STATD fully as root NeilBrown
2016-04-27 17:33 ` Steve Dickson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.