Skip to contentSkip to conversation

nbd/server: Reject 0-length block status request

PATCH In review Eric Blake 3 participants 4 messages Jun 21, 2018

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

PATCH 1/1 nbd/server: Reject 0-length block status request

The NBD spec says that behavior is unspecified if the client requests 0 length for block status; but since the structured reply is documenting as returning a non-zero length, it's easier to just diagnose this with an EINVAL error than to figure out what to return.

---
 nbd/server.c | 4 ++++
 1 file changed, 4 insertions(+)
nbd/server.c +4 -0
index 9e1f2271784..493a926e063 100644
@@ -2007,6 +2007,10 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
                                       "discard failed", errp);
 
     case NBD_CMD_BLOCK_STATUS:
+        if (!request->len) {
+            return nbd_send_generic_reply(client, request->handle, -EINVAL,
+                                          "need non-zero length", errp);
+        }
         if (client->export_meta.valid && client->export_meta.base_allocation) {
             return nbd_co_send_block_status(client, request->handle,
                                             blk_bs(exp->blk), request->from,
Signature · 1 line
2.14.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Blake

The NBD spec says that behavior is unspecified if the client requests 0 length for block status; but since the structured reply is documenting as returning a non-zero length, it's easier to just diagnose this with an EINVAL error than to figure out what to return.

Quoted 19 lines
---
  nbd/server.c | 4 ++++
  1 file changed, 4 insertions(+)
nbd/server.c +4 -0
index 9e1f2271784..493a926e063 100644
@@ -2007,6 +2007,10 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
                                        "discard failed", errp);
 
      case NBD_CMD_BLOCK_STATUS:
+        if (!request->len) {
+            return nbd_send_generic_reply(client, request->handle, -EINVAL,
+                                          "need non-zero length", errp);
+        }
          if (client->export_meta.valid && client->export_meta.base_allocation) {
              return nbd_co_send_block_status(client, request->handle,
                                              blk_bs(exp->blk), request->from,
Signature · 2 lines
Best regards,
Vladimir
author
#2 lore raw
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
Quoted 8 lines · Eric Blake

The NBD spec says that behavior is unspecified if the client requests 0 length for block status; but since the structured reply is documenting as returning a non-zero length, it's easier to just diagnose this with an EINVAL error than to figure out what to return.

Thanks; added to my NBD queue. Doing this makes it easier to add the assertion necessary to shut up gcc warning about an uninitialized variable in the other patches ready to pull.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 1/1
#3 lore raw
In reply to Eric Blake
Quoted 6 lines · Eric Blake

The NBD spec says that behavior is unspecified if the client requests 0 length for block status; but since the structured reply is documenting as returning a non-zero length, it's easier to just diagnose this with an EINVAL error than to figure out what to return.

Relevant section:

REQUEST TYPES / NBD_CMD_BLOCK_STATUS (7)

"A block status query request. Length and offset define the range of interest. The client SHOULD NOT request a status length of 0; the behavior of a server on such a request is unspecified although the server SHOULD NOT disconnect."

Leave a little breadcrumb in the commit message because it's headed to -stable.

Quoted 12 lines
---
 nbd/server.c | 4 ++++
 1 file changed, 4 insertions(+)
nbd/server.c +0 -0
index 9e1f2271784..493a926e063 100644

nbd/server.c static coroutine_fn int nbd_handle_request(NBDClient *client, · line 2016

Quoted 10 lines
nbd/server.c +4 -0
@@ -2007,6 +2007,10 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
                                       "discard failed", errp);
 
     case NBD_CMD_BLOCK_STATUS:
+        if (!request->len) {
+            return nbd_send_generic_reply(client, request->handle, -EINVAL,
+                                          "need non-zero length", errp);
+        }
         if (client->export_meta.valid && client->export_meta.base_allocation) {
             return nbd_co_send_block_status(client, request->handle,
                                             blk_bs(exp->blk), request->from,

Looks correct assuming spec agrees.