diff options
author | mav <mav@FreeBSD.org> | 2018-03-22 23:47:04 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2018-03-22 23:47:04 +0000 |
commit | ab49be49bf935affea20c20d5c09a9c50db5063e (patch) | |
tree | c8b3002a2f4ace20afc6b972d8b70b8bbec806a3 /cddl/contrib/opensolaris/lib/libzfs/common | |
parent | bd0fcf6a6fbf23b0abf49fe66cd14779cbdc64ea (diff) | |
download | FreeBSD-src-ab49be49bf935affea20c20d5c09a9c50db5063e.zip FreeBSD-src-ab49be49bf935affea20c20d5c09a9c50db5063e.tar.gz |
MFC r329659: MFV r316873: 7233 dir_is_empty should open directory with CLOEXEC
illumos/illumos-gate@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@delphix.com>
Reviewed by: Paul Dagnelie <pcd@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Author: Alex Reece <alex@delphix.com>
Diffstat (limited to 'cddl/contrib/opensolaris/lib/libzfs/common')
-rw-r--r-- | cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c index 8830b86..0c907eb 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c @@ -22,7 +22,7 @@ /* * Copyright 2015 Nexenta Systems, Inc. All rights reserved. * 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@gmail.com> * Copyright 2017 Joyent, Inc. * Copyright 2017 RackTop Systems. @@ -67,6 +67,7 @@ #include <dirent.h> #include <dlfcn.h> #include <errno.h> +#include <fcntl.h> #include <libgen.h> #include <libintl.h> #include <stdio.h> @@ -187,9 +188,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) { |