Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/sysv: v7: adjust sanity checks for some volumes

Newly mkfs-ed filesystems from Seventh Edition have last modification time
set to zero, but are otherwise perfectly valid.

Also, tighten up other sanity checks to filter out most filesystems with

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Lubomir Rintel and committed by
Linus Torvalds
0bcaa65a a36517e9

+15 -2
+4 -2
fs/sysv/super.c
··· 469 469 v7sb = (struct v7_super_block *) bh->b_data; 470 470 if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE || 471 471 fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD || 472 - fs32_to_cpu(sbi, v7sb->s_time) == 0) 472 + fs32_to_cpu(sbi, v7sb->s_fsize) > V7_MAXSIZE) 473 473 goto failed; 474 474 475 475 /* plausibility check on root inode: it is a directory, ··· 479 479 v7i = (struct sysv_inode *)(bh2->b_data + 64); 480 480 if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR || 481 481 (fs32_to_cpu(sbi, v7i->i_size) == 0) || 482 - (fs32_to_cpu(sbi, v7i->i_size) & 017) != 0) 482 + (fs32_to_cpu(sbi, v7i->i_size) & 017) || 483 + (fs32_to_cpu(sbi, v7i->i_size) > V7_NFILES * 484 + sizeof(struct sysv_dir_entry))) 483 485 goto failed; 484 486 brelse(bh2); 485 487 bh2 = NULL;
+11
include/linux/sysv_fs.h
··· 148 148 char s_fname[6]; /* file system name */ 149 149 char s_fpack[6]; /* file system pack name */ 150 150 }; 151 + /* Constants to aid sanity checking */ 152 + /* This is not a hard limit, nor enforced by v7 kernel. It's actually just 153 + * the limit used by Seventh Edition's ls, though is high enough to assume 154 + * that no reasonable file system would have that much entries in root 155 + * directory. Thus, if we see anything higher, we just probably got the 156 + * endiannes wrong. */ 157 + #define V7_NFILES 1024 158 + /* The disk addresses are three-byte (despite direct block addresses being 159 + * aligned word-wise in inode). If the most significant byte is non-zero, 160 + * something is most likely wrong (not a filesystem, bad bytesex). */ 161 + #define V7_MAXSIZE 0x00ffffff 151 162 152 163 /* Coherent super-block data on disk */ 153 164 #define COH_NICINOD 100 /* number of inode cache entries */