Skip to contentSkip to conversation

udf: prevent memory leak in udf_new_inode

PATCH In review Navid Emamdoost 3 participants 4 messages Sep 25, 2019 – Sep 27, 2019 UDF filesystem

lore
Share & tools
lore
#0 lore raw

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
index 0adb40718a5d..b8ab3acab6b6 100644
@@ -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
#1 lore raw
Quoted 2 lines · Navid Emamdoost

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.

"... because of such-and-such reasons" part appears to be missing. Why should it be released there?

Quoted 10 lines
---
 fs/udf/ialloc.c | 2 ++
 1 file changed, 2 insertions(+)
fs/udf/ialloc.c +0 -0
index 0adb40718a5d..b8ab3acab6b6 100644

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.

#2 lore raw
Quoted 29 lines · Al Viro
Quoted 2 lines · Navid Emamdoost

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.

"... because of such-and-such reasons" part appears to be missing. Why should it be released there?

Quoted 10 lines
---
 fs/udf/ialloc.c | 2 ++
 1 file changed, 2 insertions(+)
fs/udf/ialloc.c +0 -0
index 0adb40718a5d..b8ab3acab6b6 100644

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>

Quoted 4 lines

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?

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
#3 lore raw
Quoted 35 lines · Jan Kara
Quoted 29 lines · Al Viro
Quoted 2 lines · Navid Emamdoost

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.

"... because of such-and-such reasons" part appears to be missing. Why should it be released there?

Quoted 10 lines
---
 fs/udf/ialloc.c | 2 ++
 1 file changed, 2 insertions(+)
fs/udf/ialloc.c +0 -0
index 0adb40718a5d..b8ab3acab6b6 100644

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>

Quoted 4 lines

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?

Quoted 4 lines

Exactly. udf_evict_inode() is responsible for freeing iinfo->i_ext.i_data so the patch would result in double free.

Honza

Thanks for clarification.

Quoted 3 lines
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR