提交 c974befa 编写于 作者: J Jeff Layton 提交者: Steve French

cifs: untangle server->maxBuf and CIFSMaxBufSize

server->maxBuf is the maximum SMB size (including header) that the
server can handle. CIFSMaxBufSize is the maximum amount of data (sans
header) that the client can handle. Currently maxBuf is being capped at
CIFSMaxBufSize + the max headers size, and the two values are used
somewhat interchangeably in the code.

This makes little sense as these two values are not related at all.
Separate them and make sure the code uses the right values in the right
places.
Signed-off-by: NJeff Layton <jlayton@redhat.com>
Signed-off-by: NSteve French <smfrench@gmail.com>
上级 f3a6a60e
...@@ -453,8 +453,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses) ...@@ -453,8 +453,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses)
} }
server->sec_mode = (__u8)le16_to_cpu(rsp->SecurityMode); server->sec_mode = (__u8)le16_to_cpu(rsp->SecurityMode);
server->maxReq = le16_to_cpu(rsp->MaxMpxCount); server->maxReq = le16_to_cpu(rsp->MaxMpxCount);
server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), server->maxBuf = le16_to_cpu(rsp->MaxBufSize);
(__u32)CIFSMaxBufSize + MAX_CIFS_HDR_SIZE);
server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs);
/* even though we do not use raw we might as well set this /* even though we do not use raw we might as well set this
accurately, in case we ever find a need for it */ accurately, in case we ever find a need for it */
...@@ -561,8 +560,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses) ...@@ -561,8 +560,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses)
little endian */ little endian */
server->maxReq = le16_to_cpu(pSMBr->MaxMpxCount); server->maxReq = le16_to_cpu(pSMBr->MaxMpxCount);
/* probably no need to store and check maxvcs */ /* probably no need to store and check maxvcs */
server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize), server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize);
(__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE);
server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); server->max_rw = le32_to_cpu(pSMBr->MaxRawSize);
cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); cFYI(DBG2, "Max buf = %d", ses->server->maxBuf);
server->capabilities = le32_to_cpu(pSMBr->Capabilities); server->capabilities = le32_to_cpu(pSMBr->Capabilities);
...@@ -2812,8 +2810,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifs_tcon *tcon, ...@@ -2812,8 +2810,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifs_tcon *tcon,
pSMB->TotalDataCount = 0; pSMB->TotalDataCount = 0;
pSMB->MaxParameterCount = cpu_to_le32(2); pSMB->MaxParameterCount = cpu_to_le32(2);
/* BB find exact data count max from sess structure BB */ /* BB find exact data count max from sess structure BB */
pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00);
MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
pSMB->MaxSetupCount = 4; pSMB->MaxSetupCount = 4;
pSMB->Reserved = 0; pSMB->Reserved = 0;
pSMB->ParameterOffset = 0; pSMB->ParameterOffset = 0;
...@@ -3306,8 +3303,7 @@ smb_init_nttransact(const __u16 sub_command, const int setup_count, ...@@ -3306,8 +3303,7 @@ smb_init_nttransact(const __u16 sub_command, const int setup_count,
pSMB->Reserved = 0; pSMB->Reserved = 0;
pSMB->TotalParameterCount = cpu_to_le32(parm_len); pSMB->TotalParameterCount = cpu_to_le32(parm_len);
pSMB->TotalDataCount = 0; pSMB->TotalDataCount = 0;
pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00);
MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
pSMB->ParameterCount = pSMB->TotalParameterCount; pSMB->ParameterCount = pSMB->TotalParameterCount;
pSMB->DataCount = pSMB->TotalDataCount; pSMB->DataCount = pSMB->TotalDataCount;
temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + temp_offset = offsetof(struct smb_com_ntransact_req, Parms) +
...@@ -3977,8 +3973,7 @@ CIFSFindFirst(const int xid, struct cifs_tcon *tcon, ...@@ -3977,8 +3973,7 @@ CIFSFindFirst(const int xid, struct cifs_tcon *tcon,
params = 12 + name_len /* includes null */ ; params = 12 + name_len /* includes null */ ;
pSMB->TotalDataCount = 0; /* no EAs */ pSMB->TotalDataCount = 0; /* no EAs */
pSMB->MaxParameterCount = cpu_to_le16(10); pSMB->MaxParameterCount = cpu_to_le16(10);
pSMB->MaxDataCount = cpu_to_le16((tcon->ses->server->maxBuf - pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00);
MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
pSMB->MaxSetupCount = 0; pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0; pSMB->Reserved = 0;
pSMB->Flags = 0; pSMB->Flags = 0;
...@@ -4052,8 +4047,7 @@ CIFSFindFirst(const int xid, struct cifs_tcon *tcon, ...@@ -4052,8 +4047,7 @@ CIFSFindFirst(const int xid, struct cifs_tcon *tcon,
psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + psrch_inf->index_of_last_entry = 2 /* skip . and .. */ +
psrch_inf->entries_in_buffer; psrch_inf->entries_in_buffer;
lnoff = le16_to_cpu(parms->LastNameOffset); lnoff = le16_to_cpu(parms->LastNameOffset);
if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < if (CIFSMaxBufSize < lnoff) {
lnoff) {
cERROR(1, "ignoring corrupt resume name"); cERROR(1, "ignoring corrupt resume name");
psrch_inf->last_entry = NULL; psrch_inf->last_entry = NULL;
return rc; return rc;
...@@ -4097,9 +4091,7 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon, ...@@ -4097,9 +4091,7 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
byte_count = 0; byte_count = 0;
pSMB->TotalDataCount = 0; /* no EAs */ pSMB->TotalDataCount = 0; /* no EAs */
pSMB->MaxParameterCount = cpu_to_le16(8); pSMB->MaxParameterCount = cpu_to_le16(8);
pSMB->MaxDataCount = pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00);
cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) &
0xFFFFFF00);
pSMB->MaxSetupCount = 0; pSMB->MaxSetupCount = 0;
pSMB->Reserved = 0; pSMB->Reserved = 0;
pSMB->Flags = 0; pSMB->Flags = 0;
...@@ -4181,8 +4173,7 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon, ...@@ -4181,8 +4173,7 @@ int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
psrch_inf->index_of_last_entry += psrch_inf->index_of_last_entry +=
psrch_inf->entries_in_buffer; psrch_inf->entries_in_buffer;
lnoff = le16_to_cpu(parms->LastNameOffset); lnoff = le16_to_cpu(parms->LastNameOffset);
if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < if (CIFSMaxBufSize < lnoff) {
lnoff) {
cERROR(1, "ignoring corrupt resume name"); cERROR(1, "ignoring corrupt resume name");
psrch_inf->last_entry = NULL; psrch_inf->last_entry = NULL;
return rc; return rc;
...@@ -6035,12 +6026,7 @@ int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon, ...@@ -6035,12 +6026,7 @@ int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon,
pSMB->TotalParameterCount = 0 ; pSMB->TotalParameterCount = 0 ;
pSMB->TotalDataCount = 0; pSMB->TotalDataCount = 0;
pSMB->MaxParameterCount = cpu_to_le32(2); pSMB->MaxParameterCount = cpu_to_le32(2);
/* BB find exact data count max from sess structure BB */ pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00);
pSMB->MaxDataCount = 0; /* same in little endian or be */
/* BB VERIFY verify which is correct for above BB */
pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf -
MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
pSMB->MaxSetupCount = 4; pSMB->MaxSetupCount = 4;
pSMB->Reserved = 0; pSMB->Reserved = 0;
pSMB->ParameterOffset = 0; pSMB->ParameterOffset = 0;
......
...@@ -181,7 +181,7 @@ cifs_reconnect(struct TCP_Server_Info *server) ...@@ -181,7 +181,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
-EINVAL = invalid transact2 -EINVAL = invalid transact2
*/ */
static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize) static int check2ndT2(struct smb_hdr *pSMB)
{ {
struct smb_t2_rsp *pSMBt; struct smb_t2_rsp *pSMBt;
int remaining; int remaining;
...@@ -214,9 +214,9 @@ static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize) ...@@ -214,9 +214,9 @@ static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize)
cFYI(1, "missing %d bytes from transact2, check next response", cFYI(1, "missing %d bytes from transact2, check next response",
remaining); remaining);
if (total_data_size > maxBufSize) { if (total_data_size > CIFSMaxBufSize) {
cERROR(1, "TotalDataSize %d is over maximum buffer %d", cERROR(1, "TotalDataSize %d is over maximum buffer %d",
total_data_size, maxBufSize); total_data_size, CIFSMaxBufSize);
return -EINVAL; return -EINVAL;
} }
return remaining; return remaining;
...@@ -486,7 +486,7 @@ find_cifs_mid(struct TCP_Server_Info *server, struct smb_hdr *buf, ...@@ -486,7 +486,7 @@ find_cifs_mid(struct TCP_Server_Info *server, struct smb_hdr *buf,
mid->command != buf->Command) mid->command != buf->Command)
continue; continue;
if (*length == 0 && check2ndT2(buf, server->maxBuf) > 0) { if (*length == 0 && check2ndT2(buf) > 0) {
/* We have a multipart transact2 resp */ /* We have a multipart transact2 resp */
*is_multi_rsp = true; *is_multi_rsp = true;
if (mid->resp_buf) { if (mid->resp_buf) {
...@@ -3130,8 +3130,7 @@ cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info) ...@@ -3130,8 +3130,7 @@ cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)
cFYI(DBG2, "no very large read support, rsize now 127K"); cFYI(DBG2, "no very large read support, rsize now 127K");
} }
if (!(tcon->ses->capabilities & CAP_LARGE_READ_X)) if (!(tcon->ses->capabilities & CAP_LARGE_READ_X))
cifs_sb->rsize = min(cifs_sb->rsize, cifs_sb->rsize = min(cifs_sb->rsize, CIFSMaxBufSize);
(tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
cifs_sb->wsize = cifs_negotiate_wsize(tcon, volume_info); cifs_sb->wsize = cifs_negotiate_wsize(tcon, volume_info);
......
...@@ -1868,7 +1868,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, ...@@ -1868,7 +1868,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
if ((pTcon->ses) && if ((pTcon->ses) &&
!(pTcon->ses->capabilities & CAP_LARGE_FILES)) { !(pTcon->ses->capabilities & CAP_LARGE_FILES)) {
current_read_size = min_t(const int, current_read_size, current_read_size = min_t(const int, current_read_size,
pTcon->ses->server->maxBuf - 128); CIFSMaxBufSize);
} }
rc = -EAGAIN; rc = -EAGAIN;
while (rc == -EAGAIN) { while (rc == -EAGAIN) {
......
...@@ -124,7 +124,9 @@ static __u32 cifs_ssetup_hdr(struct cifs_ses *ses, SESSION_SETUP_ANDX *pSMB) ...@@ -124,7 +124,9 @@ static __u32 cifs_ssetup_hdr(struct cifs_ses *ses, SESSION_SETUP_ANDX *pSMB)
/* that we use in next few lines */ /* that we use in next few lines */
/* Note that header is initialized to zero in header_assemble */ /* Note that header is initialized to zero in header_assemble */
pSMB->req.AndXCommand = 0xFF; pSMB->req.AndXCommand = 0xFF;
pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf); pSMB->req.MaxBufferSize = cpu_to_le16(min_t(u32,
CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4,
USHRT_MAX));
pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq); pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq);
pSMB->req.VcNumber = get_next_vcnum(ses); pSMB->req.VcNumber = get_next_vcnum(ses);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册