Received: from eggs.gnu.org ([2001:4830:134:3::10]:42423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWaj5-0004zn-Cw for qemu-devel@nongnu.org; Mon, 31 Aug 2015 21:51:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWaj2-0004FU-7c for qemu-devel@nongnu.org; Mon, 31 Aug 2015 21:51:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWaj2-0004FM-2j for qemu-devel@nongnu.org; Mon, 31 Aug 2015 21:51:04 -0400 Date: Mon, 31 Aug 2015 21:51:00 -0400 From: Jeff Cody Message-ID: <20150901015100.GI31272@localhost.localdomain> References: <1441070971-22535-1-git-send-email-namei.unix@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1441070971-22535-1-git-send-email-namei.unix@gmail.com> Subject: Re: [Qemu-devel] [PATCH] sheepdog: discard the payload if the header is invalid List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Yuan Cc: Kevin Wolf , sheepdog-ng@googlegroups.com, Stefan Hajnoczi , qemu-devel@nongnu.org On Tue, Sep 01, 2015 at 09:29:31AM +0800, Liu Yuan wrote: > From: Liu Yuan > > We need to discard the payload if we get a invalid header due to whatever reason > to avoid data stream curruption. If the header is invalid / corrupted, how can rsp.data_length be trusted? Out of curiosity, is this an issue you are seeing occur "in the wild"? > For e.g., the response consists of header plus > data payload. If we simply read the header then the data payload is left in the > socket buffer and the next time we would read the garbage data and currupt the > whole connection. > > Cc: qemu-devel@nongnu.org > Cc: Jeff Cody > Cc: Kevin Wolf > Cc: Stefan Hajnoczi > Signed-off-by: Liu Yuan > --- > block/sheepdog.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/block/sheepdog.c b/block/sheepdog.c > index 9585beb..9ed3458 100644 > --- a/block/sheepdog.c > +++ b/block/sheepdog.c > @@ -794,6 +794,14 @@ static void coroutine_fn aio_read_response(void *opaque) > } > } > if (!aio_req) { > + if (rsp.data_length) { > + void *garbage = g_malloc(rsp.data_length); > + ret = qemu_co_recv(fd, garbage, rsp.data_length); > + if (ret != rsp.data_length) { > + error_report("failed to discard the data, %s", strerror(errno)); > + } > + g_free(garbage); > + } > error_report("cannot find aio_req %x", rsp.id); > goto err; > } > -- > 1.9.1 >