Skip to content

Commit

Permalink
ubifs: free the encrypted symlink target
Browse files Browse the repository at this point in the history
ubifs_symlink() forgot to free the kmalloc()'ed buffer holding the
encrypted symlink target, creating a memory leak.  Fix it.

(UBIFS could actually encrypt directly into ui->data, removing the
temporary buffer, but that is left for the patch that switches to use
the symlink helper functions.)

Fixes: ca7f85b ("ubifs: Add support for encrypted symlinks")
Cc: <[email protected]> # v4.10+
Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
ebiggers authored and tytso committed Jan 12, 2018
1 parent f2329cb commit 6b46d44
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions fs/ubifs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,10 +1216,8 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
ostr.len = disk_link.len;

err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
if (err) {
kfree(sd);
if (err)
goto out_inode;
}

sd->len = cpu_to_le16(ostr.len);
disk_link.name = (char *)sd;
Expand Down Expand Up @@ -1251,11 +1249,10 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
goto out_cancel;
mutex_unlock(&dir_ui->ui_mutex);

ubifs_release_budget(c, &req);
insert_inode_hash(inode);
d_instantiate(dentry, inode);
fscrypt_free_filename(&nm);
return 0;
err = 0;
goto out_fname;

out_cancel:
dir->i_size -= sz_change;
Expand All @@ -1268,6 +1265,7 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
fscrypt_free_filename(&nm);
out_budg:
ubifs_release_budget(c, &req);
kfree(sd);
return err;
}

Expand Down

0 comments on commit 6b46d44

Please sign in to comment.