NBD patches through 2026-11-10
The following changes since commit 4bcd55a1f4b926ae86872087f7f3bc9f9e1d065e:
Merge tag 'pull-trivial-patches' of https://gitlab.com/mjt0k/qemu into staging (2026-11-12 21:14:41 -0700)
are available in the Git repository at:
https://gitlab.com/ebblake/qemu.git tags/pull-nbd-2026-11-10-v2
for you to fetch changes up to e682c0e570179bd7fa01ea896358a8cdad196a3b:
iotests: Add another nbd-robustness test (2026-11-13 08:02:09 -0600)
In v2, defer Guillame's patches (the bug was minor, and the unit test to verify the bug fix was flaky) to a later date
----------------------------------------------------------------
NBD patches through 2026-11-10
A few bug fixes:
- Eric Blake: fix two low-severity CVEs with non-compliant NBD clients
----------------------------------------------------------------
Eric Blake (6):
docs: Mention security considerations for NBD
iotests: Refactor python NBD server setup
nbd/server: Reject rather than assert on non-compliant BLOCK_STATUS
iotests: Add new nbd-robustness test
nbd/server: Reject rather than assert on non-compliant NBD_OPT_SET_META_CONTEXT
iotests: Add another nbd-robustness test
docs/system/security.rst | 23 ++++ nbd/server.c | 10 +- tests/qemu-iotests/iotests.py | 30 ++++ tests/qemu-iotests/tests/nbd-multiconn | 44 ++---- tests/qemu-iotests/tests/nbd-robustness | 205 ++++++++++++++++++++++++++++ tests/qemu-iotests/tests/nbd-robustness.out | 5 + 6 files changed, 279 insertions(+), 38 deletions(-) create mode 100755 tests/qemu-iotests/tests/nbd-robustness create mode 100644 tests/qemu-iotests/tests/nbd-robustness.out
Signature · 1 line
2.56.0
[PULL v2 1/6] docs: Mention security considerations for NBD
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.
Message-ID: <[email protected]>
--- docs/system/security.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
docs/system/security.rst +23 -0
@@ -320,3 +320,26 @@ encryption and authorization control policy on client connections. In summary, the monitor console is considered a privileged control interface 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=on' 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.
Signature · 1 line
2.56.0
[PULL v2 2/6] iotests: Refactor python NBD server setup
In reply to Eric BlakeExtract code from nbd-multiconn that I plan to use in another upcoming unit test.
Message-ID: <[email protected]>
--- tests/qemu-iotests/iotests.py | 30 ++++++++++++++++++ tests/qemu-iotests/tests/nbd-multiconn | 44 +++++--------------------- 2 files changed, 38 insertions(+), 36 deletions(-)
tests/qemu-iotests/iotests.py +30 -0
@@ -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] = None) -> Iterator[None]: + args: Dict[str, Any] = { + 'addr': { + 'type': 'unix', + 'data': {'path': nbd_sock} + } + } + if max_conn is not None: + args['max-connections'] = 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] = None) -> None: + args: Dict[str, Any] = { + 'type': 'nbd', + 'id': name, + 'node-name': node_name, + 'name': name, + } + if writable is not None: + args['writable'] = writable + + self.vm.cmd('block-export-add', args) def notrun(reason): '''Skip this test suite'''
tests/qemu-iotests/tests/nbd-multiconn +8 -36
63 lines not on this page · raw message
Signature · 1 line
2.56.0
[PULL v2 3/6] nbd/server: Reject rather than assert on non-compliant BLOCK_STATUS
In reply to Eric BlakeThe 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.
Message-ID: <[email protected]>
--- nbd/server.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
nbd/server.c +3 -2
@@ -2584,17 +2584,18 @@ nbd_co_block_status_payload_read(NBDClient *client, NBDRequest *request,return -EINVAL ; } -assert (client->contexts.exp == client->exp); nr_bitmaps = client->exp->nr_export_bitmaps; request->contexts =g_new0 (NBDMetaContexts,1 ); request->contexts->exp = 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 == client->exp); buf =g_malloc (payload_len); if (nbd_read(client->ioc, buf, payload_len,
Signature · 1 line
2.56.0
[PULL v2 4/6] iotests: Add new nbd-robustness test
In reply to Eric BlakeConvert 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
Message-ID: <[email protected]>
--- 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
tests/qemu-iotests/tests/nbd-robustness new file +132 -0
@@ -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 = 0x4e42444d41474943 # "NBDMAGIC" +NBD_MAGIC_OPTS = 0x49484156454f5054 # "IHAVEOPT" +NBD_MAGIC_REPLY = 0x0003e889045565a9 # Reply magic +NBD_MAGIC_EXT_REPLY = 0x6e8a278c # Structured reply magic +NBD_FLAG_C_FIXED_NEWSTYLE = 0x1 +NBD_OPT_GO = 7 +NBD_OPT_SET_META_CONTEXT = 10 +NBD_OPT_EXTENDED_HEADERS = 11 +NBD_REP_ACK = 1 +NBD_REP_INFO = 3 +NBD_CMD_BLOCK_STATUS = 7 + +disk = os.path.join(iotests.test_dir, 'disk') +size = '4M' +nbd_sock = 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 = 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 = bytearray() + while len(buf) < n: + chunk = 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 = self.recv_exact(s, 18) + magic, opt, flags = 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 = self.recv_exact(s, 20) + magic, opt, reply, length = 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 = 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 = self.recv_exact(s, 20) + magic, opt, reply, length = struct.unpack(">QIII", data) + self.assertEqual(magic, NBD_MAGIC_REPLY) + self.assertEqual(opt, NBD_OPT_GO) + payload = self.recv_exact(s, length) + if reply != 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 negotiated), + # but should not crash the server. + payload = 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 = self.recv_exact(s, 32) + magic, flags, rtype, cookie, _, length = \ + 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__ == '__main__': + iotests.main(supported_fmts=['qcow2'])
tests/qemu-iotests/tests/nbd-robustness.out new file +5 -0
@@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK
Signature · 1 line
2.56.0
[PULL v2 6/6] iotests: Add another nbd-robustness test
In reply to Eric BlakeConvert 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
Message-ID: <[email protected]>
--- tests/qemu-iotests/tests/nbd-robustness | 73 +++++++++++++++++++++ tests/qemu-iotests/tests/nbd-robustness.out | 4 +- 2 files changed, 75 insertions(+), 2 deletions(-)
tests/qemu-iotests/tests/nbd-robustness +73 -0
@@ -21,6 +21,7 @@ NBD_MAGIC_REPLY = 0x0003e889045565a9 # Reply magic NBD_MAGIC_EXT_REPLY = 0x6e8a278c # Structured reply magic NBD_FLAG_C_FIXED_NEWSTYLE = 0x1 NBD_OPT_GO = 7 +NBD_OPT_STRUCTURED_REPLY = 8 NBD_OPT_SET_META_CONTEXT = 10 NBD_OPT_EXTENDED_HEADERS = 11 NBD_REP_ACK = 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 = self.recv_exact(s, 18) + magic, opt, flags = 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 = self.recv_exact(s, 20) + magic, opt, reply, length = 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 = struct.pack(">I", 1) + b'r' + payload += 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 = 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 = self.recv_exact(s, 20) + magic, opt, reply, length = 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 = s.recv(1) + self.assertEqual(data, b'') + except ConnectionResetError: + pass + + # Further writes must trigger an error (EPIPE / ECONNRESET) + with self.assertRaises((BrokenPipeError, ConnectionResetError, + OSError)): + s.sendall(b'X') + + # QEMU should still be up + self.assertIsNone(self.vm.exitcode()) + self.assertTrue(self.vm.is_running()) + res = self.vm.cmd('query-status') + self.assertEqual(res['status'], 'running') + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2'])
tests/qemu-iotests/tests/nbd-robustness.out +2 -2
@@ -1,5 +1,5 @@ -. +.. ---------------------------------------------------------------------- -Ran 1 tests +Ran 2 tests OK
Signature · 1 line
2.56.0
[PULL v2 5/6] nbd/server: Reject rather than assert on non-compliant NBD_OPT_SET_META_CONTEXT
In reply to Eric BlakeThe 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).
Message-ID: <[email protected]>
--- nbd/server.c | 5 +++++ 1 file changed, 5 insertions(+)
nbd/server.c +5 -0
@@ -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 = nbd_negotiate_send_meta_context(client, "base:allocation",
Signature · 1 line
2.56.0
Richard Henderson
AppliedQuoted 12 lines · Eric Blake
The following changes since commit
4bcd55a1f4b926ae86872087f7f3bc9f9e1d065e:Merge tag 'pull-trivial-patches' ofhttps://gitlab.com/mjt0k/qemu into staging (2026-11-12 21:14:41 -0700)are available in the Git repository at:
https://gitlab.com/ebblake/qemu.git tags/pull-nbd-2026-11-10-v2for you to fetch changes up to
e682c0e570179bd7fa01ea896358a8cdad196a3b:iotests: Add another nbd-robustness test (2026-11-13 08:02:09 -0600)
Quoted 8 lines
In v2, defer Guillame's patches (the bug was minor, and the unit test to verify the bug fix was flaky) to a later date
----------------------------------------------------------------
NBD patches through 2026-11-10A few bug fixes:
- Eric Blake: fix two low-severity CVEs with non-compliant NBD clients
Applied, thanks.
r~
Quoted 37 lines · Eric Blake
The following changes since commit
4bcd55a1f4b926ae86872087f7f3bc9f9e1d065e:Merge tag 'pull-trivial-patches' of https://gitlab.com/mjt0k/qemu into staging (2026-11-12 21:14:41 -0700)are available in the Git repository at:
https://gitlab.com/ebblake/qemu.git tags/pull-nbd-2026-11-10-v2for you to fetch changes up to
e682c0e570179bd7fa01ea896358a8cdad196a3b:iotests: Add another nbd-robustness test (2026-11-13 08:02:09 -0600)In v2, defer Guillame's patches (the bug was minor, and the unit test to verify the bug fix was flaky) to a later date
----------------------------------------------------------------
NBD patches through 2026-11-10A few bug fixes:
- Eric Blake: fix two low-severity CVEs with non-compliant NBD clients----------------------------------------------------------------
Eric Blake (6):
docs: Mention security considerations for NBD
iotests: Refactor python NBD server setup
nbd/server: Reject rather than assert on non-compliantBLOCK_STATUS
iotests: Add new nbd-robustness test
nbd/server: Reject rather than assert on non-compliantNBD_OPT_SET_META_CONTEXT
iotests: Add another nbd-robustness testdocs/system/security.rst | 23 ++++ nbd/server.c | 10 +- tests/qemu-iotests/iotests.py | 30 ++++ tests/qemu-iotests/tests/nbd-multiconn | 44 ++---- tests/qemu-iotests/tests/nbd-robustness | 205 ++++++++++++++++++++++++++++ tests/qemu-iotests/tests/nbd-robustness.out | 5 + 6 files changed, 279 insertions(+), 38 deletions(-)
Quoted 2 lines
create mode 100755 tests/qemu-iotests/tests/nbd-robustness create mode 100644 tests/qemu-iotests/tests/nbd-robustness.out
I'm picking up this whole Pull Request to the stable qemu series, - besides 2 fixes it includes the tests and the documentation update.
Please let me know if I should not :)
Thanks,
/mjt
Quoted 9 lines · Michael Tokarev
Quoted 8 lines
----------------------------------------------------------------
Eric Blake (6):
docs: Mention security considerations for NBD
iotests: Refactor python NBD server setup
nbd/server: Reject rather than assert on non-compliantBLOCK_STATUS
iotests: Add new nbd-robustness test
nbd/server: Reject rather than assert on non-compliantNBD_OPT_SET_META_CONTEXT
iotests: Add another nbd-robustness test
Quoted 4 lines
I'm picking up this whole Pull Request to the stable qemu series, - besides 2 fixes it includes the tests and the documentation update.
Please let me know if I should not :)
While the two patches for the CVE fixes are essential, I see no problem with the rest of the series also going into stable. Testing that a CVE fix works even in the backport always sounds reasonable to me! And the doc update is useful information on best practices for minimizing security risks.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org