summaryrefslogtreecommitdiffstats
path: root/sys/ufs
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2016-01-27 21:27:05 +0000
committermckusick <mckusick@FreeBSD.org>2016-01-27 21:27:05 +0000
commit32cb8b928ab479168c225f3499c467fc1c2c443f (patch)
treed22f67a7c76d31bd8a0cf76aca44675ab9a88dbd /sys/ufs
parent0b10a802f877a41beb1b823c21a6a4b241ed8e28 (diff)
downloadFreeBSD-src-32cb8b928ab479168c225f3499c467fc1c2c443f.zip
FreeBSD-src-32cb8b928ab479168c225f3499c467fc1c2c443f.tar.gz
This fixes a bug in UFS2 exported NFS volumes. An NFS client can
crash a server that has exported UFS2 by presenting a filehandle with an inode number that references an uninitialized inode in a cylinder group. The problem is that UFS2 only initializes blocks of inodes as they are first allocated and ffs_fhtovp() does not validate that the inode is in a range of inodes that have been initialized. Attempting to read an uninitialized inode gets random data from the disk. When the kernel tries to interpret it as an inode, panics often arise. Reported by: Christos Zoulas (from NetBSD) Reviewed by: kib
Diffstat (limited to 'sys/ufs')
-rw-r--r--sys/ufs/ffs/ffs_vfsops.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c
index 82c22fd..a82ef61 100644
--- a/sys/ufs/ffs/ffs_vfsops.c
+++ b/sys/ufs/ffs/ffs_vfsops.c
@@ -1797,6 +1797,7 @@ ffs_vgetf(mp, ino, flags, vpp, ffs_flags)
*
* Have to be really careful about stale file handles:
* - check that the inode number is valid
+ * - for UFS2 check that the inode number is initialized
* - call ffs_vget() to get the locked inode
* - check for an unallocated inode (i_mode == 0)
* - check that the given client host has export rights and return
@@ -1810,13 +1811,37 @@ ffs_fhtovp(mp, fhp, flags, vpp)
struct vnode **vpp;
{
struct ufid *ufhp;
+ struct ufsmount *ump;
struct fs *fs;
+ struct cg *cgp;
+ struct buf *bp;
+ ino_t ino;
+ u_int cg;
+ int error;
ufhp = (struct ufid *)fhp;
- fs = VFSTOUFS(mp)->um_fs;
- if (ufhp->ufid_ino < ROOTINO ||
- ufhp->ufid_ino >= fs->fs_ncg * fs->fs_ipg)
+ ino = ufhp->ufid_ino;
+ ump = VFSTOUFS(mp);
+ fs = ump->um_fs;
+ if (ino < ROOTINO || ino >= fs->fs_ncg * fs->fs_ipg)
return (ESTALE);
+ /*
+ * Need to check if inode is initialized because UFS2 does lazy
+ * initialization and nfs_fhtovp can offer arbitrary inode numbers.
+ */
+ if (fs->fs_magic != FS_UFS2_MAGIC)
+ return (ufs_fhtovp(mp, ufhp, flags, vpp));
+ cg = ino_to_cg(fs, ino);
+ error = bread(ump->um_devvp, fsbtodb(fs, cgtod(fs, cg)),
+ (int)fs->fs_cgsize, NOCRED, &bp);
+ if (error)
+ return (error);
+ cgp = (struct cg *)bp->b_data;
+ if (!cg_chkmagic(cgp) || ino >= cg * fs->fs_ipg + cgp->cg_initediblk) {
+ brelse(bp);
+ return (ESTALE);
+ }
+ brelse(bp);
return (ufs_fhtovp(mp, ufhp, flags, vpp));
}
OpenPOWER on IntegriCloud