From patchwork Thu Dec 5 14:06:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anisse Astier X-Patchwork-Id: 11274843 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27DE214B7 for ; Thu, 5 Dec 2019 14:14:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DEDAE2245C for ; Thu, 5 Dec 2019 14:14:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DEDAE2245C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=freebox.fr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icrtg-0000M9-9W for patchwork-qemu-devel@patchwork.kernel.org; Thu, 05 Dec 2019 09:14:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59730) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icrmY-0000hx-OW for qemu-devel@nongnu.org; Thu, 05 Dec 2019 09:07:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icrmX-0002zt-87 for qemu-devel@nongnu.org; Thu, 05 Dec 2019 09:07:02 -0500 Received: from smtp3-g21.free.fr ([2a01:e0c:1:1599::12]:21377) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1icrmW-0002kT-U3 for qemu-devel@nongnu.org; Thu, 05 Dec 2019 09:07:01 -0500 Received: from anisse-station.iliad.local (unknown [IPv6:2a01:e34:ec0d:40e0:6c55:3f21:f604:859c]) by smtp3-g21.free.fr (Postfix) with ESMTPS id 50C3F13F8DC; Thu, 5 Dec 2019 15:06:50 +0100 (CET) From: Anisse Astier To: qemu-devel@nongnu.org Subject: [PATCH] socket: websocket refresh of max_size outside of poll Date: Thu, 5 Dec 2019 15:06:45 +0100 Message-Id: <20191205140645.6071-1-aastier@freebox.fr> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 2a01:e0c:1:1599::12 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anisse Astier , Julia Suvorova , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Because serial backend readiness isn't checked, the socket frontend (in websocket mode) would send new characters before previous characters were consumed. This lead to skipped characters, or worse, SysRq keys being triggered. This patch ensures the readable size is refreshed before consuming any data. Normally, this size is refreshed in the event loop by the glib prepare io_watch_poll_prepare; but since the websocket reader is a greedy one to decode the websocket protocol, (whereas tcp one ready bytes as necessary), there's nothing to read or poll, so the max_size wouldn't be refreshed. Buglink: https://bugs.launchpad.net/qemu/+bug/1828608 Signed-off-by: Anisse Astier --- chardev/char-socket.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 185fe38dda..5e093e6605 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -505,6 +505,9 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) uint8_t buf[CHR_READ_BUF_LEN]; int len, size; + if(s->is_websock) + /* Greedy reader does not have event loop refresh by tcp_chr_read_poll */ + s->max_size = qemu_chr_be_can_write(chr); if ((s->state != TCP_CHARDEV_STATE_CONNECTED) || s->max_size <= 0) { return TRUE;