linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vxfs fix
@ 2001-08-01 21:03 Andries.Brouwer
  2001-08-01 21:18 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Andries.Brouwer @ 2001-08-01 21:03 UTC (permalink / raw)
  To: alan, hch, torvalds, viro; +Cc: linux-kernel

Dear Linus, Alan, Al, Christoph, all,

If one mounts without specifying a type, mount will try
all available types. After having tried vxfs the next type
will cause
	set_blocksize: b_count 1 ...
since vxfs forgets to free a block.
The patch below adds the missing brelse().
(In fact there are more resources that are never freed there -
maybe the maintainer can have a look some time -
I only added a comment.)

When mount continues to try all types, it may try V7.
That always succeeds, there is no test for magic or so,
and after garbage has been mounted as a V7 filesystem,
the kernel crashes or hangs or fails in other sad ways.
Have not tried to debug.

Andries


--- ../linux-2.4.7/linux/fs/freevxfs/vxfs_super.c	Sat Jul 28 17:08:46 2001
+++ linux/fs/freevxfs/vxfs_super.c	Wed Aug  1 22:41:24 2001
@@ -178,7 +178,8 @@
 	}
 
 	if (rsbp->vs_version < 2 || rsbp->vs_version > 4) {
-		printk(KERN_NOTICE "vxfs: unsupported VxFS version (%d)\n", rsbp->vs_version);
+		printk(KERN_NOTICE "vxfs: unsupported VxFS version (%d)\n",
+		       rsbp->vs_version);
 		goto out;
 	}
 
@@ -221,6 +222,7 @@
 	if (vxfs_read_fshead(sbp)) {
 		printk(KERN_WARNING "vxfs: unable to read fshead\n");
 		return NULL;
+		/* BUG: lots of gets not matched by puts here */
 	}
 
 	sbp->s_op = &vxfs_super_ops;
@@ -229,6 +231,7 @@
 	
 	printk(KERN_WARNING "vxfs: unable to get root dentry.\n");
 out:
+	brelse(bp);
 	kfree(infp);
 	return NULL;
 }

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [PATCH] vxfs fix
@ 2001-08-02 19:15 Andries.Brouwer
  0 siblings, 0 replies; 9+ messages in thread
From: Andries.Brouwer @ 2001-08-02 19:15 UTC (permalink / raw)
  To: Andries.Brouwer, torvalds; +Cc: alan, hch, linux-kernel, viro

	From: Linus Torvalds <torvalds@transmeta.com>

	On Wed, 1 Aug 2001 Andries.Brouwer@cwi.nl wrote:
	>
	> When mount continues to try all types, it may try V7.
	> That always succeeds, there is no test for magic or so,
	> and after garbage has been mounted as a V7 filesystem,
	> the kernel crashes or hangs or fails in other sad ways.

	Even on filesystems that have bad (limited or non-existent)
	magic numbers, 	the read_super() function should really be able
	to do a fair amount of sanity-checking. If nothing else,
	then things like verifying that the root inode really is
	a directory with a proper size, for example.

Added.

	From: Christoph Hellwig

	I'd like to propose:
	s_nfree <= V7_NICFREE, s_ninode <= V7_NICINOD, s_time != 0

Added.

	From: Al Viro

	It shouldn't crash the box, though - I'll look into that.

Good!

	From: Alan

	Alternatively pass a flag to the mount command saying
	"this is a guesswork special" then V7 fs can just return 'not me'

Parse failure.

Below a patch.

Andries


diff -r -u ../linux-2.4.7/linux/fs/sysv/super.c linux/fs/sysv/super.c
--- ../linux-2.4.7/linux/fs/sysv/super.c	Sat Jul 28 17:08:46 2001
+++ linux/fs/sysv/super.c	Thu Aug  2 19:47:58 2001
@@ -197,6 +197,8 @@
 		sb->sv_bytesex = BYTESEX_BE;
 	else
 		return 0;
+
+	/* BUG? no endian conversion on s_time? */
 	if (sbd->s_time < JAN_1_1980) {
 		/* this is likely to happen on SystemV2 FS */
 		if (sbd->s_type > 3 || sbd->s_type < 1)
@@ -294,7 +296,8 @@
 	sb->sv_toobig_block = 10 + bsize_4 * (1 + bsize_4 * (1 + bsize_4));
 	sb->sv_ind_per_block_bits = n_bits-2;
 
-	sb->sv_ninodes = (sb->sv_firstdatazone - sb->sv_firstinodezone) << sb->sv_inodes_per_block_bits;
+	sb->sv_ninodes = (sb->sv_firstdatazone - sb->sv_firstinodezone)
+		<< sb->sv_inodes_per_block_bits;
 
 	sb->s_blocksize = bsize;
 	sb->s_blocksize_bits = n_bits;
@@ -346,13 +349,10 @@
 	sb->sv_block_base = 0;
 
 	for (i = 0; i < sizeof(flavours)/sizeof(flavours[0]) && !size; i++) {
-		struct buffer_head *next_bh;
-		next_bh = bread(dev, flavours[i].block, BLOCK_SIZE);
-		if (!next_bh)
-			continue;
 		brelse(bh);
-		bh = next_bh;
-
+		bh = bread(dev, flavours[i].block, BLOCK_SIZE);
+		if (!bh)
+			continue;
 		size = flavours[i].test(sb, bh);
 	}
 
@@ -411,8 +411,10 @@
 static struct super_block *v7_read_super(struct super_block *sb,void *data,
 				  int silent)
 {
-	struct buffer_head *bh;
+	struct buffer_head *bh, *bh2 = NULL;
 	kdev_t dev = sb->s_dev;
+	struct v7_super_block *v7sb;
+	struct sysv_inode *v7i;
 
 	if (440 != sizeof (struct v7_super_block))
 		panic("V7 FS: bad super-block size");
@@ -422,23 +424,41 @@
 	sb->sv_type = FSTYPE_V7;
 	sb->sv_bytesex = BYTESEX_PDP;
 
-	set_blocksize(dev,512);
+	set_blocksize(dev, 512);
 
 	if ((bh = bread(dev, 1, 512)) == NULL) {
 		if (!silent)
-			printk("VFS: unable to read V7 FS superblock on device "
-			       "%s.\n", bdevname(dev));
+			printk("VFS: unable to read V7 FS superblock on "
+			       "device %s.\n", bdevname(dev));
 		goto failed;
 	}
 
+	/* plausibility check on superblock */
+	v7sb = (struct v7_super_block *) bh->b_data;
+	if (fs16_to_cpu(sb,v7sb->s_nfree) > V7_NICFREE ||
+	    fs16_to_cpu(sb,v7sb->s_ninode) > V7_NICINOD ||
+	    fs32_to_cpu(sb,v7sb->s_time) == 0)
+		goto failed;
+
+	/* plausibility check on root inode: it is a directory,
+	   with a nonzero size that is a multiple of 16 */
+	if ((bh2 = bread(dev, 2, 512)) == NULL)
+		goto failed;
+	v7i = (struct sysv_inode *)(bh2->b_data + 64);
+	if ((fs16_to_cpu(sb,v7i->i_mode) & ~0777) != S_IFDIR ||
+	    (fs32_to_cpu(sb,v7i->i_size) == 0) ||
+	    (fs32_to_cpu(sb,v7i->i_size) & 017) != 0)
+		goto failed;
+	brelse(bh2);
 
 	sb->sv_bh1 = bh;
 	sb->sv_bh2 = bh;
 	if (complete_read_super(sb, silent, 1))
 		return sb;
 
-	brelse(bh);
 failed:
+	brelse(bh2);
+	brelse(bh);
 	return NULL;
 }
 

^ permalink raw reply	[flat|nested] 9+ messages in thread
[parent not found: <no.id>]
* Re: [PATCH] vxfs fix
@ 2001-08-02 20:25 Andries.Brouwer
  0 siblings, 0 replies; 9+ messages in thread
From: Andries.Brouwer @ 2001-08-02 20:25 UTC (permalink / raw)
  To: Andries.Brouwer, alan; +Cc: hch, linux-kernel, torvalds, viro

> Let me try again

OK - now I see what you mean, but I think you misunderstand.
The system call mount(2) has an obligatory parameter "type".
The kernel never guesses.

[Apart from the situation at boot time, where it knows the
device and guesses the type. This is bad, and I hope it
will go away. Some types are very difficult to distinguish.]

So, the kernel only does what it is told.

But mount(8) has users, and they are a lazy bunch.
Instead of saying "mount -t iso9660 image /mnt -o loop,ro"
they type "mount image /mnt" and hope that mount(8) can
figure out the rest. And mount(8) knows about the magic numbers
of a handful of filesystems, and if one of these is recognized
it will try that type. Otherwise it will just try all remaining
types in /proc/filesystems. It is this guessing that leads to
crashes in case the kernel succeeds in mounting garbage.

Andries


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2001-08-02 21:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-01 21:03 [PATCH] vxfs fix Andries.Brouwer
2001-08-01 21:18 ` Christoph Hellwig
2001-08-01 21:19 ` Alexander Viro
2001-08-01 22:29 ` Linus Torvalds
2001-08-02  0:15   ` Alan Cox
2001-08-02 19:15 Andries.Brouwer
     [not found] <no.id>
2001-08-02 19:41 ` Alan Cox
2001-08-02 20:57   ` Andreas Dilger
2001-08-02 20:25 Andries.Brouwer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).