From patchwork Mon Oct 30 20:11:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10033051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C867C600C5 for ; Mon, 30 Oct 2017 20:12:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7CD128967 for ; Mon, 30 Oct 2017 20:12:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A97FE2896A; Mon, 30 Oct 2017 20:12:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 8996928967 for ; Mon, 30 Oct 2017 20:12:56 +0000 (UTC) Received: from localhost ([::1]:42364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9GQZ-0003UW-6j for patchwork-qemu-devel@patchwork.kernel.org; Mon, 30 Oct 2017 16:12:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9GPn-0003R4-Ta for qemu-devel@nongnu.org; Mon, 30 Oct 2017 16:12:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9GPm-0007AD-Jx for qemu-devel@nongnu.org; Mon, 30 Oct 2017 16:12:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44428) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9GPd-00074y-KX; Mon, 30 Oct 2017 16:11:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E68D7EA95; Mon, 30 Oct 2017 20:11:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9E68D7EA95 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com Received: from [10.10.123.123] (ovpn-123-123.rdu2.redhat.com [10.10.123.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9288B5D9C7; Mon, 30 Oct 2017 20:11:54 +0000 (UTC) To: Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org References: <20171027104037.8319-1-eblake@redhat.com> <20171027104037.8319-7-eblake@redhat.com> <59449c29-0335-9eaf-47a6-edd6cc35bf73@virtuozzo.com> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: <5b8fbdd6-c3cd-aed8-f633-ad5f0d07507d@redhat.com> Date: Mon, 30 Oct 2017 21:11:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <59449c29-0335-9eaf-47a6-edd6cc35bf73@virtuozzo.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Oct 2017 20:11:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: Re: [Qemu-devel] [PATCH v6 06/12] nbd/server: Refactor zero-length option check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On 10/30/2017 06:22 PM, Vladimir Sementsov-Ogievskiy wrote: > 27.10.2017 13:40, Eric Blake wrote: >> Consolidate the response for a non-zero-length option payload >> into a new function, nbd_reject_length().  This check will >> also be used when introducing support for structured replies. >> >> Note that STARTTLS response differs based on time: if the connection >> is still unencrypted, we set fatal to true (a client that can't >> request TLS correctly may still think that we are ready to start >> the TLS handshake, so we must disconnect); while if the connection >> is already encrypted, the client is sending a bogus request but >> is no longer at risk of being confused by continuing the connection. >> >>               switch (option) { >>               case NBD_OPT_STARTTLS: >> -                tioc = nbd_negotiate_handle_starttls(client, length, >> errp); >> +                if (length) { >> +                    /* Unconditionally drop the connection if the client >> +                     * can't start a TLS negotiation correctly */ >> +                    nbd_reject_length(client, length, option, true, >> errp); >> +                    return -EINVAL; > > why not to return nbd_reject_length's result? this EINVAL may not > correspond to errp (about EIO for example).. Somewhat true, if nbd_reject_length() fails. But nbd_reject_length() may also return 0 without setting errp, in which case, maybe this code should set errp rather than just blindly returning -EINVAL. > > with or without this fixed: > > Reviewed-by: Vladimir Sementsov-Ogievskiy > Okay, I'll squash this in, and include it in my pull request to be sent shortly. } tioc = nbd_negotiate_handle_starttls(client, errp); if (!tioc) { diff --git i/nbd/server.c w/nbd/server.c index a9480e42cd..91f81a0f19 100644 --- i/nbd/server.c +++ w/nbd/server.c @@ -684,8 +684,13 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags, if (length) { /* Unconditionally drop the connection if the client * can't start a TLS negotiation correctly */ - nbd_reject_length(client, length, option, true, errp); - return -EINVAL; + ret = nbd_reject_length(client, length, option, true, errp); + if (!ret) { + error_setg(errp, "option '%s' should have zero length", + nbd_opt_lookup(option)); + ret = -EINVAL; + } + return ret;