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

inode numbering: change libfs sb creation routines to avoid collisions with their root inodes

This patch makes it so that simple_fill_super and get_sb_pseudo assign their
root inodes to be number 1. It also fixes up a couple of callers of
simple_fill_super that were passing in files arrays that had an index at
number 1, and adds a warning for any caller that sends in such an array.

It would have been nice to have made it so that it wasn't possible to make
such a collision, but some callers need to be able to control what inode
number their entries get, so I think this is the best that can be done.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jeff Layton and committed by
Linus Torvalds
1a1c9bb4 866b04fc

+26 -3
+1 -1
drivers/infiniband/hw/ipath/ipath_fs.c
··· 523 523 int ret; 524 524 525 525 static struct tree_descr files[] = { 526 - [1] = {"atomic_stats", &atomic_stats_ops, S_IRUGO}, 526 + [2] = {"atomic_stats", &atomic_stats_ops, S_IRUGO}, 527 527 {""}, 528 528 }; 529 529
+2 -2
fs/binfmt_misc.c
··· 727 727 static int bm_fill_super(struct super_block * sb, void * data, int silent) 728 728 { 729 729 static struct tree_descr bm_files[] = { 730 - [1] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO}, 731 - [2] = {"register", &bm_register_operations, S_IWUSR}, 730 + [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO}, 731 + [3] = {"register", &bm_register_operations, S_IWUSR}, 732 732 /* last one */ {""} 733 733 }; 734 734 int err = simple_fill_super(sb, 0x42494e4d, bm_files);
+23
fs/libfs.c
··· 220 220 root = new_inode(s); 221 221 if (!root) 222 222 goto Enomem; 223 + /* 224 + * since this is the first inode, make it number 1. New inodes created 225 + * after this must take care not to collide with it (by passing 226 + * max_reserved of 1 to iunique). 227 + */ 228 + root->i_ino = 1; 223 229 root->i_mode = S_IFDIR | S_IRUSR | S_IWUSR; 224 230 root->i_uid = root->i_gid = 0; 225 231 root->i_atime = root->i_mtime = root->i_ctime = CURRENT_TIME; ··· 366 360 return 0; 367 361 } 368 362 363 + /* 364 + * the inodes created here are not hashed. If you use iunique to generate 365 + * unique inode values later for this filesystem, then you must take care 366 + * to pass it an appropriate max_reserved value to avoid collisions. 367 + */ 369 368 int simple_fill_super(struct super_block *s, int magic, struct tree_descr *files) 370 369 { 371 370 struct inode *inode; ··· 387 376 inode = new_inode(s); 388 377 if (!inode) 389 378 return -ENOMEM; 379 + /* 380 + * because the root inode is 1, the files array must not contain an 381 + * entry at index 1 382 + */ 383 + inode->i_ino = 1; 390 384 inode->i_mode = S_IFDIR | 0755; 391 385 inode->i_uid = inode->i_gid = 0; 392 386 inode->i_blocks = 0; ··· 407 391 for (i = 0; !files->name || files->name[0]; i++, files++) { 408 392 if (!files->name) 409 393 continue; 394 + 395 + /* warn if it tries to conflict with the root inode */ 396 + if (unlikely(i == 1)) 397 + printk(KERN_WARNING "%s: %s passed in a files array" 398 + "with an index of 1!\n", __func__, 399 + s->s_type->name); 400 + 410 401 dentry = d_alloc_name(root, files->name); 411 402 if (!dentry) 412 403 goto out;