Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Apr 2021 15:25:46 GMT
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: e49d3eb40324 - main - Fix race in case of device destruction.
Message-ID:  <202104131525.13DFPkfh090431@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=e49d3eb40324eaffaa13b93f2c4173dfa04dfa34

commit e49d3eb40324eaffaa13b93f2c4173dfa04dfa34
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2021-04-13 15:19:10 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2021-04-13 15:25:27 +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
---
 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104131525.13DFPkfh090431>