From owner-dev-commits-src-all@freebsd.org Tue Apr 27 12:48:59 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 846CF5F03B5; Tue, 27 Apr 2021 12:48:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FV1mC3C3qz3wX1; Tue, 27 Apr 2021 12:48:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 60FC21B113; Tue, 27 Apr 2021 12:48:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13RCmxMs001551; Tue, 27 Apr 2021 12:48:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13RCmxmN001550; Tue, 27 Apr 2021 12:48:59 GMT (envelope-from git) Date: Tue, 27 Apr 2021 12:48:59 GMT Message-Id: <202104271248.13RCmxmN001550@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 95b86ac22728 - stable/12 - Fix race in case of device destruction. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 95b86ac2272885b4e1b9b3c2f0aafca7ea90fabc Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Apr 2021 12:48:59 -0000 The branch stable/12 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=95b86ac2272885b4e1b9b3c2f0aafca7ea90fabc commit 95b86ac2272885b4e1b9b3c2f0aafca7ea90fabc Author: Alexander Motin AuthorDate: 2021-04-13 15:19:10 +0000 Commit: Alexander Motin CommitDate: 2021-04-27 12:48:57 +0000 Fix race in case of device destruction. During device destruction it is possible that open() succeed, but fdevname() return NULL, that can't be assigned to string variable. Fix that by adding explicit NULL check. Also while there switch from fdevname() to fdevname_r(). Sponsored by: iXsystems, Inc. MFC after: 2 weeks (cherry picked from commit e49d3eb40324eaffaa13b93f2c4173dfa04dfa34) --- lib/libdevdctl/event.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/libdevdctl/event.cc b/lib/libdevdctl/event.cc index 36c9b725fed1..76ef1896975a 100644 --- a/lib/libdevdctl/event.cc +++ b/lib/libdevdctl/event.cc @@ -277,6 +277,7 @@ Event::GetTimestamp() const bool Event::DevPath(std::string &path) const { + char buf[SPECNAMELEN + 1]; string devName; if (!DevName(devName)) @@ -288,7 +289,11 @@ Event::DevPath(std::string &path) const return (false); /* Normalize the device name in case the DEVFS event is for a link. */ - devName = fdevname(devFd); + if (fdevname_r(devFd, buf, sizeof(buf)) == NULL) { + close(devFd); + return (false); + } + devName = buf; path = _PATH_DEV + devName; close(devFd);