From owner-freebsd-bugs@FreeBSD.ORG Sat Sep 6 10:30:16 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3C70E16A4BF for ; Sat, 6 Sep 2003 10:30:16 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id BB74D43F3F for ; Sat, 6 Sep 2003 10:30:15 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h86HUFUp084162 for ; Sat, 6 Sep 2003 10:30:15 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h86HUFft084161; Sat, 6 Sep 2003 10:30:15 -0700 (PDT) Date: Sat, 6 Sep 2003 10:30:15 -0700 (PDT) Message-Id: <200309061730.h86HUFft084161@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jonathan Lennox Subject: Re: bin/56500: rpc.lockd needs to use reserved ports X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Jonathan Lennox List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Sep 2003 17:30:16 -0000 The following reply was made to PR bin/56500; it has been noted by GNATS. From: Jonathan Lennox To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org Cc: Subject: Re: bin/56500: rpc.lockd needs to use reserved ports Date: Sat, 6 Sep 2003 13:28:13 -0400 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;