Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Jan 2019 22:34:47 +0000 (UTC)
From:      Kirk McKusick <mckusick@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r342819 - in stable/11/sys: fs/ext2fs kern ufs/ffs ufs/ufs
Message-ID:  <201901062234.x06MYld7054661@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mckusick
Date: Sun Jan  6 22:34:47 2019
New Revision: 342819
URL: https://svnweb.freebsd.org/changeset/base/342819

Log:
  MFC of 342548
  
  When loading an inode from disk, verify that its mode is valid.
  
  Sponsored by:	Netflix

Modified:
  stable/11/sys/fs/ext2fs/ext2_vnops.c
  stable/11/sys/kern/vfs_subr.c
  stable/11/sys/ufs/ffs/ffs_snapshot.c
  stable/11/sys/ufs/ufs/ufs_vnops.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/fs/ext2fs/ext2_vnops.c
==============================================================================
--- stable/11/sys/fs/ext2fs/ext2_vnops.c	Sun Jan  6 22:30:27 2019	(r342818)
+++ stable/11/sys/fs/ext2fs/ext2_vnops.c	Sun Jan  6 22:34:47 2019	(r342819)
@@ -1857,6 +1857,11 @@ ext2_vinit(struct mount *mntp, struct vop_vector *fifo
 	vp = *vpp;
 	ip = VTOI(vp);
 	vp->v_type = IFTOVT(ip->i_mode);
+	/*
+	 * Only unallocated inodes should be of type VNON.
+	 */
+	if (ip->i_mode != 0 && vp->v_type == VNON)
+		return (EINVAL);
 	if (vp->v_type == VFIFO)
 		vp->v_op = fifoops;
 

Modified: stable/11/sys/kern/vfs_subr.c
==============================================================================
--- stable/11/sys/kern/vfs_subr.c	Sun Jan  6 22:30:27 2019	(r342818)
+++ stable/11/sys/kern/vfs_subr.c	Sun Jan  6 22:34:47 2019	(r342819)
@@ -150,7 +150,7 @@ SYSCTL_COUNTER_U64(_vfs, OID_AUTO, vnodes_created, CTL
  */
 enum vtype iftovt_tab[16] = {
 	VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
-	VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
+	VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VNON
 };
 int vttoif_tab[10] = {
 	0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK,

Modified: stable/11/sys/ufs/ffs/ffs_snapshot.c
==============================================================================
--- stable/11/sys/ufs/ffs/ffs_snapshot.c	Sun Jan  6 22:30:27 2019	(r342818)
+++ stable/11/sys/ufs/ffs/ffs_snapshot.c	Sun Jan  6 22:34:47 2019	(r342819)
@@ -1991,15 +1991,19 @@ ffs_snapshot_mount(mp)
 			continue;
 		}
 		ip = VTOI(vp);
-		if (!IS_SNAPSHOT(ip) || ip->i_size ==
+		if (vp->v_type != VREG) {
+			reason = "non-file snapshot";
+		} else if (!IS_SNAPSHOT(ip)) {
+			reason = "non-snapshot";
+		} else if (ip->i_size ==
 		    lblktosize(fs, howmany(fs->fs_size, fs->fs_frag))) {
-			if (!IS_SNAPSHOT(ip)) {
-				reason = "non-snapshot";
-			} else {
-				reason = "old format snapshot";
-				(void)ffs_truncate(vp, (off_t)0, 0, NOCRED);
-				(void)ffs_syncvnode(vp, MNT_WAIT, 0);
-			}
+			reason = "old format snapshot";
+			(void)ffs_truncate(vp, (off_t)0, 0, NOCRED);
+			(void)ffs_syncvnode(vp, MNT_WAIT, 0);
+		} else {
+			reason = NULL;
+		}
+		if (reason != NULL) {
 			printf("ffs_snapshot_mount: %s inode %d\n",
 			    reason, fs->fs_snapinum[snaploc]);
 			vput(vp);

Modified: stable/11/sys/ufs/ufs/ufs_vnops.c
==============================================================================
--- stable/11/sys/ufs/ufs/ufs_vnops.c	Sun Jan  6 22:30:27 2019	(r342818)
+++ stable/11/sys/ufs/ufs/ufs_vnops.c	Sun Jan  6 22:34:47 2019	(r342819)
@@ -2511,6 +2511,11 @@ ufs_vinit(mntp, fifoops, vpp)
 	vp = *vpp;
 	ip = VTOI(vp);
 	vp->v_type = IFTOVT(ip->i_mode);
+	/*
+	 * Only unallocated inodes should be of type VNON.
+	 */
+	if (ip->i_mode != 0 && vp->v_type == VNON)
+		return (EINVAL);
 	if (vp->v_type == VFIFO)
 		vp->v_op = fifoops;
 	ASSERT_VOP_LOCKED(vp, "ufs_vinit");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201901062234.x06MYld7054661>