bin/56500: rpc.lockd needs to use reserved ports
Jonathan Lennox
lennox at cs.columbia.edu
Sat Sep 6 10:28:16 PDT 2003
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;
More information about the freebsd-bugs
mailing list