svn commit: r316873 - vendor/illumos/dist/lib/libzfs/common

Andriy Gapon avg at FreeBSD.org
Fri Apr 14 17:22:56 UTC 2017


Author: avg
Date: Fri Apr 14 17:22:54 2017
New Revision: 316873
URL: https://svnweb.freebsd.org/changeset/base/316873

Log:
  7233 dir_is_empty should open directory with CLOEXEC
  
  illumos/illumos-gate at d420209d9c807f782c1d31f5683be74798142198
  https://github.com/illumos/illumos-gate/commit/d420209d9c807f782c1d31f5683be74798142198
  
  https://www.illumos.org/issues/7233
    This fixes a race where one thread is executing zfs_mount() while another
    thread forks and execs. If the fork occurs while the directory is open, the
    child process will inherit (but not necessarily close immediately) the open fd
    for the directory, preventing the mount.
  
  Reviewed by: Matthew Ahrens <mahrens at delphix.com>
  Reviewed by: Paul Dagnelie <pcd at delphix.com>
  Approved by: Richard Lowe <richlowe at richlowe.net>
  Author: Alex Reece <alex at delphix.com>

Modified:
  vendor/illumos/dist/lib/libzfs/common/libzfs_mount.c

Modified: vendor/illumos/dist/lib/libzfs/common/libzfs_mount.c
==============================================================================
--- vendor/illumos/dist/lib/libzfs/common/libzfs_mount.c	Fri Apr 14 17:20:26 2017	(r316872)
+++ vendor/illumos/dist/lib/libzfs/common/libzfs_mount.c	Fri Apr 14 17:22:54 2017	(r316873)
@@ -21,7 +21,7 @@
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2014 by Delphix. All rights reserved.
+ * Copyright (c) 2014, 2015 by Delphix. All rights reserved.
  * Copyright 2016 Igor Kozhukhov <ikozhukhov at gmail.com>
  */
 
@@ -64,6 +64,7 @@
 #include <dirent.h>
 #include <dlfcn.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <libgen.h>
 #include <libintl.h>
 #include <stdio.h>
@@ -179,9 +180,16 @@ dir_is_empty(const char *dirname)
 {
 	DIR *dirp;
 	struct dirent64 *dp;
+	int dirfd;
 
-	if ((dirp = opendir(dirname)) == NULL)
+	if ((dirfd = openat(AT_FDCWD, dirname,
+	    O_RDONLY | O_NDELAY | O_LARGEFILE | O_CLOEXEC, 0)) < 0) {
 		return (B_TRUE);
+	}
+
+	if ((dirp = fdopendir(dirfd)) == NULL) {
+		return (B_TRUE);
+	}
 
 	while ((dp = readdir64(dirp)) != NULL) {
 


More information about the svn-src-all mailing list