linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Len Baker <len.baker@gmx.com>, Steve French <sfrench@samba.org>,
	Suresh Jayaraman <sjayaraman@suse.de>
Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
	linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH] CIFS: Fix a potencially linear read overflow
Date: Wed, 18 Aug 2021 09:21:57 -0400	[thread overview]
Message-ID: <2f3a644e279a8a0933343339fa0add8e76276bf8.camel@kernel.org> (raw)
In-Reply-To: <20210817102709.15046-1-len.baker@gmx.com>

On Tue, 2021-08-17 at 12:27 +0200, Len Baker wrote:
> 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>
> ---
>  fs/cifs/cifs_unicode.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
> index 9bd03a231032..171ad8b42107 100644
> --- a/fs/cifs/cifs_unicode.c
> +++ b/fs/cifs/cifs_unicode.c
> @@ -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
> 

Reviewed-by: Jeff Layton <jlayton@kernel.org>


  parent reply	other threads:[~2021-08-18 13:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 10:27 Len Baker
2021-08-18  0:28 ` Paulo Alcantara
2021-08-18  2:46   ` Steve French
2021-08-18 13:21 ` Jeff Layton [this message]
2021-08-20  5:58   ` Steve French

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2f3a644e279a8a0933343339fa0add8e76276bf8.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=keescook@chromium.org \
    --cc=len.baker@gmx.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    --cc=sjayaraman@suse.de \
    --subject='Re: [PATCH] CIFS: Fix a potencially linear read overflow' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).