From: "Randy.Dunlap" Subject: [PATCH] check sb_set_blocksize/sb_min_blocksize returns Date: Thu, 16 Oct 2003 22:21:53 -0700 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20031016222153.633ae523.rddunlap@osdl.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Received: from fw.osdl.org ([65.172.181.6]:35735 "EHLO mail.osdl.org") by vger.kernel.org with ESMTP id S263304AbTJQFXN (ORCPT ); Fri, 17 Oct 2003 01:23:13 -0400 Received: from midway.verizon.net (build.pdx.osdl.net [172.20.1.2]) by mail.osdl.org (8.11.6/8.11.6) with SMTP id h9H5NAo06062 for ; Thu, 16 Oct 2003 22:23:10 -0700 To: linux-fsdevel@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org This patch checks the success/failure (return value) of sb_set_blocksize() and sb_min_blocksize() calls in all filesystems (well, there were a couple of calls that I omitted since they looked safe). Comments? Thanks, -- ~Randy description: check success/failure of sb_set_blocksize() and sb_min_blocksize() calls in all filesystems product_versions: Linux 2.6.0-test7 patch_name: fs_setblocksize.patch patch_version: 2003-10-16.22:14:47 author: Randy.Dunlap diffstat:= fs/befs/linuxvfs.c | 11 +++++++++-- fs/bfs/inode.c | 7 ++++++- fs/ext3/super.c | 6 +++++- fs/fat/inode.c | 5 ++++- fs/hfs/super.c | 6 +++++- fs/hpfs/super.c | 6 +++++- fs/isofs/inode.c | 7 ++++++- fs/jfs/super.c | 8 +++++++- fs/qnx4/inode.c | 6 +++++- fs/reiserfs/super.c | 7 ++++++- fs/romfs/inode.c | 6 +++++- fs/sysv/super.c | 25 +++++++++++++++++++++---- fs/xfs/linux/xfs_super.c | 6 +++++- 13 files changed, 89 insertions(+), 17 deletions(-) diff -Naur ./fs/xfs/linux/xfs_super.c~setblocksize ./fs/xfs/linux/xfs_super.c --- ./fs/xfs/linux/xfs_super.c~setblocksize 2003-10-08 12:24:44.000000000 -0700 +++ ./fs/xfs/linux/xfs_super.c 2003-10-16 22:01:26.000000000 -0700 @@ -753,7 +753,11 @@ goto fail_vfsop; } - sb_min_blocksize(sb, BBSIZE); + if (!sb_min_blocksize(sb, BBSIZE)) { + printk(KERN_ERR "XFS: unable to set min blocksize\n"); + bhv_remove_all_vfsops(vfsp, 1); + goto fail_vfsop; + } sb->s_export_op = &linvfs_export_ops; sb->s_qcop = &linvfs_qops; sb->s_op = &linvfs_sops; diff -Naur ./fs/jfs/super.c~setblocksize ./fs/jfs/super.c --- ./fs/jfs/super.c~setblocksize 2003-10-08 12:24:04.000000000 -0700 +++ ./fs/jfs/super.c 2003-10-16 20:55:23.000000000 -0700 @@ -325,13 +325,19 @@ if (newLVSize) { printk(KERN_ERR "resize option for remount only\n"); + kfree(sbi); return -EINVAL; } /* * Initialize blocksize to 4K. */ - sb_set_blocksize(sb, PSIZE); + if (!sb_set_blocksize(sb, PSIZE)) { + printk(KERN_ERR "JFS: device does not support %d byte blocks\n", + PSIZE); + kfree(sbi); + return -EINVAL; + } /* * Set method vectors. diff -Naur ./fs/hfs/super.c~setblocksize ./fs/hfs/super.c --- ./fs/hfs/super.c~setblocksize 2003-10-08 12:24:03.000000000 -0700 +++ ./fs/hfs/super.c 2003-10-16 20:59:45.000000000 -0700 @@ -518,7 +518,11 @@ } /* set the device driver to 512-byte blocks */ - sb_set_blocksize(s, HFS_SECTOR_SIZE); + if (!sb_set_blocksize(s, HFS_SECTOR_SIZE)) { + hfs_warn("HFS: device does not support %d byte blocks\n", + HFS_SECTOR_SIZE); + goto bail2; + } #ifdef CONFIG_MAC_PARTITION /* check to see if we're in a partition */ diff -Naur ./fs/bfs/inode.c~setblocksize ./fs/bfs/inode.c --- ./fs/bfs/inode.c~setblocksize 2003-10-08 12:24:04.000000000 -0700 +++ ./fs/bfs/inode.c 2003-10-16 21:03:51.000000000 -0700 @@ -303,7 +303,11 @@ s->s_fs_info = info; memset(info, 0, sizeof(*info)); - sb_set_blocksize(s, BFS_BSIZE); + if (!sb_set_blocksize(s, BFS_BSIZE)) { + printk(KERN_ERR "BFS: device does not support %d byte blocks\n", + BFS_BSIZE); + goto out2; + } bh = sb_bread(s, 0); if(!bh) @@ -375,6 +379,7 @@ out: brelse(bh); +out2: kfree(info); s->s_fs_info = NULL; return -EINVAL; diff -Naur ./fs/reiserfs/super.c~setblocksize ./fs/reiserfs/super.c --- ./fs/reiserfs/super.c~setblocksize 2003-10-08 12:24:04.000000000 -0700 +++ ./fs/reiserfs/super.c 2003-10-16 21:07:55.000000000 -0700 @@ -961,7 +961,12 @@ // // ok, reiserfs signature (old or new) found in at the given offset // - sb_set_blocksize (s, sb_blocksize(rs)); + if (!sb_set_blocksize (s, sb_blocksize(rs))) { + printk(KERN_ERR "sh-2006b: device does not support %d byte blocks\n", + sb_blocksize(rs)); + brelse(bh); + return 1; + } brelse (bh); bh = sb_bread (s, offset / s->s_blocksize); diff -Naur ./fs/befs/linuxvfs.c~setblocksize ./fs/befs/linuxvfs.c --- ./fs/befs/linuxvfs.c~setblocksize 2003-10-08 12:24:04.000000000 -0700 +++ ./fs/befs/linuxvfs.c 2003-10-16 21:58:14.000000000 -0700 @@ -826,7 +826,10 @@ * least 1k to get the second 512 bytes of the volume. * -WD 10-26-01 */ - sb_min_blocksize(sb, 1024); + if (!sb_min_blocksize(sb, 1024)) { + befs_error(sb, "unable to set min blocksize"); + goto unaquire_priv_sbp; + } if (!(bh = sb_bread(sb, sb_block))) { befs_error(sb, "unable to read superblock"); @@ -860,7 +863,11 @@ */ sb->s_magic = BEFS_SUPER_MAGIC; /* Set real blocksize of fs */ - sb_set_blocksize(sb, (ulong) befs_sb->block_size); + if (!sb_set_blocksize(sb, (ulong) befs_sb->block_size)) { + printk(KERN_ERR "BEFS: device does not support %d byte blocks\n", + befs_sb->block_size); + goto unaquire_priv_sbp; + } sb->s_op = (struct super_operations *) &befs_sops; sb->s_root = d_alloc_root(iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir)))); diff -Naur ./fs/sysv/super.c~setblocksize ./fs/sysv/super.c --- ./fs/sysv/super.c~setblocksize 2003-10-08 12:24:02.000000000 -0700 +++ ./fs/sysv/super.c 2003-10-16 21:48:31.000000000 -0700 @@ -369,7 +369,11 @@ sbi->s_block_base = 0; sb->s_fs_info = sbi; - sb_set_blocksize(sb, BLOCK_SIZE); + if (!sb_set_blocksize(sb, BLOCK_SIZE)) { + printk(KERN_ERR "SystemV FS: device does not support %d byte blocks\n", + BLOCK_SIZE); + goto failed; + } for (i = 0; i < sizeof(flavours)/sizeof(flavours[0]) && !size; i++) { brelse(bh); @@ -386,7 +390,11 @@ case 1: blocknr = bh->b_blocknr << 1; brelse(bh); - sb_set_blocksize(sb, 512); + if (!sb_set_blocksize(sb, 512)) { + printk(KERN_ERR "SystemV FS: device does not support %d byte blocks\n", + 512); + goto failed; + } bh1 = sb_bread(sb, blocknr); bh = sb_bread(sb, blocknr + 1); break; @@ -396,7 +404,11 @@ case 3: blocknr = bh->b_blocknr >> 1; brelse(bh); - sb_set_blocksize(sb, 2048); + if (!sb_set_blocksize(sb, 2048)) { + printk(KERN_ERR "SystemV FS: device does not support %d byte blocks\n", + 2048); + goto failed; + } bh1 = bh = sb_bread(sb, blocknr); break; default: @@ -455,7 +467,11 @@ sbi->s_bytesex = BYTESEX_PDP; sb->s_fs_info = sbi; - sb_set_blocksize(sb, 512); + if (!sb_set_blocksize(sb, 512)) { + printk(KERN_ERR "SystemV FS: device does not support %d byte blocks\n", + 512); + goto fail_sbi; + } if ((bh = sb_bread(sb, 1)) == NULL) { if (!silent) @@ -490,6 +506,7 @@ failed: brelse(bh2); brelse(bh); +fail_sbi: kfree(sbi); return -EINVAL; } diff -Naur ./fs/hpfs/super.c~setblocksize ./fs/hpfs/super.c --- ./fs/hpfs/super.c~setblocksize 2003-10-08 12:24:14.000000000 -0700 +++ ./fs/hpfs/super.c 2003-10-16 21:15:21.000000000 -0700 @@ -495,7 +495,11 @@ } /*sbi->sb_mounting = 1;*/ - sb_set_blocksize(s, 512); + if (!sb_set_blocksize(s, 512)) { + printk(KERN_ERR "HPFS: device does not support %d byte blocks\n", + 512); + goto bail0; + } sbi->sb_fs_size = -1; if (!(bootblock = hpfs_map_sector(s, 0, &bh0, 0))) goto bail1; if (!(superblock = hpfs_map_sector(s, 16, &bh1, 1))) goto bail2; diff -Naur ./fs/fat/inode.c~setblocksize ./fs/fat/inode.c --- ./fs/fat/inode.c~setblocksize 2003-10-08 12:24:04.000000000 -0700 +++ ./fs/fat/inode.c 2003-10-16 21:53:28.000000000 -0700 @@ -791,7 +791,10 @@ init_MUTEX(&sbi->fat_lock); error = -EIO; - sb_min_blocksize(sb, 512); + if (!sb_min_blocksize(sb, 512)) { + printk(KERN_ERR "FAT: unable to set min blocksize\n"); + goto out_fail; + } bh = sb_bread(sb, 0); if (bh == NULL) { printk(KERN_ERR "FAT: unable to read boot sector\n"); diff -Naur ./fs/ext3/super.c~setblocksize ./fs/ext3/super.c --- ./fs/ext3/super.c~setblocksize 2003-10-08 12:24:44.000000000 -0700 +++ ./fs/ext3/super.c 2003-10-16 21:19:05.000000000 -0700 @@ -1169,7 +1169,11 @@ } brelse (bh); - sb_set_blocksize(sb, blocksize); + if (!sb_set_blocksize(sb, blocksize)) { + printk(KERN_ERR "EXT3-fs: device does not support %d byte blocks\n", + blocksize); + goto failed_mount; + } logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize; offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize; bh = sb_bread(sb, logic_sb_block); diff -Naur ./fs/isofs/inode.c~setblocksize ./fs/isofs/inode.c --- ./fs/isofs/inode.c~setblocksize 2003-10-08 12:24:51.000000000 -0700 +++ ./fs/isofs/inode.c 2003-10-16 21:26:06.000000000 -0700 @@ -791,7 +791,8 @@ * entries. By forcing the blocksize in this way, we ensure * that we will never be required to do this. */ - sb_set_blocksize(s, orig_zonesize); + if (!sb_set_blocksize(s, orig_zonesize)) + goto out_bad_blocksize; sbi->s_nls_iocharset = NULL; @@ -904,6 +905,10 @@ printk(KERN_WARNING "Bad logical zone size %ld\n", sbi->s_log_zone_size); goto out_freebh; +out_bad_blocksize: + printk(KERN_ERR "ISOFS: device does not support %d byte blocks\n", + orig_zonesize); + goto out_freesbi; out_bad_size: printk(KERN_WARNING "Logical zone size(%d) < hardware blocksize(%u)\n", orig_zonesize, opt.blocksize); diff -Naur ./fs/romfs/inode.c~setblocksize ./fs/romfs/inode.c --- ./fs/romfs/inode.c~setblocksize 2003-10-08 12:24:17.000000000 -0700 +++ ./fs/romfs/inode.c 2003-10-16 21:28:26.000000000 -0700 @@ -119,7 +119,11 @@ /* I would parse the options here, but there are none.. :) */ - sb_set_blocksize(s, ROMBSIZE); + if (!sb_set_blocksize(s, ROMBSIZE)) { + printk(KERN_ERR "romfs: device does not support %d byte blocks\n", + ROMBSIZE); + goto outnobh; + } s->s_maxbytes = 0xFFFFFFFF; bh = sb_bread(s, 0); diff -Naur ./fs/qnx4/inode.c~setblocksize ./fs/qnx4/inode.c --- ./fs/qnx4/inode.c~setblocksize 2003-10-08 12:24:43.000000000 -0700 +++ ./fs/qnx4/inode.c 2003-10-16 21:30:56.000000000 -0700 @@ -357,7 +357,11 @@ s->s_fs_info = qs; memset(qs, 0, sizeof(struct qnx4_sb_info)); - sb_set_blocksize(s, QNX4_BLOCK_SIZE); + if (!sb_set_blocksize(s, QNX4_BLOCK_SIZE)) { + printk(KERN_ERR "qnx4: device does not support %d byte blocks\n", + QNX4_BLOCK_SIZE); + goto outnobh; + } /* Check the superblock signature. Since the qnx4 code is dangerous, we should leave as quickly as possible