vfs: Avoid creation of directory loops for corrupted filesystems
Subsystems (3)
Jan Kara
reviewerPATCH v2 1/5 vfs: Avoid creation of directory loops for corrupted filesystems
When a directory hierarchy is corrupted (e. g. due to a bit flip on the media), it can happen that it contains loops of directories. That creates possibilities for deadlock when locking directories.
Fix the problem by checking in d_splice_alias() that when we splice a directory, it does not have any other connected alias.
--- fs/dcache.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
Sorry guys, I'm resending this again because I messed up list address
previously.
fs/dcache.c +5 -0
@@ -1658,6 +1658,11 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)d_move (new, dentry);iput (inode); }else { +if (unlikely (!list_empty (&inode->i_dentry))) { +spin_unlock (&inode->i_lock); +iput (inode); +return ERR_PTR (-EIO ); + }/* already taking inode->i_lock, so d_add() by hand */ __d_instantiate (dentry, inode);spin_unlock (&inode->i_lock);
Signature · 1 line
1.7.1
Jan Kara
reviewerPATCH 2/5 ext2: Handle error from d_splice_alias()
When directory hiearchy is corrupted and contains cycles, d_splice_alias() can fail. Warn user and mark filesystem as with errors when that happens.
--- fs/ext2/namei.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
fs/ext2/namei.c +7 -1
@@ -59,6 +59,7 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str {struct inode * inode;ino_t ino; +struct dentry *ret;if (dentry->d_name.len >EXT2_NAME_LEN )return ERR_PTR (-ENAMETOOLONG );
@@ -74,7 +75,12 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, strreturn ERR_PTR (-EIO ); } } -return d_splice_alias (inode, dentry); + ret =d_splice_alias (inode, dentry); +if (IS_ERR (ret)) { +ext2_error (dir->i_sb, __func__,"directory #%lu corrupted" , + dir->i_ino); + } +return ret; }struct dentry *ext2_get_parent (struct dentry *child)
Signature · 1 line
1.7.1
Jan Kara
reviewerPATCH 3/5 ext3: Handle error from d_splice_alias()
In reply to Jan KaraWhen directory hiearchy is corrupted and contains cycles, d_splice_alias() can fail. Warn user and mark filesystem as with errors when that happens.
--- fs/ext3/namei.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
fs/ext3/namei.c +7 -1
@@ -1016,6 +1016,7 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, strstruct inode * inode;struct ext3_dir_entry_2 * de;struct buffer_head * bh; +struct dentry *ret;if (dentry->d_name.len >EXT3_NAME_LEN )return ERR_PTR (-ENAMETOOLONG );
@@ -1038,7 +1039,12 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, strreturn ERR_PTR (-EIO ); } } -return d_splice_alias (inode, dentry); + ret =d_splice_alias (inode, dentry); +if (IS_ERR (ret)) { +ext3_error (dir->i_sb, __func__,"directory #%lu corrupted" , + dir->i_ino); + } +return ret; }
Signature · 1 line
1.7.1
Jan Kara
reviewerPATCH 4/5 ext4: Handle error from d_splice_alias()
In reply to Jan KaraWhen directory hiearchy is corrupted and contains cycles, d_splice_alias() can fail. Warn user and mark filesystem as with errors when that happens.
--- fs/ext4/namei.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
fs/ext4/namei.c +5 -1
@@ -1317,6 +1317,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, strustruct inode *inode;struct ext4_dir_entry_2 *de;struct buffer_head *bh; +struct dentry *ret;if (dentry->d_name.len >EXT4_NAME_LEN )return ERR_PTR (-ENAMETOOLONG );
@@ -1344,7 +1345,10 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, strureturn ERR_PTR (-EIO ); } } -return d_splice_alias (inode, dentry); + ret =d_splice_alias (inode, dentry); +if (IS_ERR (ret)) +EXT4_ERROR_INODE (dir,"directory corrupted" ); +return ret; }
Signature · 1 line
1.7.1
Jan Kara
reviewerPATCH 5/5 exofs: Handle error from d_splice_alias()
In reply to Jan KaraFrom: Boaz Harrosh <[email protected]>
When directory hierarchy is corrupted and contains cycles, d_splice_alias() can fail. Warn user if that happens.
--- fs/exofs/namei.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
fs/exofs/namei.c +5 -1
@@ -50,13 +50,17 @@ static struct dentry *exofs_lookup(struct inode *dir, struct dentry *dentry, {struct inode *inode;ino_t ino; +struct dentry *ret;if (dentry->d_name.len >EXOFS_NAME_LEN )return ERR_PTR (-ENAMETOOLONG ); ino =exofs_inode_by_name (dir, dentry); inode = ino ?exofs_iget (dir->i_sb, ino) :NULL ; -return d_splice_alias (inode, dentry); + ret =d_splice_alias (inode, dentry); +if (IS_ERR (ret)) +EXOFS_ERR ("directory #%lu corrupted" , dir->i_ino); +return ret; } static int exofs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
Signature · 1 line
1.7.1
Jan Kara
reviewerQuoted 6 lines · Jan Kara
When a directory hierarchy is corrupted (e. g. due to a bit flip on the media), it can happen that it contains loops of directories. That creates possibilities for deadlock when locking directories.
Fix the problem by checking in
d_splice_alias()that when we splice a directory, it does not have any other connected alias.
Al, any opinion on this patch series?
Honza
Quoted 29 lines
Reported-by Sami Liedes <[email protected]>CC "J. Bruce Fields" <[email protected]>Signed-off-by Jan Kara <[email protected]>--- fs/dcache.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)Sorry guys, I'm resending this again because I messed up list address
previously.fs/dcache.c +5
-0@@ -1658,6 +1658,11 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)d_move (new, dentry);iput (inode); }else { +if (unlikely (!list_empty (&inode->i_dentry))) { +spin_unlock (&inode->i_lock); +iput (inode); +return ERR_PTR (-EIO ); + }/* already taking inode->i_lock, so d_add() by hand */ __d_instantiate (dentry, inode);spin_unlock (&inode->i_lock);Signature · 1 line
1.7.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR