Skip to content

Commit dd26bc0

Browse files
palismfrench
authored andcommitted
cifs: Validate content of native symlink
Check that path buffer has correct length (it is non-zero and in UNICODE mode it has even number of bytes) and check that buffer does not contain null character (UTF-16 null codepoint in UNICODE mode or null byte in non-unicode mode) because Linux cannot process symlink with null byte. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 723f4ef commit dd26bc0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

fs/smb/client/reparse.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,25 @@ int smb2_parse_native_symlink(char **target, const char *buf, unsigned int len,
547547
int rc;
548548
int i;
549549

550+
/* Check that length it valid for unicode/non-unicode mode */
551+
if (!len || (unicode && (len % 2))) {
552+
cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
553+
rc = -EIO;
554+
goto out;
555+
}
556+
557+
/*
558+
* Check that buffer does not contain UTF-16 null codepoint in unicode
559+
* mode or null byte in non-unicode mode because Linux cannot process
560+
* symlink with null byte.
561+
*/
562+
if ((unicode && UniStrnlen((wchar_t *)buf, len/2) != len/2) ||
563+
(!unicode && strnlen(buf, len) != len)) {
564+
cifs_dbg(VFS, "srv returned null byte in native symlink target location\n");
565+
rc = -EIO;
566+
goto out;
567+
}
568+
550569
smb_target = cifs_strndup_from_utf16(buf, len, unicode, cifs_sb->local_nls);
551570
if (!smb_target) {
552571
rc = -ENOMEM;

0 commit comments

Comments
 (0)