Don't leak mount flags into kernel
[zfs.git] / cmd / mount_zfs / mount_zfs.c
index 0a69d69..fd685fa 100644 (file)
@@ -131,15 +131,6 @@ parse_option(char *mntopt, unsigned long *mntflags,
                if (strncmp(name, opt->name, strlen(name)) == 0) {
                        *mntflags |= opt->mntmask;
                        *zfsflags |= opt->zfsmask;
-
-                       /* MS_USERS implies default user options */
-                       if (opt->mntmask & (MS_USERS))
-                               *mntflags |= (MS_NOEXEC|MS_NOSUID|MS_NODEV);
-
-                       /* MS_OWNER|MS_GROUP imply default owner options */
-                       if (opt->mntmask & (MS_OWNER | MS_GROUP))
-                               *mntflags |= (MS_NOSUID|MS_NODEV);
-
                        error = 0;
                        goto out;
                }
@@ -311,7 +302,8 @@ main(int argc, char **argv)
        char mntopts[MNT_LINE_MAX] = { '\0' };
        char badopt[MNT_LINE_MAX] = { '\0' };
        char mtabopt[MNT_LINE_MAX] = { '\0' };
-       char *dataset, *mntpoint;
+       char mntpoint[PATH_MAX];
+       char *dataset;
        unsigned long mntflags = 0, zfsflags = 0, remount = 0;
        int sloppy = 0, fake = 0, verbose = 0, nomtab = 0, zfsutil = 0;
        int error, c;
@@ -367,7 +359,14 @@ main(int argc, char **argv)
        }
 
        dataset = parse_dataset(argv[0]);
-       mntpoint = argv[1];
+
+       /* canonicalize the mount point */
+       if (realpath(argv[1], mntpoint) == NULL) {
+               (void) fprintf(stderr, gettext("filesystem '%s' cannot be "
+                   "mounted at '%s' due to canonicalization error %d.\n"),
+                   dataset, argv[1], errno);
+               return (MOUNT_SYSERR);
+       }
 
        /* validate mount options and set mntflags */
        error = parse_options(mntopts, &mntflags, &zfsflags, sloppy,
@@ -467,7 +466,8 @@ main(int argc, char **argv)
                return (MOUNT_USAGE);
        }
 
-       if (!zfsutil && strcmp(legacy, ZFS_MOUNTPOINT_LEGACY) && !remount) {
+       if (!zfsutil && !(remount || fake) &&
+           strcmp(legacy, ZFS_MOUNTPOINT_LEGACY)) {
                (void) fprintf(stderr, gettext(
                    "filesystem '%s' cannot be mounted using 'mount'.\n"
                    "Use 'zfs set mountpoint=%s' or 'zfs mount %s'.\n"