From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCV8i-0002Nu-HZ for qemu-devel@nongnu.org; Mon, 13 Jun 2016 12:55:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCV8f-0007JD-Cr for qemu-devel@nongnu.org; Mon, 13 Jun 2016 12:55:04 -0400 References: <1463006384-7734-1-git-send-email-eblake@redhat.com> <1463006384-7734-5-git-send-email-eblake@redhat.com> <7c7619a2-a6f3-c30c-c8d0-aac1f96ae661@redhat.com> From: Eric Blake Message-ID: <575EE55A.4020807@redhat.com> Date: Mon, 13 Jun 2016 10:54:50 -0600 MIME-Version: 1.0 In-Reply-To: <7c7619a2-a6f3-c30c-c8d0-aac1f96ae661@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="o7KS6a8VC7a4cJAd0fiLx5TeDoT7gtjHR" Subject: Re: [Qemu-devel] [PATCH v4 04/11] nbd: Improve server handling of bogus commands List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, alex@alex.org.uk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --o7KS6a8VC7a4cJAd0fiLx5TeDoT7gtjHR Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/13/2016 06:19 AM, Paolo Bonzini wrote: >> + /* Sanity checks, part 2. */ >> + if (request->from + request->len > client->exp->size) { >> + LOG("operation past EOF; From: %" PRIu64 ", Len: %" PRIu32 >> + ", Size: %" PRIu64, request->from, request->len, >> + (uint64_t)client->exp->size); >> + rc =3D -EINVAL; >=20 > For writes, this should be ENOSPC according to the spec. Good call. >> + if (nbd_co_send_reply(req, &reply, 0) < 0 || command =3D=3D N= BD_CMD_READ || >> + (command =3D=3D NBD_CMD_WRITE && !req->complete)) { >=20 > It's simpler to always set req->complete. Putting everything together:= >=20 > diff --git a/nbd/server.c b/nbd/server.c > index 4743316..73505dc 100644 > --- a/nbd/server.c > +++ b/nbd/server.c > @@ -1017,6 +1017,11 @@ static ssize_t nbd_co_receive_request(NBDRequest= *req, > TRACE("Decoding type"); > =20 > command =3D request->type & NBD_CMD_MASK_COMMAND; > + if (command !=3D NBD_CMD_WRITE) { > + /* No payload, we are ready to read the next request. */ > + req->complete =3D true; > + } > + Nice. > @@ -1213,12 +1218,9 @@ static void nbd_trip(void *opaque) > LOG("invalid request type (%" PRIu32 ") received", request.typ= e); > reply.error =3D EINVAL; > error_reply: > - /* We must disconnect after replying with an error to > - * NBD_CMD_READ, since we choose not to send bogus filler > - * data; likewise after NBD_CMD_WRITE if we did not read the > - * payload. */ > - if (nbd_co_send_reply(req, &reply, 0) < 0 || command =3D=3D NB= D_CMD_READ || > - (command =3D=3D NBD_CMD_WRITE && !req->complete)) { > + /* We must disconnect after NBD_CMD_WRITE if we did not > + * read the payload. */ > + if (nbd_co_send_reply(req, &reply, 0) < 0 || !req->complete)) = { I'm not sure I agree with your change on NBD_CMD_READ, but we can hash that out with upstream NBD list on the correct protocol, and make any further changes as a followup. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --o7KS6a8VC7a4cJAd0fiLx5TeDoT7gtjHR Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXXuVaAAoJEKeha0olJ0Nqh9kH/iYb+w/B3VNA4phJTE0CTjMa Q2pCnOAruKfUIOjVEwvOP6zOJozifiygqosYQX5dO+SbxQFMdW9dcBIAFqFf/M3X k90lKelPLoaVTww2FzdjbfC+Sk0w2L1UA8GO6wX3vLYvWanErr8fIBhfSsUpB3DQ i5+vEUgFBabX/23L93yXk17QjBXMF3/a6xTa2BercrIw9iPEeaGCDG5Lf98Rr9sl Lhwg9ykd4mTzM7Oa9OfhaFUBx/m8Gq3EGGu3qAKuRoI4LCjz+dKJyHS6FS3kwHxd i89ysAqFok3Lca4ACJzHEdvKabtzMrq9SFlXAKK7xgfyEhgT/ibFUpyZgTLInlM= =O4Q2 -----END PGP SIGNATURE----- --o7KS6a8VC7a4cJAd0fiLx5TeDoT7gtjHR--