From nobody Mon Nov 23 04:44:09 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=1794369158; cv=none; d=zohomail.com; s=zohoarc; b=VAr/hXLhVzf7f5qXhJfcUiEobc2gp2j/Y6t1fjWuJH6cbqdvTxoUVgYUW9T5NiMyrqU7e8S3V3yYTmbtaG0GRkppOiDvJU6xBTTeUlXLwswUM+WL6lG41H2Fj+/NXwT7MGHvDRm5OE7UoWqO43oE93YhSIoP6Gag8n+G7WsmWpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794369158; 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=i1AKJqaPnLKcQBMZBJ4NYyAtNxNC0XPLX9fc9JpHWoI=; b=aSHBzwmleBjFDMilqBGMnIsDxcU5zt1AB1b4mAhbOkvC+U1zKUHRejL9/NR6uPmHMe5e/wY9ezSYDUfvUxPyMWHcIzV/cR48v7P0ZsZFU/3yDWZdvXEAfnP+95KwF1aIBxRyWwuOxujBzcPSY9orMmfADZggbCfp4JbvSdaBU+c= 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 1794369158694198.23180516629168; Tue, 10 Nov 2026 19:52:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQzNf-0007zz-W9; Tue, 10 Nov 2026 22:52:16 -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 1xQzNd-0007xq-8o for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:13 -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 1xQzNb-0006hz-J2 for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:13 -0500 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-672-34Ytw5b_OvS1PkMZ6cNa8Q-1; Tue, 10 Nov 2026 22:52:06 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 2F32C180054F; Wed, 11 Nov 2026 03:52:05 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E9444300019F; Wed, 11 Nov 2026 03:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794369130; 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=i1AKJqaPnLKcQBMZBJ4NYyAtNxNC0XPLX9fc9JpHWoI=; b=caN3LSlKuOpWUMXbdnc2H/aPoqx81CsHIXGXCY7MNjCG0NvufV28o/l1dnjc16XgqYHF/M tnJvs975uIkYZSMUx6rjgXnEmrvup4edoHfH/HCGn2ZzQft87yxwd4+C6GIlXZQSF/45B4 Wa5/sYbwgcesTYnkJRMHIMGJjIPCWnU= X-MC-Unique: 34Ytw5b_OvS1PkMZ6cNa8Q-1 X-Mimecast-MFC-AGG-ID: 34Ytw5b_OvS1PkMZ6cNa8Q_1794369125 From: Eric Blake To: qemu-devel@nongnu.org Cc: Guillaume Vincke , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 1/8] nbd/client-connection: Fix client returning a closed channel Date: Tue, 10 Nov 2026 21:51:26 -0600 Message-ID: <20261111035200.1751734-11-eblake@redhat.com> In-Reply-To: <20261111035200.1751734-10-eblake@redhat.com> References: <20261111035200.1751734-10-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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: -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_H3=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: 1794369161636158500 Content-Type: text/plain; charset="utf-8" From: Guillaume Vincke When a server closes the connection after a successful handshake but before running any operations, the channel returned by nbd_co_establish_connection() is the closed one and the connect thread is not started. When configured with reconnect-delay=3D0 (the default), this situation generates at least two IO errors. The first one happens when trying to issue an operation to the closed socket. The connect thread will be started on the next request, which may happen long after, and will create the second error as nbd_co_establish_connection() returns a NULL channel. Peeking the channel to detect FIN or RST avoids the first IO error and does not delay the starting of the connect thread. Signed-off-by: Guillaume Vincke Reviewed-by: Eric Blake Message-ID: <20261105164124.249395-2-guillaume.vincke@ovhcloud.com> Signed-off-by: Eric Blake --- nbd/client-connection.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/nbd/client-connection.c b/nbd/client-connection.c index 6a4f0807170..aec62934d1a 100644 --- a/nbd/client-connection.c +++ b/nbd/client-connection.c @@ -274,6 +274,23 @@ void nbd_client_connection_release(NBDClientConnection= *conn) } } +/* Only true when the peer closed the channel. Does not detect if dead. */ +static bool nbd_channel_is_closed(QIOChannel *ioc) +{ + char data; + struct iovec iov =3D { .iov_base =3D &data, .iov_len =3D 1 }; + ssize_t len =3D -1; + + if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) { + return false; + } + + len =3D qio_channel_readv_full( + ioc, &iov, 1, NULL, NULL, QIO_CHANNEL_READ_FLAG_MSG_PEEK, NULL); + + return len =3D=3D 0 || (len < 0 && len !=3D QIO_CHANNEL_ERR_BLOCK); +} + /* * Get a new connection in context of @conn: * if the thread is running, wait for completion @@ -295,6 +312,7 @@ nbd_co_establish_connection(NBDClientConnection *conn, = NBDExportInfo *info, bool blocking, Error **errp) { QemuThread thread; + QIOChannel *ioc; if (conn->do_negotiation) { assert(info); @@ -308,6 +326,20 @@ nbd_co_establish_connection(NBDClientConnection *conn,= NBDExportInfo *info, assert(!conn->wait_co); if (!conn->running) { + if (conn->sioc) { + /* discard if the socket got closed by its peer */ + ioc =3D QIO_CHANNEL(conn->sioc); + if (!qio_channel_set_blocking(ioc, false, NULL) || + nbd_channel_is_closed(ioc)) { + + qio_channel_close(ioc, NULL); + object_unref(OBJECT(conn->sioc)); + conn->sioc =3D NULL; + object_unref(OBJECT(conn->ioc)); + conn->ioc =3D NULL; + } + } + if (conn->sioc) { /* Previous attempt finally succeeded in background */ if (conn->do_negotiation) { --=20 2.56.0 From nobody Mon Nov 23 04:44:09 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=1794369156; cv=none; d=zohomail.com; s=zohoarc; b=gH7zap19rQTojZeEcsn5rhv+5zfa7IQ+ncGbA3sOAqJqoFGPkEmv5OWDnhWVidXjdq33SJLIcwWVkqQ2ulRhOc+Rq3+5FAUTAoqgXYNy9tkLPEU4AEifQEpDiJQgZEw9/iMcw7QWMMoHugKr7Iq4u+Do8DqndaCAlDekZSo245g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794369156; 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=SDB5ZSWebPg3KznoweaVluLCjG/Fe/G5yGe36con4AM=; b=kZQ38IhaWglDAtghK6pRSe3jd6cBsiIfua55ESobQZhDsEXaz7RpK5lLzl45rHbKwkpXbpvlrianLK5+X55+9c/mkTmg952fanTLoiH7HqMTRu/xJOiEKh8v7R0RqEWXQYY/dgXYqqEIOkaHh1zjsaTj3h5OzU5d0cZnNJaqBeM= 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 1794369156763501.98963618664925; Tue, 10 Nov 2026 19:52:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQzNe-0007yv-GH; Tue, 10 Nov 2026 22:52:14 -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 1xQzNd-0007yC-DB for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:13 -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 1xQzNb-0006h8-J6 for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:13 -0500 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-227-UWXz1LjNOyGSpNAU3EUXxg-1; Tue, 10 Nov 2026 22:52:08 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 191721800599; Wed, 11 Nov 2026 03:52:07 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 839AD3001DA0; Wed, 11 Nov 2026 03:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794369130; 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=SDB5ZSWebPg3KznoweaVluLCjG/Fe/G5yGe36con4AM=; b=Ni47f4oYCl7qXM+qyMav2nHnd/XcdxfmyhAEV9VDk4SUC7r8DfGlKi8yDFKaLCyaQ3PcLm QNx7GeaRBQoz8CcMDII9+9cZoXJhWGihVS9sYaR/TOA4CSH29rP7idJXRgEsM8jsAHluDl Az5mBbsPtMntAqgDEu+JThyOUFQ2d9c= X-MC-Unique: UWXz1LjNOyGSpNAU3EUXxg-1 X-Mimecast-MFC-AGG-ID: UWXz1LjNOyGSpNAU3EUXxg_1794369127 From: Eric Blake To: qemu-devel@nongnu.org Cc: Guillaume Vincke , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 2/8] iotests: Add coverage for NBD connect thread start delay Date: Tue, 10 Nov 2026 21:51:27 -0600 Message-ID: <20261111035200.1751734-12-eblake@redhat.com> In-Reply-To: <20261111035200.1751734-10-eblake@redhat.com> References: <20261111035200.1751734-10-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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: 1794369159568158500 Content-Type: text/plain; charset="utf-8" From: Guillaume Vincke Test the connect thread starting condition with reconnect-delay=3D0 when the server disconnects after a successful handshake but before running operations. Prior to the change to nbd_co_establish_connection(), this test would demonstrate two I/O errors. The tests 264 and 277 covering reconnection do not use reconnect-delay=3D0 so this case is not exercised. Add a test that provokes multiple errors in order to put an NBD client in the above-mentioned situation and shows that the first operation starts the connect thread and leads to successful subsequent I/O. Signed-off-by: Guillaume Vincke Message-ID: <20261105164124.249395-3-guillaume.vincke@ovhcloud.com> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- tests/qemu-iotests/tests/nbd-stale-connection | 60 +++++++++++++++++++ .../tests/nbd-stale-connection.out | 17 ++++++ 2 files changed, 77 insertions(+) create mode 100755 tests/qemu-iotests/tests/nbd-stale-connection create mode 100644 tests/qemu-iotests/tests/nbd-stale-connection.out diff --git a/tests/qemu-iotests/tests/nbd-stale-connection b/tests/qemu-iot= ests/tests/nbd-stale-connection new file mode 100755 index 00000000000..e361bccfa98 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-stale-connection @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# group: quick +# +# Test the NBD client stale channel discard +# +# Copyright (C) 2026 OVHcloud +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import time +import iotests +from iotests import qemu_nbd_popen, qemu_img_create, file_path, log + + +# estimated duration required by the connect thread to reach a running ser= ver +MAX_NBD_CONNECT_DURATION =3D 1 + +iotests.script_initialize(supported_fmts=3D['qcow2']) +nbd_sock =3D file_path('nbd-sock', base_dir=3Diotests.sock_dir) +disk =3D file_path('disk') +qemu_img_create('-f', iotests.imgfmt, disk, '1M') + +with iotests.VM() as vm: + + vm.launch() + + with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk): + vm.cmd('blockdev-add', { + 'driver': 'nbd', + 'node-name': 'nbd0', + 'server': {'type': 'unix', 'path': nbd_sock}, + }) + iotests.log('=3D=3D=3D NBD Device connected =3D=3D=3D') + log(vm.qmp('x-qemu-io', device=3D'nbd0', command=3D'write -P 0x5a = 0 64k')) + + iotests.log('=3D=3D=3D NBD server down. Detect the break and start the= connect ' + 'thread =3D=3D=3D') + # client was in CONNECTED state a new operation updates to CONNECTING + log(vm.qmp('x-qemu-io', device=3D'nbd0', command=3D'write -P 0x5a 0 64= k')) + + with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk): + iotests.log('=3D=3D=3D NBD server up. Wait for the connect thread = to park ' + 'the channel =3D=3D=3D') + # in CONNECTING, the operation starts the connect thread + log(vm.qmp('x-qemu-io', device=3D'nbd0', command=3D'write -P 0x5a = 0 64k')) + # wait for the connect thread to get a new channel and stop + time.sleep(MAX_NBD_CONNECT_DURATION) + + iotests.log('=3D=3D=3D NBD server down. The parked channel is closed = =3D=3D=3D') + + with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk): + iotests.log('=3D=3D=3D NBD server up. Restart the connect thread = =3D=3D=3D') + # operation will determine that the channel got closed and restart= the + # connect thread + log(vm.qmp('x-qemu-io', device=3D'nbd0', command=3D'write -P 0x5a = 0 64k')) + # Wait for it to succeed + iotests.log('=3D=3D=3D Wait for the connect thread to park the new= channel. ' + 'Subsequent operations are successful =3D=3D=3D') + time.sleep(MAX_NBD_CONNECT_DURATION) + log(vm.qmp('x-qemu-io', device=3D'nbd0', command=3D'write -P 0x5a = 0 64k')) diff --git a/tests/qemu-iotests/tests/nbd-stale-connection.out b/tests/qemu= -iotests/tests/nbd-stale-connection.out new file mode 100644 index 00000000000..065ba329e96 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-stale-connection.out @@ -0,0 +1,17 @@ +Start NBD server +=3D=3D=3D NBD Device connected =3D=3D=3D +{"return": {}} +Kill NBD server +=3D=3D=3D NBD server down. Detect the break and start the connect thread = =3D=3D=3D +{"error": {"class": "GenericError", "desc": "write failed: Input/output er= ror"}} +Start NBD server +=3D=3D=3D NBD server up. Wait for the connect thread to park the channel = =3D=3D=3D +{"error": {"class": "GenericError", "desc": "write failed: Input/output er= ror"}} +Kill NBD server +=3D=3D=3D NBD server down. The parked channel is closed =3D=3D=3D +Start NBD server +=3D=3D=3D NBD server up. Restart the connect thread =3D=3D=3D +{"error": {"class": "GenericError", "desc": "write failed: Input/output er= ror"}} +=3D=3D=3D Wait for the connect thread to park the new channel. Subsequent = operations are successful =3D=3D=3D +{"return": {}} +Kill NBD server --=20 2.56.0 From nobody Mon Nov 23 04:44:09 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=1794369206; cv=none; d=zohomail.com; s=zohoarc; b=ZHLT0N1ExZnspvcAxCO56ZRUoZvknp/kEBWegnIIwnl3H/JgeHEXnnbNEsV3JduR5RaYGjXclSK7Mj7F1/bh5seAUn+a4+G2GtmQeB9Btj1l1kMbTZvbG2Dtszi4ZmVVkPfIx0VDG1XqR2UdtTWpFlKQ1pQyvTD4tNWv4MhUf1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794369206; 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=yoQIbQfgmmyie51BVddX2mLTDo85i8ct0729KATeyGw=; b=Zuj9y7jZAdn68/JuatfnVYFAw2s6CbGK+DKKmuF4jkKFIeihl9xhEBKR0QehIvazjT3jDKs89gXs1a9I1VGg9IsQxBszIR2ChWj0tdF7KsVuDOrrZAwCp61CU8XvKOzNirUCpLTu03wXG5xErt6JLf1pezVHH1vlLtuKCeUFQ0c= 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 1794369206669546.368224771075; Tue, 10 Nov 2026 19:53:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQzNi-00081L-Bm; Tue, 10 Nov 2026 22:52:18 -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 1xQzNe-0007yx-JW for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:14 -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 1xQzNc-0006iW-3h for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:14 -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-631-ZerGfsODMgGlTHRo-7Q0fQ-1; Tue, 10 Nov 2026 22:52:09 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 75955195609D; Wed, 11 Nov 2026 03:52:08 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 683B93001DA3; Wed, 11 Nov 2026 03:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794369131; 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=yoQIbQfgmmyie51BVddX2mLTDo85i8ct0729KATeyGw=; b=W9QgB5QQMwiuX/4+VeqSeUC6MEameM8RYT1WB5ufZoqqnf2MvhxG9odj04g4kJkykeNglU WFsmla0ynFDey85K21Jx6bJUblvFmVJ7Ui7jZFQCfdKnmV9o4qcfVMyByWLOCWsHrHyKot YWQ/N001UU2l27TDw3kbN/DjgnWafYg= X-MC-Unique: ZerGfsODMgGlTHRo-7Q0fQ-1 X-Mimecast-MFC-AGG-ID: ZerGfsODMgGlTHRo-7Q0fQ_1794369128 From: Eric Blake To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi , Pierrick Bouvier Subject: [PULL 3/8] docs: Mention security considerations for NBD Date: Tue, 10 Nov 2026 21:51:28 -0600 Message-ID: <20261111035200.1751734-13-eblake@redhat.com> In-Reply-To: <20261111035200.1751734-10-eblake@redhat.com> References: <20261111035200.1751734-10-eblake@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.4 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: 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_H5=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: 1794369207723158500 Document a policy that NBD connections should strongly consider using TLS and x509 certificates to filter out unwanted clients. If a malicious server or client can trigger a QEMU assertion failure on a plaintext connection, but can trivially have risk mitigated by enabling TLS to weed out unknown partners (so that a full-on attack of QEMU would first require chaining some other attack to convince a "trusted" client to break protocol in the first place), then that reduces the CVSS-BE score of the QEMU bug. In turn, our policy already states that low severity scores can be fixed without an embargo. Signed-off-by: Eric Blake Message-ID: <20261110155356.1520433-7-eblake@redhat.com> Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Stefan Hajnoczi --- docs/system/security.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/system/security.rst b/docs/system/security.rst index e211fdd2344..e30f771731a 100644 --- a/docs/system/security.rst +++ b/docs/system/security.rst @@ -320,3 +320,26 @@ 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 any external process a +potential attack vector via 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 cannot prevent a client from +violating protocol, but does increase the complexity of an attack, +because a malicious actor must first find a way to convince an +authenticated client to send the bytes that will trigger any QEMU +misbehavior. Use of a hardened connection is therefore an +environmental factor used in determining the risk and severity of a +network-triggered bug. --=20 2.56.0 From nobody Mon Nov 23 04:44:09 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=1794369186; cv=none; d=zohomail.com; s=zohoarc; b=H1UoVmifsG+dpAd/042upeCwn7NltIwrRjzrnmJ8gO4nEL/5nHuuwyKG5GNHTB1A5ysSjrVf5jyTzAvzB44pPBSznjnqFQ4UxBF5wnau0sGg+S9dZmggGVOuutB9CTn3T6YWpUlr2OFHqujTiucSHPLphHb3fRlLgqNxWu4e95E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794369186; 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=jL1ZY5YGV4jNZ0LlyOE5AfrHB7c9oeMeQZiaZa21c20=; b=nBdMluXMo7K4UL7FlVjTJZ7W5ehicH/eSjJSTxN9H2j4f34WYod01D3XfxxPShwxwoBt509hqBEFic04qkRNZlWWYlOuEZQqorwgxGv5NVYDalbajXdi9M/U8W4VkwGjidoE26cGUBfzK/JtJjtujU6bShxoPbVlIN9VrCUTn08= 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 1794369186731726.4452775208337; Tue, 10 Nov 2026 19:53:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQzNi-000815-21; Tue, 10 Nov 2026 22:52:18 -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 1xQzNg-00080M-HB for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:16 -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 1xQzNe-0006uD-FR for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:16 -0500 Received: from mx-prod-mc-03.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-48-i3NWjXe-N4KoibFHQWmWOA-1; Tue, 10 Nov 2026 22:52:12 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0E8719772E6; Wed, 11 Nov 2026 03:52:10 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D11D9300019F; Wed, 11 Nov 2026 03:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794369133; 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=jL1ZY5YGV4jNZ0LlyOE5AfrHB7c9oeMeQZiaZa21c20=; b=HhpxvZs8g5uG3FCqdGkmQLw9oihB4kgwzfHbnqnfWHO5UzK3cR2w/YhdlJWB82As9P1Af3 upshg+9e04uXW0iwMpqldxqJcKlLMvLmfXu8QQ/DmIZiEqJjLUkG4Tolxt+6RX19BmvlVT JmueHhMdVQbPJRltjQMDuXJ6JjYAzkM= X-MC-Unique: i3NWjXe-N4KoibFHQWmWOA-1 X-Mimecast-MFC-AGG-ID: i3NWjXe-N4KoibFHQWmWOA_1794369131 From: Eric Blake To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi , Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Block layer core) Subject: [PULL 4/8] iotests: Refactor python NBD server setup Date: Tue, 10 Nov 2026 21:51:29 -0600 Message-ID: <20261111035200.1751734-14-eblake@redhat.com> In-Reply-To: <20261111035200.1751734-10-eblake@redhat.com> References: <20261111035200.1751734-10-eblake@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.4 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: 1794369187713158500 Extract code from nbd-multiconn that I plan to use in another upcoming unit test. Signed-off-by: Eric Blake Message-ID: <20261110155356.1520433-8-eblake@redhat.com> Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Stefan Hajnoczi --- tests/qemu-iotests/iotests.py | 30 ++++++++++++++++++ tests/qemu-iotests/tests/nbd-multiconn | 44 +++++--------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 642a160bb28..7017d2016cf 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -1385,6 +1385,36 @@ def case_skip(self, reason): case_notrun(reason) self.skipTest(reason) + @contextmanager + def run_nbd_server(self, nbd_sock: str, + max_conn: Optional[int] =3D None) -> Iterator[None]: + args: Dict[str, Any] =3D { + 'addr': { + 'type': 'unix', + 'data': {'path': nbd_sock} + } + } + if max_conn is not None: + args['max-connections'] =3D max_conn + + self.vm.cmd('nbd-server-start', args) + try: + yield + finally: + self.vm.cmd('nbd-server-stop') + + def add_nbd_export(self, node_name: str, name: str, + writable: Optional[bool] =3D None) -> None: + args: Dict[str, Any] =3D { + 'type': 'nbd', + 'id': name, + 'node-name': node_name, + 'name': name, + } + if writable is not None: + args['writable'] =3D writable + + self.vm.cmd('block-export-add', args) def notrun(reason): '''Skip this test suite''' diff --git a/tests/qemu-iotests/tests/nbd-multiconn b/tests/qemu-iotests/te= sts/nbd-multiconn index 479e872f2a8..96efe01e583 100755 --- a/tests/qemu-iotests/tests/nbd-multiconn +++ b/tests/qemu-iotests/tests/nbd-multiconn @@ -62,55 +62,27 @@ class TestNbdMulticonn(iotests.QMPTestCase): 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_default_settings(self): - with self.run_server(): - self.add_export('r') - self.add_export('w', writable=3DTrue) + with self.run_nbd_server(nbd_sock): + self.add_nbd_export('n', 'r') + self.add_nbd_export('n', 'w', writable=3DTrue) with open_nbd('r') as h: self.assertTrue(h.can_multi_conn()) with open_nbd('w') as h: self.assertTrue(h.can_multi_conn()) def test_limited_connections(self): - with self.run_server(max_connections=3D1): - self.add_export('r') - self.add_export('w', writable=3DTrue) + with self.run_nbd_server(nbd_sock, max_conn=3D1): + self.add_nbd_export('n', 'r') + self.add_nbd_export('n', 'w', writable=3DTrue) with open_nbd('r') as h: self.assertFalse(h.can_multi_conn()) with open_nbd('w') as h: self.assertFalse(h.can_multi_conn()) def test_parallel_writes(self): - with self.run_server(): - self.add_export('w', writable=3DTrue) + with self.run_nbd_server(nbd_sock): + self.add_nbd_export('n', 'w', writable=3DTrue) clients =3D [nbd.NBD() for _ in range(3)] for c in clients: --=20 2.56.0 From nobody Mon Nov 23 04:44:09 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=1794369160; cv=none; d=zohomail.com; s=zohoarc; b=Bux+GMopNjU97Vl8yCmxypZE1DUHekhGOX+db4n4llVIyXxHRM7VaLb/7H6eQ0lqNsZruj1WcjyjSEtNKa9DGSDwvQJfz3S77RheAK33Pc97Ra5NCjmnu6LIzcWjCsqat8F4QmENnHL/0/dkBWNwAaBzrmbsUqHIopDltwdMV+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794369160; 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=D4QDAx78KWHUqPNjDA4H6eTXFRcl1oPkhjcemO9bHjY=; b=HUd/2TEjVnLJ9TJeOmHzwRzG8qcoZceyd66ZwUsEmwwlffQp3zTZiUsliCJFPWYywUNwf80GY2ikJ7sZl4Nkmj9h9Rg8WkXq35jiwqzzQBdMU1vRMV3ls6a7Mp+V7l2Y4hF1AT8adEBRUtJrhovlYSlmXm/b7pxVH4Ja4athLkE= 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 1794369160186308.7167954451842; Tue, 10 Nov 2026 19:52:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQzNx-0000AK-3J; Tue, 10 Nov 2026 22:52:33 -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 1xQzNu-00006P-9d for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:30 -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 1xQzNs-0007OB-DB for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:30 -0500 Received: from mx-prod-mc-03.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-121-LkYeFxC8Ni2eVtfzD4iGjA-1; Tue, 10 Nov 2026 22:52:20 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DE4EB1956054; Wed, 11 Nov 2026 03:52:14 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A3A04300019F; Wed, 11 Nov 2026 03:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794369147; 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=D4QDAx78KWHUqPNjDA4H6eTXFRcl1oPkhjcemO9bHjY=; b=FFRFNa7xO2KwSqjQSzDQ1Of6mO03sI9Mz49NBenmhnV5KpygdVhiZ3bwTlxZ7XcTVmJJ9R iKSbgMaotsZ92kD7YjtQdV0XMQGjtIrHkNR4tvPuemW/gIq3g9MdMR0yjo/joDX7xJZ0mM XjtTYnAVizObRc0Z97/WdLSOkdjBb7E= X-MC-Unique: LkYeFxC8Ni2eVtfzD4iGjA-1 X-Mimecast-MFC-AGG-ID: LkYeFxC8Ni2eVtfzD4iGjA_1794369135 From: Eric Blake To: qemu-devel@nongnu.org Cc: Feifan Qian , Haotian Jiang , qemu-stable@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 5/8] nbd/server: Reject rather than assert on non-compliant BLOCK_STATUS Date: Tue, 10 Nov 2026 21:51:30 -0600 Message-ID: <20261111035200.1751734-15-eblake@redhat.com> In-Reply-To: <20261111035200.1751734-10-eblake@redhat.com> References: <20261111035200.1751734-10-eblake@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.4 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: 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_H5=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: 1794369163400158500 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 for the current export. 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. The assertion can also be tripped by initially requesting the context for one export, then using NBD_OPT_GO on a different export (nbd_check_meta_export() sets contexts.count to 0, but did not wipe contexts.exp). Forcing the client command to be rejected if contexts.count is 0 solves both triggers, and allows the assertion to still operate cleanly at a later location. If you do not use recommended practice to prevent unwanted clients from connecting to QEMU's NBD server, then any client can cause a denial of service with minimal effort. However, with TLS and x509 certs in place, an attacker must first chain in an attack to convince the client to send unwanted traffic, which is a factor in declaring this a lower-risk denial of service. Fixes: CVE-2026-124559 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 Message-ID: <20261110155356.1520433-9-eblake@redhat.com> Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Stefan Hajnoczi --- nbd/server.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index e6c47f8c2e3..8a01c27de07 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2584,17 +2584,18 @@ 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)) { goto skip; } + assert(client->contexts.exp =3D=3D client->exp); buf =3D g_malloc(payload_len); if (nbd_read(client->ioc, buf, payload_len, --=20 2.56.0 From nobody Mon Nov 23 04:44:09 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=1794369176; cv=none; d=zohomail.com; s=zohoarc; b=HNYjWnV9DNWW2Gk7dOMleSd220lrJZQLGG2ydsKPDbmspPwa7WQNNhpIudvYENlhBEPF7cJk6QlaSUK9bky9daoP1VZqtSwYkPVOcYpo25+TiqEVAVzJcyCG0AJILVjw67k16BYrsGEm986AxTExQHmYuhXI0GupT1Mz1OA9TSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794369176; 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=vrUJBGn2vUH1UR3OPTAuN/Q+khfW6r7FRV+4klOWrSI=; b=E+Yib6RAtKIe+xEXpswi8UIS8MGWRAmSu89q0dhdQ0gJXTZzQtVvPc1OraKlB8PilIoTyUdbCq5e/rXVwnZ/1wma52/MFrb8VXjxrB8rMvDjGEWubUQgnQOgmQSVq2vC3nnGZvqW5jXN3MShnWuIq9aJ7Bv/XyIkZ/5zf10LPRk= 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 1794369176610862.5616574762494; Tue, 10 Nov 2026 19:52:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQzNp-0008IX-7w; Tue, 10 Nov 2026 22:52:25 -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 1xQzNn-0008A9-0B for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:23 -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 1xQzNk-0007Gk-Un for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:22 -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-225-MeEFWG4lPfC9zCRhjExQxA-1; Tue, 10 Nov 2026 22:52:17 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 DD0AD195605E; Wed, 11 Nov 2026 03:52:16 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 50085300019F; Wed, 11 Nov 2026 03:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794369140; 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=vrUJBGn2vUH1UR3OPTAuN/Q+khfW6r7FRV+4klOWrSI=; b=OYJqWXBynG+Ni0ffzMScKQfU2FEETm7Gl1BehWVcFDgYYi/95ufl1FSdTiP49v+g66ypQ5 wYu2zKNJVTNL2PZi7lB3OPfU1x+UsHTEOEMteeWodpTM32/92qVTvo+b9xQy5xbPtN+Jpo NgEdwe3q5i7GX4tsU8jypB773FVUCq0= X-MC-Unique: MeEFWG4lPfC9zCRhjExQxA-1 X-Mimecast-MFC-AGG-ID: MeEFWG4lPfC9zCRhjExQxA_1794369137 From: Eric Blake To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 6/8] iotests: Add new nbd-robustness test Date: Tue, 10 Nov 2026 21:51:31 -0600 Message-ID: <20261111035200.1751734-16-eblake@redhat.com> In-Reply-To: <20261111035200.1751734-10-eblake@redhat.com> References: <20261111035200.1751734-10-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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: 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_H5=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: 1794369177741158500 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 Message-ID: <20261110155356.1520433-10-eblake@redhat.com> Reviewed-by: Stefan Hajnoczi --- tests/qemu-iotests/tests/nbd-robustness | 132 ++++++++++++++++++++ tests/qemu-iotests/tests/nbd-robustness.out | 5 + 2 files changed, 137 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..fe61a839250 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-robustness @@ -0,0 +1,132 @@ +#!/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 +import socket +import struct + +import iotests +from iotests import qemu_img_create, qemu_io + +# Selected NBD Protocol Constants +NBD_MAGIC_INIT =3D 0x4e42444d41474943 # "NBDMAGIC" +NBD_MAGIC_OPTS =3D 0x49484156454f5054 # "IHAVEOPT" +NBD_MAGIC_REPLY =3D 0x0003e889045565a9 # Reply magic +NBD_MAGIC_EXT_REPLY =3D 0x6e8a278c # Structured reply magic +NBD_FLAG_C_FIXED_NEWSTYLE =3D 0x1 +NBD_OPT_GO =3D 7 +NBD_OPT_SET_META_CONTEXT =3D 10 +NBD_OPT_EXTENDED_HEADERS =3D 11 +NBD_REP_ACK =3D 1 +NBD_REP_INFO =3D 3 +NBD_CMD_BLOCK_STATUS =3D 7 + +disk =3D os.path.join(iotests.test_dir, 'disk') +size =3D '4M' +nbd_sock =3D os.path.join(iotests.sock_dir, 'nbd_sock') + + +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': iotests.imgfmt, + '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 + + def recv_exact(self, s: socket.socket, n: int) -> bytes: + buf =3D bytearray() + while len(buf) < n: + chunk =3D s.recv(n - len(buf)) + if not chunk: + raise EOFError(f"Unexpected EOF while reading {n} bytes " + f"(got {len(buf)})") + buf.extend(chunk) + return bytes(buf) + + def test_invalid_block_status(self): + with self.run_nbd_server(nbd_sock): + self.add_nbd_export('n', '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 self.recv_exact(s, 18) + magic, opt, flags =3D struct.unpack(">QQH", data) + self.assertEqual(magic, NBD_MAGIC_INIT) + self.assertEqual(opt, NBD_MAGIC_OPTS) + self.assertEqual(flags, 0x3) + + # Reply with flags(4) - just fixed newstyle flag + s.sendall(struct.pack(">I", NBD_FLAG_C_FIXED_NEWSTYLE)) + + # Request NBD_OPT_EXTENDED_HEADERS, no extra payload + s.sendall(struct.pack(">QII", NBD_MAGIC_OPTS, + NBD_OPT_EXTENDED_HEADERS, 0)) + + # Expect successful reply: + # magic(8) + option(4) + reply(4) + length(4) + data =3D self.recv_exact(s, 20) + magic, opt, reply, length =3D struct.unpack(">QIII", data) + self.assertEqual(magic, NBD_MAGIC_REPLY) + self.assertEqual(opt, NBD_OPT_EXTENDED_HEADERS) + self.assertEqual(reply, NBD_REP_ACK) + self.assertEqual(length, 0) + + # Request NBD_OPT_GO, name but no info as payload + payload =3D struct.pack(">I", 1) + b'r' + struct.pack(">H"= , 0) + s.sendall(struct.pack(">QII", NBD_MAGIC_OPTS, NBD_OPT_GO, + len(payload)) + payload) + + # Expect (and ignore) zero or more info packets before ack + while True: + data =3D self.recv_exact(s, 20) + magic, opt, reply, length =3D struct.unpack(">QIII", d= ata) + self.assertEqual(magic, NBD_MAGIC_REPLY) + self.assertEqual(opt, NBD_OPT_GO) + payload =3D self.recv_exact(s, length) + if reply !=3D NBD_REP_INFO: + break + self.assertEqual(reply, NBD_REP_ACK) + + # 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.sendall(struct.pack(">IHHQQQ", 0x21e41c71, 0x20, + NBD_CMD_BLOCK_STATUS, 1, 0, + len(payload)) + payload) + + # Expect a rejection. + data =3D self.recv_exact(s, 32) + magic, flags, rtype, cookie, _, length =3D \ + struct.unpack(">IHHQQQ", data) + self.assertEqual(magic, NBD_MAGIC_EXT_REPLY) + self.assertEqual(rtype & 0x8000, 0x8000) + self.assertEqual(cookie, 1) + self.recv_exact(s, length) + + self.assertTrue(self.vm.is_running()) + +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 From nobody Mon Nov 23 04:44:09 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=1794369185; cv=none; d=zohomail.com; s=zohoarc; b=TsI916hxcPl4ZfSbz9FBx8Qf++lJKwSWFSu3tswFc9IdwVt2tOabbyLCOh6lpkW8r1EZBgezd1nPvOd9KQ4JiDZ1lMT3H3z0ENdKnwOnS4T+73HntftABpxQy5CawwnXt4yy6cEsrJx7f+zD0aukQ/TB2+9VY6BpIPkEfXK/pPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794369185; 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=wrZedr75GGg9WN9k+O0G0oSPPKkMM+sHh5y9JswdQsU=; b=bJWre64Rtx0aC9SQFE63K/Fs3PLyT2j2art7UlFU/OBD0Kd3GQXNdFCWbl6CfDQn+9d3uVhniNsef5NMI4edlWyXXhKBVg4klDMkIRQ6gTiL9pQsfGPFt9xmEzsDqKuvw9Il1ZXqdW1GcTGWd36whbhoZ2mksRCiB96n6V+umBY= 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 179436918572924.239429314287463; Tue, 10 Nov 2026 19:53:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQzNr-0008Oo-C7; Tue, 10 Nov 2026 22:52:27 -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 1xQzNp-0008JU-FF for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:25 -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 1xQzNn-0007NO-TO for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:25 -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-633-9Z4IVmTRN12JVYBwngrxWg-1; Tue, 10 Nov 2026 22:52:19 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 7CFC11956060; Wed, 11 Nov 2026 03:52:18 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 27AB3300019F; Wed, 11 Nov 2026 03:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794369143; 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=wrZedr75GGg9WN9k+O0G0oSPPKkMM+sHh5y9JswdQsU=; b=b9Hv7I02oYSfGi3Cih1qURs6nHMj9/4LW5h10RNWg318HLbMQsRH8oo45OrdEYpl2EoiqN v+9/By2gr4zlaPhrUHyczIsEDnsuRM54pz9n23PWDesCsp4Q+XBXxbdRALEFiYbQnWLiLb Cd4+5TBFu0AkJhikOIrx1SEupEWK60I= X-MC-Unique: 9Z4IVmTRN12JVYBwngrxWg-1 X-Mimecast-MFC-AGG-ID: 9Z4IVmTRN12JVYBwngrxWg_1794369138 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 7/8] nbd/server: Reject rather than assert on non-compliant NBD_OPT_SET_META_CONTEXT Date: Tue, 10 Nov 2026 21:51:32 -0600 Message-ID: <20261111035200.1751734-17-eblake@redhat.com> In-Reply-To: <20261111035200.1751734-10-eblake@redhat.com> References: <20261111035200.1751734-10-eblake@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.4 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: 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_H5=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: 1794369187687158500 The NBD protocol says that NBD_OPT_{LIST,SET}_META_CONTEXT sends several lengths that must be consistent: an overall option reply length, then a series of smaller lengths/data pairs representing the export name and zero or more context names. If the smaller lengths within the payload do not add up to the larger value, the client has sent garbage bytes that will trigger the server's parse of the client's next option to be out of sync. However, QEMU was dying with an assertion failure rather than diagnosing the issue, which a malicious client can then exploit to mount a denial-of-service attack against QEMU as the NBD server. As with several other recent NBD protocol violations, the likelihood of this attack can be reduced by using TLS and x509 certs to reject unwanted clients (a "trusted" client can still trigger the problem, but you first have to compromise the trusted client into sending arbitrary traffic). Fixes: CVE-2026-125683 Fixes: e7b1948d51 ("nbd: BLOCK_STATUS for standard get_block_status functio= n: server part", v2.12.0) Reported-by: TonySD via https://gitlab.com/qemu-project/qemu/-/work_items/4= 843 CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Message-ID: <20261110155356.1520433-11-eblake@redhat.com> Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Stefan Hajnoczi --- nbd/server.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nbd/server.c b/nbd/server.c index 8a01c27de07..8c45f9fc43f 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1095,6 +1095,11 @@ nbd_negotiate_meta_queries(NBDClient *client, Error = **errp) } } } + if (client->optlen > 0) { + return nbd_opt_invalid(client, errp, + "Inconsistent lengths in option %s", + nbd_opt_lookup(client->opt)); + } if (meta->base_allocation) { ret =3D nbd_negotiate_send_meta_context(client, "base:allocation", --=20 2.56.0 From nobody Mon Nov 23 04:44:09 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=1794369202; cv=none; d=zohomail.com; s=zohoarc; b=c8LAyW/aTj52AenZMG1+30bNOsuYgfHfvsYAbpZg7WAePULqkPeAhRYaK0vs6lYpJjsJSTuHkBKYyCUPdT4fYFcPpN0wZRnDYH4FHRj7KnBS4rIVaTdItuWe2LLUO1nEWeOA+jVMxEkxJ0hKXWMFk18hFNeboewGiC5ThjlASSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794369202; 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=kQey4jsGrhUt0ZwEtQIa2PPXxdz1oC6d1Y293m8BGtI=; b=PJMX+siRlZraKzc4WIlWlYsV88jisQd+QRJmjUkgj4ho8+1UTOOE013Fd84jF7YSpqHpk5rKjXcTnv5mY8eTwVX3MXzT2GUiCURNPlimfDdIwPbZdTOckv5JGzn60MIAKk0Hop1OE6zJkYz3wYEN1WkYOCfMT13OKaE3br0ewIM= 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 17943692026911015.7669775051696; Tue, 10 Nov 2026 19:53:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQzNt-0008UM-22; Tue, 10 Nov 2026 22:52:29 -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 1xQzNr-0008QG-MP for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:27 -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 1xQzNp-0007Ni-Iv for qemu-devel@nongnu.org; Tue, 10 Nov 2026 22:52:27 -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-377-6TYNEQf6ND2ou5za189I5g-1; Tue, 10 Nov 2026 22:52:21 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 84BFD1800562; Wed, 11 Nov 2026 03:52:20 +0000 (UTC) Received: from eblake.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D194B3001DA0; Wed, 11 Nov 2026 03:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794369144; 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=kQey4jsGrhUt0ZwEtQIa2PPXxdz1oC6d1Y293m8BGtI=; b=TfRcutKBpP42meMww//+dLD1CPNYZA2mlXniob6tLCqbQZ3uFAVgoayFQ5bbJ8bxbJxDRB ZhE4wcEOcxathVSCBmp9iz6jj/Sh8WrO+oIdbx8r/P/NMuN+dvsssod8GqtBBJnoi2PFgF IfxRz2Ii85ozTI3btrMR+iJIsg0DOiM= X-MC-Unique: 6TYNEQf6ND2ou5za189I5g-1 X-Mimecast-MFC-AGG-ID: 6TYNEQf6ND2ou5za189I5g_1794369140 From: Eric Blake To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 8/8] iotests: Add another nbd-robustness test Date: Tue, 10 Nov 2026 21:51:33 -0600 Message-ID: <20261111035200.1751734-18-eblake@redhat.com> In-Reply-To: <20261111035200.1751734-10-eblake@redhat.com> References: <20261111035200.1751734-10-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=unavailable 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: 1794369203936158500 Content-Type: text/plain; charset="utf-8" Convert the proof of concept test by TonySD into another case of the iotest. This is yet another instance where a hard-coded exchange is easier than forcing libnbd into producing an exchange that violates the protocol. 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/4843 Signed-off-by: Eric Blake Message-ID: <20261110155356.1520433-12-eblake@redhat.com> Reviewed-by: Stefan Hajnoczi --- tests/qemu-iotests/tests/nbd-robustness | 73 +++++++++++++++++++++ tests/qemu-iotests/tests/nbd-robustness.out | 4 +- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/tests/nbd-robustness b/tests/qemu-iotests/t= ests/nbd-robustness index fe61a839250..410dfca04e3 100755 --- a/tests/qemu-iotests/tests/nbd-robustness +++ b/tests/qemu-iotests/tests/nbd-robustness @@ -21,6 +21,7 @@ NBD_MAGIC_REPLY =3D 0x0003e889045565a9 # Reply ma= gic NBD_MAGIC_EXT_REPLY =3D 0x6e8a278c # Structured reply magic NBD_FLAG_C_FIXED_NEWSTYLE =3D 0x1 NBD_OPT_GO =3D 7 +NBD_OPT_STRUCTURED_REPLY =3D 8 NBD_OPT_SET_META_CONTEXT =3D 10 NBD_OPT_EXTENDED_HEADERS =3D 11 NBD_REP_ACK =3D 1 @@ -128,5 +129,77 @@ class TestNbdRobustness(iotests.QMPTestCase): self.assertTrue(self.vm.is_running()) + def test_invalid_set_meta_context(self): + with self.run_nbd_server(nbd_sock): + self.add_nbd_export('n', '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 self.recv_exact(s, 18) + magic, opt, flags =3D struct.unpack(">QQH", data) + self.assertEqual(magic, NBD_MAGIC_INIT) + self.assertEqual(opt, NBD_MAGIC_OPTS) + self.assertEqual(flags, 0x3) + + # Reply with flags(4) - just fixed newstyle flag + s.sendall(struct.pack(">I", NBD_FLAG_C_FIXED_NEWSTYLE)) + + # Request NBD_OPT_STRUCTURED_REPLY, no extra payload + s.sendall(struct.pack(">QII", NBD_MAGIC_OPTS, + NBD_OPT_STRUCTURED_REPLY, 0)) + + # Expect successful reply: + # magic(8) + option(4) + reply(4) + length(4) + data =3D self.recv_exact(s, 20) + magic, opt, reply, length =3D struct.unpack(">QIII", data) + self.assertEqual(magic, NBD_MAGIC_REPLY) + self.assertEqual(opt, NBD_OPT_STRUCTURED_REPLY) + self.assertEqual(reply, NBD_REP_ACK) + self.assertEqual(length, 0) + + # Request NBD_OPT_SET_META_CONTEXT with invalid length + # namelen(4) + str + queries(4) + {querylen(4) + str) + payload =3D struct.pack(">I", 1) + b'r' + payload +=3D struct.pack(">II", 1, 1) + b'X' + s.sendall(struct.pack(">QII", NBD_MAGIC_OPTS, + NBD_OPT_SET_META_CONTEXT, + len(payload) + 1) + payload) + + # Request NBD_OPT_GO, name but no info as payload + # (request is early, but does not hurt here) + payload =3D struct.pack(">I", 1) + b'r' + struct.pack(">H"= , 0) + s.sendall(struct.pack(">QII", NBD_MAGIC_OPTS, NBD_OPT_GO, + len(payload)) + payload) + + # Expect error reply to SET_META_CONTEXT: + # magic(8) + option(4) + reply(4) + length(4) + data =3D self.recv_exact(s, 20) + magic, opt, reply, length =3D struct.unpack(">QIII", data) + self.assertEqual(magic, NBD_MAGIC_REPLY) + self.assertEqual(opt, NBD_OPT_SET_META_CONTEXT) + self.assertEqual(reply & 0x80000000, 0x80000000) + self.recv_exact(s, length) + + # Expect early disconnect for unaligned GO. Could show up = as + # either b'' or ConnectionResetError + try: + data =3D s.recv(1) + self.assertEqual(data, b'') + except ConnectionResetError: + pass + + # Further writes must trigger an error (EPIPE / ECONNRESET) + with self.assertRaises((BrokenPipeError, ConnectionResetEr= ror, + OSError)): + s.sendall(b'X') + + # QEMU should still be up + self.assertIsNone(self.vm.exitcode()) + self.assertTrue(self.vm.is_running()) + res =3D self.vm.cmd('query-status') + self.assertEqual(res['status'], 'running') + 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 index ae1213e6f86..fbc63e62f88 100644 --- a/tests/qemu-iotests/tests/nbd-robustness.out +++ b/tests/qemu-iotests/tests/nbd-robustness.out @@ -1,5 +1,5 @@ -. +.. ---------------------------------------------------------------------- -Ran 1 tests +Ran 2 tests OK --=20 2.56.0