diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2008-12-30 01:52:35 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2008-12-31 18:07:43 -0500 |
commit | 41080b5a240113328c607f22b849f653373db0ce (patch) | |
tree | aa8fd483c241140ebe73b6c71b370f4ad6a12251 /fs/ext2/ialloc.c | |
parent | 261bca86ed4f7f391d1938167624e78da61dcc6b (diff) |
nfsd race fixes: ext2
* make ext2_new_inode() put the inode into icache in locked state
* do not unlock until the inode is fully set up; otherwise nfsd
might pick it in half-baked state.
* make sure that ext2_new_inode() does *not* lead to two inodes with the
same inumber hashed at the same time; otherwise a bogus fhandle coming
from nfsd might race with inode creation:
nfsd: iget_locked() creates inode
nfsd: try to read from disk, block on that.
ext2_new_inode(): allocate inode with that inumber
ext2_new_inode(): insert it into icache, set it up and dirty
ext2_write_inode(): get the relevant part of inode table in cache,
set the entry for our inode (and start writing to disk)
nfsd: get CPU again, look into inode table, see nice and sane on-disk
inode, set the in-core inode from it
oops - we have two in-core inodes with the same inumber live in icache,
both used for IO. Welcome to fs corruption...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/ext2/ialloc.c')
-rw-r--r-- | fs/ext2/ialloc.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c index 8d0add625870..c454d5db28a5 100644 --- a/fs/ext2/ialloc.c +++ b/fs/ext2/ialloc.c | |||
@@ -585,7 +585,10 @@ got: | |||
585 | spin_lock(&sbi->s_next_gen_lock); | 585 | spin_lock(&sbi->s_next_gen_lock); |
586 | inode->i_generation = sbi->s_next_generation++; | 586 | inode->i_generation = sbi->s_next_generation++; |
587 | spin_unlock(&sbi->s_next_gen_lock); | 587 | spin_unlock(&sbi->s_next_gen_lock); |
588 | insert_inode_hash(inode); | 588 | if (insert_inode_locked(inode) < 0) { |
589 | err = -EINVAL; | ||
590 | goto fail_drop; | ||
591 | } | ||
589 | 592 | ||
590 | if (DQUOT_ALLOC_INODE(inode)) { | 593 | if (DQUOT_ALLOC_INODE(inode)) { |
591 | err = -EDQUOT; | 594 | err = -EDQUOT; |
@@ -612,6 +615,7 @@ fail_drop: | |||
612 | DQUOT_DROP(inode); | 615 | DQUOT_DROP(inode); |
613 | inode->i_flags |= S_NOQUOTA; | 616 | inode->i_flags |= S_NOQUOTA; |
614 | inode->i_nlink = 0; | 617 | inode->i_nlink = 0; |
618 | unlock_new_inode(inode); | ||
615 | iput(inode); | 619 | iput(inode); |
616 | return ERR_PTR(err); | 620 | return ERR_PTR(err); |
617 | 621 | ||