From 66eb352a709af18134489f1727c2404dd0e7b033 Mon Sep 17 00:00:00 2001
From: Aurelien Aptel <aaptel@suse.com>
Date: Thu, 8 Aug 2019 18:42:17 +0200
Subject: [PATCH] cifs: do not accept filenames containing dir separators
Check for / in all connection types and additionally check for \ in
non-posix paths connections.
By returning early we do not add this directory entry via dir_emits(),
essentially skipping it.
Since the code relies on ctx->pos being incremented regardless of
errors, we return 0.
This fix addresses CVE-2019-10220.
Link: https://bugzilla.samba.org/show_bug.cgi?id=14072
CC: <stable@vger.kernel.org>
Signed-off-by: Paulo Alcantara (SUSE) <paulo@paulo.ac>
Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/cifs/readdir.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
@@ -744,6 +744,20 @@ static int cifs_filldir(char *find_entry, struct file *file,
name.len = de.namelen;
}
+ /*
+ * Regardless of connection type, / is always forbidden
+ * IFF we use normal windows paths then \ is forbidden
+ */
+
+ if (strnchr(name.name, name.len, '/')
+ || (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
+ && strnchr(name.name, name.len, '\\'))) {
+ cifs_dbg(VFS, "server returned name containing dir separator");
+ /* skip this entry for next readdir() interaction */
+ file_info->srch_inf.entries_in_buffer--;
+ return 0;
+ }
+
switch (file_info->srch_inf.info_level) {
case SMB_FIND_FILE_UNIX:
cifs_unix_basic_to_fattr(&fattr,
--
2.20.1