Skip to contentSkip to conversation

nbd: Don't kill server on client that doesn't request TLS

PATCH In review Eric Blake 3 participants 6 messages Apr 7, 2016 – Apr 14, 2016

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

PATCH 1/1 nbd: Don't kill server on client that doesn't request TLS

Upstream NBD is documenting 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 does not do NBD_OPT_STARTTLS first, but rather wants to take advantage of the conditional modes it might find elsewhere.

Since we require TLS, we are within our rights to drop connections on any client that doesn't negotiate it right away, or which attempts to negotiate it incorrectly, without violating the intent of the NBD Protocol. However, it's better to allow the client to continue trying, on the grounds that maybe the client will get the hint to send NBD_OPT_STARTTLS.

---

My earlier patch was arguably incomplete:
https://lists.gnu.org/archive/html/qemu-devel/2016-04/msg01265.html

But as it is already in a pull request, and as this one is a bit more controversial, it's best to keep it as a separate patch.

 nbd/server.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
nbd/server.c +8 -2
index 7843584..2b727f0 100644
@@ -450,9 +450,12 @@ static int nbd_negotiate_options(NBDClient *client)
 
             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) {
@@ -470,6 +473,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,
@@ -479,7 +485,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) {
Signature · 1 line
2.5.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Eric Blake

Upstream NBD is documenting 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 does not do NBD_OPT_STARTTLS first, but rather wants to take advantage of the conditional modes it might find elsewhere.

Quoted 8 lines

Since we require TLS, we are within our rights to drop connections on any client that doesn't negotiate it right away, or which attempts to negotiate it incorrectly, without violating the intent of the NBD Protocol. However, it's better to allow the client to continue trying, on the grounds that maybe the client will get the hint to send NBD_OPT_STARTTLS.

Looks right to me - untested.

Quoted 52 lines

---

My earlier patch was arguably incomplete:
https://lists.gnu.org/archive/html/qemu-devel/2016-04/msg01265.html

But as it is already in a pull request, and as this one is a bit more controversial, it's best to keep it as a separate patch.

nbd/server.c | 10 ++++++++--

1 file changed, 8 insertions(+), 2 deletions(-)
nbd/server.c +8 -2
index 7843584..2b727f0 100644
@@ -450,9 +450,12 @@ static int nbd_negotiate_options(NBDClient *client)
 
            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) {
@@ -470,6 +473,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,
@@ -479,7 +485,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) {
Signature · 1 line
2.5.5
Signature · 1 line
Alex Bligh
author
#2 lore raw
In reply to Eric Blake

[adding qemu-block in cc, since Paolo can't send pull request]

Quoted 68 lines · Eric Blake

Upstream NBD is documenting 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 does not do NBD_OPT_STARTTLS first, but rather wants to take advantage of the conditional modes it might find elsewhere.

Since we require TLS, we are within our rights to drop connections on any client that doesn't negotiate it right away, or which attempts to negotiate it incorrectly, without violating the intent of the NBD Protocol. However, it's better to allow the client to continue trying, on the grounds that maybe the client will get the hint to send NBD_OPT_STARTTLS.

---

My earlier patch was arguably incomplete:
https://lists.gnu.org/archive/html/qemu-devel/2016-04/msg01265.html

But as it is already in a pull request, and as this one is a bit more controversial, it's best to keep it as a separate patch.

 nbd/server.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
nbd/server.c +8 -2
index 7843584..2b727f0 100644
@@ -450,9 +450,12 @@ static int nbd_negotiate_options(NBDClient *client)
 
             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) {
@@ -470,6 +473,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,
@@ -479,7 +485,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) {
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by
#3 lore raw
Quoted 22 lines · Eric Blake

[adding qemu-block in cc, since Paolo can't send pull request]

Quoted 19 lines · Eric Blake

Upstream NBD is documenting 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 does not do NBD_OPT_STARTTLS first, but rather wants to take advantage of the conditional modes it might find elsewhere.

Since we require TLS, we are within our rights to drop connections on any client that doesn't negotiate it right away, or which attempts to negotiate it incorrectly, without violating the intent of the NBD Protocol. However, it's better to allow the client to continue trying, on the grounds that maybe the client will get the hint to send NBD_OPT_STARTTLS.

It is worth noting that this change (assuming I've read it right) in no way means that qemu would be serving resources without TLS enabled when configured with TLS, or even providing information about those resources. It's simply saying "TLS is required" (and not dropping the connection so the client can ask for TLS) if the client doesn't ask for TLS first thing. This removes the need for the client and server to communicate out of band that TLS is required (as well as conforming to the spec).

Alex

Quoted 45 lines
Quoted 45 lines

---

My earlier patch was arguably incomplete:
https://lists.gnu.org/archive/html/qemu-devel/2016-04/msg01265.html

But as it is already in a pull request, and as this one is a bit more controversial, it's best to keep it as a separate patch.

nbd/server.c | 10 ++++++++--

1 file changed, 8 insertions(+), 2 deletions(-)
nbd/server.c +8 -2
index 7843584..2b727f0 100644
@@ -450,9 +450,12 @@ static int nbd_negotiate_options(NBDClient *client)
 
            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) {
@@ -470,6 +473,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,
@@ -479,7 +485,7 @@ static int nbd_negotiate_options(NBDClient *client)
                    nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_POLICY,
                                           clientflags);
                }
-                return -EINVAL;
+                break;
Quoted 9 lines

nbd/server.c static int nbd_negotiate_options(NBDClient *client) · line 491

Quoted 4 lines
nbd/server.c +0 -0
            default:
                TRACE("Unsupported option 0x%x", clientflags);
                if (nbd_negotiate_drop_sync(client->ioc, length) != length) {

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

--
Alex Bligh

#4 lore raw
In reply to Eric Blake
Quoted 36 lines · Eric Blake

Upstream NBD is documenting 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 does not do NBD_OPT_STARTTLS first, but rather wants to take advantage of the conditional modes it might find elsewhere.

Since we require TLS, we are within our rights to drop connections on any client that doesn't negotiate it right away, or which attempts to negotiate it incorrectly, without violating the intent of the NBD Protocol. However, it's better to allow the client to continue trying, on the grounds that maybe the client will get the hint to send NBD_OPT_STARTTLS.

---

My earlier patch was arguably incomplete:
https://lists.gnu.org/archive/html/qemu-devel/2016-04/msg01265.html

But as it is already in a pull request, and as this one is a bit more controversial, it's best to keep it as a separate patch.

 nbd/server.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
nbd/server.c +0 -0
index 7843584..2b727f0 100644
@@ -450,9 +450,12 @@ static int nbd_negotiate_options(NBDClient *client)
 

nbd/server.c static int nbd_negotiate_options(NBDClient *client) · line 459

Quoted 10 lines
nbd/server.c +4 -1
             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;
             }

What about NBD_OPT_EXPORTNAME? The specification says that this option does not allow for errors, and so the session must be terminated if this option is sent in FORCEDTLS mode without TLS having been negotiated.

Max

Quoted 22 lines
nbd/server.c +4 -1
         } else if (fixedNewstyle) {
             switch (clientflags) {
@@ -470,6 +473,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,
@@ -479,7 +485,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) {
author
#5 lore raw
Quoted 25 lines · Max Reitz
Quoted 24 lines · Eric Blake

Upstream NBD is documenting 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 does not do NBD_OPT_STARTTLS first, but rather wants to take advantage of the conditional modes it might find elsewhere.

Since we require TLS, we are within our rights to drop connections on any client that doesn't negotiate it right away, or which attempts to negotiate it incorrectly, without violating the intent of the NBD Protocol. However, it's better to allow the client to continue trying, on the grounds that maybe the client will get the hint to send NBD_OPT_STARTTLS.

---

+++ b/nbd/server.c

(quoted diff) +0 -0
@@ -450,9 +450,12 @@ static int nbd_negotiate_options(NBDClient *client)
 
Quoted 14 lines

nbd/server.c static int nbd_negotiate_options(NBDClient *client) · line 459

Quoted 10 lines
nbd/server.c +4 -1
             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;
             }

What about NBD_OPT_EXPORTNAME? The specification says that this option does not allow for errors, and so the session must be terminated if this option is sent in FORCEDTLS mode without TLS having been negotiated.

Oh, good catch. v2 coming up.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org