qemu/qapi
Eric Blake c8a76dbd90 nbd/server: CVE-2024-7409: Cap default max-connections to 100
Allowing an unlimited number of clients to any web service is a recipe
for a rudimentary denial of service attack: the client merely needs to
open lots of sockets without closing them, until qemu no longer has
any more fds available to allocate.

For qemu-nbd, we default to allowing only 1 connection unless more are
explicitly asked for (-e or --shared); this was historically picked as
a nice default (without an explicit -t, a non-persistent qemu-nbd goes
away after a client disconnects, without needing any additional
follow-up commands), and we are not going to change that interface now
(besides, someday we want to point people towards qemu-storage-daemon
instead of qemu-nbd).

But for qemu proper, and the newer qemu-storage-daemon, the QMP
nbd-server-start command has historically had a default of unlimited
number of connections, in part because unlike qemu-nbd it is
inherently persistent until nbd-server-stop.  Allowing multiple client
sockets is particularly useful for clients that can take advantage of
MULTI_CONN (creating parallel sockets to increase throughput),
although known clients that do so (such as libnbd's nbdcopy) typically
use only 8 or 16 connections (the benefits of scaling diminish once
more sockets are competing for kernel attention).  Picking a number
large enough for typical use cases, but not unlimited, makes it
slightly harder for a malicious client to perform a denial of service
merely by opening lots of connections withot progressing through the
handshake.

This change does not eliminate CVE-2024-7409 on its own, but reduces
the chance for fd exhaustion or unlimited memory usage as an attack
surface.  On the other hand, by itself, it makes it more obvious that
with a finite limit, we have the problem of an unauthenticated client
holding 100 fds opened as a way to block out a legitimate client from
being able to connect; thus, later patches will further add timeouts
to reject clients that are not making progress.

This is an INTENTIONAL change in behavior, and will break any client
of nbd-server-start that was not passing an explicit max-connections
parameter, yet expects more than 100 simultaneous connections.  We are
not aware of any such client (as stated above, most clients aware of
MULTI_CONN get by just fine on 8 or 16 connections, and probably cope
with later connections failing by relying on the earlier connections;
libvirt has not yet been passing max-connections, but generally
creates NBD servers with the intent for a single client for the sake
of live storage migration; meanwhile, the KubeSAN project anticipates
a large cluster sharing multiple clients [up to 8 per node, and up to
100 nodes in a cluster], but it currently uses qemu-nbd with an
explicit --shared=0 rather than qemu-storage-daemon with
nbd-server-start).

We considered using a deprecation period (declare that omitting
max-parameters is deprecated, and make it mandatory in 3 releases -
then we don't need to pick an arbitrary default); that has zero risk
of breaking any apps that accidentally depended on more than 100
connections, and where such breakage might not be noticed under unit
testing but only under the larger loads of production usage.  But it
does not close the denial-of-service hole until far into the future,
and requires all apps to change to add the parameter even if 100 was
good enough.  It also has a drawback that any app (like libvirt) that
is accidentally relying on an unlimited default should seriously
consider their own CVE now, at which point they are going to change to
pass explicit max-connections sooner than waiting for 3 qemu releases.
Finally, if our changed default breaks an app, that app can always
pass in an explicit max-parameters with a larger value.

It is also intentional that the HMP interface to nbd-server-start is
not changed to expose max-connections (any client needing to fine-tune
things should be using QMP).

Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-ID: <20240807174943.771624-12-eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[ericb: Expand commit message to summarize Dan's argument for why we
break corner-case back-compat behavior without a deprecation period]
Signed-off-by: Eric Blake <eblake@redhat.com>
2024-08-08 16:02:23 -05:00
..
acpi.json qapi: convert "Example" sections without titles 2024-07-17 10:20:53 +02:00
audio.json audio/pw: Pipewire->PipeWire case fix for user-visible text 2023-07-17 15:22:56 +04:00
authz.json qapi: Reformat doc comments to conform to current conventions 2023-05-10 10:01:01 +02:00
block-core.json qapi-block-core: Clean up blockdev-snapshot-internal-sync doc 2024-08-06 20:12:39 +02:00
block-export.json nbd/server: CVE-2024-7409: Cap default max-connections to 100 2024-08-08 16:02:23 -05:00
block.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
char.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
common.json qapi: document PCIe Gen5/Gen6 speeds since 9.0 2024-03-18 04:57:45 -04:00
compat.json qapi: Belatedly update CompatPolicy documentation for unstable 2023-10-19 07:02:29 +02:00
control.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
crypto.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
cryptodev.json spelling: information 2023-06-09 23:38:16 +03:00
cxl.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
dump.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
ebpf.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
error.json qapi: Reformat doc comments to conform to current conventions 2023-05-10 10:01:01 +02:00
introspect.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
job.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
machine-common.json CPU topology: extend with s390 specifics 2023-10-20 07:16:53 +02:00
machine-target.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
machine.json qmp: Fix higher half vaddrs for [p]memsave 2024-08-05 09:34:34 +02:00
meson.build qapi/vfio: Add VFIO migration QAPI event 2024-05-16 16:59:19 +02:00
migration.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
misc-target.json qapi: convert "Example" sections without titles 2024-07-17 10:20:53 +02:00
misc.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
net.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
opts-visitor.c qapi: Inline and remove QERR_INVALID_PARAMETER definition 2024-04-24 09:50:58 +02:00
pci.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
pragma.json qapi: document parameters of query-cpu-model-* QAPI commands 2024-03-26 06:36:08 +01:00
qapi-clone-visitor.c qapi: Do not cast function pointers 2024-05-29 12:41:56 +02:00
qapi-dealloc-visitor.c qapi: Make visitor functions taking Error ** return bool, not void 2020-07-10 15:18:08 +02:00
qapi-forward-visitor.c qapi: remove needless include 2022-03-22 14:46:18 +04:00
qapi-schema.json qapi/vfio: Add VFIO migration QAPI event 2024-05-16 16:59:19 +02:00
qapi-type-helpers.c qapi: New strv_from_str_list() 2024-03-04 07:12:40 +01:00
qapi-util.c qapi: Fix dangling references to docs/devel/qapi-code-gen.txt 2024-01-26 07:04:53 +01:00
qapi-visit-core.c qapi: Factor out compat_policy_input_ok() 2021-10-29 21:27:20 +02:00
qdev.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
qmp-dispatch.c Revert "monitor: use aio_co_reschedule_self()" 2024-06-10 11:05:43 +02:00
qmp-event.c Replace qemu_gettimeofday() with g_get_real_time() 2022-04-06 10:50:37 +02:00
qmp-registry.c qapi: Generalize command policy checking 2021-10-29 18:24:46 +02:00
qobject-input-visitor.c qapi: Inline QERR_INVALID_PARAMETER_TYPE definition (constant value) 2024-04-24 09:50:58 +02:00
qobject-output-visitor.c qapi: Extend -compat to set policy for unstable interfaces 2021-10-29 21:28:01 +02:00
qom.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
replay.json qapi: convert "Example" sections without titles 2024-07-17 10:20:53 +02:00
rocker.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
run-state.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
sockets.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
stats.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
string-input-visitor.c qapi: Inline QERR_INVALID_PARAMETER_TYPE definition (constant value) 2024-04-24 09:50:58 +02:00
string-output-visitor.c string-output-visitor: Fix (pseudo) struct handling 2024-01-26 11:16:58 +01:00
tpm.json qapi: convert "Example" sections without titles 2024-07-17 10:20:53 +02:00
trace-events qapi: Generalize struct member policy checking 2021-10-29 18:23:09 +02:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
trace.json qapi: convert "Example" sections without titles 2024-07-17 10:20:53 +02:00
transaction.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
ui.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
vfio.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
virtio.json qapi: Refill doc comments to conform to conventions 2024-08-05 09:31:51 +02:00
yank.json qapi: convert "Example" sections without titles 2024-07-17 10:20:53 +02:00