Skip to content

Commit a1d2eb5

Browse files
Paulo AlcantaraSteve French
authored andcommitted
cifs: skip extra NULL byte in filenames
Since commit: cifs: alloc_path_with_tree_prefix: do not append sep. if the path is empty alloc_path_with_tree_prefix() function was no longer including the trailing separator when @path is empty, although @out_len was still assuming a path separator thus adding an extra byte to the final filename. This has caused mount issues in some Synology servers due to the extra NULL byte in filenames when sending SMB2_CREATE requests with SMB2_FLAGS_DFS_OPERATIONS set. Fix this by checking if @path is not empty and then add extra byte for separator. Also, do not include any trailing NULL bytes in filename as MS-SMB2 requires it to be 8-byte aligned and not NULL terminated. Cc: stable@vger.kernel.org Fixes: 7eacba3 ("cifs: alloc_path_with_tree_prefix: do not append sep. if the path is empty") Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent ba08030 commit a1d2eb5

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

fs/cifs/smb2pdu.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,19 +2572,15 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len,
25722572

25732573
path_len = UniStrnlen((wchar_t *)path, PATH_MAX);
25742574

2575-
/*
2576-
* make room for one path separator between the treename and
2577-
* path
2578-
*/
2579-
*out_len = treename_len + 1 + path_len;
2575+
/* make room for one path separator only if @path isn't empty */
2576+
*out_len = treename_len + (path[0] ? 1 : 0) + path_len;
25802577

25812578
/*
2582-
* final path needs to be null-terminated UTF16 with a
2583-
* size aligned to 8
2579+
* final path needs to be 8-byte aligned as specified in
2580+
* MS-SMB2 2.2.13 SMB2 CREATE Request.
25842581
*/
2585-
2586-
*out_size = roundup((*out_len+1)*2, 8);
2587-
*out_path = kzalloc(*out_size, GFP_KERNEL);
2582+
*out_size = roundup(*out_len * sizeof(__le16), 8);
2583+
*out_path = kzalloc(*out_size + sizeof(__le16) /* null */, GFP_KERNEL);
25882584
if (!*out_path)
25892585
return -ENOMEM;
25902586

0 commit comments

Comments
 (0)