From nobody Mon May 6 07:30:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575641323; cv=none; d=zohomail.com; s=zohoarc; b=BZTzs3i1RprL8YZMssT4ov+SUD8dh1L7fszxVRVw7Mvf3VWjDggqeFTGGzHLVmyYtLSt29flYYJt/2bYWVB2TiSsYLv7UtKvrCMIIjwWXrsfsJ2z2NtPXLR6arGKmfatMJuo0ptcEmgXctwZo6J299n/v0nlC3VL/t++JtJ20jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575641323; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5TtN3Klz1gBAW13YBEc8Fs4OtB5nCG0xb9i0Kl1Ykm8=; b=IkHVwWOEGbRETZ03NoNzA6utEuzVF6xWTLiy0cHZtMhfyvfn/Ig3eGc5Gw8DETTY9Q64a6Odvx0I60OkLIHwVD8GkdDvok89zVHslNQ9T4KnfFYovJYf3iCowLqzbVoxl3M60diheKqtJDlTyvvMpMRsIoZGRlrUQr2IV3YybgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157564132308475.92040715068822; Fri, 6 Dec 2019 06:08:43 -0800 (PST) Received: from localhost ([::1]:37832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idEHh-0001zl-AV for importer@patchew.org; Fri, 06 Dec 2019 09:08:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50125) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idEGR-00014j-0z for qemu-devel@nongnu.org; Fri, 06 Dec 2019 09:07:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idEGP-00077t-Ms for qemu-devel@nongnu.org; Fri, 06 Dec 2019 09:07:22 -0500 Received: from smtpfb2-g21.free.fr ([212.27.42.10]:44602) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1idEGP-0006ym-2J for qemu-devel@nongnu.org; Fri, 06 Dec 2019 09:07:21 -0500 Received: from smtp3-g21.free.fr (smtp3-g21.free.fr [212.27.42.3]) by smtpfb2-g21.free.fr (Postfix) with ESMTP id 032BA42D5E4 for ; Fri, 6 Dec 2019 09:51:16 +0100 (CET) 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 E81C713F85F; Fri, 6 Dec 2019 09:51:08 +0100 (CET) From: Anisse Astier To: qemu-devel@nongnu.org Subject: [PATCH v2] socket: websocket refresh of max_size outside of poll Date: Fri, 6 Dec 2019 09:50:57 +0100 Message-Id: <20191206085057.15612-1-aastier@freebox.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157556562680.28471.17998029208459109470@37313f22b938> References: <157556562680.28471.17998029208459109470@37313f22b938> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.27.42.10 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=20P=20=2E=20Berrang=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 calling tcp_chr_read_poll; but since the websocket reader is a greedy because it needs a buffer 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 --- Changes since v1: - style changes --- chardev/char-socket.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 185fe38dda..9267ecd813 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -505,6 +505,9 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondi= tion cond, void *opaque) uint8_t buf[CHR_READ_BUF_LEN]; int len, size; =20 + if (s->is_websock) + /* Buffered greedy reader needs max_size refresh */ + s->max_size =3D qemu_chr_be_can_write(chr); if ((s->state !=3D TCP_CHARDEV_STATE_CONNECTED) || s->max_size <=3D 0) { return TRUE; --=20 2.20.1