2024-11-20 13:30:48 +00:00
|
|
|
From 785893c171d994bbcffe0585953ca0d290f3c27e Mon Sep 17 00:00:00 2001
|
2024-08-27 15:10:21 +00:00
|
|
|
From: Eric Blake <eblake@redhat.com>
|
|
|
|
Date: Wed, 7 Aug 2024 08:50:01 -0500
|
2024-11-20 13:30:48 +00:00
|
|
|
Subject: [PATCH 2/5] nbd/server: Plumb in new args to nbd_client_add()
|
2024-08-27 15:10:21 +00:00
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
RH-Author: Eric Blake <eblake@redhat.com>
|
2024-11-20 13:30:48 +00:00
|
|
|
RH-MergeRequest: 263: nbd/server: fix CVE-2024-7409 (qemu crash on nbd-server-stop) [RHEL 10.0]
|
|
|
|
RH-Jira: RHEL-52599
|
2024-08-27 15:10:21 +00:00
|
|
|
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
2024-11-20 13:30:48 +00:00
|
|
|
RH-Commit: [1/4] 68e9f83d467704d3dfbf0a879b2bb4d9a568f81c (redhat/centos-stream/src/qemu-kvm)
|
2024-08-27 15:10:21 +00:00
|
|
|
|
|
|
|
Upcoming patches to fix a CVE need to track an opaque pointer passed
|
|
|
|
in by the owner of a client object, as well as request for a time
|
|
|
|
limit on how fast negotiation must complete. Prepare for that by
|
|
|
|
changing the signature of nbd_client_new() and adding an accessor to
|
|
|
|
get at the opaque pointer, although for now the two servers
|
|
|
|
(qemu-nbd.c and blockdev-nbd.c) do not change behavior even though
|
|
|
|
they pass in a new default timeout value.
|
|
|
|
|
|
|
|
Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
|
|
|
|
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
|
Message-ID: <20240807174943.771624-11-eblake@redhat.com>
|
|
|
|
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
|
[eblake: s/LIMIT/MAX_SECS/ as suggested by Dan]
|
|
|
|
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
|
|
|
|
|
(cherry picked from commit fb1c2aaa981e0a2fa6362c9985f1296b74f055ac)
|
2024-11-20 13:30:48 +00:00
|
|
|
Jira: https://issues.redhat.com/browse/RHEL-52599
|
2024-08-27 15:10:21 +00:00
|
|
|
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
|
---
|
|
|
|
blockdev-nbd.c | 6 ++++--
|
|
|
|
include/block/nbd.h | 11 ++++++++++-
|
|
|
|
nbd/server.c | 20 +++++++++++++++++---
|
|
|
|
qemu-nbd.c | 4 +++-
|
|
|
|
4 files changed, 34 insertions(+), 7 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
|
2024-11-20 13:30:48 +00:00
|
|
|
index 213012435f..267a1de903 100644
|
2024-08-27 15:10:21 +00:00
|
|
|
--- a/blockdev-nbd.c
|
|
|
|
+++ b/blockdev-nbd.c
|
2024-11-20 13:30:48 +00:00
|
|
|
@@ -64,8 +64,10 @@ static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc,
|
2024-08-27 15:10:21 +00:00
|
|
|
nbd_update_server_watch(nbd_server);
|
|
|
|
|
|
|
|
qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server");
|
|
|
|
- nbd_client_new(cioc, nbd_server->tlscreds, nbd_server->tlsauthz,
|
|
|
|
- nbd_blockdev_client_closed);
|
|
|
|
+ /* TODO - expose handshake timeout as QMP option */
|
|
|
|
+ nbd_client_new(cioc, NBD_DEFAULT_HANDSHAKE_MAX_SECS,
|
|
|
|
+ nbd_server->tlscreds, nbd_server->tlsauthz,
|
|
|
|
+ nbd_blockdev_client_closed, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nbd_update_server_watch(NBDServerData *s)
|
|
|
|
diff --git a/include/block/nbd.h b/include/block/nbd.h
|
2024-11-20 13:30:48 +00:00
|
|
|
index 4e7bd6342f..1d4d65922d 100644
|
2024-08-27 15:10:21 +00:00
|
|
|
--- a/include/block/nbd.h
|
|
|
|
+++ b/include/block/nbd.h
|
2024-11-20 13:30:48 +00:00
|
|
|
@@ -33,6 +33,12 @@ typedef struct NBDMetaContexts NBDMetaContexts;
|
2024-08-27 15:10:21 +00:00
|
|
|
|
|
|
|
extern const BlockExportDriver blk_exp_nbd;
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * NBD_DEFAULT_HANDSHAKE_MAX_SECS: Number of seconds in which client must
|
|
|
|
+ * succeed at NBD_OPT_GO before being forcefully dropped as too slow.
|
|
|
|
+ */
|
|
|
|
+#define NBD_DEFAULT_HANDSHAKE_MAX_SECS 10
|
|
|
|
+
|
|
|
|
/* Handshake phase structs - this struct is passed on the wire */
|
|
|
|
|
2024-11-20 13:30:48 +00:00
|
|
|
typedef struct NBDOption {
|
|
|
|
@@ -403,9 +409,12 @@ AioContext *nbd_export_aio_context(NBDExport *exp);
|
2024-08-27 15:10:21 +00:00
|
|
|
NBDExport *nbd_export_find(const char *name);
|
|
|
|
|
|
|
|
void nbd_client_new(QIOChannelSocket *sioc,
|
|
|
|
+ uint32_t handshake_max_secs,
|
|
|
|
QCryptoTLSCreds *tlscreds,
|
|
|
|
const char *tlsauthz,
|
|
|
|
- void (*close_fn)(NBDClient *, bool));
|
|
|
|
+ void (*close_fn)(NBDClient *, bool),
|
|
|
|
+ void *owner);
|
|
|
|
+void *nbd_client_owner(NBDClient *client);
|
|
|
|
void nbd_client_get(NBDClient *client);
|
|
|
|
void nbd_client_put(NBDClient *client);
|
|
|
|
|
|
|
|
diff --git a/nbd/server.c b/nbd/server.c
|
2024-11-20 13:30:48 +00:00
|
|
|
index 892797bb11..e50012499f 100644
|
2024-08-27 15:10:21 +00:00
|
|
|
--- a/nbd/server.c
|
|
|
|
+++ b/nbd/server.c
|
2024-11-20 13:30:48 +00:00
|
|
|
@@ -124,12 +124,14 @@ struct NBDMetaContexts {
|
2024-08-27 15:10:21 +00:00
|
|
|
struct NBDClient {
|
2024-11-20 13:30:48 +00:00
|
|
|
int refcount; /* atomic */
|
2024-08-27 15:10:21 +00:00
|
|
|
void (*close_fn)(NBDClient *client, bool negotiated);
|
|
|
|
+ void *owner;
|
|
|
|
|
2024-11-20 13:30:48 +00:00
|
|
|
QemuMutex lock;
|
|
|
|
|
2024-08-27 15:10:21 +00:00
|
|
|
NBDExport *exp;
|
|
|
|
QCryptoTLSCreds *tlscreds;
|
|
|
|
char *tlsauthz;
|
|
|
|
+ uint32_t handshake_max_secs;
|
|
|
|
QIOChannelSocket *sioc; /* The underlying data channel */
|
|
|
|
QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) */
|
|
|
|
|
2024-11-20 13:30:48 +00:00
|
|
|
@@ -3191,6 +3193,7 @@ static coroutine_fn void nbd_co_client_start(void *opaque)
|
2024-08-27 15:10:21 +00:00
|
|
|
|
|
|
|
qemu_co_mutex_init(&client->send_lock);
|
|
|
|
|
|
|
|
+ /* TODO - utilize client->handshake_max_secs */
|
|
|
|
if (nbd_negotiate(client, &local_err)) {
|
|
|
|
if (local_err) {
|
|
|
|
error_report_err(local_err);
|
2024-11-20 13:30:48 +00:00
|
|
|
@@ -3205,14 +3208,17 @@ static coroutine_fn void nbd_co_client_start(void *opaque)
|
2024-08-27 15:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
- * Create a new client listener using the given channel @sioc.
|
|
|
|
+ * Create a new client listener using the given channel @sioc and @owner.
|
|
|
|
* Begin servicing it in a coroutine. When the connection closes, call
|
|
|
|
- * @close_fn with an indication of whether the client completed negotiation.
|
|
|
|
+ * @close_fn with an indication of whether the client completed negotiation
|
|
|
|
+ * within @handshake_max_secs seconds (0 for unbounded).
|
|
|
|
*/
|
|
|
|
void nbd_client_new(QIOChannelSocket *sioc,
|
|
|
|
+ uint32_t handshake_max_secs,
|
|
|
|
QCryptoTLSCreds *tlscreds,
|
|
|
|
const char *tlsauthz,
|
|
|
|
- void (*close_fn)(NBDClient *, bool))
|
|
|
|
+ void (*close_fn)(NBDClient *, bool),
|
|
|
|
+ void *owner)
|
|
|
|
{
|
|
|
|
NBDClient *client;
|
|
|
|
Coroutine *co;
|
2024-11-20 13:30:48 +00:00
|
|
|
@@ -3225,13 +3231,21 @@ void nbd_client_new(QIOChannelSocket *sioc,
|
2024-08-27 15:10:21 +00:00
|
|
|
object_ref(OBJECT(client->tlscreds));
|
|
|
|
}
|
|
|
|
client->tlsauthz = g_strdup(tlsauthz);
|
|
|
|
+ client->handshake_max_secs = handshake_max_secs;
|
|
|
|
client->sioc = sioc;
|
|
|
|
qio_channel_set_delay(QIO_CHANNEL(sioc), false);
|
|
|
|
object_ref(OBJECT(client->sioc));
|
|
|
|
client->ioc = QIO_CHANNEL(sioc);
|
|
|
|
object_ref(OBJECT(client->ioc));
|
|
|
|
client->close_fn = close_fn;
|
|
|
|
+ client->owner = owner;
|
|
|
|
|
|
|
|
co = qemu_coroutine_create(nbd_co_client_start, client);
|
|
|
|
qemu_coroutine_enter(co);
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+void *
|
|
|
|
+nbd_client_owner(NBDClient *client)
|
|
|
|
+{
|
|
|
|
+ return client->owner;
|
|
|
|
+}
|
|
|
|
diff --git a/qemu-nbd.c b/qemu-nbd.c
|
2024-11-20 13:30:48 +00:00
|
|
|
index d7b3ccab21..48e2fa5858 100644
|
2024-08-27 15:10:21 +00:00
|
|
|
--- a/qemu-nbd.c
|
|
|
|
+++ b/qemu-nbd.c
|
2024-11-20 13:30:48 +00:00
|
|
|
@@ -390,7 +390,9 @@ static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc,
|
2024-08-27 15:10:21 +00:00
|
|
|
|
|
|
|
nb_fds++;
|
|
|
|
nbd_update_server_watch();
|
|
|
|
- nbd_client_new(cioc, tlscreds, tlsauthz, nbd_client_closed);
|
|
|
|
+ /* TODO - expose handshake timeout as command line option */
|
|
|
|
+ nbd_client_new(cioc, NBD_DEFAULT_HANDSHAKE_MAX_SECS,
|
|
|
|
+ tlscreds, tlsauthz, nbd_client_closed, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nbd_update_server_watch(void)
|
|
|
|
--
|
|
|
|
2.39.3
|
|
|
|
|