Skip to content

Commit f2aae74

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubifs: xattr: Fix some potential memory leaks while iterating entries
Fix some potential memory leaks in error handling branches while iterating xattr entries. For example, function ubifs_tnc_remove_ino() forgets to free pxent if it exists. Similar problems also exist in ubifs_purge_xattrs(), ubifs_add_orphan() and ubifs_jnl_write_inode(). Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Cc: <stable@vger.kernel.org> Fixes: 1e51764 ("UBIFS: add new flash file system") Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent e4c26fa commit f2aae74

4 files changed

Lines changed: 9 additions & 0 deletions

File tree

fs/ubifs/journal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode)
894894
if (err == -ENOENT)
895895
break;
896896

897+
kfree(pxent);
897898
goto out_release;
898899
}
899900

@@ -906,6 +907,7 @@ int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode)
906907
ubifs_err(c, "dead directory entry '%s', error %d",
907908
xent->name, err);
908909
ubifs_ro_mode(c, err);
910+
kfree(pxent);
909911
kfree(xent);
910912
goto out_release;
911913
}

fs/ubifs/orphan.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
173173
err = PTR_ERR(xent);
174174
if (err == -ENOENT)
175175
break;
176+
kfree(pxent);
176177
return err;
177178
}
178179

@@ -182,6 +183,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
182183

183184
xattr_orphan = orphan_add(c, xattr_inum, orphan);
184185
if (IS_ERR(xattr_orphan)) {
186+
kfree(pxent);
185187
kfree(xent);
186188
return PTR_ERR(xattr_orphan);
187189
}

fs/ubifs/tnc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,6 +2885,7 @@ int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum)
28852885
err = PTR_ERR(xent);
28862886
if (err == -ENOENT)
28872887
break;
2888+
kfree(pxent);
28882889
return err;
28892890
}
28902891

@@ -2898,6 +2899,7 @@ int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum)
28982899
fname_len(&nm) = le16_to_cpu(xent->nlen);
28992900
err = ubifs_tnc_remove_nm(c, &key1, &nm);
29002901
if (err) {
2902+
kfree(pxent);
29012903
kfree(xent);
29022904
return err;
29032905
}
@@ -2906,6 +2908,7 @@ int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum)
29062908
highest_ino_key(c, &key2, xattr_inum);
29072909
err = ubifs_tnc_remove_range(c, &key1, &key2);
29082910
if (err) {
2911+
kfree(pxent);
29092912
kfree(xent);
29102913
return err;
29112914
}

fs/ubifs/xattr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ int ubifs_purge_xattrs(struct inode *host)
522522
xent->name, err);
523523
ubifs_ro_mode(c, err);
524524
kfree(pxent);
525+
kfree(xent);
525526
return err;
526527
}
527528

@@ -531,6 +532,7 @@ int ubifs_purge_xattrs(struct inode *host)
531532
err = remove_xattr(c, host, xino, &nm);
532533
if (err) {
533534
kfree(pxent);
535+
kfree(xent);
534536
iput(xino);
535537
ubifs_err(c, "cannot remove xattr, error %d", err);
536538
return err;

0 commit comments

Comments
 (0)