udf: prevent memory leak in udf_new_inode
PATCH 1/1 udf: prevent memory leak in udf_new_inode
In udf_new_inode if either udf_new_block or insert_inode_locked fials the allocated memory for iinfo->i_ext.i_data should be released.
--- fs/udf/ialloc.c | 2 ++ 1 file changed, 2 insertions(+)
fs/udf/ialloc.c +2 -0
@@ -86,6 +86,7 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode) dinfo->i_location.partitionReferenceNum, start, &err);if (err) { +kfree (iinfo->i_ext.i_data);iput (inode);return ERR_PTR (err); }
@@ -130,6 +131,7 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode) inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode); iinfo->i_crtime = inode->i_mtime;if (unlikely (insert_inode_locked (inode) <0 )) { +kfree (iinfo->i_ext.i_data);make_bad_inode (inode);iput (inode);return ERR_PTR (-EIO );
Signature · 1 line
2.17.1
Quoted 2 lines · Navid Emamdoost
In
udf_new_inodeif eitherudf_new_blockorinsert_inode_lockedfials the allocated memory foriinfo->i_ext.i_datashould be released.
"... because of such-and-such reasons" part appears to be missing. Why should it be released there?
Quoted 10 lines
Signed-off-by Navid Emamdoost <[email protected]>--- fs/udf/ialloc.c | 2 ++ 1 file changed, 2 insertions(+)fs/udf/ialloc.c +0
-0
fs/udf/ialloc.c struct inode *udf_new_inode(struct inode *dir, umode_t mode) · line 92
Quoted 7 lines
fs/udf/ialloc.c +1
-0@@ -86,6 +86,7 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode) dinfo->i_location.partitionReferenceNum, start, &err);if (err) { +kfree (iinfo->i_ext.i_data);iput (inode);return ERR_PTR (err); }
Have you tested that? Because it has all earmarks of double-free; normal eviction pathway ought to free the damn thing. <greps around a bit>
Mind explaining what's to stop ->evict_inode (== udf_evict_inode) from hitting
kfree(iinfo->i_ext.i_data);
considering that this call of kfree() appears to be unconditional there?
fs/udf/ialloc.c struct inode *udf_new_inode(struct inode *dir, umode_t mode) · line 137
Quoted 8 lines
fs/udf/ialloc.c +1
-0@@ -130,6 +131,7 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode) inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode); iinfo->i_crtime = inode->i_mtime;if (unlikely (insert_inode_locked (inode) <0 )) { +kfree (iinfo->i_ext.i_data);make_bad_inode (inode);iput (inode);return ERR_PTR (-EIO );
And the same here.
Quoted 29 lines · Al Viro
Quoted 2 lines · Navid Emamdoost
In
udf_new_inodeif eitherudf_new_blockorinsert_inode_lockedfials the allocated memory foriinfo->i_ext.i_datashould be released."... because of such-and-such reasons" part appears to be missing. Why should it be released there?
Quoted 10 lines
Signed-off-by Navid Emamdoost <[email protected]>--- fs/udf/ialloc.c | 2 ++ 1 file changed, 2 insertions(+)fs/udf/ialloc.c +0
-0fs/udf/ialloc.c struct inode *udf_new_inode(struct inode *dir, umode_t mode) · line 92
Quoted 7 lines
fs/udf/ialloc.c +1
-0@@ -86,6 +86,7 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode) dinfo->i_location.partitionReferenceNum, start, &err);if (err) { +kfree (iinfo->i_ext.i_data);iput (inode);return ERR_PTR (err); }Have you tested that? Because it has all earmarks of double-free; normal eviction pathway ought to free the damn thing. <greps around a bit>
Quoted 4 lines
Mind explaining what's to stop ->evict_inode (==
udf_evict_inode) from hittingkfree(iinfo->i_ext.i_data);considering that this call of
kfree()appears to be unconditional there?
Exactly. udf_evict_inode() is responsible for freeing iinfo->i_ext.i_data so the patch would result in double free.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 35 lines · Jan Kara
Quoted 29 lines · Al Viro
Quoted 2 lines · Navid Emamdoost
In
udf_new_inodeif eitherudf_new_blockorinsert_inode_lockedfials the allocated memory foriinfo->i_ext.i_datashould be released."... because of such-and-such reasons" part appears to be missing. Why should it be released there?
Quoted 10 lines
Signed-off-by Navid Emamdoost <[email protected]>--- fs/udf/ialloc.c | 2 ++ 1 file changed, 2 insertions(+)fs/udf/ialloc.c +0
-0fs/udf/ialloc.c struct inode *udf_new_inode(struct inode *dir, umode_t mode) · line 92
Quoted 7 lines
fs/udf/ialloc.c +1
-0@@ -86,6 +86,7 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode) dinfo->i_location.partitionReferenceNum, start, &err);if (err) { +kfree (iinfo->i_ext.i_data);iput (inode);return ERR_PTR (err); }Have you tested that? Because it has all earmarks of double-free; normal eviction pathway ought to free the damn thing. <greps around a bit>
Quoted 4 lines
Mind explaining what's to stop ->evict_inode (==
udf_evict_inode) from hittingkfree(iinfo->i_ext.i_data);considering that this call of
kfree()appears to be unconditional there?
Quoted 4 lines
Exactly.
udf_evict_inode()is responsible for freeingiinfo->i_ext.i_dataso the patch would result in double free.Honza
Thanks for clarification.
Quoted 3 lines
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR