From nobody Mon Nov 23 05:00:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791364526; cv=none; d=zohomail.com; s=zohoarc; b=jzrqvJntBuJ1S4mAKb6bAphUxp8INQmy8iU4iSLvxanpeekr1OkJIlAQ/8yQxRe77DCUR3+JvuRsXHd6qUAWIcjCyeX6e8n4bey84ddwM+qLKI7EbnWhstKDQubrdmOae9AjEvHlqcwnscvZiKjoEvlUy4rrR1ixKYrPCDRnxhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791364526; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pUoskSKOEsQ6F4h4hz7HH+gJ3d/gimy4L9+CReBhylM=; b=lr/zTYx5/nZdY9waxKTBUgR/h1EqIKtT6mBEt5IZjhFFhb6kJbmmTBjFsVaGSkWGQSQ4w+2GMayFlWcSHvkC3STw/eATcjwmiWgUq/WhTEs4xprFmjRDn1uLlLQeP9rtjM8S3B2Qqfki2ohFYsbW/bAyNmCZVG+adq1SFmgr+Fk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791364526284256.042107795687; Wed, 7 Oct 2026 02:15:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENIQ-0006Z0-U3; Wed, 07 Oct 2026 04:46:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEJmU-0000dm-7L for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:01:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEJmL-0004et-Rb for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:01:27 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-NcUcqjnXNa6-zezUY3aONg-1; Tue, 06 Oct 2026 04:34:55 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D70521851277 for ; Tue, 6 Oct 2026 08:34:54 +0000 (UTC) Received: from berrange.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EFF05180035F; Tue, 6 Oct 2026 08:34:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791349275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pUoskSKOEsQ6F4h4hz7HH+gJ3d/gimy4L9+CReBhylM=; b=Z1QvQ882Kcy2+oCO68u4TicKfEwxlJdWZJi6wSuG/of+wGPhZeqt+CsxyLSb5lHF9erjoY JAnuKXcVNlsJ528Fm467GHkR6n+NKrMLbTvS4Ob38b85mi7RA2mhaiMVt1oYfpI3bRwiHk M+q41zgJc6tAZKRGHWMASLij4zmux2I= X-MC-Unique: NcUcqjnXNa6-zezUY3aONg-1 X-Mimecast-MFC-AGG-ID: NcUcqjnXNa6-zezUY3aONg_1791275695 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Tommaso Califano Subject: [PULL 1/4] hw/usb: Fix USB MTP Use-After-Free in usb_mtp_deletefn List Iteration Date: Tue, 6 Oct 2026 09:34:48 +0100 Message-ID: <20261006083451.956881-2-berrange@redhat.com> In-Reply-To: <20261006083451.956881-1-berrange@redhat.com> References: <20261006083451.956881-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791364527362158500 From: Tommaso Califano In QEMU's USB MTP (Media Transfer Protocol) device emulation, the usb_mtp_d= eletefn() function in hw/usb/dev-mtp.c iterates over a child object list using QLIST_= FOREACH while the recursive call may free the current element. After the free, the = macro reads the le_next field from freed memory to advance the iterator. Replace QLIST_FOREACH with QLIST_FOREACH_SAFE, which saves the next pointer= before the iteration body executes. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3991 Signed-off-by: Tommaso Califano Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- hw/usb/dev-mtp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 1d8cfd32dc6..c2d36a73cf9 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -1152,7 +1152,7 @@ enum { =20 static int usb_mtp_deletefn(MTPState *s, MTPObject *o, uint32_t trans) { - MTPObject *iter, *iter2; + MTPObject *iter, *iter2, *iter2_next; int ret =3D 0; =20 /* @@ -1161,7 +1161,7 @@ static int usb_mtp_deletefn(MTPState *s, MTPObject *o= , uint32_t trans) =20 QLIST_FOREACH(iter, &o->children, list) { if (iter->format =3D=3D FMT_ASSOCIATION) { - QLIST_FOREACH(iter2, &iter->children, list) { + QLIST_FOREACH_SAFE(iter2, &iter->children, list, iter2_next) { ret |=3D usb_mtp_deletefn(s, iter2, trans); } } --=20 2.55.0 From nobody Mon Nov 23 05:00:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791364314; cv=none; d=zohomail.com; s=zohoarc; b=TOoYh7tMualj6zTaHMM37h030Jzy7x37Uf3WlwH2+5jkKcKM2HZDAkOMGYoDsrulgepvqne1Se5XaTKs+5EQmCSf35AcPom4rPg6qXRuMHl9HfzpOfJ/NU/BOkbOd4QFVt8dCm0GEWOH2Z7O5xA+Z0UTBNEu2REj2bbf/hzD+Jo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791364314; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wUNp40dELhxkrVqCrHeTOnt3HA64O6ujKf9u59tRT3s=; b=n/kw86Rax3kJvBKg5nL/z2Us98CtNt6TeZrqRpc+8t6bC9tl/NytUNiba+M0DFMgSaVqjCntUMpcsO//qOL/23HpNk2Zgm4jbnrx6xf0XCT0Vi5+IsviDowe5yU/016UOe4pSl6a6qaiso5GCh7eQ5WaYgMRGwpobR6SQ4BrP4s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791364314192795.8671391057458; Wed, 7 Oct 2026 02:11:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENLE-0004Fs-2W; Wed, 07 Oct 2026 04:49:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEK0z-00032W-UF for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:16:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEK0w-0006AK-TR for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:16:29 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-Z1_XNN5gPEuYVUZnau7EyQ-1; Tue, 06 Oct 2026 04:34:57 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4AAB5195607F; Tue, 6 Oct 2026 08:34:56 +0000 (UTC) Received: from berrange.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 36067180034F; Tue, 6 Oct 2026 08:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791350182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wUNp40dELhxkrVqCrHeTOnt3HA64O6ujKf9u59tRT3s=; b=P0TDDPOHMneIDKJ+cjGfjVHyHV8iTH4TdODpU3E5Ks6Kl7fjus0KCyBjCYpq99kD3wuRO1 7MvfuSQwQC4XpWkyJCc1RE/eJwsa90gTltytI0REsHz2Qs/wXM7nks1SWsTmajIovJWUqj 03f8uk7ttv5S7DfRflSCam2WaBu/iFE= X-MC-Unique: Z1_XNN5gPEuYVUZnau7EyQ-1 X-Mimecast-MFC-AGG-ID: Z1_XNN5gPEuYVUZnau7EyQ_1791275696 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 2/4] io: prevent unbounded read of websocket data from client Date: Tue, 6 Oct 2026 09:34:49 +0100 Message-ID: <20261006083451.956881-3-berrange@redhat.com> In-Reply-To: <20261006083451.956881-1-berrange@redhat.com> References: <20261006083451.956881-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791364316156158500 The QIOChannelWebsock class wraps an underlying QIOChannel instance, providing a websocket server handshake and packet encoding/decoding. When a watch is added to QIOChannelWebsock, this in turn creates a watch on the underlying QIOChannel that is always monitoring G_IO_IN, as long as the 'encinput' buffer has space. When this watch fires, it reads data off the wire into 'encinput' and then decodes as much of 'encinput' as possible into the 'rawinput' buffer. The qio_channel_websock_set_watch method checks to see that 'encinput' does not exceed a max limit, but fails to check that 'rawinput' size. Since any data read into 'encinput', can usually be immediately decoded into 'rawinput', the 'encinput' size check is largely a no-op, and so 'rawinput' will grow without bound. This is readily seen with the chardev socket backend if enabling websockets, connecting a client that sends data, while not running any guest OS to consume data from the chardev via a virtual serial port. The qio_channel_websock_read_wire() method will also unconditionally read more data into 'encinput' if it has less than 4k present, which is then decoded into 'rawinput'. IOW, if qio_channel_websock_read_wire() is triggered for lots of small reads, it will be reading and decoding more data to 'rawinput' than is consumed. Skip reading more data if 'rawinput' is already at its max size. Reported-by: Aisle Research Fixes: CVE-2026-101291 Fixes: 2d1d0e70cf3e ("io: add QIOChannelWebsock class") Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- io/channel-websock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/io/channel-websock.c b/io/channel-websock.c index 461abcae487..646cd45be2a 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -970,7 +970,8 @@ static ssize_t qio_channel_websock_read_wire(QIOChannel= Websock *ioc, { ssize_t ret; =20 - if (ioc->encinput.offset < 4096) { + if (ioc->encinput.offset < 4096 && + ioc->rawinput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER) { size_t want =3D 4096 - ioc->encinput.offset; =20 buffer_reserve(&ioc->encinput, want); @@ -1091,6 +1092,7 @@ static void qio_channel_websock_set_watch(QIOChannelW= ebsock *ioc) cond |=3D G_IO_OUT; } if (ioc->encinput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER && + ioc->rawinput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER && !ioc->io_eof) { cond |=3D G_IO_IN; } --=20 2.55.0 From nobody Mon Nov 23 05:00:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791364391; cv=none; d=zohomail.com; s=zohoarc; b=WTN1dtJplTFCUI5vR+HxcqzhLfyEwDxXBuWz7+eqxNWBIp3tacok1bCfOrKKiZX6C3f+OwLhoLMOw3wk3z06MDuu8fcf/Cvxlc/RTG1CEqb5rSrPXXFzyqxGEE9hxx98Dp21hY1Bl5CiZTAFxbwb3mguqliuVAtEJMJRXWwNH+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791364391; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FCndgU01yR3d8HyPbhGVfu21sZ38RP7fYu7mPLwomlA=; b=OBGzIb0GABPPA4MMbW3k1SKtC/P/pFCTYcdppu4HKXEoSoqGA+vvuEuNJ0IfYyrjE2RT6PX18YaTagFcN6QBjtqMOiS0K9BAljeVUysxCzwWW/58j0iAcr++k8KE7VFRC1FlwvZee4HJq248aa4Z9w6jprUF6s/C7zJvXcveh5U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791364391890410.2102987097819; Wed, 7 Oct 2026 02:13:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENLA-0003yA-Ig; Wed, 07 Oct 2026 04:49:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEJqq-0001MB-0q for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:06:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEJqg-000570-2r for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:05:57 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-191-ZVcJpECSPzSlLvDnt-yzUg-1; Tue, 06 Oct 2026 04:34:58 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 14E0718512E4 for ; Tue, 6 Oct 2026 08:34:58 +0000 (UTC) Received: from berrange.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6EB2180034F; Tue, 6 Oct 2026 08:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791349544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FCndgU01yR3d8HyPbhGVfu21sZ38RP7fYu7mPLwomlA=; b=Z1vDV9xiOQahSoUNDrBRzZq7nnL6Yzb4dv1wS8bjc4iwIfZDUEqOCJ2DyACaPpTe1O1w3J r0qrLotmcNXcQfHpmMwqcJSaNszxOTBW1BH9Es3olIZFK+mgrN9JDPOxyuEA4VFv0esVCL XntV0amXfTTeZzfUE+I48DVonoNIfp0= X-MC-Unique: ZVcJpECSPzSlLvDnt-yzUg-1 X-Mimecast-MFC-AGG-ID: ZVcJpECSPzSlLvDnt-yzUg_1791275698 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Juraj Marcin Subject: [PULL 3/4] io: cork TLS writes to avoid small TLS records Date: Tue, 6 Oct 2026 09:34:50 +0100 Message-ID: <20261006083451.956881-4-berrange@redhat.com> In-Reply-To: <20261006083451.956881-1-berrange@redhat.com> References: <20261006083451.956881-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791364392664158500 The migration code caches vmstate/ram writes into an iovec and flushes this periodically. The total amount of data to sent may be 100's of KB, but split across many iovec, each of which is potentially quite small. The QIOChannelTLS receives the iovec, but since GNUTLS cannot accept iovec data, it iterates calling send for each element. As a result of the migration data pattern, this results in GNUTLS putting lots of small TLS records on the wire. This has shown writes alternate between about 4k and 30 bytes in some tests. This is triggering the nagle algorithm on migration-test for many of the TLS test cases, resulting in a "go slow" for I/O that eventually hits the migration timeout configured by the test. Not every contributor reports seeing the "go slow" but for those who do see it, it hits >=3D 95% of the time for at least one of the migration TLS test cases run by 'make check'. While we could disable the nagle algorithm (and multifd channels already do this), that would stil result in lots of small TLS records hitting the wire which is not good for throughput. The migration code flushes in batches because it wants large writes for high throughput. To achieve this we must tell GNUTLS to encrypt data but not immediately sent TLS records by "corking" its output. Once the complete iovec has been written to GNUTLS, it can be uncorked allowing it to hit the wire. There is added complexity with uncorking on non-blocking channels as not all encrypted data can be sent at once. qio_channel_write() will return what was sent, but some data might remain pending inside GNUTLS buffers. A later call to qio_channel_write() will provide the same plain text data buffers that have already been cached. Thus the code must attempt to uncork GNUTLS again to clear pending data and then deduct the equivalent amount of plain text. Overall this corking action fixes the test suite timeouts, but more importantly, it also improves the performance of TLS protection migrations in the real world. Tests with one workload show at 36% increase in throughput. Reviewed-by: Peter Xu Tested-by: Juraj Marcin Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/tlssession.c | 45 +++++++++++++++++++ include/crypto/tlssession.h | 25 +++++++++++ include/io/channel-tls.h | 1 + io/channel-tls.c | 87 ++++++++++++++++++++++++++++++++++--- 4 files changed, 152 insertions(+), 6 deletions(-) diff --git a/crypto/tlssession.c b/crypto/tlssession.c index 314e3e96ba8..b343d1a5956 100644 --- a/crypto/tlssession.c +++ b/crypto/tlssession.c @@ -513,6 +513,39 @@ qcrypto_tls_session_read(QCryptoTLSSession *session, } =20 =20 +void qcrypto_tls_session_write_cork(QCryptoTLSSession *sess) +{ + gnutls_record_cork(sess->handle); +} + + +ssize_t qcrypto_tls_session_write_uncork(QCryptoTLSSession *sess, + Error **errp) +{ + int ret; + ret =3D gnutls_record_uncork(sess->handle, 0); + if (ret =3D=3D GNUTLS_E_AGAIN || + ret =3D=3D GNUTLS_E_INTERRUPTED) { + ret =3D gnutls_record_check_corked(sess->handle); + if (ret < 0) { + error_setg(errp, + "Cannot query pending TLS output: %s", + gnutls_strerror(ret)); + return -1; + } + + return ret; + } else if (ret < 0) { + error_setg(errp, + "Cannot uncork TLS output: %s", + gnutls_strerror(ret)); + return -1; + } + + return 0; +} + + size_t qcrypto_tls_session_check_pending(QCryptoTLSSession *session) { @@ -757,4 +790,16 @@ qcrypto_tls_session_get_peer_name(QCryptoTLSSession *s= ess) return NULL; } =20 +void qcrypto_tls_session_write_cork(QCryptoTLSSession *sess) +{ +} + + +ssize_t qcrypto_tls_session_write_uncork(QCryptoTLSSession *sess, + Error **errp) +{ + error_setg(errp, "TLS requires GNUTLS support"); + return -1; +} + #endif diff --git a/include/crypto/tlssession.h b/include/crypto/tlssession.h index 28e419681e4..5415503ebab 100644 --- a/include/crypto/tlssession.h +++ b/include/crypto/tlssession.h @@ -208,6 +208,31 @@ typedef ssize_t (*QCryptoTLSSessionReadFunc)(void *buf, void *opaque, Error **errp); =20 +/** + * qcrypto_tls_session_write_cork: + * @sess: the TLS session object + * + * Causes future qcrypto_tls_session_write() calls to encrypt + * and queue data, without sending on the wire. + */ +void qcrypto_tls_session_write_cork(QCryptoTLSSession *sess); + +/** + * qcrypto_tls_session_write_uncork: + * @sess: the TLS session object + * @errp: pointer to a NULL-initialized error object + * + * Attempt to send previously queued data. If the underlying + * stream is non-blocking, then only a subset of data (if any) + * may be written. To process outstanding data, this method + * must be called again until it returns 0. + * + * Returns: the number of bytes remaining to be sent, + * or -1 on error. + */ +ssize_t qcrypto_tls_session_write_uncork(QCryptoTLSSession *sess, + Error **errp); + /** * qcrypto_tls_session_set_callbacks: * @sess: the TLS session object diff --git a/include/io/channel-tls.h b/include/io/channel-tls.h index 7e9023570d8..9e9b00c034b 100644 --- a/include/io/channel-tls.h +++ b/include/io/channel-tls.h @@ -50,6 +50,7 @@ struct QIOChannelTLS { QIOChannelShutdown shutdown; guint hs_ioc_tag; guint bye_ioc_tag; + size_t corked; }; =20 /** diff --git a/io/channel-tls.c b/io/channel-tls.c index 31ec4d236de..05317ed5a38 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/module.h" +#include "qemu/iov.h" #include "io/channel-tls.h" #include "trace.h" #include "qemu/atomic.h" @@ -448,12 +449,24 @@ static ssize_t qio_channel_tls_writev(QIOChannel *ioc, QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(ioc); size_t i; ssize_t done =3D 0; + ssize_t remain; + g_autofree struct iovec *tmpiov =3D NULL; + size_t ntmpiov =3D 0; =20 - for (i =3D 0 ; i < niov ; i++) { - ssize_t ret =3D qcrypto_tls_session_write(tioc->session, - iov[i].iov_base, - iov[i].iov_len, - errp); + /* + * The previous write encrypted all the data, but some + * was not able to be sent on the wire when uncorked, + * so we returned a short write. The encrypted data + * will still be cached by GNUTLS and the session will + * be in a corked state. + * + * This write call will be trying to write the remaining + * plain text data again, but we must avoid sending that + * into GNUTLS. Instead flush the previously encrypted + * pending data. + */ + while (tioc->corked) { + ssize_t ret =3D qcrypto_tls_session_write_uncork(tioc->session, er= rp); if (ret =3D=3D QCRYPTO_TLS_SESSION_ERR_BLOCK) { if (done) { return done; @@ -463,12 +476,74 @@ static ssize_t qio_channel_tls_writev(QIOChannel *ioc, } else if (ret < 0) { return -1; } + done +=3D (tioc->corked - ret); + tioc->corked =3D ret; + } + + /* + * If we flushed pending data, we must discard an + * equivalent amount of plain text data from this + * write call, and then process what's left over, + * if any. + */ + if (done) { + ssize_t total =3D iov_size(iov, niov); + if (done =3D=3D total) { + return done; + } + + tmpiov =3D g_new0(struct iovec, niov); + ntmpiov =3D iov_copy(tmpiov, niov, iov, niov, + done, total - done); + + iov =3D tmpiov; + niov =3D ntmpiov; + } + + /* + * At this point we should ony be processing "new" + * data, not seen by a previous write call so we + * send to GNUTLS as normal. + */ + qcrypto_tls_session_write_cork(tioc->session); + for (i =3D 0 ; i < niov ; i++) { + ssize_t ret =3D qcrypto_tls_session_write(tioc->session, + iov[i].iov_base, + iov[i].iov_len, + errp); + if (ret =3D=3D QCRYPTO_TLS_SESSION_ERR_BLOCK) { + error_setg(errp, "Unexpected TLS blocking I/O while corked"); + return -1; + } else if (ret < 0) { + return -1; + } done +=3D ret; if (ret < iov[i].iov_len) { break; } } - return done; + + /* + * On non-blocking sockets, uncorking may not succeed + * in sending all encrypted data, so we have to check + * what was actually sent to see if GNUTLS remains in + * the corked state with pending data. + */ + remain =3D qcrypto_tls_session_write_uncork(tioc->session, errp); + if (remain < 0) { + return -1; + } else if (remain) { + tioc->corked =3D remain; + } + /* + * done =3D=3D what we sent to GNUTLS for encryption & sending + * remain =3D=3D subset of 'done' that was encrypted but not sent + */ + if (done && (remain =3D=3D done)) { + return QIO_CHANNEL_ERR_BLOCK; + } else { + return done - remain; + } } =20 static int qio_channel_tls_set_blocking(QIOChannel *ioc, --=20 2.55.0 From nobody Mon Nov 23 05:00:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1791363829; cv=none; d=zohomail.com; s=zohoarc; b=A/4a35Fk4HSUqQ2IsrMhoEf1LXv21SnjwqPikAwQlPqFLgk8EQNJB7KkI1vJ8Um8Pje9huf6TkNFoLVIGwwnsTEcYTdUPRyK9KaWdOsdfKdxvWH48CMExvm1FAs61sc7dADV81oqxMs4WAIF/7sEadeB2ygVIBQX7cb3DZJOu3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791363829; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S1SEmEFGXTOO8eYndp8ctq8G7E/DAJIG11Mq9r7apRQ=; b=ClwRnQU2XUvMPp60+yxnwpX/otDey3/D7fgee1nywameAVTqYCO72Jf4v/KLkshiVbUDXnDrGhp6fxfP5ggNGrioA+LiYh68vuXOHxCgsq4cLzUIo3D5Gmku73DoQPqGhv9iBL1oFnvYOT/6k4x2BOyUYCskxDwB3QujkwYqciM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791363829355766.5239450770242; Wed, 7 Oct 2026 02:03:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xENLC-0004Al-MW; Wed, 07 Oct 2026 04:49:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEK0z-00032V-Tv for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:16:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEK0r-0006AC-Ux for qemu-devel@nongnu.org; Wed, 07 Oct 2026 01:16:27 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-208-ap1KMDXNMdO8sXP-XrFlcw-1; Tue, 06 Oct 2026 04:35:00 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 509861954211 for ; Tue, 6 Oct 2026 08:34:59 +0000 (UTC) Received: from berrange.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 678BC180034F; Tue, 6 Oct 2026 08:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791350178; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S1SEmEFGXTOO8eYndp8ctq8G7E/DAJIG11Mq9r7apRQ=; b=gEjraWAZOkNIXnAizTDGnWUGSyH82yclSDoHH3yDJqvL7kPRZF2YJJ5K+ZBsqSemKzeS0y rZSEvcwPSYNyiiRDKIpBT9ip/oyQwrai6vmnIShwBOaRWi/uzfgLuz3wAPtU6MPy26xWTu wdzCUilBfm6+YuEkGlfbCIxyRz4BDfc= X-MC-Unique: ap1KMDXNMdO8sXP-XrFlcw-1 X-Mimecast-MFC-AGG-ID: ap1KMDXNMdO8sXP-XrFlcw_1791275699 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 4/4] seccomp: fix blocking of setns/execveat/unshare Date: Tue, 6 Oct 2026 09:34:51 +0100 Message-ID: <20261006083451.956881-5-berrange@redhat.com> In-Reply-To: <20261006083451.956881-1-berrange@redhat.com> References: <20261006083451.956881-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1791363831733158500 The initializer for these syscalls missed the seccomp action field, so it got the default action which was to kill the calling thread, instead of returning an errno value, which the other equivalent syscalls use. Since we don't ever intend to use a seccomp filter without a defined action, use an assert to validate that action is always set to non-zero. Reported-by: Igor Santos-Grueiro (gitlab:@igorsantosgrueiro) Fixes: https://gitlab.com/qemu-project/qemu/-/work_items/4600 Fixes: 4638057110 (seccomp: block setns, unshare and execveat syscalls) Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Daniel P. Berrang=C3=A9 --- system/qemu-seccomp.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/system/qemu-seccomp.c b/system/qemu-seccomp.c index f8e1238b914..3889d48b4f2 100644 --- a/system/qemu-seccomp.c +++ b/system/qemu-seccomp.c @@ -249,10 +249,13 @@ static const struct QemuSeccompSyscall denylist[] =3D= { 0, NULL, SCMP_ACT_ERRNO(ENOSYS) }, #endif #ifdef __SNR_execveat - { SCMP_SYS(execveat), QEMU_SECCOMP_SET_SPAWN }, + { SCMP_SYS(execveat), QEMU_SECCOMP_SET_SPAWN, + ARRAY_SIZE(clone_arg_none), clone_arg_none, SCMP_ACT_ERRNO(EPERM) }, #endif - { SCMP_SYS(setns), QEMU_SECCOMP_SET_SPAWN }, - { SCMP_SYS(unshare), QEMU_SECCOMP_SET_SPAWN }, + { SCMP_SYS(setns), QEMU_SECCOMP_SET_SPAWN, + ARRAY_SIZE(clone_arg_none), clone_arg_none, SCMP_ACT_ERRNO(EPERM) }, + { SCMP_SYS(unshare), QEMU_SECCOMP_SET_SPAWN, + ARRAY_SIZE(clone_arg_none), clone_arg_none, SCMP_ACT_ERRNO(EPERM) }, /* resource control */ { SCMP_SYS(setpriority), QEMU_SECCOMP_SET_RESOURCECTL, 0, NULL, SCMP_ACT_ERRNO(EPERM) }, @@ -337,6 +340,12 @@ static int seccomp_start(uint32_t seccomp_opts, Error = **errp) if (!(seccomp_opts & denylist[i].set)) { continue; } + /* + * action =3D=3D 0 is SCMP_ACT_KILL_THREAD which is not + * something we ever want to use. Validate it to protect + * against missing struct field initializers + */ + assert(denylist[i].action); =20 action =3D qemu_seccomp_update_action(denylist[i].action); rc =3D seccomp_rule_add_array(ctx, action, denylist[i].num, --=20 2.55.0