]> Git Repo - linux.git/commitdiff
cifs: Check for UTF-16 null codepoint in SFU symlink target location
authorPali Rohár <[email protected]>
Fri, 27 Sep 2024 18:20:39 +0000 (20:20 +0200)
committerSteve French <[email protected]>
Sun, 29 Sep 2024 22:28:40 +0000 (17:28 -0500)
Check that read buffer of SFU symlink target location does not contain
UTF-16 null codepoint (via UniStrnlen() call) because Linux cannot process
symlink with null byte, it truncates everything in buffer after null byte.

Fixes: cf2ce67345d6 ("cifs: Add support for reading SFU symlink location")
Signed-off-by: Pali Rohár <[email protected]>
Signed-off-by: Steve French <[email protected]>
fs/smb/client/inode.c

index 647f9bedd9fc44c9225f2494c6913a795c2fd6ad..eff3f57235eef3212fa9f7e510335baeecda4485 100644 (file)
@@ -629,10 +629,16 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
                                                                               &symlink_len_utf16,
                                                                               &symlink_buf_utf16,
                                                                               &buf_type);
+                                       /*
+                                        * Check that read buffer has valid length and does not
+                                        * contain UTF-16 null codepoint (via UniStrnlen() call)
+                                        * because Linux cannot process symlink with null byte.
+                                        */
                                        if ((rc == 0) &&
                                            (symlink_len_utf16 > 0) &&
                                            (symlink_len_utf16 < fattr->cf_eof-8 + 1) &&
-                                           (symlink_len_utf16 % 2 == 0)) {
+                                           (symlink_len_utf16 % 2 == 0) &&
+                                           (UniStrnlen((wchar_t *)symlink_buf_utf16, symlink_len_utf16/2) == symlink_len_utf16/2)) {
                                                fattr->cf_symlink_target =
                                                        cifs_strndup_from_utf16(symlink_buf_utf16,
                                                                                symlink_len_utf16,
This page took 0.060008 seconds and 4 git commands to generate.