From patchwork Wed Apr 6 22:48:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8766441 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5E4BEC0553 for ; Wed, 6 Apr 2016 22:49:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ADEB1201E4 for ; Wed, 6 Apr 2016 22:48:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5D0F201D3 for ; Wed, 6 Apr 2016 22:48:58 +0000 (UTC) Received: from localhost ([::1]:46120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anwFu-0000q0-1K for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Apr 2016 18:48:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anwFk-0000oh-E4 for qemu-devel@nongnu.org; Wed, 06 Apr 2016 18:48:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anwFh-0000rl-34 for qemu-devel@nongnu.org; Wed, 06 Apr 2016 18:48:48 -0400 Received: from resqmta-po-10v.sys.comcast.net ([2001:558:fe16:19:96:114:154:169]:39745) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anwFg-0000rg-St for qemu-devel@nongnu.org; Wed, 06 Apr 2016 18:48:45 -0400 Received: from resomta-po-06v.sys.comcast.net ([96.114.154.230]) by comcast with SMTP id nwFdaBhipZjFtnwFfaZ3Of; Wed, 06 Apr 2016 22:48:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1459982923; bh=SWeU9/i7gg1wUFp1gPmTVpjVnC4O+mmS0uA+WKuDGow=; h=Received:Received:From:To:Subject:Date:Message-Id; b=Hqahm1wYXr/MJdUkcDii9C7+y+jMIFuNdfYSV7wzb88M+BBjRVZzNi2jeYlVKvxdc K5PbCuklJVgoyHWidxHKKLlEHvni9yDgeQNSA+3eEMUeJYUphKU9Pnf0BoEeu9bizH sx9ufCRIIhRGsfz2IyT02491hnVOwdbl3igSsjfUIx/cZ2sl0XKxCTNMreHAd6qHIw EmMHf9Tbqbxjkfmni1gdRBqdW5UZEwEV5RsiJ+H8VwG1U+L/v7+uETpIA4IeKswzpT yHGltjscIfTA+0HhQNe3fQIYN+ALoBEn0vjPa8lx5zLv5Qq4giliQvrOPXXQ3oW9kj pfPbn38kVmfpQ== Received: from red.redhat.com ([24.10.254.122]) by resomta-po-06v.sys.comcast.net with comcast id fAog1s0082fD5rL01Aoi3w; Wed, 06 Apr 2016 22:48:43 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 6 Apr 2016 16:48:38 -0600 Message-Id: <1459982918-32229-1-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1459961962-18771-1-git-send-email-eblake@redhat.com> References: <1459961962-18771-1-git-send-email-eblake@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:169 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 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 { /*