qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, alex@alex.org.uk
Subject: [Qemu-devel] [PATCH v2 2/1 for-2.6] nbd: Don't kill server when client requests unknown option
Date: Wed,  6 Apr 2016 16:48:38 -0600	[thread overview]
Message-ID: <1459982918-32229-1-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1459961962-18771-1-git-send-email-eblake@redhat.com>

nbd-server.c currently fails to handle unsupported options properly.
If during option haggling the client sends an unknown request, the
server kills the connection instead of letting the client try to
fall back to something older.  This is precisely what advertising
NBD_FLAG_FIXED_NEWSTYLE was supposed to fix.

Signed-off-by: Eric Blake <eblake@redhat.com>
---

Turns out our server has a very similar bug to the client.
If desired, I can spin a v3 that moves the hunk in nbd/client.c
to the previous patch.

 nbd/client.c | 2 ++
 nbd/server.c | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/nbd/client.c b/nbd/client.c
index 67116b9..fc382c5 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -109,6 +109,8 @@ static int nbd_handle_reply_err(QIOChannel *ioc, uint32_t opt, uint32_t type,

     switch (type) {
     case NBD_REP_ERR_UNSUP:
+        TRACE("server doesn't understand request %d, attempting fallback",
+              opt);
         result = 0;
         goto cleanup;

diff --git a/nbd/server.c b/nbd/server.c
index b95571b..7843584 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -482,9 +482,12 @@ static int nbd_negotiate_options(NBDClient *client)
                 return -EINVAL;
             default:
                 TRACE("Unsupported option 0x%x", clientflags);
+                if (nbd_negotiate_drop_sync(client->ioc, length) != length) {
+                    return -EIO;
+                }
                 nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_UNSUP,
                                        clientflags);
-                return -EINVAL;
+                break;
             }
         } else {
             /*
-- 
2.5.5

  reply	other threads:[~2016-04-06 22:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-06 16:59 [Qemu-devel] [PATCH v2] nbd: Fix NBD unsupported options Eric Blake
2016-04-06 22:48 ` Eric Blake [this message]
2016-04-07  8:50   ` [Qemu-devel] [PATCH v2 2/1 for-2.6] nbd: Don't kill server when client requests unknown option Paolo Bonzini
2016-04-09 22:41   ` Eric Blake

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=1459982918-32229-1-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=alex@alex.org.uk \
    --cc=pbonzini@redhat.com \
    --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).