From nobody Mon Nov 23 04:34:11 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=1794092404; cv=none; d=zohomail.com; s=zohoarc; b=gQE4P7MBtQksDptoR5e7chYIfxeO+9dYD67sjdf2bOVJLqjjCaq4SNrfIXjt+mVHh11Gn0bB5bbVsyFUfbURRMoEWINinGinyFbjJXEKssdLtzv3olDb/ZNqrnY0gsBMnxRETNnAotd65K1HnYszY9O5f0T1DOXAJ0Fycma4YMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794092404; 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=Ed41uV7/MDec/L7nxah8JDQN7dNidJNpoC1RnOdFGOU=; b=TmP+VlHTelCNMeGEKGGqQJfyYbwrw8sttHRQheaIbxjCvheT6CY5xGAm9rAElkKAlVMd+NrKRdLVe4yXZKVh7mm7nNNYNpy3CoRaKOQ0RTN3DdD82yt23GHePfiOiXfeSlm672yyk4KWzsGU54FgWVlwrnqEblK8A+LC3HO02Es= 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 17940924044571018.4159724062372; Sat, 7 Nov 2026 15:00:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xPpN3-0007l1-2Z; Sat, 07 Nov 2026 17:58:49 -0500 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 1xPpN0-0007ju-Te for qemu-devel@nongnu.org; Sat, 07 Nov 2026 17:58:47 -0500 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 1xPpMz-0002WV-55 for qemu-devel@nongnu.org; Sat, 07 Nov 2026 17:58:46 -0500 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-674-wT33DzpxPBmWO4BYcSE3oQ-1; Sat, 07 Nov 2026 17:58:42 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 45CBE1956094; Sat, 7 Nov 2026 22:58:41 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BB8D61956087; Sat, 7 Nov 2026 22:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794092324; 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=Ed41uV7/MDec/L7nxah8JDQN7dNidJNpoC1RnOdFGOU=; b=H6YBZ2ePWaXPOYuGMgToPM8FtnvqAXRCkBCKn2P+sz/M+CX0hHnxKvUnW4zMkY7wqydT0B ZEKReHFds0YZJo4vHd9ZTdfJhmALe/1j1ZvsG+xIz4Lf+js/GDeX3L3UOs2z0rh6Rb4Uw8 KAPrIYA2Khhn5K043XD+v+Cs2a8pfI0= X-MC-Unique: wT33DzpxPBmWO4BYcSE3oQ-1 X-Mimecast-MFC-AGG-ID: wT33DzpxPBmWO4BYcSE3oQ_1794092321 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, berrange@redhat.com, qemu-block@nongnu.org, Pierrick Bouvier Subject: [PATCH v2 1/3] docs: Mention security considerations for NBD Date: Sat, 7 Nov 2026 16:54:36 -0600 Message-ID: <20261107225834.778738-6-eblake@redhat.com> In-Reply-To: <20261107225834.778738-5-eblake@redhat.com> References: <20261107225834.778738-5-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MARKETING_PARTNERS=0.001, RCVD_IN_DNSWL_LOW=-0.7, 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: 1794092406746158500 Content-Type: text/plain; charset="utf-8" Document a policy that NBD connections should strongly consider using TLS and x509 certificates to filter out untrusted clients. If a malicious server or client can trigger a QEMU assertion failure on a plaintext connection, but can be trivially mitigated by enabling TLS to weed out untrusted partners that would violate the protocol in the first place, then I prefer to treat the bug as a lower-priority issue, which our policy states can be fixed without an embargo. Signed-off-by: Eric Blake --- docs/system/security.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/system/security.rst b/docs/system/security.rst index e211fdd2344..7b422d51472 100644 --- a/docs/system/security.rst +++ b/docs/system/security.rst @@ -320,3 +320,24 @@ encryption and authorization control policy on client = connections. In summary, the monitor console is considered a privileged control interfa= ce to QEMU and as such should only be made accessible to a trusted management application or user. + +Block device network protocols (NBD, NFS, etc.) +''''''''''''''''''''''''''''''''''''''''''''''' + +When using QEMU to access remote storage over a network (such as QEMU +acting as an NBD or NFS client) or to provide remote storage access +(such as QEMU acting as an NBD server), it is important to realize +that an unencrypted connection can allow an external process a +potential attack vector over the network port. When possible, QEMU +should be configured to require TLS to prevent a man-in-the-middle +attack, as well as use x509 client certificates with the +tls-creds-x509 object set with 'verify-peer=3Don' to check that the peer +is allowed to connect. It may also be worth using 'tls-authz' to +filter which certificates are allowed if the CA issues certs more +broadly. + +Proper hardening of network connections can prevent the use of +untrusted clients, and is therefore a factor when considering whether +a malicious network partner that intentionally violates the +communication protocol to trigger a QEMU bug can be treated as a lower +priority bug. --=20 2.56.0 From nobody Mon Nov 23 04:34:11 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=1794092396; cv=none; d=zohomail.com; s=zohoarc; b=ADBW8NXxRE6YRBhhlneuEHTS+5MAyo2WuEHx9+0mtWKQ8X2RKLrTraYUmajZbA8/KC3v2J2szUD7wKOiKWnQh/XWkahm5BXp2YxkU5IshOXvhrm2pbzAJMBI/Bk3vQzGOnaq5gZP6FXt45xO+K26i5/ezO+MeMSzGkLbp+coycs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794092396; 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=Da/T+fUtd44qm5xafJ/rRrWKWUlWL/xwLeHZkwQ3Kqw=; b=d9cjK2ugY04Q/UvXe9Ky9n1lVxVqL0ulNeg8z0ZYMLO4q6EHSKLD1XpeVmCTmYoP92LkgoLEaON/x/Vo8QeI1fVbOha/u1/dHl/oY9/QXMp8M3VVdr4lKqvlv6XY1HpByUlSsvA1T64dedg28jHLcPvMZ0k7hTV88Ge9UXkQKd4= 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 1794092396501334.3924213176043; Sat, 7 Nov 2026 14:59:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xPpN6-0007mJ-47; Sat, 07 Nov 2026 17:58:52 -0500 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 1xPpN4-0007lX-Bt for qemu-devel@nongnu.org; Sat, 07 Nov 2026 17:58:50 -0500 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 1xPpN2-0002XS-N6 for qemu-devel@nongnu.org; Sat, 07 Nov 2026 17:58:50 -0500 Received: from mx-prod-mc-06.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-553-r1q105RLOHO0SroZb-WNoA-1; Sat, 07 Nov 2026 17:58:44 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6D1791800366; Sat, 7 Nov 2026 22:58:43 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 966431956087; Sat, 7 Nov 2026 22:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794092328; 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=Da/T+fUtd44qm5xafJ/rRrWKWUlWL/xwLeHZkwQ3Kqw=; b=E56lhQ0le1EvOhCvPA8jV+yTvl0bvEc/vSWcBThKqEt2ALxKhN0SKKqilQau2g8F0bjOfB +7WVoU3HehKd6n+Dr6L87myGQUgo2IedJWR6nCA5x/NbfZq6bnhD/4N3ujYSsuP0Z4Y2pm 96Q0OQWJdlzCpET27CxZWtqRFmxTUdY= X-MC-Unique: r1q105RLOHO0SroZb-WNoA-1 X-Mimecast-MFC-AGG-ID: r1q105RLOHO0SroZb-WNoA_1794092323 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, berrange@redhat.com, qemu-block@nongnu.org, Feifan Qian , Haotian Jiang , Vladimir Sementsov-Ogievskiy Subject: [PATCH v2 2/3] nbd/server: Reject rather than assert on non-compliant BLOCK_STATUS Date: Sat, 7 Nov 2026 16:54:37 -0600 Message-ID: <20261107225834.778738-7-eblake@redhat.com> In-Reply-To: <20261107225834.778738-5-eblake@redhat.com> References: <20261107225834.778738-5-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=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: 1794092398664158500 Content-Type: text/plain; charset="utf-8" The NBD spec is clear that a client must not send NBD_BLOCK_STATUS requests to a server if it did not negotiate any metacontexts with NBD_OPT_SET_META_CONTEXT. However, if the non-compliant client uses NBD_OPT_EXTENDED_HEADERS and then passes in the relatively new NBD_CMD_FLAG_PAYLOAD_LEN flag alongside an inappropriate block status request, this was enough to trigger an assertion in qemu. If you do not use recommended practice to prevent untrusted clients from connecting to QEMU's NBD server, then you are at risk of a denial of service attack from a rogue client. Per our stated policy on flaws triggered by network connections, this is considered a low-severity security flaw, since it is trivial to avoid by using proper configuration of TLS and x509 certificate authorization to reject rogue clients; therefore, no CVE has been assigned yet. Fixes: 2dcbb11b ("nbd/server: Add FLAG_PAYLOAD support to CMD_BLOCK_STATUS"= , v8.2.0) Reported-by: Feifan Qian Reported-by: https://gitlab.com/qemu-project/qemu/-/work_items/3796 CC: Haotian Jiang CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- nbd/server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index e6c47f8c2e3..bc37cbcb338 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2584,12 +2584,12 @@ nbd_co_block_status_payload_read(NBDClient *client,= NBDRequest *request, return -EINVAL; } - assert(client->contexts.exp =3D=3D client->exp); nr_bitmaps =3D client->exp->nr_export_bitmaps; request->contexts =3D g_new0(NBDMetaContexts, 1); request->contexts->exp =3D client->exp; - if (payload_len % sizeof(uint32_t) || + if (!client->contexts.count || + payload_len % sizeof(uint32_t) || payload_len < sizeof(NBDBlockStatusPayload) || payload_len > (sizeof(NBDBlockStatusPayload) + sizeof(id) * client->contexts.count)) { --=20 2.56.0 From nobody Mon Nov 23 04:34:11 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=1794092426; cv=none; d=zohomail.com; s=zohoarc; b=R9JDtDT5Tm44Xyfy3R3iAULUOoOGOYrVNjv/1kZYSDezSQKQ9BlRP3kx/cbd3ODVpbyeiX4/KmthixT7IZYz9uzarHsX2h4uWGh1GNfjSG/DqYscKOtvTY9f5Ld6Cg8WwSl4R8sxOqchTMJSOu2UQpxlawJwbPbC4acpfxH5v7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794092426; 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=KqYUq7WMHzVCDZljDRU/WxFMBp9GRrRbOTtyuv50r2g=; b=iKzP5onD4KXsBBEBtF4H6ywKsK6yCWGDOuwzASn4Pfdgg/mLxSgvmxBALSgjQtr+veVyEiG9MfkveBFvVrxQqUEGklktKH8+bu2T+550jSgVGBBvrECvKWvtK9nRZ9KSVIlg9AiPjmfCyKWKDtFfKpNReMNnvy1h5uqtLY+XFK0= 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 1794092426564768.1166800528329; Sat, 7 Nov 2026 15:00:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xPpN8-0007nQ-HQ; Sat, 07 Nov 2026 17:58:54 -0500 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 1xPpN6-0007mQ-8K for qemu-devel@nongnu.org; Sat, 07 Nov 2026 17:58:52 -0500 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 1xPpN4-0002Xq-A4 for qemu-devel@nongnu.org; Sat, 07 Nov 2026 17:58:51 -0500 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-594-GwHORIs4P86dv8FYVZfJVA-1; Sat, 07 Nov 2026 17:58:46 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 1438F19560AF; Sat, 7 Nov 2026 22:58:45 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B06B01956087; Sat, 7 Nov 2026 22:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794092329; 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=KqYUq7WMHzVCDZljDRU/WxFMBp9GRrRbOTtyuv50r2g=; b=Qeq22Y+mFZ6JTtELD8eeRhLmf2TTOYWvpf1qEEeI9xUMKEd4y8te4LiiWjyLCamEXUL7zR GVaQuNfsQHj8bK3uw8H4bLPODLQuUw0///9Z8bECONGAdLHXjK6U67TfiYk4Z/84NjHKdg 49Q5N7SaZfc0ylCMdpMF62RztJTQ2kQ= X-MC-Unique: GwHORIs4P86dv8FYVZfJVA-1 X-Mimecast-MFC-AGG-ID: GwHORIs4P86dv8FYVZfJVA_1794092325 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, berrange@redhat.com, qemu-block@nongnu.org, Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz Subject: [PATCH v2 3/3] iotests: Add new nbd-robustness test Date: Sat, 7 Nov 2026 16:54:38 -0600 Message-ID: <20261107225834.778738-8-eblake@redhat.com> In-Reply-To: <20261107225834.778738-5-eblake@redhat.com> References: <20261107225834.778738-5-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: 1794092428907158500 Content-Type: text/plain; charset="utf-8" Convert the proof of concept test by Sunday Jiang into an iotest. I tried to get libnbd to trigger the situation, but forcing a block status command when no status has been initiated is not something that libnbd is willing to do. So this results in a hard-coded sequence of bytes sent over a raw socket. Swapping the order with the previous patch shows the assertion failure that was previously reachable. Based-on: https://gitlab.com/qemu-project/qemu/-/work_items/4091 Signed-off-by: Eric Blake --- tests/qemu-iotests/tests/nbd-robustness | 137 ++++++++++++++++++++ tests/qemu-iotests/tests/nbd-robustness.out | 5 + 2 files changed, 142 insertions(+) create mode 100755 tests/qemu-iotests/tests/nbd-robustness create mode 100644 tests/qemu-iotests/tests/nbd-robustness.out diff --git a/tests/qemu-iotests/tests/nbd-robustness b/tests/qemu-iotests/t= ests/nbd-robustness new file mode 100755 index 00000000000..602b7060854 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-robustness @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +# group: rw auto quick +# +# Test cases for NBD robustness against malicious clients +# +# Copyright (C) 2026 Red Hat, Inc. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +from contextlib import contextmanager + +import iotests +from iotests import qemu_img_create, qemu_io + +import socket +import struct + + +disk =3D os.path.join(iotests.test_dir, 'disk') +size =3D '4M' +nbd_sock =3D os.path.join(iotests.sock_dir, 'nbd_sock') +nbd_uri =3D 'nbd+unix:///{}?socket=3D' + nbd_sock +nbd: ModuleType + + +class TestNbdRobustness(iotests.QMPTestCase): + def setUp(self): + qemu_img_create('-f', iotests.imgfmt, disk, size) + qemu_io('-c', 'w -P 1 0 2M', '-c', 'w -P 2 2M 2M', disk) + + self.vm =3D iotests.VM() + self.vm.launch() + self.vm.cmd('blockdev-add', { + 'driver': 'qcow2', + 'node-name': 'n', + 'file': {'driver': 'file', 'filename': disk} + }) + + def tearDown(self): + self.vm.shutdown() + os.remove(disk) + try: + os.remove(nbd_sock) + except OSError: + pass + + @contextmanager + def run_server(self, max_connections=3DNone): + args =3D { + 'addr': { + 'type': 'unix', + 'data': {'path': nbd_sock} + } + } + if max_connections is not None: + args['max-connections'] =3D max_connections + + self.vm.cmd('nbd-server-start', args) + yield + + self.vm.cmd('nbd-server-stop') + + def add_export(self, name, writable=3DNone): + args =3D { + 'type': 'nbd', + 'id': name, + 'node-name': 'n', + 'name': name, + } + if writable is not None: + args['writable'] =3D writable + + self.vm.cmd('block-export-add', args) + + def test_invalid_block_status(self): + with self.run_server(): + self.add_export('r') + + # Use raw socket traffic to intentionally violate NBD protocol + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: + s.connect(nbd_sock) + # Server sends NBDMAGIC(8) + IHAVEOPT(8) + flags(2) + data =3D s.recv(18) + magic, opt, flags =3D struct.unpack(">QQH", data) + assert magic =3D=3D 0x4e42444d41474943 + assert opt =3D=3D 0x49484156454f5054 + assert flags =3D=3D 0x3 + + # Reply with flags(4) - just fixed newstyle flag + s.send(struct.pack(">I", 1)) + + # Request NBD_OPT_EXTENDED_HEADERS, no extra payload + s.send(struct.pack(">QII", 0x49484156454f5054, 11, 0)) + + # Expect successful reply: + # magic(8) + option(4) + reply(4) + length(4) + data =3D s.recv(20) + magic, opt, reply, length =3D struct.unpack(">QIII", data) + assert magic =3D=3D 0x3e889045565a9 + assert opt =3D=3D 11 + assert reply =3D=3D 1 + assert length =3D=3D 0 + + # Request NBD_OPT_GO, name but no info as payload + payload =3D struct.pack(">I", 1) + b'r' + struct.pack(">H"= , 0) + s.send(struct.pack(">QII", 0x49484156454f5054, 7, len(payl= oad)) + + payload) + + # Expect (and ignore) zero or more info packets before ack + while True: + data =3D s.recv(20) + magic, opt, reply, length =3D struct.unpack(">QIII", d= ata) + assert magic =3D=3D 0x3e889045565a9 + assert opt =3D=3D 7 + payload =3D s.recv(length) + if reply !=3D 3: + break + assert reply =3D=3D 1 + + # Send invalid NBD_CMD_BLOCK_STATUS with payload flag. This + # violates the NBD protocol (since no context was negotiat= ed), + # but should not crash the server. + payload =3D struct.pack(">QI", 0x1000, 0) + s.send(struct.pack(">IHHQQQ", 0x21e41c71, 0x20, 7, 1, 0, + len(payload)) + payload) + + # Expect a rejection. + data =3D s.recv(32) + magic, flags, rtype, cookie, offs, length =3D struct.unpac= k(">IHHQQQ", data) + assert magic =3D=3D 0x6e8a278c + assert rtype & 0x8000 =3D=3D 0x8000 + assert cookie =3D=3D 1 + s.recv(length) + +if __name__ =3D=3D '__main__': + iotests.main(supported_fmts=3D['qcow2']) diff --git a/tests/qemu-iotests/tests/nbd-robustness.out b/tests/qemu-iotes= ts/tests/nbd-robustness.out new file mode 100644 index 00000000000..ae1213e6f86 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-robustness.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK --=20 2.56.0