Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Sep 2003 13:28:13 -0400
From:      Jonathan Lennox <lennox@cs.columbia.edu>
To:        FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Subject:   Re: bin/56500: rpc.lockd needs to use reserved ports
Message-ID:  <16218.6445.294271.622770@cnr.cs.columbia.edu>
In-Reply-To: <200309051730.h85HUDxE019269@freefall.freebsd.org>
References:  <200309051722.h85HMPbj085465@cnr.cs.columbia.edu> <200309051730.h85HUDxE019269@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
After a day or so of untangling how RPC code works, I've worked out a patch.

I'm pretty sure that this patch regains root privileges for the absolute
minimum amount of time necessary to bind to a reserved port.

I've tested this, and it does (along with the patch in kern/56461) allow me
to sucessfully lock files from a Linux server -- and thus to invoke movemail
on my mailspool, and thus to read my mail on my FreeBSD machine, which was
the whole motivation.

--- usr.sbin/rpc.lockd/lock_proc.c.orig	Sat Sep  6 12:48:10 2003
+++ usr.sbin/rpc.lockd/lock_proc.c	Sat Sep  6 13:18:08 2003
@@ -197,6 +197,8 @@
 	const char *netid;
 	struct netconfig *nconf;
 	char host[NI_MAXHOST];
+	uid_t old_euid;
+	int clnt_fd;
 
 	gettimeofday(&time_now, NULL);
 
@@ -270,6 +272,22 @@
 		syslog(LOG_ERR, "Unable to return result to %s", host);
 		return NULL;
 	}
+
+	/* Get the FD of the client, for bindresvport. */ 
+	clnt_control(client, CLGET_FD, &clnt_fd);
+
+	/* Regain root privileges, for bindresvport. */
+	old_euid = geteuid();
+	seteuid(0);
+
+	/*
+	 * Bind the client FD to a reserved port.
+	 * Some NFS servers reject any NLM request from a non-reserved port. 
+	 */ 
+	bindresvport(clnt_fd, NULL);
+
+	/* Drop root privileges again. */
+	seteuid(old_euid);
 
 	/* Success - update the cache entry */
 	clnt_cache_ptr[clnt_cache_next_to_use] = client;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?16218.6445.294271.622770>