aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2011-02-17 09:21:39 -0800
committerBrian Behlendorf <[email protected]>2011-02-17 09:35:43 -0800
commitf03e41e8da6d184039ea3b03ba4937f4786a3f22 (patch)
tree2041b8075118e717e397e38635655822ca2fa5ad
parent8b4f9a2d55fc5ee28f69b29f2fece7d8e2cb5c7a (diff)
Improve 'zpool import' safety
There are three improvements here to 'zpool import' proposed by Fajar in Github issue #98. They are all good so I'm commiting all three. 1) Add descriptions for "hpet" and "core" blacklist entries. 2) Add "core" to the blacklist, as described in the issue accessing this device will crash Xen dom0. 3) Refine probing behavior to use fstatat64(). This allows us to determine if a device is a block device or a regular file without having to open it. This is the safest appraoch when probing /dev/ because the simple act of opening a device may have unexpected consequences. Closes #98
-rw-r--r--lib/libzfs/libzfs_import.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c
index 8668583b2..7048a52c9 100644
--- a/lib/libzfs/libzfs_import.c
+++ b/lib/libzfs/libzfs_import.c
@@ -1078,6 +1078,10 @@ zpool_find_import_impl(libzfs_handle_t *hdl, importargs_t *iarg)
* parport* - Parallel port interface.
* lp* - Printer interface.
* fd* - Floppy interface.
+ * hpet - High Precision Event Timer, crashes qemu
+ * when accessed from a virtual machine.
+ * core - Symlink to /proc/kcore, causes a crash
+ * when access from Xen dom0.
*/
if ((strncmp(name, "watchdog", 8) == 0) ||
(strncmp(name, "fuse", 4) == 0) ||
@@ -1087,22 +1091,21 @@ zpool_find_import_impl(libzfs_handle_t *hdl, importargs_t *iarg)
(strncmp(name, "parport", 7) == 0) ||
(strncmp(name, "lp", 2) == 0) ||
(strncmp(name, "fd", 2) == 0) ||
- (strncmp(name, "hpet", 4) == 0))
- continue;
-
- if ((fd = openat64(dfd, name, O_RDONLY)) < 0)
+ (strncmp(name, "hpet", 4) == 0) ||
+ (strncmp(name, "core", 4) == 0))
continue;
/*
* Ignore failed stats. We only want regular
- * files and block devs.
+ * files and block devices.
*/
- if (fstat64(fd, &statbuf) != 0 ||
+ if ((fstatat64(dfd, name, &statbuf, 0) != 0) ||
(!S_ISREG(statbuf.st_mode) &&
- !S_ISBLK(statbuf.st_mode))) {
- (void) close(fd);
+ !S_ISBLK(statbuf.st_mode)))
+ continue;
+
+ if ((fd = openat64(dfd, name, O_RDONLY)) < 0)
continue;
- }
if ((zpool_read_label(fd, &config)) != 0) {
(void) close(fd);