Commit 3792c173 authored by Pavel Shilovsky's avatar Pavel Shilovsky Committed by Pavel Shilovsky

CIFS: Respect SMB2 header/max header size

Use SMB2 header size values for allocation and memset because they
are bigger and suitable for both CIFS and SMB2.
Signed-off-by: default avatarPavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: default avatarSteve French <smfrench@gmail.com>
parent 093b2bda
...@@ -48,6 +48,9 @@ ...@@ -48,6 +48,9 @@
#include <linux/key-type.h> #include <linux/key-type.h>
#include "cifs_spnego.h" #include "cifs_spnego.h"
#include "fscache.h" #include "fscache.h"
#ifdef CONFIG_CIFS_SMB2
#include "smb2pdu.h"
#endif
#define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
int cifsFYI = 0; int cifsFYI = 0;
...@@ -980,6 +983,14 @@ cifs_destroy_inodecache(void) ...@@ -980,6 +983,14 @@ cifs_destroy_inodecache(void)
static int static int
cifs_init_request_bufs(void) cifs_init_request_bufs(void)
{ {
size_t max_hdr_size = MAX_CIFS_HDR_SIZE;
#ifdef CONFIG_CIFS_SMB2
/*
* SMB2 maximum header size is bigger than CIFS one - no problems to
* allocate some more bytes for CIFS.
*/
max_hdr_size = MAX_SMB2_HDR_SIZE;
#endif
if (CIFSMaxBufSize < 8192) { if (CIFSMaxBufSize < 8192) {
/* Buffer size can not be smaller than 2 * PATH_MAX since maximum /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
Unicode path name has to fit in any SMB/CIFS path based frames */ Unicode path name has to fit in any SMB/CIFS path based frames */
...@@ -991,8 +1002,7 @@ cifs_init_request_bufs(void) ...@@ -991,8 +1002,7 @@ cifs_init_request_bufs(void)
} }
/* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */ /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
cifs_req_cachep = kmem_cache_create("cifs_request", cifs_req_cachep = kmem_cache_create("cifs_request",
CIFSMaxBufSize + CIFSMaxBufSize + max_hdr_size, 0,
MAX_CIFS_HDR_SIZE, 0,
SLAB_HWCACHE_ALIGN, NULL); SLAB_HWCACHE_ALIGN, NULL);
if (cifs_req_cachep == NULL) if (cifs_req_cachep == NULL)
return -ENOMEM; return -ENOMEM;
......
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
#include "smberr.h" #include "smberr.h"
#include "nterr.h" #include "nterr.h"
#include "cifs_unicode.h" #include "cifs_unicode.h"
#ifdef CONFIG_CIFS_SMB2
#include "smb2pdu.h"
#endif
extern mempool_t *cifs_sm_req_poolp; extern mempool_t *cifs_sm_req_poolp;
extern mempool_t *cifs_req_poolp; extern mempool_t *cifs_req_poolp;
...@@ -143,17 +146,27 @@ struct smb_hdr * ...@@ -143,17 +146,27 @@ struct smb_hdr *
cifs_buf_get(void) cifs_buf_get(void)
{ {
struct smb_hdr *ret_buf = NULL; struct smb_hdr *ret_buf = NULL;
size_t buf_size = sizeof(struct smb_hdr);
/* We could use negotiated size instead of max_msgsize - #ifdef CONFIG_CIFS_SMB2
but it may be more efficient to always alloc same size /*
albeit slightly larger than necessary and maxbuffersize * SMB2 header is bigger than CIFS one - no problems to clean some
defaults to this and can not be bigger */ * more bytes for CIFS.
*/
buf_size = sizeof(struct smb2_hdr);
#endif
/*
* We could use negotiated size instead of max_msgsize -
* but it may be more efficient to always alloc same size
* albeit slightly larger than necessary and maxbuffersize
* defaults to this and can not be bigger.
*/
ret_buf = mempool_alloc(cifs_req_poolp, GFP_NOFS); ret_buf = mempool_alloc(cifs_req_poolp, GFP_NOFS);
/* clear the first few header bytes */ /* clear the first few header bytes */
/* for most paths, more is cleared in header_assemble */ /* for most paths, more is cleared in header_assemble */
if (ret_buf) { if (ret_buf) {
memset(ret_buf, 0, sizeof(struct smb_hdr) + 3); memset(ret_buf, 0, buf_size + 3);
atomic_inc(&bufAllocCount); atomic_inc(&bufAllocCount);
#ifdef CONFIG_CIFS_STATS2 #ifdef CONFIG_CIFS_STATS2
atomic_inc(&totBufAllocCount); atomic_inc(&totBufAllocCount);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment