Skip to content

Commit 2dd8c16

Browse files
charsyamnamjaejeon
authored andcommitted
ntfs: fix WSL symlink target leak on reparse failure
ntfs_reparse_set_wsl_symlink() converts the symlink target into an allocated NLS string and transfers ownership to ni->target only after ntfs_set_ntfs_reparse_data() succeeds. If setting the reparse data fails, the converted target is left unreferenced and leaks. Free the converted target on the reparse update failure path. Use kfree() for the other local failure path as well, matching the ntfs_ucstonls() allocation contract. Fixes: fc053f0 ("ntfs: add reparse and ea operations") Signed-off-by: DaeMyung Kang <charsyam@gmail.com> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent b5198fc commit 2dd8c16

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

fs/ntfs/reparse.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ int ntfs_reparse_set_wsl_symlink(struct ntfs_inode *ni,
505505
struct reparse_point *reparse;
506506
struct wsl_link_reparse_data *data;
507507

508-
utarget = (char *)NULL;
509508
len = ntfs_ucstonls(ni->vol, target, target_len, &utarget, 0);
510509
if (len <= 0)
511510
return -EINVAL;
@@ -514,7 +513,7 @@ int ntfs_reparse_set_wsl_symlink(struct ntfs_inode *ni,
514513
reparse = kvzalloc(reparse_len, GFP_NOFS);
515514
if (!reparse) {
516515
err = -ENOMEM;
517-
kvfree(utarget);
516+
kfree(utarget);
518517
} else {
519518
data = (struct wsl_link_reparse_data *)reparse->reparse_data;
520519
reparse->reparse_tag = IO_REPARSE_TAG_LX_SYMLINK;
@@ -528,6 +527,8 @@ int ntfs_reparse_set_wsl_symlink(struct ntfs_inode *ni,
528527
kvfree(reparse);
529528
if (!err)
530529
ni->target = utarget;
530+
else
531+
kfree(utarget);
531532
}
532533
return err;
533534
}

0 commit comments

Comments
 (0)