From patchwork Mon Jan 30 21:39:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovskiy X-Patchwork-Id: 9546127 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 EB0C3604CC for ; Mon, 30 Jan 2017 21:44:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01E47283B4 for ; Mon, 30 Jan 2017 21:44:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB39B283F9; Mon, 30 Jan 2017 21:44:00 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 3B6FF283F4 for ; Mon, 30 Jan 2017 21:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754529AbdA3Vn4 (ORCPT ); Mon, 30 Jan 2017 16:43:56 -0500 Received: from mail-by2nam03on0095.outbound.protection.outlook.com ([104.47.42.95]:53632 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754562AbdA3Vnp (ORCPT ); Mon, 30 Jan 2017 16:43:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xGxdoNkNw7Gbn6Skx9ozXgN0znIHb1TWnf5wF6zLZMw=; b=EFTRkLEteBcQ1hTeHMChJ36pGtwb+JHv3KR3rlxfwPpETXTO3P/zG1XUck/9895ShUXn97KKLV/ouzgtcwQ4VB9YtvwqyFA+g9ybjE6q4m7/BqiPg+asmknT8afa54xNQYverjYJFegdixF6J6/Vc7sjRTyWf6fJKaDKQnbQN2A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pshilov@microsoft.com; Received: from ubuntu-vm.corp.microsoft.com (2001:4898:80e8:b::63b) by BN6PR03MB2545.namprd03.prod.outlook.com (10.173.142.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.874.12; Mon, 30 Jan 2017 21:41:10 +0000 From: Pavel Shilovsky To: Subject: [PATCH v2 14/15] CIFS: Add capability to decrypt big read responses Date: Mon, 30 Jan 2017 13:39:43 -0800 Message-ID: <1485812384-28870-15-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485812384-28870-1-git-send-email-pshilov@microsoft.com> References: <1485812384-28870-1-git-send-email-pshilov@microsoft.com> MIME-Version: 1.0 X-Originating-IP: [2001:4898:80e8:b::63b] X-ClientProxiedBy: BN6PR1401CA0011.namprd14.prod.outlook.com (10.174.237.149) To BN6PR03MB2545.namprd03.prod.outlook.com (10.173.142.148) X-MS-Office365-Filtering-Correlation-Id: 217ba4f8-bf8c-4f8f-8f00-08d44958b4ea X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN6PR03MB2545; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2545; 3:BmfxJtYyotWLLHiWzegKl5Po69u05hR2dC8UeJ2xgY4khGksQuUi1XLPUL2OgQJY85YzgKd4v6lqzGBYUkekg625xvh7NZB/v3GXKZ5HBVCgr4Pcvz90MIWk4dufYvuEUihpHR7yt/jErNly4PqlVhWanejFp1chsth262Wbd+lWaCnPENm7kTSV/FI16mkcv5p4o1CDLrSaWsO2cm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WzvHxd11nneN404tGQIMfcjBZvUvxh51HJoFHuBEps96ZnN4zTiwOlcedfrhBefHbxPkAjpmJBJA//RGUbWaHJhFmf7O37uaknBuLmXL68MvgoMZT/XbmnezZ6yUM2B3qR89D4/+0bRMS5EGDlVRz6PTBzDt1i+6f8dqLw1AEajZgFaAH0hv2KPOKrQKFugS4mE82FFsH4x4plNQp0gyUOISA74LpR5rkbbQ9qkUsMzseTqmrQk7SgBTuUmUNe4JB4Y3nUadPP59mb8oStdgo5nhAwvJauQdcNbGb/F89EyMDVzyvDzfLXY1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(158342451672863); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123564025)(20161123562025)(20161123560025)(6072148)(6047074); SRVR:BN6PR03MB2545; BCL:0; PCL:0; RULEID:; SRVR:BN6PR03MB2545; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2545; 4:rKHQWP94liJ/hHeZyA3KxagVuefXNr2Xy8kv2WbB0QOrLeOYxOz5V0RPCGRdbE65UKwVYCAl/1LjN0xRCUtv6fAV2nUR2AGGsrrjJ8s5e60snW/5F19mxEB+Tq15nOdr8e7VWHltrvahhCXfGIZ+9820PrH/dZ1GtpU1t2xWp/Lnu42eecJl0//AbuXW2DjkFNCYTuIVQ9I/ZarA9KhNg3Rnax9oo9vdqThDd3I3nt0FVwLkXMdQ8RGxiFG8jayCFbmJ4QtiNlCq7f5ib5ad3WdoAFeCKD1cG0XEX3sRkObxU5R5vrrPlxE/1E3uMQbb7c2tM66Uawr3t/b9ed8cef2u9r8CXIXeifBr6MOnuabg12Cm/yuYoUp1TIpDK1Y4sXVYaIhE4MxeO1grvgqcc7NNU70KPmj+SAUde3dLrDJ25FY6M+To4cLaLC7GwwRsxdpULUy3NVZgm+E9PDzYyHicRZvGKKpXtTK2zfrKjr8p0ech93lkDf8B83xgervR9Ubq/G1V6N4Wl2QKQWg2UzIs8nKdVDRD4ezGb/3OSkdiJ3jJgIt2mZ9rgWeyNh+HY22alBLqq80oRX/mZZVslLKE8/VkLLtDcYnya9m98fihNEk7gm5TSDvaK0qbo0hH9nEQpoJ3wkk3+M9ba1KDgdXLcqiBv8h3Hiq6pbSzNI8= X-Forefront-PRVS: 0203C93D51 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39850400002)(39860400002)(39840400002)(39450400003)(39410400002)(69234005)(189002)(199003)(305945005)(5660300001)(8676002)(81166006)(5003940100001)(6116002)(50466002)(48376002)(81156014)(53936002)(101416001)(42186005)(110136003)(7736002)(10290500002)(47776003)(5005710100001)(10090500001)(33646002)(36756003)(92566002)(2351001)(6486002)(2950100002)(50226002)(105586002)(76176999)(189998001)(50986999)(106356001)(86362001)(38730400001)(86612001)(25786008)(6916009)(6666003)(2906002)(450100001)(107886002)(68736007)(97736004); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR03MB2545; H:ubuntu-vm.corp.microsoft.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2545; 23:+0v8M4dKgDPlmP3c0aBgbr8TbkTqD5AwgAiDNdbId?= =?us-ascii?Q?40L5lsEI/WwztisTic5jLfW8Bs+YHazx55+TPLYxvotPh0o3dPCiVLecMk/x?= =?us-ascii?Q?OezLqfTC8q+IY6KxU6dDYLseYiY1CLNmPxVZvIswLRP6b5OYyOpzmKbrhMD6?= =?us-ascii?Q?h4sO+9vCG7hcBvxWx7b6Q6r1ryF62nDcSpDaLeFDJVErSucQ2CYGd8sp/ngn?= =?us-ascii?Q?1hY02UxyXQhi1UHfBxPtqWjrp0siknx4+15SM/WQJ8kky88ID+GQNAk+N/QN?= =?us-ascii?Q?3VL3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FvSyDw?= =?us-ascii?Q?25SWnx1ZEWrkZClW5wO4gIAwDK4OJXGuzKooVyVmDCASBCLPf/fpAjd3TWOb?= =?us-ascii?Q?BvuKP6sik6M6QQ6k2ut3geClAw2ENw25Ko4DJ/oKzolNWgkTy5pxx5JBWSN+?= =?us-ascii?Q?dnmk8ENvO/PfkAd1B9S6+g=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2545; 6:qHWeEmbSF0/cOZxZsLPmYUKxHIHMcbY8emiwYOCDMgrnn+iZAId/cZfibvhu1+CUwqsWmCUG4DL9I+jUz2kVosV8095RjG9S7BsOTrXeJ0tgiGINiVttVmWrh6LPqlrFPhEFi7+YQwftu5ujNJTjrw0BL4BBHjhRFaRIrajH4TbgONX8PLmgHRb2fYNY5zUY96FueXKow4FCU2Sq5/9Wx36lVZGH0oKbZ2cdcvgaR/CCNg7ErQflP6KMeE9sSMywEJtgSnVjJ6vHWSXUWHEY7tfPwVuuP8toNy/zflqELJOKbjSOGO1TbGalHM47JkT+P+114+/8SsuQ38qzfw+k0GPh/Vdv6aqxQAwm33JqJIq35weEZfdrZS2qu3D2ibVIyJFlj+WE6mb2QJqZXAn3jW8LNPrUnnA1mohPIFN49+DO29rldwiRd/v2NjMr2+dK; 5:6apQPyxRin1cwg0kYJ//4P+7/yONfwbGtnSZe1kRXdTpJ3IbY/TQaxHBXRWUot6UuZ2lMvp9RWtqC1Cg1tm+p3QTWY24YEi21VAJWAJDCrmPYzlu6UzMvY44RcZBRLH7+wmtz86Bszv4vJp3BY8MMl/TVpibgGVoFaapenCzIHU=; 24:AWwseM2TH/0rBo0f+WD1bJOhpt5wF0siL3miZOiiYCu0ssCNfZ/qjSL3sJTJwqZ4FdiYD/kwTvO3qrWi8DPtMvAho1cGmqNzhqSngQznyBM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2545; 7:PkqS3iiJrmUiXJum78LYDKlsP+51kEMHQdI/dqr8Uyf5RIfp0WkzIBg7vhNlH2lRkZKW8r9SlcgAvc9fNXjPbij9qF7SBP8PPt8aI7vlgH6/bFjcwBxOiMuaHVO/uJmnvHEgUhOFrd0hk8c2sE5IGA1oYFSfsn6vRRD39MStLctVh/TSXioc5B71P/YCsxt/8DVUxOdo+MTUcObEPl2QMZdho7kn/vZzvlVR8Pw2flBi1XllQ6BktnwGeDaRw8qruM8PgO+nVAG0xxpVwA2uuRNtY2aDCvqKszOzNG4oj5mxWjKa3Ui2c16e/Nt0SoBYyVjAij/tRp6YuFD+MDQW+COiH6Q2FtINZC+VtaGZtflUhueEesR6c/bBGUn4AmcwX+qQDxDODGUA90RUCNiQ7JNyx2N74Qln2B7PWvtprH8iJfsudnrpDCY8EIGU/LzqB0n1SQNl9fVaGskrxA28Dw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2017 21:41:10.5031 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR03MB2545 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 Allow to decrypt transformed packets that are bigger than the big buffer size. In particular it is used for read responses that can only exceed the big buffer size. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsproto.h | 1 + fs/cifs/cifssmb.c | 8 +-- fs/cifs/smb2ops.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 169 insertions(+), 13 deletions(-) diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 0eb35d2..0dbafc8 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -76,6 +76,7 @@ extern void cifs_delete_mid(struct mid_q_entry *mid); extern void cifs_wake_up_task(struct mid_q_entry *mid); extern int cifs_handle_standard(struct TCP_Server_Info *server, struct mid_q_entry *mid); +extern int cifs_discard_remaining_data(struct TCP_Server_Info *server); extern int cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, mid_receive_t *receive, mid_callback_t *callback, diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 8326212..5d9ad38 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -1399,8 +1399,8 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, * Discard any remaining data in the current SMB. To do this, we borrow the * current bigbuf. */ -static int -discard_remaining_data(struct TCP_Server_Info *server) +int +cifs_discard_remaining_data(struct TCP_Server_Info *server) { unsigned int rfclen = get_rfc1002_length(server->smallbuf); int remaining = rfclen + 4 - server->total_read; @@ -1426,7 +1426,7 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) int length; struct cifs_readdata *rdata = mid->callback_data; - length = discard_remaining_data(server); + length = cifs_discard_remaining_data(server); dequeue_mid(mid, rdata->result); return length; } @@ -1459,7 +1459,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) if (server->ops->is_status_pending && server->ops->is_status_pending(buf, server, 0)) { - discard_remaining_data(server); + cifs_discard_remaining_data(server); return -1; } diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 86b8ab2..0764c32 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1844,12 +1844,72 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf, } static int +read_data_into_pages(struct TCP_Server_Info *server, struct page **pages, + unsigned int npages, unsigned int len) +{ + int i; + int length; + + for (i = 0; i < npages; i++) { + struct page *page = pages[i]; + size_t n; + + n = len; + if (len >= PAGE_SIZE) { + /* enough data to fill the page */ + n = PAGE_SIZE; + len -= n; + } else { + zero_user(page, len, PAGE_SIZE - len); + len = 0; + } + length = cifs_read_page_from_socket(server, page, n); + if (length < 0) + return length; + server->total_read += length; + } + + return 0; +} + +static int +init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size, + unsigned int cur_off, struct bio_vec **page_vec) +{ + struct bio_vec *bvec; + int i; + + bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL); + if (!bvec) + return -ENOMEM; + + for (i = 0; i < npages; i++) { + bvec[i].bv_page = pages[i]; + bvec[i].bv_offset = (i == 0) ? cur_off : 0; + bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size); + data_size -= bvec[i].bv_len; + } + + if (data_size != 0) { + cifs_dbg(VFS, "%s: something went wrong\n", __func__); + kfree(bvec); + return -EIO; + } + + *page_vec = bvec; + return 0; +} + +static int handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, char *buf, unsigned int buf_len, struct page **pages, unsigned int npages, unsigned int page_data_size) { unsigned int data_offset; unsigned int data_len; + unsigned int cur_off; + unsigned int cur_page_idx; + unsigned int pad_len; struct cifs_readdata *rdata = mid->callback_data; struct smb2_sync_hdr *shdr = get_sync_hdr(buf); struct bio_vec *bvec = NULL; @@ -1895,9 +1955,37 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, return 0; } + pad_len = data_offset - server->vals->read_rsp_size; + if (buf_len <= data_offset) { /* read response payload is in pages */ - /* BB add code to init iter with pages */ + cur_page_idx = pad_len / PAGE_SIZE; + cur_off = pad_len % PAGE_SIZE; + + if (cur_page_idx != 0) { + /* data offset is beyond the 1st page of response */ + cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n", + __func__, data_offset); + rdata->result = -EIO; + dequeue_mid(mid, rdata->result); + return 0; + } + + if (data_len > page_data_size - pad_len) { + /* data_len is corrupt -- discard frame */ + rdata->result = -EIO; + dequeue_mid(mid, rdata->result); + return 0; + } + + rdata->result = init_read_bvec(pages, npages, page_data_size, + cur_off, &bvec); + if (rdata->result != 0) { + dequeue_mid(mid, rdata->result); + return 0; + } + + iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len); } else if (buf_len >= data_offset + data_len) { /* read response payload is in buf */ WARN_ONCE(npages > 0, "read data can be either in buf or in pages"); @@ -1932,6 +2020,79 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, } static int +receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid) +{ + char *buf = server->smallbuf; + struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; + unsigned int npages; + struct page **pages; + unsigned int len; + unsigned int buflen = get_rfc1002_length(buf) + 4; + int rc; + int i = 0; + + len = min_t(unsigned int, buflen, server->vals->read_rsp_size - 4 + + sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; + + rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); + if (rc < 0) + return rc; + server->total_read += rc; + + len = le32_to_cpu(tr_hdr->OriginalMessageSize) + 4 - + server->vals->read_rsp_size; + npages = DIV_ROUND_UP(len, PAGE_SIZE); + + pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); + if (!pages) { + rc = -ENOMEM; + goto discard_data; + } + + for (; i < npages; i++) { + pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); + if (!pages[i]) { + rc = -ENOMEM; + goto discard_data; + } + } + + /* read read data into pages */ + rc = read_data_into_pages(server, pages, npages, len); + if (rc) + goto free_pages; + + rc = cifs_discard_remaining_data(server); + if (rc) + goto free_pages; + + rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size - 4, + pages, npages, len); + if (rc) + goto free_pages; + + *mid = smb2_find_mid(server, buf); + if (*mid == NULL) + cifs_dbg(FYI, "mid not found\n"); + else { + cifs_dbg(FYI, "mid found\n"); + (*mid)->decrypted = true; + rc = handle_read_data(server, *mid, buf, + server->vals->read_rsp_size, + pages, npages, len); + } + +free_pages: + for (i = i - 1; i >= 0; i--) + put_page(pages[i]); + kfree(pages); + return rc; +discard_data: + cifs_discard_remaining_data(server); + goto free_pages; +} + +static int receive_encrypted_standard(struct TCP_Server_Info *server, struct mid_q_entry **mid) { @@ -2000,14 +2161,8 @@ smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid) return -ECONNABORTED; } - if (pdu_length + 4 > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) { - cifs_dbg(VFS, "Decoding responses of big size (%u) is not supported\n", - pdu_length); - /* BB add code to allocate and fill highmem pages here */ - cifs_reconnect(server); - wake_up(&server->response_q); - return -ECONNABORTED; - } + if (pdu_length + 4 > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) + return receive_encrypted_read(server, mid); return receive_encrypted_standard(server, mid); }