Mon Mar 6 10:10:43 2017 UTC ()
Deny unmounting file systems below layered file systems.


(hannken)
diff -r1.48 -r1.49 src/sys/kern/vfs_mount.c

cvs diff -r1.48 -r1.49 src/sys/kern/vfs_mount.c (expand / switch to unified diff)

--- src/sys/kern/vfs_mount.c 2017/02/22 09:50:13 1.48
+++ src/sys/kern/vfs_mount.c 2017/03/06 10:10:43 1.49
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_mount.c,v 1.48 2017/02/22 09:50:13 hannken Exp $ */ 1/* $NetBSD: vfs_mount.c,v 1.49 2017/03/06 10:10:43 hannken Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran. 9 * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 * 65 *
66 * @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94 66 * @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.48 2017/02/22 09:50:13 hannken Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.49 2017/03/06 10:10:43 hannken Exp $");
71 71
72#include <sys/param.h> 72#include <sys/param.h>
73#include <sys/kernel.h> 73#include <sys/kernel.h>
74 74
75#include <sys/atomic.h> 75#include <sys/atomic.h>
76#include <sys/buf.h> 76#include <sys/buf.h>
77#include <sys/conf.h> 77#include <sys/conf.h>
78#include <sys/fcntl.h> 78#include <sys/fcntl.h>
79#include <sys/filedesc.h> 79#include <sys/filedesc.h>
80#include <sys/device.h> 80#include <sys/device.h>
81#include <sys/kauth.h> 81#include <sys/kauth.h>
82#include <sys/kmem.h> 82#include <sys/kmem.h>
83#include <sys/module.h> 83#include <sys/module.h>
@@ -807,36 +807,49 @@ err_unmounted: @@ -807,36 +807,49 @@ err_unmounted:
807 807
808 return error; 808 return error;
809} 809}
810 810
811/* 811/*
812 * Do the actual file system unmount. File system is assumed to have 812 * Do the actual file system unmount. File system is assumed to have
813 * been locked by the caller. 813 * been locked by the caller.
814 * 814 *
815 * => Caller hold reference to the mount, explicitly for dounmount(). 815 * => Caller hold reference to the mount, explicitly for dounmount().
816 */ 816 */
817int 817int
818dounmount(struct mount *mp, int flags, struct lwp *l) 818dounmount(struct mount *mp, int flags, struct lwp *l)
819{ 819{
 820 struct mount *cmp;
820 vnode_t *coveredvp; 821 vnode_t *coveredvp;
821 int error, async, used_syncer, used_extattr; 822 int error, async, used_syncer, used_extattr;
822 823
823#if NVERIEXEC > 0 824#if NVERIEXEC > 0
824 error = veriexec_unmountchk(mp); 825 error = veriexec_unmountchk(mp);
825 if (error) 826 if (error)
826 return (error); 827 return (error);
827#endif /* NVERIEXEC > 0 */ 828#endif /* NVERIEXEC > 0 */
828 829
829 /* 830 /*
 831 * No unmount below layered mounts.
 832 */
 833 mutex_enter(&mountlist_lock);
 834 TAILQ_FOREACH(cmp, &mountlist, mnt_list) {
 835 if (cmp->mnt_lower == mp) {
 836 mutex_exit(&mountlist_lock);
 837 return EBUSY;
 838 }
 839 }
 840 mutex_exit(&mountlist_lock);
 841
 842 /*
830 * XXX Freeze syncer. Must do this before locking the 843 * XXX Freeze syncer. Must do this before locking the
831 * mount point. See dounmount() for details. 844 * mount point. See dounmount() for details.
832 */ 845 */
833 mutex_enter(&syncer_mutex); 846 mutex_enter(&syncer_mutex);
834 847
835 /* 848 /*
836 * Abort unmount attempt when the filesystem is in use 849 * Abort unmount attempt when the filesystem is in use
837 */ 850 */
838 mutex_enter(&mp->mnt_unmounting); 851 mutex_enter(&mp->mnt_unmounting);
839 if (mp->mnt_busynest != 0) { 852 if (mp->mnt_busynest != 0) {
840 mutex_exit(&mp->mnt_unmounting); 853 mutex_exit(&mp->mnt_unmounting);
841 mutex_exit(&syncer_mutex); 854 mutex_exit(&syncer_mutex);
842 return EBUSY; 855 return EBUSY;