From patchwork Sat Apr 27 03:43:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 10919907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA2A31398 for ; Sat, 27 Apr 2019 03:43:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B71328E9F for ; Sat, 27 Apr 2019 03:43:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78D9D28EA4; Sat, 27 Apr 2019 03:43:36 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 D300D28E9F for ; Sat, 27 Apr 2019 03:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727268AbfD0Dne (ORCPT ); Fri, 26 Apr 2019 23:43:34 -0400 Received: from mail-pf1-f182.google.com ([209.85.210.182]:44410 "EHLO mail-pf1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727016AbfD0Dne (ORCPT ); Fri, 26 Apr 2019 23:43:34 -0400 Received: by mail-pf1-f182.google.com with SMTP id y13so2597639pfm.11 for ; Fri, 26 Apr 2019 20:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=sZbCaZd62RS0HQMtWC9xQRU9LnEXwU3GPpKJ1bKnoJA=; b=rOIAjWkezocb9LriJ43gCCSPA2z2AYHoJ1gXJ3oNcF2+xLjzZhbj/wdrOLtjd6LKZq XnftfjmwUgQjrKsGoPa1AskWLnL8myeiNO3GCFKrT4NsmsvjKMmMjgP7mcIvUPUDlVb+ BApicCX/+SFFDRy3E0Dfj81koz5RqrCTlRaVgAJxPrwJrFFHv2gTcPM8xlPu4bpGurus STyxYJlNTP54FTFjneE8hui66Y0lkAdqcB5MHm2B9AJNSaFK+iRfo2CLel08yx3CcRqA Z1OFVhlpUDPjs9UZQavwPN4gPBXBp5gQzVSLGHycJhTeixuUMmwqd8/iHPshT/dNUN07 K/xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=sZbCaZd62RS0HQMtWC9xQRU9LnEXwU3GPpKJ1bKnoJA=; b=r0iUu7KPRywmqVJ87oHpRcKKa6eednLd1qFAE6xdt2Hr+gdRYJ3akcHIT+C4Wbb70z 6wvgoWn4yAa5qdJ0Ycag7j4f5m/rWJ7e3InhTtIIFtbAsUTpc023dXYKDNFk9oWpFkxv nn7oGKunpQPnHZ2FAv/HmyAN+uwYXUnRcZBrFbGzKOc4FYwL+Wjg0/AKt0Xo8WrsWcv5 2N9donsLJAufot2JLatanaIU74Oe9nwJcSk+fvu1vfMMKWTHJBcFcZazz6hkstsKREi+ pOmeQbeDnQ2itSWO8V+b3cE1S/bgBdEB62UC6Ge1KV8eyQ/w+rGLgMVOVnZzCtPo3eNp iLqQ== X-Gm-Message-State: APjAAAVrGR6Ibb6xUP4uRUiW6ZRPoy0MwbauMoIkUJFizgBKZdNxgrU1 U8kpMUWguKJ3TTI0ieybFfVitWlz7g6V44NUbxpI2BmZ X-Google-Smtp-Source: APXvYqx/gKxIw8coVqotCs0Qyl3DkTIPwjGV+5l30fi9VuYSqY7oeTrEX9eW8vYvNtys7WlRSecimE9ry2+wdAJTeBU= X-Received: by 2002:a62:528b:: with SMTP id g133mr5306107pfb.246.1556336613339; Fri, 26 Apr 2019 20:43:33 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Fri, 26 Apr 2019 20:43:22 -0700 Message-ID: Subject: Add support for new Compression Negotiate Context To: CIFS , samba-technical 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 Add support to negotiate the compression context, and also saved off to display in /proc/fs/cifs/DebugData. Future patch will add use for it on the wire. Note in /proc/fs/cifs/DebugData below (mounted to Windows 10) it defaulted to LZ77 compression algorithm. See MS-SMB2 2.2.3.1 and and MS-XCA Servers: Number of credits: 326 Dialect 0x311 COMPRESS_LZ77 signed 1) Name: 192.168.92.17 Uses: 1 Capability: 0x300067 Session Status: 1 TCP status: 1 Instance: 1 From 7f87c6faf547071e0e503f4311349025411e3fdf Mon Sep 17 00:00:00 2001 From: Steve French Date: Fri, 26 Apr 2019 20:36:08 -0700 Subject: [PATCH] [smb3] Negotiate and save preferred compression algorithms New negotiate context (3) allows the server and client to negotiate which compression algorithms to use. Add support for this and save it off in the server structure. Also now displayed in /proc/fs/cifs/DebugData (see below example to Windows 10) where compression algoirthm "LZ77" was negotiated: Servers: Number of credits: 326 Dialect 0x311 COMPRESS_LZ77 signed 1) Name: 192.168.92.17 Uses: 1 Capability: 0x300067 Session Status: 1 TCP status: 1 Instance: 1 See MS-XCA and MS-SMB2 2.2.3.1 for more details. Signed-off-by: Steve French --- fs/cifs/cifs_debug.c | 6 ++++++ fs/cifs/cifsglob.h | 1 + fs/cifs/smb2pdu.c | 47 +++++++++++++++++++++++++++++++++++++++++++- fs/cifs/smb2pdu.h | 7 +++++-- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c index 5ff0b3d4c484..6a69f11aacf7 100644 --- a/fs/cifs/cifs_debug.c +++ b/fs/cifs/cifs_debug.c @@ -332,6 +332,12 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) #endif seq_printf(m, "\nNumber of credits: %d Dialect 0x%x", server->credits, server->dialect); + if (server->compress_algorithm == SMB3_COMPRESS_LZNT1) + seq_printf(m, " COMPRESS_LZNT1"); + else if (server->compress_algorithm == SMB3_COMPRESS_LZ77) + seq_printf(m, " COMPRESS_LZ77"); + else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF) + seq_printf(m, " COMPRESS_LZ77_HUFF"); if (server->sign) seq_printf(m, " signed"); if (server->posix_ext_supported) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 5ffe0e538cec..d244bcfb4252 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -734,6 +734,7 @@ struct TCP_Server_Info { #endif /* STATS2 */ unsigned int max_read; unsigned int max_write; + __u16 compress_algorithm; __le16 cipher_type; /* save initital negprot hash */ __u8 preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE]; diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 634800c0bc06..82e2a27bccc0 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -472,6 +472,19 @@ build_preauth_ctxt(struct smb2_preauth_neg_context *pneg_ctxt) pneg_ctxt->HashAlgorithms = SMB2_PREAUTH_INTEGRITY_SHA512; } +static void +build_compression_ctxt(struct smb2_compression_capabilities_context *pneg_ctxt) +{ + pneg_ctxt->ContextType = SMB2_COMPRESSION_CAPABILITIES; + pneg_ctxt->DataLength = + cpu_to_le16(sizeof(struct smb2_compression_capabilities_context) + - sizeof(struct smb2_neg_context)); + pneg_ctxt->CompressionAlgorithmCount = cpu_to_le16(3); + pneg_ctxt->CompressionAlgorithms[0] = SMB3_COMPRESS_LZ77; + pneg_ctxt->CompressionAlgorithms[1] = SMB3_COMPRESS_LZ77_HUFF; + pneg_ctxt->CompressionAlgorithms[2] = SMB3_COMPRESS_LZNT1; +} + static void build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt) { @@ -538,10 +551,17 @@ assemble_neg_contexts(struct smb2_negotiate_req *req, *total_len += ctxt_len; pneg_ctxt += ctxt_len; + build_compression_ctxt((struct smb2_compression_capabilities_context *) + pneg_ctxt); + ctxt_len = DIV_ROUND_UP( + sizeof(struct smb2_compression_capabilities_context), 8) * 8; + *total_len += ctxt_len; + pneg_ctxt += ctxt_len; + build_posix_ctxt((struct smb2_posix_neg_context *)pneg_ctxt); *total_len += sizeof(struct smb2_posix_neg_context); - req->NegotiateContextCount = cpu_to_le16(3); + req->NegotiateContextCount = cpu_to_le16(4); } static void decode_preauth_context(struct smb2_preauth_neg_context *ctxt) @@ -559,6 +579,28 @@ static void decode_preauth_context(struct smb2_preauth_neg_context *ctxt) printk_once(KERN_WARNING "unknown SMB3 hash algorithm\n"); } +static void decode_compress_ctx(struct TCP_Server_Info *server, + struct smb2_compression_capabilities_context *ctxt) +{ + unsigned int len = le16_to_cpu(ctxt->DataLength); + + /* sizeof compress context is a one element compression capbility struct */ + if (len < 10) { + printk_once(KERN_WARNING "server sent bad compression cntxt\n"); + return; + } + if (le16_to_cpu(ctxt->CompressionAlgorithmCount) != 1) { + printk_once(KERN_WARNING "illegal SMB3 compress algorithm count\n"); + return; + } + if (le16_to_cpu(ctxt->CompressionAlgorithms[0]) > 3) { + printk_once(KERN_WARNING "unknown compression algorithm\n"); + return; + } + server->compress_algorithm = + le16_to_cpu(ctxt->CompressionAlgorithms[0]); +} + static int decode_encrypt_ctx(struct TCP_Server_Info *server, struct smb2_encryption_neg_context *ctxt) { @@ -623,6 +665,9 @@ static int smb311_decode_neg_context(struct smb2_negotiate_rsp *rsp, else if (pctx->ContextType == SMB2_ENCRYPTION_CAPABILITIES) rc = decode_encrypt_ctx(server, (struct smb2_encryption_neg_context *)pctx); + else if (pctx->ContextType == SMB2_COMPRESSION_CAPABILITIES) + decode_compress_ctx(server, + (struct smb2_compression_capabilities_context *)pctx); else if (pctx->ContextType == SMB2_POSIX_EXTENSIONS_AVAILABLE) server->posix_ext_supported = true; else diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index 82686e9d9e05..afa837b34226 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h @@ -303,10 +303,13 @@ struct smb2_encryption_neg_context { #define SMB3_COMPRESS_LZ77_HUFF 0x0003 struct smb2_compression_capabilities_context { + __le16 ContextType; /* 3 */ + __le16 DataLength; + __u32 Reserved; __le16 CompressionAlgorithmCount; __u16 Padding; - __u32 Reserved; - __u16 CompressionAlgorithms[1]; + __u32 Reserved1; + __u16 CompressionAlgorithms[3]; } __packed; /* -- 2.17.1