From patchwork Thu Mar 22 04:24:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 10300829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 63CD2600F6 for ; Thu, 22 Mar 2018 04:24:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 544C1298C6 for ; Thu, 22 Mar 2018 04:24:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 477E5298DE; Thu, 22 Mar 2018 04:24:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEC70298C6 for ; Thu, 22 Mar 2018 04:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751507AbeCVEYa (ORCPT ); Thu, 22 Mar 2018 00:24:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46618 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750992AbeCVEY3 (ORCPT ); Thu, 22 Mar 2018 00:24:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 328F1406DE12; Thu, 22 Mar 2018 04:24:29 +0000 (UTC) Received: from test1190.test.redhat.com (vpn2-54-110.bne.redhat.com [10.64.54.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3B1B6353B; Thu, 22 Mar 2018 04:24:27 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 09/16] cifs: update init_sg and crypt_message to take an array of rqst Date: Thu, 22 Mar 2018 15:24:00 +1100 Message-Id: <20180322042407.7599-10-lsahlber@redhat.com> In-Reply-To: <20180322042407.7599-1-lsahlber@redhat.com> References: <20180322042407.7599-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 22 Mar 2018 04:24:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 22 Mar 2018 04:24:29 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lsahlber@redhat.com' RCPT:'' Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is used for SMB3 encryption and compounded requests. The first rqst begins with a smb3 transform header as the first iov. Signed-off-by: Ronnie Sahlberg --- fs/cifs/smb2ops.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 47db072a1e1c..158b7767e5c3 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -2080,29 +2080,43 @@ static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf, * rqst->rq_iov[1+] data to be encrypted/decrypted */ static struct scatterlist * -init_sg(struct smb_rqst *rqst, u8 *sign) +init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign) { unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1; unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20; struct scatterlist *sg; unsigned int i; unsigned int j; + unsigned int idx = 0; sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL); if (!sg) return NULL; sg_init_table(sg, sg_len); - smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 20, assoc_data_len); - for (i = 1; i < rqst->rq_nvec; i++) - smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base, - rqst->rq_iov[i].iov_len); - for (j = 0; i < sg_len - 1; i++, j++) { - unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz - : rqst->rq_tailsz; - sg_set_page(&sg[i], rqst->rq_pages[j], len, 0); - } - smb2_sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE); + for (i = 0; i < num_rqst; i++) { + /* the first rqst has a transform header where the first 20 + * bytes are not part of the encrypted blob + */ + if (i == 0) + smb2_sg_set_buf(&sg[idx++], + rqst[i].rq_iov[i].iov_base + 20, + assoc_data_len); + else + smb2_sg_set_buf(&sg[idx++], rqst[i].rq_iov[i].iov_base, + rqst[i].rq_iov[0].iov_len); + + for (j = 1; j < rqst[i].rq_nvec; j++) + smb2_sg_set_buf(&sg[idx++], rqst[i].rq_iov[j].iov_base, + rqst[i].rq_iov[j].iov_len); + + for (j = 0; j < rqst[i].rq_npages; j++) { + unsigned int len = (j < rqst[i].rq_npages - 1) ? + rqst[i].rq_pagesz : rqst[i].rq_tailsz; + sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, 0); + } + } + smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE); return sg; } @@ -2134,7 +2148,8 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) * untouched. */ static int -crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) +crypt_message(struct TCP_Server_Info *server, int num_rqst, + struct smb_rqst *rqst, int enc) { struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base; @@ -2188,7 +2203,7 @@ crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) crypt_len += SMB2_SIGNATURE_SIZE; } - sg = init_sg(rqst, sign); + sg = init_sg(num_rqst, rqst, sign); if (!sg) { cifs_dbg(VFS, "%s: Failed to init sg", __func__); rc = -ENOMEM; @@ -2272,7 +2287,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst, new_rq->rq_iov = iov; new_rq->rq_nvec = old_rq->rq_nvec + 1; - /* fill the 2nd iov with a transform header */ + /* fill the 1nd iov with a transform header */ fill_transform_hdr(tr_hdr, orig_len, old_rq); new_rq->rq_iov[0].iov_base = tr_hdr; new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr); @@ -2288,7 +2303,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst, kunmap(old_rq->rq_pages[i]); } - rc = crypt_message(server, new_rq, 1); + rc = crypt_message(server, num_rqst, new_rq, 1); cifs_dbg(FYI, "encrypt message returned %d", rc); if (rc) goto err_free_iov; @@ -2352,7 +2367,7 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf, rqst.rq_pagesz = PAGE_SIZE; rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE; - rc = crypt_message(server, &rqst, 0); + rc = crypt_message(server, 1, &rqst, 0); cifs_dbg(FYI, "decrypt message returned %d\n", rc); if (rc)