From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 19/19] nbd: Don't kill server on client that doesn't request TLS
Date: Fri, 15 Apr 2016 19:02:22 +0200 [thread overview]
Message-ID: <1460739742-5315-20-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1460739742-5315-1-git-send-email-kwolf@redhat.com>
From: Eric Blake <eblake@redhat.com>
Upstream NBD documents (as of commit 4feebc95) that servers MAY
choose to operate in a conditional mode, where it is up to the
client whether to use TLS. For qemu's case, we want to always be
in FORCEDTLS mode, because of the risk of man-in-the-middle
attacks, and since we never export more than one device; likewise,
the qemu client will ALWAYS send NBD_OPT_STARTTLS as its first
option. But now that SELECTIVETLS servers exist, it is feasible
to encounter a (non-qemu) client that is programmed to talk to
such a server, and does not do NBD_OPT_STARTTLS first, but rather
wants to probe if it can use a non-encrypted export.
The NBD protocol documents that we should let such a client
continue trying, on the grounds that maybe the client will get the
hint to send NBD_OPT_STARTTLS, rather than immediately dropping
the connection.
Note that NBD_OPT_EXPORT_NAME is a special case: since it is the
only option request that can't have an error return, we have to
(continue to) drop the connection on that one; rather, what we are
fixing here is that all other replies prior to TLS initiation tell
the client NBD_REP_ERR_TLS_REQD, but keep the connection alive.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-id: 1460671343-18485-1-git-send-email-eblake@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
nbd/server.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index 2a4dd10..a13a691 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -449,11 +449,19 @@ static int nbd_negotiate_options(NBDClient *client)
client->ioc = QIO_CHANNEL(tioc);
break;
+ case NBD_OPT_EXPORT_NAME:
+ /* No way to return an error to client, so drop connection */
+ TRACE("Option 0x%x not permitted before TLS", clientflags);
+ return -EINVAL;
+
default:
TRACE("Option 0x%x not permitted before TLS", clientflags);
+ if (nbd_negotiate_drop_sync(client->ioc, length) != length) {
+ return -EIO;
+ }
nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_TLS_REQD,
clientflags);
- return -EINVAL;
+ break;
}
} else if (fixedNewstyle) {
switch (clientflags) {
@@ -471,6 +479,9 @@ static int nbd_negotiate_options(NBDClient *client)
return nbd_negotiate_handle_export_name(client, length);
case NBD_OPT_STARTTLS:
+ if (nbd_negotiate_drop_sync(client->ioc, length) != length) {
+ return -EIO;
+ }
if (client->tlscreds) {
TRACE("TLS already enabled");
nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_INVALID,
@@ -480,7 +491,7 @@ static int nbd_negotiate_options(NBDClient *client)
nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_POLICY,
clientflags);
}
- return -EINVAL;
+ break;
default:
TRACE("Unsupported option 0x%x", clientflags);
if (nbd_negotiate_drop_sync(client->ioc, length) != length) {
--
1.8.3.1
next prev parent reply other threads:[~2016-04-15 17:03 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-15 17:02 [Qemu-devel] [PULL 00/19] Block layer patches for 2.6.0-rc3 Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 01/19] qemu-io: Support 'aio_write -z' Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 02/19] block: Fix blk_aio_write_zeroes() Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 03/19] block/vpc: set errp in vpc_create Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 04/19] vpc: use current_size field for XenServer VHD images Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 05/19] block/vpc: use current_size field for XenConverter " Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 06/19] block/vpc: Use the correct max sector count for " Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 07/19] block/vpc: make checks on max table size a bit more lax Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 08/19] block/vpc: set errp in vpc_open Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 09/19] block/vpc: update comments to be compliant w/coding guidelines Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 10/19] block: Don't ignore flags in blk_{, co, aio}_write_zeroes() Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 11/19] Fix pflash migration Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 12/19] qemu-iotests: drop unused _within_tolerance() filter Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 13/19] qemu-iotests: common.rc: drop unused _do() Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 14/19] qemu-iotests: tests: do not set unused tmp variable Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 15/19] qemu-iotests: place valgrind log file in scratch dir Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 16/19] qemu-iotests: 041: More robust assertion on quorum node Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 17/19] nbd: Don't fail handshake on NBD_OPT_LIST descriptions Kevin Wolf
2016-04-15 17:02 ` [Qemu-devel] [PULL 18/19] nbd: fix assert() on qemu-nbd stop Kevin Wolf
2016-04-15 17:02 ` Kevin Wolf [this message]
2016-04-18 8:54 ` [Qemu-devel] [PULL 00/19] Block layer patches for 2.6.0-rc3 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460739742-5315-20-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).