From owner-svn-src-all@FreeBSD.ORG Mon Apr 8 19:03:02 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 27EEB767; Mon, 8 Apr 2013 19:03:02 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 1A2851F7; Mon, 8 Apr 2013 19:03:02 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r38J31Ku084694; Mon, 8 Apr 2013 19:03:01 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r38J31FG084693; Mon, 8 Apr 2013 19:03:01 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201304081903.r38J31FG084693@svn.freebsd.org> From: John Baldwin Date: Mon, 8 Apr 2013 19:03:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r249263 - head/sys/rpc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Apr 2013 19:03:02 -0000 Author: jhb Date: Mon Apr 8 19:03:01 2013 New Revision: 249263 URL: http://svnweb.freebsd.org/changeset/base/249263 Log: Fix a potential socket leak in the NFS server. If a client closes its connection after it was accepted by the userland nfsd process but before it was handled off to svc_vc_create() in the kernel, then svc_vc_create() would see it as a new listen socket and try to listen on it leaving a dangling reference to the socket. Instead, check for disconnected sockets and treat them like a connected socket. The call to pru_getaddr() should fail and cause svc_vc_create() to fail. Note that we need to lock the socket to get a consistent snapshot of so_state since there is a window in soisdisconnected() where both flags are clear. Reviewed by: dfr, rmacklem MFC after: 1 week Modified: head/sys/rpc/svc_vc.c Modified: head/sys/rpc/svc_vc.c ============================================================================== --- head/sys/rpc/svc_vc.c Mon Apr 8 18:46:35 2013 (r249262) +++ head/sys/rpc/svc_vc.c Mon Apr 8 19:03:01 2013 (r249263) @@ -146,7 +146,9 @@ svc_vc_create(SVCPOOL *pool, struct sock struct sockaddr* sa; int error; - if (so->so_state & SS_ISCONNECTED) { + SOCK_LOCK(so); + if (so->so_state & (SS_ISCONNECTED|SS_ISDISCONNECTED)) { + SOCK_UNLOCK(so); error = so->so_proto->pr_usrreqs->pru_peeraddr(so, &sa); if (error) return (NULL); @@ -154,6 +156,7 @@ svc_vc_create(SVCPOOL *pool, struct sock free(sa, M_SONAME); return (xprt); } + SOCK_UNLOCK(so); xprt = svc_xprt_alloc(); sx_init(&xprt->xp_lock, "xprt->xp_lock");