From owner-svn-src-all@freebsd.org Tue Dec 22 09:26:25 2015 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 EF15DA4F9C6; Tue, 22 Dec 2015 09:26:25 +0000 (UTC) (envelope-from hselasky@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 BA6F31310; Tue, 22 Dec 2015 09:26:25 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBM9QOEN044470; Tue, 22 Dec 2015 09:26:24 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBM9QOq3044469; Tue, 22 Dec 2015 09:26:24 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201512220926.tBM9QOq3044469@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 22 Dec 2015 09:26:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292592 - head/sys/fs/cuse 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.20 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: Tue, 22 Dec 2015 09:26:26 -0000 Author: hselasky Date: Tue Dec 22 09:26:24 2015 New Revision: 292592 URL: https://svnweb.freebsd.org/changeset/base/292592 Log: Guard against the same process being both CUSE server and client at the same time. This can easily lead to a deadlock when destroying the character devices nodes. Modified: head/sys/fs/cuse/cuse.c Modified: head/sys/fs/cuse/cuse.c ============================================================================== --- head/sys/fs/cuse/cuse.c Tue Dec 22 09:08:21 2015 (r292591) +++ head/sys/fs/cuse/cuse.c Tue Dec 22 09:26:24 2015 (r292592) @@ -108,6 +108,7 @@ struct cuse_server { TAILQ_HEAD(, cuse_client) hcli; struct cv cv; struct selinfo selinfo; + pid_t pid; int is_closing; int refs; }; @@ -691,6 +692,10 @@ cuse_server_open(struct cdev *dev, int f free(pcs, M_CUSE); return (ENOMEM); } + + /* store current process ID */ + pcs->pid = curproc->p_pid; + TAILQ_INIT(&pcs->head); TAILQ_INIT(&pcs->hdev); TAILQ_INIT(&pcs->hcli); @@ -1357,9 +1362,15 @@ cuse_client_open(struct cdev *dev, int f if (pcsd != NULL) { pcs = pcsd->server; pcd = pcsd->user_dev; + /* + * Check that the refcount didn't wrap and that the + * same process is not both client and server. This + * can easily lead to deadlocks when destroying the + * CUSE character device nodes: + */ pcs->refs++; - if (pcs->refs < 0) { - /* overflow */ + if (pcs->refs < 0 || pcs->pid == curproc->p_pid) { + /* overflow or wrong PID */ pcs->refs--; pcsd = NULL; }