]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
CIFS: Fix a potencially linear read overflow
authorLen Baker <len.baker@gmx.com>
Tue, 17 Aug 2021 10:27:09 +0000 (12:27 +0200)
committerKelsey Skunberg <kelsey.skunberg@canonical.com>
Mon, 11 Oct 2021 23:08:50 +0000 (17:08 -0600)
BugLink: https://bugs.launchpad.net/bugs/1946024
[ Upstream commit f980d055a0f858d73d9467bb0b570721bbfcdfb8 ]

strlcpy() reads the entire source buffer first. This read may exceed the
destination size limit. This is both inefficient and can lead to linear
read overflows if a source string is not NUL-terminated.

Also, the strnlen() call does not avoid the read overflow in the strlcpy
function when a not NUL-terminated string is passed.

So, replace this block by a call to kstrndup() that avoids this type of
overflow and does the same.

Fixes: 066ce6899484d ("cifs: rename cifs_strlcpy_to_host and make it use new functions")
Signed-off-by: Len Baker <len.baker@gmx.com>
Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
fs/cifs/cifs_unicode.c

index 9bd03a2310328da6ee10095100e9b42c2595186f..171ad8b42107e255c01498354a1e05c8f4a13c3d 100644 (file)
@@ -358,14 +358,9 @@ cifs_strndup_from_utf16(const char *src, const int maxlen,
                if (!dst)
                        return NULL;
                cifs_from_utf16(dst, (__le16 *) src, len, maxlen, codepage,
-                              NO_MAP_UNI_RSVD);
+                               NO_MAP_UNI_RSVD);
        } else {
-               len = strnlen(src, maxlen);
-               len++;
-               dst = kmalloc(len, GFP_KERNEL);
-               if (!dst)
-                       return NULL;
-               strlcpy(dst, src, len);
+               dst = kstrndup(src, maxlen, GFP_KERNEL);
        }
 
        return dst;