Module Name:    src
Committed By:   maxv
Date:           Fri Feb 13 16:59:53 UTC 2015

Modified Files:
        src/sys/ufs/ffs: ffs_vfsops.c

Log Message:
Add some checks in ffs_superblock_validate():
 - fs_bsize < MINBSIZE
 - !powerof2(fs_bsize)
 - !powerof2(fs->fs_fsize)
 - fs_bsize < fs->fs_fsize

Based on makefs/ffs.


To generate a diff of this commit:
cvs rdiff -u -r1.307 -r1.308 src/sys/ufs/ffs/ffs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.307 src/sys/ufs/ffs/ffs_vfsops.c:1.308
--- src/sys/ufs/ffs/ffs_vfsops.c:1.307	Fri Feb 13 15:52:29 2015
+++ src/sys/ufs/ffs/ffs_vfsops.c	Fri Feb 13 16:59:52 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.307 2015/02/13 15:52:29 maxv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.308 2015/02/13 16:59:52 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.307 2015/02/13 15:52:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.308 2015/02/13 16:59:52 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -912,12 +912,22 @@ ffs_superblock_validate(struct fs *fs, u
 		return 0;
 
 	/* Check the file system blocksize */
-	if (fs_bsize > MAXBSIZE)
+	if (fs_bsize > MAXBSIZE || fs_bsize < MINBSIZE)
+		return 0;
+	if (!powerof2(fs_bsize))
+		return 0;
+
+	/* Check the size of frag blocks */
+	if (!powerof2(fs->fs_fsize))
 		return 0;
 
 	if (fs->fs_size == 0)
 		return 0;
 
+	/* Block size cannot be smaller than fragment size */
+	if (fs_bsize < fs->fs_fsize)
+		return 0;
+
 	return 1;
 }
 

Reply via email to