Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Pavel Shilovsky <piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] CIFS: Fix too big maxBuf size for SMB3 mounts
Date: Fri, 14 Feb 2014 14:10:13 -0500	[thread overview]
Message-ID: <20140214141013.778b8b68@tlielax.poochiereds.net> (raw)
In-Reply-To: <1392370263-10364-1-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>

On Fri, 14 Feb 2014 13:31:02 +0400
Pavel Shilovsky <piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org> wrote:

> SMB3 servers can respond with MaxTransactSize of more than 4M
> that can cause a memory allocation error returned from kmalloc
> in a lock codepath. Also the client doesn't support multicredit
> requests now and allows buffer sizes of 65536 bytes only. Set
> MaxTransactSize to this maximum supported value.
> 
> Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org # 3.7+
> Signed-off-by: Pavel Shilovsky <piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
> ---
>  fs/cifs/smb2glob.h |    3 +++
>  fs/cifs/smb2ops.c  |   14 ++++----------
>  fs/cifs/smb2pdu.c  |    4 +++-
>  3 files changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/cifs/smb2glob.h b/fs/cifs/smb2glob.h
> index c383508..bc0bb9c 100644
> --- a/fs/cifs/smb2glob.h
> +++ b/fs/cifs/smb2glob.h
> @@ -57,4 +57,7 @@
>  #define SMB2_CMACAES_SIZE (16)
>  #define SMB3_SIGNKEY_SIZE (16)
>  
> +/* Maximum buffer size value we can send with 1 credit */
> +#define SMB2_MAX_BUFFER_SIZE 65536
> +
>  #endif	/* _SMB2_GLOB_H */
> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> index 757da3e..192f51a 100644
> --- a/fs/cifs/smb2ops.c
> +++ b/fs/cifs/smb2ops.c
> @@ -182,11 +182,8 @@ smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
>  	/* start with specified wsize, or default */
>  	wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
>  	wsize = min_t(unsigned int, wsize, server->max_write);
> -	/*
> -	 * limit write size to 2 ** 16, because we don't support multicredit
> -	 * requests now.
> -	 */
> -	wsize = min_t(unsigned int, wsize, 2 << 15);
> +	/* set it to the maximum buffer size value we can send with 1 credit */
> +	wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
>  
>  	return wsize;
>  }
> @@ -200,11 +197,8 @@ smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
>  	/* start with specified rsize, or default */
>  	rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
>  	rsize = min_t(unsigned int, rsize, server->max_read);
> -	/*
> -	 * limit write size to 2 ** 16, because we don't support multicredit
> -	 * requests now.
> -	 */
> -	rsize = min_t(unsigned int, rsize, 2 << 15);
> +	/* set it to the maximum buffer size value we can send with 1 credit */
> +	rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
>  
>  	return rsize;
>  }
> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
> index 2013234..787e171 100644
> --- a/fs/cifs/smb2pdu.c
> +++ b/fs/cifs/smb2pdu.c
> @@ -413,7 +413,9 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
>  
>  	/* SMB2 only has an extended negflavor */
>  	server->negflavor = CIFS_NEGFLAVOR_EXTENDED;
> -	server->maxBuf = le32_to_cpu(rsp->MaxTransactSize);
> +	/* set it to the maximum buffer size value we can send with 1 credit */
> +	server->maxBuf = min_t(unsigned int, le32_to_cpu(rsp->MaxTransactSize),
> +			       SMB2_MAX_BUFFER_SIZE);
>  	server->max_read = le32_to_cpu(rsp->MaxReadSize);
>  	server->max_write = le32_to_cpu(rsp->MaxWriteSize);
>  	/* BB Do we need to validate the SecurityMode? */

Acked-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

  parent reply	other threads:[~2014-02-14 19:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14  9:31 [PATCH] CIFS: Fix too big maxBuf size for SMB3 mounts Pavel Shilovsky
     [not found] ` <1392370263-10364-1-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2014-02-14  9:31   ` [PATCH] CIFS: Fix wrong pos argument of cifs_find_lock_conflict Pavel Shilovsky
     [not found]     ` <1392370263-10364-2-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2014-02-14 19:28       ` Jeff Layton
2014-02-14 19:10   ` Jeff Layton [this message]
2014-02-14 22:51   ` [PATCH] CIFS: Fix too big maxBuf size for SMB3 mounts 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=20140214141013.778b8b68@tlielax.poochiereds.net \
    --to=jlayton-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox