Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4830928imm; Wed, 30 May 2018 12:55:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLW8yV5P0bNDuVI0dEqYxHdxKjWxKGhiD4omY6V0NUJL+vZzndy+Sqijx7KT3TAukHC89UD X-Received: by 2002:a17:902:7d85:: with SMTP id a5-v6mr4077024plm.356.1527710102946; Wed, 30 May 2018 12:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527710102; cv=none; d=google.com; s=arc-20160816; b=FUEeOcNTswFu2MbPkVV1dVP0qkvChPDSncCY73hl/6AGkH5euO1nMK1iWS1lsOcysw HsDT7biKiw6ubhKm+v/UM3Jqij96GuizB0+v3vqcj6+m8KfeKVvpZIA22GoR4KdH4ytP n+fOBLhCtxGupoFl8uVBXELtF6IuPYsa9oo+EF9O0bu5eKdf1mUfeviRhjmL/hlsH2Sl 8+IyUsD+tgtP51sne8tmBEYOJY94VmRI9QIJdW8DX44uKcOqX8lh5S0ar7aKR4dnB82N eykfROgFub8ROk/ylh10qP/GVlc9Io1+6U8IqzBLXmhywreBY0AfcxAad/kLl9G+JJJe bkfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=s3SxcoMFPDLw8gRT4n74VJPUAdB9b1QZ9TBWPWkq8jg=; b=HKbojaJ6+l2RLP87G+c6E4fpxdyGT5+4I1puGJdHN102Wo5qpQ1bQvUXoXtsWjmabw xpjTvLSBgPlTGb1Pznztyph4UdyxmlM+Ljbu9LYRf2zrF7VfzQMK0W2hMWJq1t5uqUvZ jj/dzsiG+9GFvVZUZJvwAQ/lDGprpM/b3iCxtj8Zo9SRHjEgOps4vjGAxvyimG7l0QXW 8eEeWOPmnmxGtabhSnwc8PKzAnoVK8RGsFf7yEXOKnI4Yh0ly46sbAgn0rek73pP81Dv +wtDrdrPe3lrsZv+/RfqyjzJbI5Hte8pffhTA1UF85AfHAET5cvhpIXu6ywUEHGuqh1+ VatA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n20-v6si35720800pff.370.2018.05.30.12.54.49; Wed, 30 May 2018 12:55:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932340AbeE3TwH (ORCPT + 99 others); Wed, 30 May 2018 15:52:07 -0400 Received: from a2nlsmtp01-05.prod.iad2.secureserver.net ([198.71.225.49]:37636 "EHLO a2nlsmtp01-05.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932252AbeE3Ttw (ORCPT ); Wed, 30 May 2018 15:49:52 -0400 Received: from linuxonhyperv2.linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id O75Nf7hZ0F1fmO75NfIEOo; Wed, 30 May 2018 12:48:51 -0700 x-originating-ip: 107.180.71.197 Received: from longli by linuxonhyperv2.linuxonhyperv.com with local (Exim 4.91) (envelope-from ) id 1fO75N-0008Fn-1s; Wed, 30 May 2018 12:48:41 -0700 From: Long Li To: Steve French , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Cc: Long Li Subject: [Patch v2 05/15] CIFS: Calculate the correct request length based on page offset and tail size Date: Wed, 30 May 2018 12:47:57 -0700 Message-Id: <20180530194807.31657-6-longli@linuxonhyperv.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180530194807.31657-1-longli@linuxonhyperv.com> References: <20180530194807.31657-1-longli@linuxonhyperv.com> Reply-To: longli@microsoft.com X-CMAE-Envelope: MS4wfO8CRb4B9gkMMC+3Kk7nmLvb1eLbHisriOoSpwinepjpeNH3pTC19tHDS3ndrePv3yW3mFFJOd8WeXKhjnfbFnVfs59BMXf8RGEpkI0tXES25Dm9xyYt z5IZzT7YLNhg3A5RM8z9HkALCDyggSU3iS2nSrJSwgzvjEaazCKPcRM9+9Yd7vGQhBTnDk5y32XJ9ifldv5M4RmnVqwfHmZpu/ppR1O6N09Z99HGg/fyARPj ciiGSlaiHBXjrq2fXzhaZ/DzboNn7P3q2Eyxwko8H6HhUewLiwmkpEJcF80dZ8LnxBfIQo7ofjm2T/KBjg1ot6Kj2pmHqI1uhCeg7k97tJu8PqfueAok2ZeV CTANKB0T8hXUEk3WH3gUhdvFBvboiHyl4ZrEwpijCTA/+4/gKN1VsQZ9crtiyUq1GXgHdT1K Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Long Li 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 --- fs/cifs/transport.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 927226a..d6b5523 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -212,10 +212,24 @@ rqst_len(struct smb_rqst *rqst) for (i = 0; i < rqst->rq_nvec; i++) buflen += iov[i].iov_len; - /* add in the page array if there is one */ + /* + * Add in the page array if there is one. The caller needs to make + * sure rq_offset and rq_tailsz are set correctly. If a buffer of + * multiple pages ends at page boundary, rq_tailsz needs to be set to + * PAGE_SIZE. + */ if (rqst->rq_npages) { - buflen += rqst->rq_pagesz * (rqst->rq_npages - 1); - buflen += rqst->rq_tailsz; + if (rqst->rq_npages == 1) + buflen += rqst->rq_tailsz; + else { + /* + * If there is more than one page, calculate the + * buffer length based on rq_offset and rq_tailsz + */ + buflen += rqst->rq_pagesz * (rqst->rq_npages - 1) - + rqst->rq_offset; + buflen += rqst->rq_tailsz; + } } return buflen; -- 2.7.4