Fix possible leakage of blocks in UDF (try 2)
PATCH 1/1 Fix possible leakage of blocks in UDF (try 2)
Hi Andrew,
attached is a new version of the patch fixing possible leakage of
preallocated blocks. This time it has survived also testing Eric gave it without any deadlock or assertion failures so hopefully it's less wrong than the previous one.. ;) Please apply, thanks.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SuSE CR Labs
We have to take care that when we call udf_discard_prealloc() from udf_clear_inode() we have to write inode ourselves afterwards (otherwise, some changes might be lost leading to leakage of blocks, use of free blocks or improperly aligned extents). Also udf_discard_prealloc() does two different things - it removes preallocated blocks and truncates the last extent to exactly match i_size. We move the latter functionality to udf_truncate_tail_extent(), call udf_discard_prealloc() when last reference to a file is dropped and call udf_truncate_tail_extent() when inode is being removed from inode cache (udf_clear_inode() call). We cannot call udf_truncate_tail_extent() earlier as subsequent open+write would find the last block of the file mapped and happily write to the end of it, although the last extent says it's shorter.
fs/udf/inode.c +10 -1
@@ -100,14 +100,23 @@ no_delete:clear_inode (inode); } +/* +* If we are going to release inode from memory, we discard preallocation and +* truncate last inode extent to proper length. We could use drop_inode() but it's +* called under inode_lock and thus we cannot mark inode dirty there. We use +* clear_inode() but we have to make sure to write inode as it's not written +* automatically. +*/ void udf_clear_inode (struct inode *inode) {if (!(inode->i_sb->s_flags &MS_RDONLY )) {lock_kernel (); +/* Discard preallocation for directories, symlinks, etc. */ udf_discard_prealloc (inode); +udf_truncate_tail_extent (inode);unlock_kernel (); +write_inode_now (inode,1 ); } -kfree (UDF_I_DATA (inode));UDF_I_DATA (inode) =NULL ; }
fs/udf/truncate.c +62 -11
110 lines not on this page · raw message
fs/udf/udfdecl.h +1 -0
@@ -146,6 +146,7 @@ extern void udf_free_inode(struct inodeextern struct inode *udf_new_inode (struct inode *,int ,int *);/* truncate.c */ +extern void udf_truncate_tail_extent (struct inode *);extern void udf_discard_prealloc (struct inode *);extern void udf_truncate_extents (struct inode *);
[Jan Kara - Mon, Jun 11, 2007 at 12:49:11PM +0200]
| Hi Andrew, | | attached is a new version of the patch fixing possible leakage of
[SNIP]
Thanks, Jan
Cyrill