CIFS: Fix a potencially linear read overflow
Subsystems (2)
PATCH 1/1 CIFS: Fix a potencially linear read overflow
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.
--- fs/cifs/cifs_unicode.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
fs/cifs/cifs_unicode.c +2 -7
@@ -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;
--
2.25.1
Quoted 7 lines · Len Baker
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.
Quoted 8 lines
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 <[email protected]>--- fs/cifs/cifs_unicode.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
tentatively merged into cifs-2.6.git for-next pending testing
Quoted 20 lines · Paulo Alcantara
Quoted 7 lines · Len Baker
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.Quoted 8 lines
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 <[email protected]>--- fs/cifs/cifs_unicode.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)Reviewed-by Paulo Alcantara (SUSE) <[email protected]>
Signature · 3 lines
Thanks, Steve
Quoted 38 lines · Len Baker
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 <[email protected]>--- fs/cifs/cifs_unicode.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)fs/cifs/cifs_unicode.c +2
-8@@ -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; --
Quoted 2 lines
2.25.1
Added RB and repushed to cifs-2.6.git for-next
Quoted 45 lines · Jeff Layton
Quoted 38 lines · Len Baker
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 <[email protected]>--- fs/cifs/cifs_unicode.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)fs/cifs/cifs_unicode.c +2
-8@@ -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; --Quoted 2 lines
2.25.1
Reviewed-by Jeff Layton <[email protected]>
Signature · 3 lines
Thanks, Steve