Message ID | 166855224228.1998592.2212551359609792175.stgit@warthog.procyon.org.uk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2977581wru; Tue, 15 Nov 2022 14:47:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7A8H2+GllYRuum04juV8myxAK9aFhQtwnIbjkbY0aahSRAV5tL6+Zy/do5ntlCVQWU4xPQ X-Received: by 2002:a17:907:76d2:b0:78d:8c6b:397b with SMTP id kf18-20020a17090776d200b0078d8c6b397bmr15104797ejc.364.1668552454673; Tue, 15 Nov 2022 14:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668552454; cv=none; d=google.com; s=arc-20160816; b=bp67+8ocJ1b4dB+pDMdkZbygwdYUBhdl6Bs0Vs+WW4FOb+n/P9IPqxZ63XpbZqT7Ks kn5j25uUYR8o8GKf1cHiERtMoIAiDhJJ9arktBuJmv/h7OoKvIgLjgPzXlDaclWAAL+Z irESQ8Q2zw4GU6YaPPDCpZ4hAlvZMJvXNUSBdv1yDfG0dUF/kU4L7Gz80VHRbzvZHZRn cfF0Bcu0hKQdFrijD2IfWCznUvg3QkD/Lg7xxTDjY1BQe3n2Z2KN8Tzx2F5r/BcAV70q sbnXpV5jXX3b6GNWnpLUYeEg/N7P+mzvgUCzW073l5R5HxBgcvld/+28NLenMmH1Xa/I ol/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject:organization :dkim-signature; bh=Sr5cmUXaaquPODOsp7wOywLMH70ji6BY41qEcJlkct8=; b=KuPSy1jxbzJ8TsuH1/BwAabQhpOI+stA4gbgVAmQPfxVgp5ebjOqpsKEXqQE9FYE2s txHg09h6uFDDyVJ0Y+8mZ1r9LKoHZG5Vyouzfm2L8Ys11S7IjQn87AkBzyKfo8Ff7t+n z+QBR6WhjhWgdk/B4JnvMWJ2EuHnewNUQl9otd9giVDgSjUUvybg2QqRnagFkxoS8S6E lWIUPwq2+dmTV+xMwJkWDHumtvH+Dr6ZMnklcz0uqymbq+3TjPWNgOw4o46Kl5wjxCFw fSht/dz+mikOjR60l1/9aRUg/4H4fPXWwnDsrAHcL7OfqGsxYEWhUkyxZDU7WF4XRYBU Et5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F33jFi2U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a170906644c00b00767e24156dbsi8302933ejn.256.2022.11.15.14.47.11; Tue, 15 Nov 2022 14:47:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F33jFi2U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231871AbiKOWpO (ORCPT <rfc822;maxim.cournoyer@gmail.com> + 99 others); Tue, 15 Nov 2022 17:45:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbiKOWpD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 15 Nov 2022 17:45:03 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CFE21CFDD for <linux-kernel@vger.kernel.org>; Tue, 15 Nov 2022 14:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668552251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Sr5cmUXaaquPODOsp7wOywLMH70ji6BY41qEcJlkct8=; b=F33jFi2UtY0+l0Zn23UUyBV8awHtqDldtvgQ7TZ8PGgUrk4oQIVtDT+37sNA/OMlrWbMN9 0QCcPpPcLyF/dXHpB6wWRCWtQ50lYwg+oQUGC3RB4VCY+Vwg8ovUGL900zSUFXxfELSF5N HB+ge0ji6lWiLapTFR2rTdXaOD5jK9c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-383-qYs-SrBBO5qTlAyD7FTboQ-1; Tue, 15 Nov 2022 17:44:06 -0500 X-MC-Unique: qYs-SrBBO5qTlAyD7FTboQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 47DD9800B23; Tue, 15 Nov 2022 22:44:06 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40F4B40C6EC3; Tue, 15 Nov 2022 22:44:05 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH] cifs: Fix problem with encrypted RDMA data read From: David Howells <dhowells@redhat.com> To: smfrench@gmail.com, tom@talpey.com Cc: Long Li <longli@microsoft.com>, Namjae Jeon <linkinjeon@kernel.org>, Stefan Metzmacher <metze@samba.org>, linux-cifs@vger.kernel.org, dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 15 Nov 2022 22:44:02 +0000 Message-ID: <166855224228.1998592.2212551359609792175.stgit@warthog.procyon.org.uk> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749604059053394872?= X-GMAIL-MSGID: =?utf-8?q?1749604059053394872?= |
Series |
cifs: Fix problem with encrypted RDMA data read
|
|
Commit Message
David Howells
Nov. 15, 2022, 10:44 p.m. UTC
When the cifs client is talking to the ksmbd server by RDMA and the ksmbd
server has "smb3 encryption = yes" in its config file, the normal PDU
stream is encrypted, but the directly-delivered data isn't in the stream
(and isn't encrypted), but is rather delivered by DDP/RDMA packets (at
least with IWarp).
Currently, the direct delivery fails with:
buf can not contain only a part of read data
WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 handle_read_data+0x393/0x405
...
RIP: 0010:handle_read_data+0x393/0x405
...
smb3_handle_read_data+0x30/0x37
receive_encrypted_standard+0x141/0x224
cifs_demultiplex_thread+0x21a/0x63b
kthread+0xe7/0xef
ret_from_fork+0x22/0x30
The problem apparently stemming from the fact that it's trying to manage
the decryption, but the data isn't in the smallbuf, the bigbuf or the page
array).
This can be fixed simply by inserting an extra case into handle_read_data()
that checks to see if use_rdma_mr is true, and if it is, just setting
rdata->got_bytes to the length of data delivered and allowing normal
continuation.
This can be seen in an IWarp packet trace. With the upstream code, it does
a DDP/RDMA packet, which produces the warning above and then retries,
retrieving the data inline, spread across several SMBDirect messages that
get glued together into a single PDU. With the patch applied, only the
DDP/RDMA packet is seen.
Note that this doesn't happen if the server isn't told to encrypt stuff and
it does also happen with softRoCE.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Steve French <smfrench@gmail.com>
cc: Tom Talpey <tom@talpey.com>
cc: Long Li <longli@microsoft.com>
cc: Namjae Jeon <linkinjeon@kernel.org>
cc: Stefan Metzmacher <metze@samba.org>
cc: linux-cifs@vger.kernel.org
---
fs/cifs/smb2ops.c | 3 +++
1 file changed, 3 insertions(+)
Comments
Hi David, see below... > When the cifs client is talking to the ksmbd server by RDMA and the ksmbd > server has "smb3 encryption = yes" in its config file, the normal PDU > stream is encrypted, but the directly-delivered data isn't in the stream > (and isn't encrypted), but is rather delivered by DDP/RDMA packets (at > least with IWarp). > > Currently, the direct delivery fails with: > > buf can not contain only a part of read data > WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 handle_read_data+0x393/0x405 > ... > RIP: 0010:handle_read_data+0x393/0x405 > ... > smb3_handle_read_data+0x30/0x37 > receive_encrypted_standard+0x141/0x224 > cifs_demultiplex_thread+0x21a/0x63b > kthread+0xe7/0xef > ret_from_fork+0x22/0x30 > > The problem apparently stemming from the fact that it's trying to manage > the decryption, but the data isn't in the smallbuf, the bigbuf or the page > array). > > This can be fixed simply by inserting an extra case into handle_read_data() > that checks to see if use_rdma_mr is true, and if it is, just setting > rdata->got_bytes to the length of data delivered and allowing normal > continuation. > > This can be seen in an IWarp packet trace. With the upstream code, it does > a DDP/RDMA packet, which produces the warning above and then retries, > retrieving the data inline, spread across several SMBDirect messages that > get glued together into a single PDU. With the patch applied, only the > DDP/RDMA packet is seen. > > Note that this doesn't happen if the server isn't told to encrypt stuff and > it does also happen with softRoCE. > > Signed-off-by: David Howells <dhowells@redhat.com> > cc: Steve French <smfrench@gmail.com> > cc: Tom Talpey <tom@talpey.com> > cc: Long Li <longli@microsoft.com> > cc: Namjae Jeon <linkinjeon@kernel.org> > cc: Stefan Metzmacher <metze@samba.org> > cc: linux-cifs@vger.kernel.org > --- > > fs/cifs/smb2ops.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c > index 880cd494afea..8d459f60f27b 100644 > --- a/fs/cifs/smb2ops.c > +++ b/fs/cifs/smb2ops.c > @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, > iov.iov_base = buf + data_offset; > iov.iov_len = data_len; > iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); > + } else if (use_rdma_mr) { > + /* The data was delivered directly by RDMA. */ > + rdata->got_bytes = data_len; > } else { > /* read response payload cannot be in both buf and pages */ > WARN_ONCE(1, "buf can not contain only a part of read data"); I'm not sure I understand why this would fix anything when encryption is enabled. Is the payload still be offloaded as plaintext? Otherwise we wouldn't have use_rdma_mr... So this rather looks like a fix for the non encrypted case. Before smbd_register_mr() is called we typically have a check like this: if (server->rdma && !server->sign && wdata->bytes >= server->smbd_conn->rdma_readwrite_threshold) { I'm wondering if server->sign is true for the encryption case, otherwise we would have to add a !encrypt check in addition as we should never use RDMA offload for encrypted connections. Latest Windows servers allow encrypted/signed offload, but that needs to be negotiated via MS-SMB2 2.2.3.1.6 SMB2_RDMA_TRANSFORM_CAPABILITIES, see https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/52b74a74-9838-4f51-b2b0-efeb23bd79d6 And SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM in MS-SMB2 2.2.20 SMB2 READ Response https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/3e3d2f2c-0e2f-41ea-ad07-fbca6ffdfd90 As well as SMB2_CHANNEL_RDMA_TRANSFORM in 2.2.21 SMB2 WRITE Request https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/e7046961-3318-4350-be2a-a8d69bb59ce8 But none of this is implemented in Linux yet. metze
2022-11-16 9:57 GMT+09:00, Stefan Metzmacher <metze@samba.org>: > Hi David, > > see below... > >> When the cifs client is talking to the ksmbd server by RDMA and the ksmbd >> server has "smb3 encryption = yes" in its config file, the normal PDU >> stream is encrypted, but the directly-delivered data isn't in the stream >> (and isn't encrypted), but is rather delivered by DDP/RDMA packets (at >> least with IWarp). >> >> Currently, the direct delivery fails with: >> >> buf can not contain only a part of read data >> WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 >> handle_read_data+0x393/0x405 >> ... >> RIP: 0010:handle_read_data+0x393/0x405 >> ... >> smb3_handle_read_data+0x30/0x37 >> receive_encrypted_standard+0x141/0x224 >> cifs_demultiplex_thread+0x21a/0x63b >> kthread+0xe7/0xef >> ret_from_fork+0x22/0x30 >> >> The problem apparently stemming from the fact that it's trying to manage >> the decryption, but the data isn't in the smallbuf, the bigbuf or the >> page >> array). >> >> This can be fixed simply by inserting an extra case into >> handle_read_data() >> that checks to see if use_rdma_mr is true, and if it is, just setting >> rdata->got_bytes to the length of data delivered and allowing normal >> continuation. >> >> This can be seen in an IWarp packet trace. With the upstream code, it >> does >> a DDP/RDMA packet, which produces the warning above and then retries, >> retrieving the data inline, spread across several SMBDirect messages that >> get glued together into a single PDU. With the patch applied, only the >> DDP/RDMA packet is seen. >> >> Note that this doesn't happen if the server isn't told to encrypt stuff >> and >> it does also happen with softRoCE. >> >> Signed-off-by: David Howells <dhowells@redhat.com> >> cc: Steve French <smfrench@gmail.com> >> cc: Tom Talpey <tom@talpey.com> >> cc: Long Li <longli@microsoft.com> >> cc: Namjae Jeon <linkinjeon@kernel.org> >> cc: Stefan Metzmacher <metze@samba.org> >> cc: linux-cifs@vger.kernel.org >> --- >> >> fs/cifs/smb2ops.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c >> index 880cd494afea..8d459f60f27b 100644 >> --- a/fs/cifs/smb2ops.c >> +++ b/fs/cifs/smb2ops.c >> @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info *server, >> struct mid_q_entry *mid, >> iov.iov_base = buf + data_offset; >> iov.iov_len = data_len; >> iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); >> + } else if (use_rdma_mr) { >> + /* The data was delivered directly by RDMA. */ >> + rdata->got_bytes = data_len; >> } else { >> /* read response payload cannot be in both buf and pages */ >> WARN_ONCE(1, "buf can not contain only a part of read data"); > > I'm not sure I understand why this would fix anything when encryption is > enabled. > > Is the payload still be offloaded as plaintext? Otherwise we wouldn't have > use_rdma_mr... > So this rather looks like a fix for the non encrypted case. ksmbd doesn't encrypt RDMA payload on read/write operation, Currently only smb2 response is encrypted for this. And as you pointed out, We need to implement SMB2 RDMA Transform to encrypt it. > > Before smbd_register_mr() is called we typically have a check like this: > > if (server->rdma && !server->sign && wdata->bytes >= > server->smbd_conn->rdma_readwrite_threshold) { > > I'm wondering if server->sign is true for the encryption case, otherwise > we would have to add a !encrypt check in addition as we should never use > RDMA offload for encrypted connections. > > Latest Windows servers allow encrypted/signed offload, but that needs to be > negotiated via MS-SMB2 2.2.3.1.6 SMB2_RDMA_TRANSFORM_CAPABILITIES, see > https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/52b74a74-9838-4f51-b2b0-efeb23bd79d6 > And SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM in MS-SMB2 2.2.20 SMB2 READ > Response > https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/3e3d2f2c-0e2f-41ea-ad07-fbca6ffdfd90 > As well as SMB2_CHANNEL_RDMA_TRANSFORM in 2.2.21 SMB2 WRITE Request > https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/e7046961-3318-4350-be2a-a8d69bb59ce8 > But none of this is implemented in Linux yet. > > metze >
Stefan Metzmacher <metze@samba.org> wrote: > I'm not sure I understand why this would fix anything when encryption is > enabled. > > Is the payload still be offloaded as plaintext? Otherwise we wouldn't have > use_rdma_mr... So this rather looks like a fix for the non encrypted case. The "inline"[*] PDUs are encrypted, but the direct RDMA data transmission is not. I'm not sure if this is a bug in ksmbd. As I understand it, encrypting and decrypting the directly transferred data would need to be done by the NIC, not the cifs driver. David [*] I don't know the correct RDMA terminology for these things.
Am 16.11.22 um 06:19 schrieb Namjae Jeon: > 2022-11-16 9:57 GMT+09:00, Stefan Metzmacher <metze@samba.org>: >> Hi David, >> >> see below... >> >>> When the cifs client is talking to the ksmbd server by RDMA and the ksmbd >>> server has "smb3 encryption = yes" in its config file, the normal PDU >>> stream is encrypted, but the directly-delivered data isn't in the stream >>> (and isn't encrypted), but is rather delivered by DDP/RDMA packets (at >>> least with IWarp). >>> >>> Currently, the direct delivery fails with: >>> >>> buf can not contain only a part of read data >>> WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 >>> handle_read_data+0x393/0x405 >>> ... >>> RIP: 0010:handle_read_data+0x393/0x405 >>> ... >>> smb3_handle_read_data+0x30/0x37 >>> receive_encrypted_standard+0x141/0x224 >>> cifs_demultiplex_thread+0x21a/0x63b >>> kthread+0xe7/0xef >>> ret_from_fork+0x22/0x30 >>> >>> The problem apparently stemming from the fact that it's trying to manage >>> the decryption, but the data isn't in the smallbuf, the bigbuf or the >>> page >>> array). >>> >>> This can be fixed simply by inserting an extra case into >>> handle_read_data() >>> that checks to see if use_rdma_mr is true, and if it is, just setting >>> rdata->got_bytes to the length of data delivered and allowing normal >>> continuation. >>> >>> This can be seen in an IWarp packet trace. With the upstream code, it >>> does >>> a DDP/RDMA packet, which produces the warning above and then retries, >>> retrieving the data inline, spread across several SMBDirect messages that >>> get glued together into a single PDU. With the patch applied, only the >>> DDP/RDMA packet is seen. >>> >>> Note that this doesn't happen if the server isn't told to encrypt stuff >>> and >>> it does also happen with softRoCE. >>> >>> Signed-off-by: David Howells <dhowells@redhat.com> >>> cc: Steve French <smfrench@gmail.com> >>> cc: Tom Talpey <tom@talpey.com> >>> cc: Long Li <longli@microsoft.com> >>> cc: Namjae Jeon <linkinjeon@kernel.org> >>> cc: Stefan Metzmacher <metze@samba.org> >>> cc: linux-cifs@vger.kernel.org >>> --- >>> >>> fs/cifs/smb2ops.c | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c >>> index 880cd494afea..8d459f60f27b 100644 >>> --- a/fs/cifs/smb2ops.c >>> +++ b/fs/cifs/smb2ops.c >>> @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info *server, >>> struct mid_q_entry *mid, >>> iov.iov_base = buf + data_offset; >>> iov.iov_len = data_len; >>> iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); >>> + } else if (use_rdma_mr) { >>> + /* The data was delivered directly by RDMA. */ >>> + rdata->got_bytes = data_len; >>> } else { >>> /* read response payload cannot be in both buf and pages */ >>> WARN_ONCE(1, "buf can not contain only a part of read data"); >> >> I'm not sure I understand why this would fix anything when encryption is >> enabled. >> >> Is the payload still be offloaded as plaintext? Otherwise we wouldn't have >> use_rdma_mr... >> So this rather looks like a fix for the non encrypted case. > ksmbd doesn't encrypt RDMA payload on read/write operation, Currently > only smb2 response is encrypted for this. And as you pointed out, We > need to implement SMB2 RDMA Transform to encrypt it. I haven't tested against a windows server yet, but my hope would be that and encrypted request with SMB2_CHANNEL_RDMA_V1* receive NT_STATUS_ACCESS_DENIED or something similar... Is someone able to check that against Windows? But the core of it is a client security problem, shown in David's capture in frame 100. metze
Am 16.11.22 um 08:00 schrieb David Howells: > Stefan Metzmacher <metze@samba.org> wrote: > >> I'm not sure I understand why this would fix anything when encryption is >> enabled. >> >> Is the payload still be offloaded as plaintext? Otherwise we wouldn't have >> use_rdma_mr... So this rather looks like a fix for the non encrypted case. > > The "inline"[*] PDUs are encrypted, but the direct RDMA data transmission is > not. I'm not sure if this is a bug in ksmbd. It's a bug in the client! > As I understand it, encrypting and decrypting the directly transferred > data would need to be done by the NIC, not the cifs driver. No, the encryption needs to happen above the RDMA/NIC layer. metze
Stefan Metzmacher <metze@samba.org> wrote: > > Stefan Metzmacher <metze@samba.org> wrote: > > > >> I'm not sure I understand why this would fix anything when encryption is > >> enabled. > >> > >> Is the payload still be offloaded as plaintext? Otherwise we wouldn't have > >> use_rdma_mr... So this rather looks like a fix for the non encrypted case. > > The "inline"[*] PDUs are encrypted, but the direct RDMA data transmission is > > not. I'm not sure if this is a bug in ksmbd. > > It's a bug in the client! Well, if you can fix it the right way, I can test the patch. I'm not sure what that would be if not what I suggested. David
Am 16.11.22 um 13:14 schrieb David Howells: > Stefan Metzmacher <metze@samba.org> wrote: > >>> Stefan Metzmacher <metze@samba.org> wrote: >>> >>>> I'm not sure I understand why this would fix anything when encryption is >>>> enabled. >>>> >>>> Is the payload still be offloaded as plaintext? Otherwise we wouldn't have >>>> use_rdma_mr... So this rather looks like a fix for the non encrypted case. >>> The "inline"[*] PDUs are encrypted, but the direct RDMA data transmission is >>> not. I'm not sure if this is a bug in ksmbd. >> >> It's a bug in the client! > > Well, if you can fix it the right way, I can test the patch. I'm not sure > what that would be if not what I suggested. As written in the other mail something like this: fs/cifs/smb2pdu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index a5695748a89b..d478b0a89890 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -4090,7 +4090,7 @@ smb2_new_read_req(void **buf, unsigned int *total_len, * If we want to do a RDMA write, fill in and append * smbd_buffer_descriptor_v1 to the end of read request */ - if (server->rdma && rdata && !server->sign && + if (server->rdma && rdata && !server->sign && !smb3_encryption_required(io_parms->tcon) && rdata->bytes >= server->smbd_conn->rdma_readwrite_threshold) { struct smbd_buffer_descriptor_v1 *v1; @@ -4517,8 +4517,8 @@ smb2_async_writev(struct cifs_writedata *wdata, * If we want to do a server RDMA read, fill in and append * smbd_buffer_descriptor_v1 to the end of write request */ - if (server->rdma && !server->sign && wdata->bytes >= - server->smbd_conn->rdma_readwrite_threshold) { + if (server->rdma && !server->sign && !smb3_encryption_required(tcon) && + wdata->bytes >= server->smbd_conn->rdma_readwrite_threshold) { struct smbd_buffer_descriptor_v1 *v1; bool need_invalidate = server->dialect == SMB30_PROT_ID;
Okay, that works - though, probably unsurprisingly, it's 5x slower.
If you want to submit this patch, you can add:
Tested-by: David Howells <dhowells@redhat.com>
David
On 11/16/2022 3:36 AM, Stefan Metzmacher wrote: > Am 16.11.22 um 06:19 schrieb Namjae Jeon: >> 2022-11-16 9:57 GMT+09:00, Stefan Metzmacher <metze@samba.org>: >>> Hi David, >>> >>> see below... >>> >>>> When the cifs client is talking to the ksmbd server by RDMA and the >>>> ksmbd >>>> server has "smb3 encryption = yes" in its config file, the normal PDU >>>> stream is encrypted, but the directly-delivered data isn't in the >>>> stream >>>> (and isn't encrypted), but is rather delivered by DDP/RDMA packets (at >>>> least with IWarp). >>>> >>>> Currently, the direct delivery fails with: >>>> >>>> buf can not contain only a part of read data >>>> WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 >>>> handle_read_data+0x393/0x405 >>>> ... >>>> RIP: 0010:handle_read_data+0x393/0x405 >>>> ... >>>> smb3_handle_read_data+0x30/0x37 >>>> receive_encrypted_standard+0x141/0x224 >>>> cifs_demultiplex_thread+0x21a/0x63b >>>> kthread+0xe7/0xef >>>> ret_from_fork+0x22/0x30 >>>> >>>> The problem apparently stemming from the fact that it's trying to >>>> manage >>>> the decryption, but the data isn't in the smallbuf, the bigbuf or the >>>> page >>>> array). >>>> >>>> This can be fixed simply by inserting an extra case into >>>> handle_read_data() >>>> that checks to see if use_rdma_mr is true, and if it is, just setting >>>> rdata->got_bytes to the length of data delivered and allowing normal >>>> continuation. >>>> >>>> This can be seen in an IWarp packet trace. With the upstream code, it >>>> does >>>> a DDP/RDMA packet, which produces the warning above and then retries, >>>> retrieving the data inline, spread across several SMBDirect messages >>>> that >>>> get glued together into a single PDU. With the patch applied, only the >>>> DDP/RDMA packet is seen. >>>> >>>> Note that this doesn't happen if the server isn't told to encrypt stuff >>>> and >>>> it does also happen with softRoCE. >>>> >>>> Signed-off-by: David Howells <dhowells@redhat.com> >>>> cc: Steve French <smfrench@gmail.com> >>>> cc: Tom Talpey <tom@talpey.com> >>>> cc: Long Li <longli@microsoft.com> >>>> cc: Namjae Jeon <linkinjeon@kernel.org> >>>> cc: Stefan Metzmacher <metze@samba.org> >>>> cc: linux-cifs@vger.kernel.org >>>> --- >>>> >>>> fs/cifs/smb2ops.c | 3 +++ >>>> 1 file changed, 3 insertions(+) >>>> >>>> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c >>>> index 880cd494afea..8d459f60f27b 100644 >>>> --- a/fs/cifs/smb2ops.c >>>> +++ b/fs/cifs/smb2ops.c >>>> @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info *server, >>>> struct mid_q_entry *mid, >>>> iov.iov_base = buf + data_offset; >>>> iov.iov_len = data_len; >>>> iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); >>>> + } else if (use_rdma_mr) { >>>> + /* The data was delivered directly by RDMA. */ >>>> + rdata->got_bytes = data_len; >>>> } else { >>>> /* read response payload cannot be in both buf and pages */ >>>> WARN_ONCE(1, "buf can not contain only a part of read >>>> data"); >>> >>> I'm not sure I understand why this would fix anything when encryption is >>> enabled. >>> >>> Is the payload still be offloaded as plaintext? Otherwise we wouldn't >>> have >>> use_rdma_mr... >>> So this rather looks like a fix for the non encrypted case. >> ksmbd doesn't encrypt RDMA payload on read/write operation, Currently >> only smb2 response is encrypted for this. And as you pointed out, We >> need to implement SMB2 RDMA Transform to encrypt it. > > I haven't tested against a windows server yet, but my hope would be that > and encrypted request with SMB2_CHANNEL_RDMA_V1* receive > NT_STATUS_ACCESS_DENIED or something similar... > > Is someone able to check that against Windows? It's not going to fail, because it's perfectly legal per the protocol. And the new SMB3 extension to perform pre-encryption of RDMA payload is not a solution, because it's only supported by one server (Windows 22H2) and in any case it does not alter the transfer model. The client will see the same two-part response (headers in the inline portion, data via RDMA), so this same code will be entered when processing it. I think David's change is on the right track because it actually processes the response. I'm a little bit skeptical of the got_bytes override however, still digging into that. > But the core of it is a client security problem, shown in David's > capture in frame 100. Sorry, what's the security problem? Both the client and server appear to be implementing the protocol itself correctly. Tom.
Am 16.11.22 um 16:41 schrieb Tom Talpey: > On 11/16/2022 3:36 AM, Stefan Metzmacher wrote: >> Am 16.11.22 um 06:19 schrieb Namjae Jeon: >>> 2022-11-16 9:57 GMT+09:00, Stefan Metzmacher <metze@samba.org>: >>>> Hi David, >>>> >>>> see below... >>>> >>>>> When the cifs client is talking to the ksmbd server by RDMA and the ksmbd >>>>> server has "smb3 encryption = yes" in its config file, the normal PDU >>>>> stream is encrypted, but the directly-delivered data isn't in the stream >>>>> (and isn't encrypted), but is rather delivered by DDP/RDMA packets (at >>>>> least with IWarp). >>>>> >>>>> Currently, the direct delivery fails with: >>>>> >>>>> buf can not contain only a part of read data >>>>> WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 >>>>> handle_read_data+0x393/0x405 >>>>> ... >>>>> RIP: 0010:handle_read_data+0x393/0x405 >>>>> ... >>>>> smb3_handle_read_data+0x30/0x37 >>>>> receive_encrypted_standard+0x141/0x224 >>>>> cifs_demultiplex_thread+0x21a/0x63b >>>>> kthread+0xe7/0xef >>>>> ret_from_fork+0x22/0x30 >>>>> >>>>> The problem apparently stemming from the fact that it's trying to manage >>>>> the decryption, but the data isn't in the smallbuf, the bigbuf or the >>>>> page >>>>> array). >>>>> >>>>> This can be fixed simply by inserting an extra case into >>>>> handle_read_data() >>>>> that checks to see if use_rdma_mr is true, and if it is, just setting >>>>> rdata->got_bytes to the length of data delivered and allowing normal >>>>> continuation. >>>>> >>>>> This can be seen in an IWarp packet trace. With the upstream code, it >>>>> does >>>>> a DDP/RDMA packet, which produces the warning above and then retries, >>>>> retrieving the data inline, spread across several SMBDirect messages that >>>>> get glued together into a single PDU. With the patch applied, only the >>>>> DDP/RDMA packet is seen. >>>>> >>>>> Note that this doesn't happen if the server isn't told to encrypt stuff >>>>> and >>>>> it does also happen with softRoCE. >>>>> >>>>> Signed-off-by: David Howells <dhowells@redhat.com> >>>>> cc: Steve French <smfrench@gmail.com> >>>>> cc: Tom Talpey <tom@talpey.com> >>>>> cc: Long Li <longli@microsoft.com> >>>>> cc: Namjae Jeon <linkinjeon@kernel.org> >>>>> cc: Stefan Metzmacher <metze@samba.org> >>>>> cc: linux-cifs@vger.kernel.org >>>>> --- >>>>> >>>>> fs/cifs/smb2ops.c | 3 +++ >>>>> 1 file changed, 3 insertions(+) >>>>> >>>>> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c >>>>> index 880cd494afea..8d459f60f27b 100644 >>>>> --- a/fs/cifs/smb2ops.c >>>>> +++ b/fs/cifs/smb2ops.c >>>>> @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info *server, >>>>> struct mid_q_entry *mid, >>>>> iov.iov_base = buf + data_offset; >>>>> iov.iov_len = data_len; >>>>> iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); >>>>> + } else if (use_rdma_mr) { >>>>> + /* The data was delivered directly by RDMA. */ >>>>> + rdata->got_bytes = data_len; >>>>> } else { >>>>> /* read response payload cannot be in both buf and pages */ >>>>> WARN_ONCE(1, "buf can not contain only a part of read data"); >>>> >>>> I'm not sure I understand why this would fix anything when encryption is >>>> enabled. >>>> >>>> Is the payload still be offloaded as plaintext? Otherwise we wouldn't have >>>> use_rdma_mr... >>>> So this rather looks like a fix for the non encrypted case. >>> ksmbd doesn't encrypt RDMA payload on read/write operation, Currently >>> only smb2 response is encrypted for this. And as you pointed out, We >>> need to implement SMB2 RDMA Transform to encrypt it. >> >> I haven't tested against a windows server yet, but my hope would be that >> and encrypted request with SMB2_CHANNEL_RDMA_V1* receive NT_STATUS_ACCESS_DENIED or something similar... >> >> Is someone able to check that against Windows? > > It's not going to fail, because it's perfectly legal per the protocol. > And the new SMB3 extension to perform pre-encryption of RDMA payload > is not a solution, because it's only supported by one server (Windows > 22H2) and in any case it does not alter the transfer model. The client > will see the same two-part response (headers in the inline portion, > data via RDMA), so this same code will be entered when processing it. > > I think David's change is on the right track because it actually > processes the response. I'm a little bit skeptical of the got_bytes > override however, still digging into that. > >> But the core of it is a client security problem, shown in David's capture in frame 100. > > Sorry, what's the security problem? Both the client and server appear > to be implementing the protocol itself correctly. Data goes in plaintext over the wire and a share that requires encryption! metze
On 11/16/2022 10:44 AM, Stefan Metzmacher wrote: > Am 16.11.22 um 16:41 schrieb Tom Talpey: >> On 11/16/2022 3:36 AM, Stefan Metzmacher wrote: >>> Am 16.11.22 um 06:19 schrieb Namjae Jeon: >>>> 2022-11-16 9:57 GMT+09:00, Stefan Metzmacher <metze@samba.org>: >>>>> Hi David, >>>>> >>>>> see below... >>>>> >>>>>> When the cifs client is talking to the ksmbd server by RDMA and >>>>>> the ksmbd >>>>>> server has "smb3 encryption = yes" in its config file, the normal PDU >>>>>> stream is encrypted, but the directly-delivered data isn't in the >>>>>> stream >>>>>> (and isn't encrypted), but is rather delivered by DDP/RDMA packets >>>>>> (at >>>>>> least with IWarp). >>>>>> >>>>>> Currently, the direct delivery fails with: >>>>>> >>>>>> buf can not contain only a part of read data >>>>>> WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 >>>>>> handle_read_data+0x393/0x405 >>>>>> ... >>>>>> RIP: 0010:handle_read_data+0x393/0x405 >>>>>> ... >>>>>> smb3_handle_read_data+0x30/0x37 >>>>>> receive_encrypted_standard+0x141/0x224 >>>>>> cifs_demultiplex_thread+0x21a/0x63b >>>>>> kthread+0xe7/0xef >>>>>> ret_from_fork+0x22/0x30 >>>>>> >>>>>> The problem apparently stemming from the fact that it's trying to >>>>>> manage >>>>>> the decryption, but the data isn't in the smallbuf, the bigbuf or the >>>>>> page >>>>>> array). >>>>>> >>>>>> This can be fixed simply by inserting an extra case into >>>>>> handle_read_data() >>>>>> that checks to see if use_rdma_mr is true, and if it is, just setting >>>>>> rdata->got_bytes to the length of data delivered and allowing normal >>>>>> continuation. >>>>>> >>>>>> This can be seen in an IWarp packet trace. With the upstream >>>>>> code, it >>>>>> does >>>>>> a DDP/RDMA packet, which produces the warning above and then retries, >>>>>> retrieving the data inline, spread across several SMBDirect >>>>>> messages that >>>>>> get glued together into a single PDU. With the patch applied, >>>>>> only the >>>>>> DDP/RDMA packet is seen. >>>>>> >>>>>> Note that this doesn't happen if the server isn't told to encrypt >>>>>> stuff >>>>>> and >>>>>> it does also happen with softRoCE. >>>>>> >>>>>> Signed-off-by: David Howells <dhowells@redhat.com> >>>>>> cc: Steve French <smfrench@gmail.com> >>>>>> cc: Tom Talpey <tom@talpey.com> >>>>>> cc: Long Li <longli@microsoft.com> >>>>>> cc: Namjae Jeon <linkinjeon@kernel.org> >>>>>> cc: Stefan Metzmacher <metze@samba.org> >>>>>> cc: linux-cifs@vger.kernel.org >>>>>> --- >>>>>> >>>>>> fs/cifs/smb2ops.c | 3 +++ >>>>>> 1 file changed, 3 insertions(+) >>>>>> >>>>>> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c >>>>>> index 880cd494afea..8d459f60f27b 100644 >>>>>> --- a/fs/cifs/smb2ops.c >>>>>> +++ b/fs/cifs/smb2ops.c >>>>>> @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info >>>>>> *server, >>>>>> struct mid_q_entry *mid, >>>>>> iov.iov_base = buf + data_offset; >>>>>> iov.iov_len = data_len; >>>>>> iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); >>>>>> + } else if (use_rdma_mr) { >>>>>> + /* The data was delivered directly by RDMA. */ >>>>>> + rdata->got_bytes = data_len; >>>>>> } else { >>>>>> /* read response payload cannot be in both buf and >>>>>> pages */ >>>>>> WARN_ONCE(1, "buf can not contain only a part of read >>>>>> data"); >>>>> >>>>> I'm not sure I understand why this would fix anything when >>>>> encryption is >>>>> enabled. >>>>> >>>>> Is the payload still be offloaded as plaintext? Otherwise we >>>>> wouldn't have >>>>> use_rdma_mr... >>>>> So this rather looks like a fix for the non encrypted case. >>>> ksmbd doesn't encrypt RDMA payload on read/write operation, Currently >>>> only smb2 response is encrypted for this. And as you pointed out, We >>>> need to implement SMB2 RDMA Transform to encrypt it. >>> >>> I haven't tested against a windows server yet, but my hope would be that >>> and encrypted request with SMB2_CHANNEL_RDMA_V1* receive >>> NT_STATUS_ACCESS_DENIED or something similar... >>> >>> Is someone able to check that against Windows? >> >> It's not going to fail, because it's perfectly legal per the protocol. >> And the new SMB3 extension to perform pre-encryption of RDMA payload >> is not a solution, because it's only supported by one server (Windows >> 22H2) and in any case it does not alter the transfer model. The client >> will see the same two-part response (headers in the inline portion, >> data via RDMA), so this same code will be entered when processing it. >> >> I think David's change is on the right track because it actually >> processes the response. I'm a little bit skeptical of the got_bytes >> override however, still digging into that. >> >>> But the core of it is a client security problem, shown in David's >>> capture in frame 100. >> >> Sorry, what's the security problem? Both the client and server appear >> to be implementing the protocol itself correctly. > > Data goes in plaintext over the wire and a share that requires encryption! That's a server issue, not the client. The server is the one that returned the plaintext data via RDMA. Changing the client to avoid such a request doesn't close that hole. It's an important policy question, of course. I still think the client needs to handle the is_rdma_mr case, along the lines of David's fix. The code looks like a vestige of TCP-only response processing. Tom.
Stefan Metzmacher <metze@samba.org> wrote: > But the core of it is a client security problem, shown in David's capture in > frame 100. Does the client actually know about the server's settings, though? David
Am 16.11.22 um 17:14 schrieb Tom Talpey: > On 11/16/2022 10:44 AM, Stefan Metzmacher wrote: >> Am 16.11.22 um 16:41 schrieb Tom Talpey: >>> On 11/16/2022 3:36 AM, Stefan Metzmacher wrote: >>>> Am 16.11.22 um 06:19 schrieb Namjae Jeon: >>>>> 2022-11-16 9:57 GMT+09:00, Stefan Metzmacher <metze@samba.org>: >>>>>> Hi David, >>>>>> >>>>>> see below... >>>>>> >>>>>>> When the cifs client is talking to the ksmbd server by RDMA and the ksmbd >>>>>>> server has "smb3 encryption = yes" in its config file, the normal PDU >>>>>>> stream is encrypted, but the directly-delivered data isn't in the stream >>>>>>> (and isn't encrypted), but is rather delivered by DDP/RDMA packets (at >>>>>>> least with IWarp). >>>>>>> >>>>>>> Currently, the direct delivery fails with: >>>>>>> >>>>>>> buf can not contain only a part of read data >>>>>>> WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 >>>>>>> handle_read_data+0x393/0x405 >>>>>>> ... >>>>>>> RIP: 0010:handle_read_data+0x393/0x405 >>>>>>> ... >>>>>>> smb3_handle_read_data+0x30/0x37 >>>>>>> receive_encrypted_standard+0x141/0x224 >>>>>>> cifs_demultiplex_thread+0x21a/0x63b >>>>>>> kthread+0xe7/0xef >>>>>>> ret_from_fork+0x22/0x30 >>>>>>> >>>>>>> The problem apparently stemming from the fact that it's trying to manage >>>>>>> the decryption, but the data isn't in the smallbuf, the bigbuf or the >>>>>>> page >>>>>>> array). >>>>>>> >>>>>>> This can be fixed simply by inserting an extra case into >>>>>>> handle_read_data() >>>>>>> that checks to see if use_rdma_mr is true, and if it is, just setting >>>>>>> rdata->got_bytes to the length of data delivered and allowing normal >>>>>>> continuation. >>>>>>> >>>>>>> This can be seen in an IWarp packet trace. With the upstream code, it >>>>>>> does >>>>>>> a DDP/RDMA packet, which produces the warning above and then retries, >>>>>>> retrieving the data inline, spread across several SMBDirect messages that >>>>>>> get glued together into a single PDU. With the patch applied, only the >>>>>>> DDP/RDMA packet is seen. >>>>>>> >>>>>>> Note that this doesn't happen if the server isn't told to encrypt stuff >>>>>>> and >>>>>>> it does also happen with softRoCE. >>>>>>> >>>>>>> Signed-off-by: David Howells <dhowells@redhat.com> >>>>>>> cc: Steve French <smfrench@gmail.com> >>>>>>> cc: Tom Talpey <tom@talpey.com> >>>>>>> cc: Long Li <longli@microsoft.com> >>>>>>> cc: Namjae Jeon <linkinjeon@kernel.org> >>>>>>> cc: Stefan Metzmacher <metze@samba.org> >>>>>>> cc: linux-cifs@vger.kernel.org >>>>>>> --- >>>>>>> >>>>>>> fs/cifs/smb2ops.c | 3 +++ >>>>>>> 1 file changed, 3 insertions(+) >>>>>>> >>>>>>> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c >>>>>>> index 880cd494afea..8d459f60f27b 100644 >>>>>>> --- a/fs/cifs/smb2ops.c >>>>>>> +++ b/fs/cifs/smb2ops.c >>>>>>> @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info *server, >>>>>>> struct mid_q_entry *mid, >>>>>>> iov.iov_base = buf + data_offset; >>>>>>> iov.iov_len = data_len; >>>>>>> iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); >>>>>>> + } else if (use_rdma_mr) { >>>>>>> + /* The data was delivered directly by RDMA. */ >>>>>>> + rdata->got_bytes = data_len; >>>>>>> } else { >>>>>>> /* read response payload cannot be in both buf and pages */ >>>>>>> WARN_ONCE(1, "buf can not contain only a part of read data"); >>>>>> >>>>>> I'm not sure I understand why this would fix anything when encryption is >>>>>> enabled. >>>>>> >>>>>> Is the payload still be offloaded as plaintext? Otherwise we wouldn't have >>>>>> use_rdma_mr... >>>>>> So this rather looks like a fix for the non encrypted case. >>>>> ksmbd doesn't encrypt RDMA payload on read/write operation, Currently >>>>> only smb2 response is encrypted for this. And as you pointed out, We >>>>> need to implement SMB2 RDMA Transform to encrypt it. >>>> >>>> I haven't tested against a windows server yet, but my hope would be that >>>> and encrypted request with SMB2_CHANNEL_RDMA_V1* receive NT_STATUS_ACCESS_DENIED or something similar... >>>> >>>> Is someone able to check that against Windows? >>> >>> It's not going to fail, because it's perfectly legal per the protocol. >>> And the new SMB3 extension to perform pre-encryption of RDMA payload >>> is not a solution, because it's only supported by one server (Windows >>> 22H2) and in any case it does not alter the transfer model. The client >>> will see the same two-part response (headers in the inline portion, >>> data via RDMA), so this same code will be entered when processing it. >>> >>> I think David's change is on the right track because it actually >>> processes the response. I'm a little bit skeptical of the got_bytes >>> override however, still digging into that. >>> >>>> But the core of it is a client security problem, shown in David's capture in frame 100. >>> >>> Sorry, what's the security problem? Both the client and server appear >>> to be implementing the protocol itself correctly. >> >> Data goes in plaintext over the wire and a share that requires encryption! > > That's a server issue, not the client. The server is the one that > returned the plaintext data via RDMA. Changing the client to avoid > such a request doesn't close that hole. It's an important policy > question, of course. No, it's the client how decides to use SMB2_CHANNEL_RDMA_V1* or SMB2_CHANNEL_NONE. And for any read or write over an signed or encrypted connection it must use SMB2_CHANNEL_NONE! Otherwise the clients memory can be written or read by any untrusted machine in the middle. MS-SMB2 says this: 3.2.4.6 Application Requests Reading from a File or Named Pipe ... If the Connection is established in RDMA mode and the size of any single operation exceeds an implementation-specific threshold <138>, and if Open.TreeConnect.Session.SigningRequired and Open.TreeConnect.Session.EncryptData are both FALSE, then the interface in [MS-SMBD] section 3.1.4.3 Register Buffer MUST be used to register the buffer provided by the calling application on the Connection with write permissions, which will receive the data to be read. The returned list of SMB_DIRECT_BUFFER_DESCRIPTOR_V1 structures MUST be stored in Request.BufferDescriptorList. The following fields of the request MUST be initialized as follows: ... 3.2.4.7 Application Requests Writing to a File or Named Pipe ... If the connection is not established in RDMA mode or if the size of the operation is less than or equal to an implementation-specific threshold <141>or if either Open.TreeConnect.Session.SigningRequired or Open.TreeConnect.Session.EncryptData is TRUE, the following fields of the request MUST be initialized as follows: - If Connection.Dialect belongs to the SMB 3.x dialect family, - The Channel field MUST be set to SMB2_CHANNEL_NONE. - The WriteChannelInfoOffset field MUST be set to 0. - The WriteChannelInfoLength field MUST be set to 0. For sure it would be great if servers would also reject SMB2_CHANNEL_RDMA_V1* on signed/encrypted connections with INVALID_PARAMETER or ACCESS_DENIED, buth the problem we currently see is a client security problem. > I still think the client needs to handle the is_rdma_mr case, along > the lines of David's fix. The code looks like a vestige of TCP-only > response processing. I'm not saying David's change is wrong, but I think it has nothing todo with encrypted or signed traffic... metze
On 11/16/2022 2:53 PM, Stefan Metzmacher wrote: > Am 16.11.22 um 17:14 schrieb Tom Talpey: >> On 11/16/2022 10:44 AM, Stefan Metzmacher wrote: >>> Am 16.11.22 um 16:41 schrieb Tom Talpey: >>>> On 11/16/2022 3:36 AM, Stefan Metzmacher wrote: >>>>> Am 16.11.22 um 06:19 schrieb Namjae Jeon: >>>>>> 2022-11-16 9:57 GMT+09:00, Stefan Metzmacher <metze@samba.org>: >>>>>>> Hi David, >>>>>>> >>>>>>> see below... >>>>>>> >>>>>>>> When the cifs client is talking to the ksmbd server by RDMA and >>>>>>>> the ksmbd >>>>>>>> server has "smb3 encryption = yes" in its config file, the >>>>>>>> normal PDU >>>>>>>> stream is encrypted, but the directly-delivered data isn't in >>>>>>>> the stream >>>>>>>> (and isn't encrypted), but is rather delivered by DDP/RDMA >>>>>>>> packets (at >>>>>>>> least with IWarp). >>>>>>>> >>>>>>>> Currently, the direct delivery fails with: >>>>>>>> >>>>>>>> buf can not contain only a part of read data >>>>>>>> WARNING: CPU: 0 PID: 4619 at fs/cifs/smb2ops.c:4731 >>>>>>>> handle_read_data+0x393/0x405 >>>>>>>> ... >>>>>>>> RIP: 0010:handle_read_data+0x393/0x405 >>>>>>>> ... >>>>>>>> smb3_handle_read_data+0x30/0x37 >>>>>>>> receive_encrypted_standard+0x141/0x224 >>>>>>>> cifs_demultiplex_thread+0x21a/0x63b >>>>>>>> kthread+0xe7/0xef >>>>>>>> ret_from_fork+0x22/0x30 >>>>>>>> >>>>>>>> The problem apparently stemming from the fact that it's trying >>>>>>>> to manage >>>>>>>> the decryption, but the data isn't in the smallbuf, the bigbuf >>>>>>>> or the >>>>>>>> page >>>>>>>> array). >>>>>>>> >>>>>>>> This can be fixed simply by inserting an extra case into >>>>>>>> handle_read_data() >>>>>>>> that checks to see if use_rdma_mr is true, and if it is, just >>>>>>>> setting >>>>>>>> rdata->got_bytes to the length of data delivered and allowing >>>>>>>> normal >>>>>>>> continuation. >>>>>>>> >>>>>>>> This can be seen in an IWarp packet trace. With the upstream >>>>>>>> code, it >>>>>>>> does >>>>>>>> a DDP/RDMA packet, which produces the warning above and then >>>>>>>> retries, >>>>>>>> retrieving the data inline, spread across several SMBDirect >>>>>>>> messages that >>>>>>>> get glued together into a single PDU. With the patch applied, >>>>>>>> only the >>>>>>>> DDP/RDMA packet is seen. >>>>>>>> >>>>>>>> Note that this doesn't happen if the server isn't told to >>>>>>>> encrypt stuff >>>>>>>> and >>>>>>>> it does also happen with softRoCE. >>>>>>>> >>>>>>>> Signed-off-by: David Howells <dhowells@redhat.com> >>>>>>>> cc: Steve French <smfrench@gmail.com> >>>>>>>> cc: Tom Talpey <tom@talpey.com> >>>>>>>> cc: Long Li <longli@microsoft.com> >>>>>>>> cc: Namjae Jeon <linkinjeon@kernel.org> >>>>>>>> cc: Stefan Metzmacher <metze@samba.org> >>>>>>>> cc: linux-cifs@vger.kernel.org >>>>>>>> --- >>>>>>>> >>>>>>>> fs/cifs/smb2ops.c | 3 +++ >>>>>>>> 1 file changed, 3 insertions(+) >>>>>>>> >>>>>>>> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c >>>>>>>> index 880cd494afea..8d459f60f27b 100644 >>>>>>>> --- a/fs/cifs/smb2ops.c >>>>>>>> +++ b/fs/cifs/smb2ops.c >>>>>>>> @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info >>>>>>>> *server, >>>>>>>> struct mid_q_entry *mid, >>>>>>>> iov.iov_base = buf + data_offset; >>>>>>>> iov.iov_len = data_len; >>>>>>>> iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); >>>>>>>> + } else if (use_rdma_mr) { >>>>>>>> + /* The data was delivered directly by RDMA. */ >>>>>>>> + rdata->got_bytes = data_len; >>>>>>>> } else { >>>>>>>> /* read response payload cannot be in both buf and >>>>>>>> pages */ >>>>>>>> WARN_ONCE(1, "buf can not contain only a part of read >>>>>>>> data"); >>>>>>> >>>>>>> I'm not sure I understand why this would fix anything when >>>>>>> encryption is >>>>>>> enabled. >>>>>>> >>>>>>> Is the payload still be offloaded as plaintext? Otherwise we >>>>>>> wouldn't have >>>>>>> use_rdma_mr... >>>>>>> So this rather looks like a fix for the non encrypted case. >>>>>> ksmbd doesn't encrypt RDMA payload on read/write operation, Currently >>>>>> only smb2 response is encrypted for this. And as you pointed out, We >>>>>> need to implement SMB2 RDMA Transform to encrypt it. >>>>> >>>>> I haven't tested against a windows server yet, but my hope would be >>>>> that >>>>> and encrypted request with SMB2_CHANNEL_RDMA_V1* receive >>>>> NT_STATUS_ACCESS_DENIED or something similar... >>>>> >>>>> Is someone able to check that against Windows? >>>> >>>> It's not going to fail, because it's perfectly legal per the protocol. >>>> And the new SMB3 extension to perform pre-encryption of RDMA payload >>>> is not a solution, because it's only supported by one server (Windows >>>> 22H2) and in any case it does not alter the transfer model. The client >>>> will see the same two-part response (headers in the inline portion, >>>> data via RDMA), so this same code will be entered when processing it. >>>> >>>> I think David's change is on the right track because it actually >>>> processes the response. I'm a little bit skeptical of the got_bytes >>>> override however, still digging into that. >>>> >>>>> But the core of it is a client security problem, shown in David's >>>>> capture in frame 100. >>>> >>>> Sorry, what's the security problem? Both the client and server appear >>>> to be implementing the protocol itself correctly. >>> >>> Data goes in plaintext over the wire and a share that requires >>> encryption! >> >> That's a server issue, not the client. The server is the one that >> returned the plaintext data via RDMA. Changing the client to avoid >> such a request doesn't close that hole. It's an important policy >> question, of course. > > No, it's the client how decides to use SMB2_CHANNEL_RDMA_V1* or > SMB2_CHANNEL_NONE. And for any read or write over an signed or encrypted > connection > it must use SMB2_CHANNEL_NONE! Otherwise the clients memory can be > written or read > by any untrusted machine in the middle. > > MS-SMB2 says this: > > 3.2.4.6 Application Requests Reading from a File or Named Pipe > ... > If the Connection is established in RDMA mode and the size of any single > operation exceeds an > implementation-specific threshold <138>, and if > Open.TreeConnect.Session.SigningRequired and > Open.TreeConnect.Session.EncryptData are both FALSE, then the interface > in [MS-SMBD] section > 3.1.4.3 Register Buffer MUST be used to register the buffer provided by > the calling application on the > Connection with write permissions, which will receive the data to be > read. The returned list of > SMB_DIRECT_BUFFER_DESCRIPTOR_V1 structures MUST be stored in > Request.BufferDescriptorList. The following fields of the request MUST > be initialized as follows: > ... > > 3.2.4.7 Application Requests Writing to a File or Named Pipe > ... > If the connection is not established in RDMA mode or if the size of the > operation is less than or equal > to an implementation-specific threshold <141>or if either > Open.TreeConnect.Session.SigningRequired or > Open.TreeConnect.Session.EncryptData is > TRUE, the following fields of the request MUST be initialized as follows: > - If Connection.Dialect belongs to the SMB 3.x dialect family, > - The Channel field MUST be set to SMB2_CHANNEL_NONE. > - The WriteChannelInfoOffset field MUST be set to 0. > - The WriteChannelInfoLength field MUST be set to 0. > > For sure it would be great if servers would also reject > SMB2_CHANNEL_RDMA_V1* > on signed/encrypted connections with INVALID_PARAMETER or ACCESS_DENIED, > buth the problem we currently see is a client security problem. > >> I still think the client needs to handle the is_rdma_mr case, along >> the lines of David's fix. The code looks like a vestige of TCP-only >> response processing. > > I'm not saying David's change is wrong, but I think it has nothing todo > with encrypted or signed traffic... Ok, I agree that this uncovered two issues. And they're independent. I'm digging into dead code and questionable read response parsing in smb2ops.c. I guess we can be thankful it failed. :) I've also asked Microsoft for clarification on the Windows SMB3 server behavior regarding non-encrypted RDMA. Tom.
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 880cd494afea..8d459f60f27b 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -4726,6 +4726,9 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, iov.iov_base = buf + data_offset; iov.iov_len = data_len; iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); + } else if (use_rdma_mr) { + /* The data was delivered directly by RDMA. */ + rdata->got_bytes = data_len; } else { /* read response payload cannot be in both buf and pages */ WARN_ONCE(1, "buf can not contain only a part of read data");