From owner-svn-src-all@freebsd.org Thu Jun 8 06:16:48 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 762B7BF7652; Thu, 8 Jun 2017 06:16:48 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4693F7603B; Thu, 8 Jun 2017 06:16:48 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v586Glua020212; Thu, 8 Jun 2017 06:16:47 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v586Glh8020211; Thu, 8 Jun 2017 06:16:47 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201706080616.v586Glh8020211@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Thu, 8 Jun 2017 06:16:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319685 - head/sys/kern 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.23 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: Thu, 08 Jun 2017 06:16:48 -0000 Author: glebius Date: Thu Jun 8 06:16:47 2017 New Revision: 319685 URL: https://svnweb.freebsd.org/changeset/base/319685 Log: Fix a degenerate case when soisdisconnected() would call soisconnected(). This happens when closing a socket with upcall, and trace is: soclose()-> ... protocol ... -> soisdisconnected() -> socantrcvmore_locked() -> sowakeup() -> soisconnected(). Right now this case is innocent for two reasons. First, soisconnected() doesn't clear SS_ISDISCONNECTED flag. Second, the mutex to lock the socket is the socket receive buffer mutex, and sodisconnected() first disables the receive buffer. But in future code, the mutex to lock socket is different to buffer mutex, and we would get undesired mutex recursion. The fix is to check SS_ISDISCONNECTED flag before calling upcall. Modified: head/sys/kern/uipc_sockbuf.c Modified: head/sys/kern/uipc_sockbuf.c ============================================================================== --- head/sys/kern/uipc_sockbuf.c Thu Jun 8 06:13:53 2017 (r319684) +++ head/sys/kern/uipc_sockbuf.c Thu Jun 8 06:16:47 2017 (r319685) @@ -322,7 +322,7 @@ sowakeup(struct socket *so, struct sockbuf *sb) wakeup(&sb->sb_acc); } KNOTE_LOCKED(&sb->sb_sel.si_note, 0); - if (sb->sb_upcall != NULL) { + if (sb->sb_upcall != NULL && !(so->so_state & SS_ISDISCONNECTED)) { ret = sb->sb_upcall(so, sb->sb_upcallarg, M_NOWAIT); if (ret == SU_ISCONNECTED) { KASSERT(sb == &so->so_rcv,