diff options
author | 2019-04-02 13:07:28 +0000 | |
---|---|---|
committer | 2019-04-02 13:07:28 +0000 | |
commit | 2861400ecbfdff6825314e1c3461615957ee810d (patch) | |
tree | 99e93c2d08e85ed0bb27d0a2f3a9538beb28e098 | |
parent | Enable frame pointer elimination on i386, amd64 and mips64 when given (diff) | |
download | wireguard-openbsd-2861400ecbfdff6825314e1c3461615957ee810d.tar.xz wireguard-openbsd-2861400ecbfdff6825314e1c3461615957ee810d.zip |
Restrict which filesystems are available for swap. This rules out
obvious misconfigurations that cannot work.
OK mpi@ tedu@
-rw-r--r-- | lib/libc/sys/swapctl.2 | 8 | ||||
-rw-r--r-- | sys/kern/vfs_init.c | 10 | ||||
-rw-r--r-- | sys/kern/vfs_subr.c | 4 | ||||
-rw-r--r-- | sys/sys/mount.h | 3 | ||||
-rw-r--r-- | sys/uvm/uvm_swap.c | 12 |
5 files changed, 26 insertions, 11 deletions
diff --git a/lib/libc/sys/swapctl.2 b/lib/libc/sys/swapctl.2 index ec000679783..35f4098dc40 100644 --- a/lib/libc/sys/swapctl.2 +++ b/lib/libc/sys/swapctl.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: swapctl.2,v 1.23 2018/04/27 13:42:08 guenther Exp $ +.\" $OpenBSD: swapctl.2,v 1.24 2019/04/02 13:07:28 visa Exp $ .\" $NetBSD: swapctl.2,v 1.10 1998/08/29 17:11:09 mrg Exp $ .\" .\" Copyright (c) 1997 Matthew R. Green @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: April 27 2018 $ +.Dd $Mdocdate: April 2 2019 $ .Dt SWAPCTL 2 .Os .Sh NAME @@ -210,6 +210,10 @@ An I/O error occurred while opening the swap device. .It Bq Er EFAULT .Fa arg points outside the process' allocated address space. +.It Bq Er ENOTSUP +The device specified by +.Fa arg +cannot be used for swapping. .El .Sh SEE ALSO .Xr config 8 , diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c index 78301377e97..adf1116645d 100644 --- a/sys/kern/vfs_init.c +++ b/sys/kern/vfs_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_init.c,v 1.41 2018/09/17 14:56:37 visa Exp $ */ +/* $OpenBSD: vfs_init.c,v 1.42 2019/04/02 13:07:28 visa Exp $ */ /* $NetBSD: vfs_init.c,v 1.6 1996/02/09 19:00:58 christos Exp $ */ /* @@ -93,7 +93,7 @@ extern const struct vfsops tmpfs_vfsops; /* Set up the filesystem operations for vnodes. */ static struct vfsconf vfsconflist[] = { #ifdef FFS - { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL, + { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL | MNT_SWAPPABLE, sizeof(struct ufs_args) }, #endif @@ -103,7 +103,7 @@ static struct vfsconf vfsconflist[] = { #endif #ifdef EXT2FS - { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL, + { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL | MNT_SWAPPABLE, sizeof(struct ufs_args) }, #endif @@ -113,12 +113,12 @@ static struct vfsconf vfsconflist[] = { #endif #ifdef MSDOSFS - { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL, + { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL | MNT_SWAPPABLE, sizeof(struct msdosfs_args) }, #endif #ifdef NFSCLIENT - { &nfs_vfsops, MOUNT_NFS, 2, 0, 0, + { &nfs_vfsops, MOUNT_NFS, 2, 0, MNT_SWAPPABLE, sizeof(struct nfs_args) }, #endif diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index ed5bbd1be61..982e45080ca 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_subr.c,v 1.286 2019/02/17 22:17:28 tedu Exp $ */ +/* $OpenBSD: vfs_subr.c,v 1.287 2019/04/02 13:07:28 visa Exp $ */ /* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */ /* @@ -184,7 +184,7 @@ vfs_mount_alloc(struct vnode *vp, struct vfsconf *vfsp) atomic_inc_int(&vfsp->vfc_refcount); mp->mnt_vfc = vfsp; mp->mnt_op = vfsp->vfc_vfsops; - mp->mnt_flag = vfsp->vfc_flags & MNT_VISFLAGMASK; + mp->mnt_flag = vfsp->vfc_flags; strncpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN); return (mp); diff --git a/sys/sys/mount.h b/sys/sys/mount.h index f11785cd0b6..6f1004324a3 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mount.h,v 1.143 2018/12/07 16:21:19 mpi Exp $ */ +/* $OpenBSD: mount.h,v 1.144 2019/04/02 13:07:28 visa Exp $ */ /* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */ /* @@ -399,6 +399,7 @@ struct mount { #define MNT_RELOAD 0x00040000 /* reload filesystem data */ #define MNT_FORCE 0x00080000 /* force unmount or readonly change */ #define MNT_STALLED 0x00100000 /* filesystem stalled */ +#define MNT_SWAPPABLE 0x00200000 /* filesystem can be used for swap */ #define MNT_WANTRDWR 0x02000000 /* want upgrade to read/write */ #define MNT_SOFTDEP 0x04000000 /* soft dependencies being done */ #define MNT_DOOMED 0x08000000 /* device behind filesystem is gone */ diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index 663f05b9562..233908ca5e2 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap.c,v 1.143 2018/02/19 08:59:53 mpi Exp $ */ +/* $OpenBSD: uvm_swap.c,v 1.144 2019/04/02 13:07:28 visa Exp $ */ /* $NetBSD: uvm_swap.c,v 1.40 2000/11/17 11:39:39 mrg Exp $ */ /* @@ -714,6 +714,16 @@ sys_swapctl(struct proc *p, void *v, register_t *retval) break; case SWAP_ON: /* + * If the device is a regular file, make sure the filesystem + * can be used for swapping. + */ + if (vp->v_type == VREG && + (vp->v_mount->mnt_flag & MNT_SWAPPABLE) == 0) { + error = ENOTSUP; + break; + } + + /* * check for duplicates. if none found, then insert a * dummy entry on the list to prevent someone else from * trying to enable this device while we are working on |