Skip to content

Commit c06a0f2

Browse files
longlimsftSteve French
authored andcommitted
CIFS: Calculate the correct request length based on page offset and tail size
It's possible that the page offset is non-zero in the pages in a request, change the function to calculate the correct data buffer length. Signed-off-by: Long Li <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent ee25c6d commit c06a0f2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

fs/cifs/transport.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,24 @@ rqst_len(struct smb_rqst *rqst)
212212
for (i = 0; i < rqst->rq_nvec; i++)
213213
buflen += iov[i].iov_len;
214214

215-
/* add in the page array if there is one */
215+
/*
216+
* Add in the page array if there is one. The caller needs to make
217+
* sure rq_offset and rq_tailsz are set correctly. If a buffer of
218+
* multiple pages ends at page boundary, rq_tailsz needs to be set to
219+
* PAGE_SIZE.
220+
*/
216221
if (rqst->rq_npages) {
217-
buflen += rqst->rq_pagesz * (rqst->rq_npages - 1);
218-
buflen += rqst->rq_tailsz;
222+
if (rqst->rq_npages == 1)
223+
buflen += rqst->rq_tailsz;
224+
else {
225+
/*
226+
* If there is more than one page, calculate the
227+
* buffer length based on rq_offset and rq_tailsz
228+
*/
229+
buflen += rqst->rq_pagesz * (rqst->rq_npages - 1) -
230+
rqst->rq_offset;
231+
buflen += rqst->rq_tailsz;
232+
}
219233
}
220234

221235
return buflen;

0 commit comments

Comments
 (0)