]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ntfs: fix WSL symlink target leak on reparse failure
authorDaeMyung Kang <charsyam@gmail.com>
Sun, 26 Apr 2026 04:02:32 +0000 (13:02 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Mon, 27 Apr 2026 13:29:08 +0000 (22:29 +0900)
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: fc053f05ca28 ("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>
fs/ntfs/reparse.c

index 8f60ec6f66c19e67a4c77901e784196d45d7e951..74713716813f22f49b23c7167ccef67b0665ec37 100644 (file)
@@ -505,7 +505,6 @@ int ntfs_reparse_set_wsl_symlink(struct ntfs_inode *ni,
        struct reparse_point *reparse;
        struct wsl_link_reparse_data *data;
 
-       utarget = (char *)NULL;
        len = ntfs_ucstonls(ni->vol, target, target_len, &utarget, 0);
        if (len <= 0)
                return -EINVAL;
@@ -514,7 +513,7 @@ int ntfs_reparse_set_wsl_symlink(struct ntfs_inode *ni,
        reparse = kvzalloc(reparse_len, GFP_NOFS);
        if (!reparse) {
                err = -ENOMEM;
-               kvfree(utarget);
+               kfree(utarget);
        } else {
                data = (struct wsl_link_reparse_data *)reparse->reparse_data;
                reparse->reparse_tag = IO_REPARSE_TAG_LX_SYMLINK;
@@ -528,6 +527,8 @@ int ntfs_reparse_set_wsl_symlink(struct ntfs_inode *ni,
                kvfree(reparse);
                if (!err)
                        ni->target = utarget;
+               else
+                       kfree(utarget);
        }
        return err;
 }