Skip to contentSkip to conversation

Misc crypto & UI patches

GIT PULL Daniel P. Berrangé 2 participants 6 messages Jul 16, 2025 – Jul 17, 2025 Crypto API

lore
Share & tools
lore
#0 lore raw

The following changes since commit c079d3a31e45093286c65f8ca5350beb3a4404a9:

Merge tag 'pull-10.1-rc0-maintainer-140725-1' of https://gitlab.com/stsquad/qemu into staging (2025-07-15 00:12:07 -0400)

are available in the Git repository at:

https://gitlab.com/berrange/qemu tags/misc-next-pull-request

for you to fetch changes up to def71a6b12d817b95a81b622bad2ca096ed5a3ab:

crypto: load all certificates in X509 CA file (2025-07-16 11:27:30 +0100)

----------------------------------------------------------------
* Fix endian defaults when no VNC pixel format message is set
* Add more trace events for VNC messages
* Fix checking of certificate loading
* Eliminate cert limit on loading CA certificates

----------------------------------------------------------------

Daniel P. Berrangé (2):
ui: fix setting client_endian field defaults
ui: add trace events for all client messages

Henry Kleynhans (1):
crypto: load all certificates in X509 CA file

Peter Maydell (1):
crypto/x509-utils: Check for error from gnutls_x509_crt_init()

 crypto/tlscredsx509.c | 23 +++++++++----------
 crypto/x509-utils.c   |  6 ++++-
 ui/trace-events       | 14 ++++++++++++
 ui/vnc.c              | 53 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 13 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

[PULL 4/4] crypto: load all certificates in X509 CA file

From: Henry Kleynhans <[email protected]>

Some CA files may contain multiple intermediaries and roots of trust. These may not fit into the hard-coded limit of 16.

Extend the validation code to allocate enough space to load all of the certificates present in the CA file and ensure they are cleaned up.

[DB: drop MAX_CERTS constant & whitespace tweaks]
---
 crypto/tlscredsx509.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
crypto/tlscredsx509.c +11 -12
index 63a72fe47c..143a4caef2 100644
@@ -426,9 +426,8 @@ qcrypto_tls_creds_load_cert(QCryptoTLSCredsX509 *creds,
 static int
 qcrypto_tls_creds_load_ca_cert_list(QCryptoTLSCredsX509 *creds,
                                     const char *certFile,
-                                    gnutls_x509_crt_t *certs,
-                                    unsigned int certMax,
-                                    size_t *ncerts,
+                                    gnutls_x509_crt_t **certs,
+                                    unsigned int *ncerts,
                                     Error **errp)
 {
     gnutls_datum_t data;
@@ -449,20 +448,18 @@ qcrypto_tls_creds_load_ca_cert_list(QCryptoTLSCredsX509 *creds,
     data.data = (unsigned char *)buf;
     data.size = strlen(buf);
 
-    if (gnutls_x509_crt_list_import(certs, &certMax, &data,
-                                    GNUTLS_X509_FMT_PEM, 0) < 0) {
+    if (gnutls_x509_crt_list_import2(certs, ncerts, &data,
+                                     GNUTLS_X509_FMT_PEM, 0) < 0) {
         error_setg(errp,
                    "Unable to import CA certificate list %s",
                    certFile);
         return -1;
     }
-    *ncerts = certMax;
 
     return 0;
 }
 
 
-#define MAX_CERTS 16
 static int
 qcrypto_tls_creds_x509_sanity_check(QCryptoTLSCredsX509 *creds,
                                     bool isServer,
@@ -471,12 +468,11 @@ qcrypto_tls_creds_x509_sanity_check(QCryptoTLSCredsX509 *creds,
                                     Error **errp)
 {
     gnutls_x509_crt_t cert = NULL;
-    gnutls_x509_crt_t cacerts[MAX_CERTS];
-    size_t ncacerts = 0;
+    gnutls_x509_crt_t *cacerts = NULL;
+    unsigned int ncacerts = 0;
     size_t i;
     int ret = -1;
 
-    memset(cacerts, 0, sizeof(cacerts));
     if (certFile &&
         access(certFile, R_OK) == 0) {
         cert = qcrypto_tls_creds_load_cert(creds,
@@ -488,8 +484,9 @@ qcrypto_tls_creds_x509_sanity_check(QCryptoTLSCredsX509 *creds,
     }
     if (access(cacertFile, R_OK) == 0) {
         if (qcrypto_tls_creds_load_ca_cert_list(creds,
-                                                cacertFile, cacerts,
-                                                MAX_CERTS, &ncacerts,
+                                                cacertFile,
+                                                &cacerts,
+                                                &ncacerts,
                                                 errp) < 0) {
             goto cleanup;
         }
@@ -526,6 +523,8 @@ qcrypto_tls_creds_x509_sanity_check(QCryptoTLSCredsX509 *creds,
     for (i = 0; i < ncacerts; i++) {
         gnutls_x509_crt_deinit(cacerts[i]);
     }
+    gnutls_free(cacerts);
+
     return ret;
 }
 
Signature · 1 line
2.49.0
#2 lore raw

[PULL 2/4] ui: add trace events for all client messages

In reply to Daniel P. Berrangé

This lets us see the full flow of RFB messages received from the client.

---
 ui/trace-events | 14 +++++++++++++
 ui/vnc.c        | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
ui/trace-events +14 -0
index 3da0d5e280..3eba9ca3a8 100644
@@ -48,13 +48,27 @@ vnc_msg_server_ext_desktop_resize(void *state, void *ioc, int width, int height,
 vnc_msg_client_audio_enable(void *state, void *ioc) "VNC client msg audio enable state=%p ioc=%p"
 vnc_msg_client_audio_disable(void *state, void *ioc) "VNC client msg audio disable state=%p ioc=%p"
 vnc_msg_client_audio_format(void *state, void *ioc, int fmt, int channels, int freq) "VNC client msg audio format state=%p ioc=%p fmt=%d channels=%d freq=%d"
+vnc_msg_client_cut_text(void *state, void *ioc, int len) "VNC client msg cut text state=%p ioc=%p len=%u"
+vnc_msg_client_cut_text_ext(void *state, void *ioc, int len, int flags) "VNC client msg cut text state=%p ioc=%p len=%u flags=%u"
+vnc_msg_client_ext_key_event(void *state, void *ioc, int down, int sym, int keycode) "VNC client msg ext key event state=%p ioc=%p down=%u sym=%u keycode=%u"
+vnc_msg_client_framebuffer_update_request(void *state, void *ioc, int incremental, int x, int y, int w, int h) "VNC client msg framebuffer update request state=%p ioc=%p incremental=%u x=%u y=%u w=%u h=%u"
+vnc_msg_client_key_event(void *state, void *ioc, int down, int sym) "VNC client msg key event state=%p ioc=%p down=%u sym=%u"
+vnc_msg_client_pointer_event(void *state, void *ioc, int button_mask, int x, int y) "VNC client msg pointer event state=%p ioc=%p button_mask=%u x=%u y=%u"
 vnc_msg_client_set_desktop_size(void *state, void *ioc, int width, int height, int screens) "VNC client msg set desktop size  state=%p ioc=%p size=%dx%d screens=%d"
+vnc_msg_client_set_encodings(void *state, void *ioc, int limit) "VNC client msg set encodings state=%p ioc=%p limit=%u"
+vnc_msg_client_set_pixel_format(void *state, void *ioc, int bpp, int big_endian, int true_color) "VNC client msg set pixel format state=%p ioc=%p bpp=%u big_endian=%u true_color=%u"
+vnc_msg_client_set_pixel_format_rgb(void *state, void *ioc, int red_max, int green_max, int blue_max, int red_shift, int green_shift, int blue_shift) "VNC client msg set pixel format RGB state=%p ioc=%p red_max=%u green_max=%u blue_max=%u red_shift=%u green_shift=%u blue_shift=%u"
+vnc_msg_client_xvp(void *state, void *ioc, int version, int action) "VNC client msg XVP state=%p ioc=%p version=%u action=%u"
 vnc_client_eof(void *state, void *ioc) "VNC client EOF state=%p ioc=%p"
 vnc_client_io_error(void *state, void *ioc, const char *msg) "VNC client I/O error state=%p ioc=%p errmsg=%s"
 vnc_client_connect(void *state, void *ioc) "VNC client connect state=%p ioc=%p"
 vnc_client_disconnect_start(void *state, void *ioc) "VNC client disconnect start state=%p ioc=%p"
 vnc_client_disconnect_finish(void *state, void *ioc) "VNC client disconnect finish state=%p ioc=%p"
 vnc_client_io_wrap(void *state, void *ioc, const char *type) "VNC client I/O wrap state=%p ioc=%p type=%s"
+vnc_client_pixel_format(void *state, void *ioc, int bpp, int depth, int endian) "VNC client pixel format state=%p ioc=%p bpp=%u depth=%u endian=%u"
+vnc_client_pixel_format_red(void *state, void *ioc, int max, int bits, int shift, int mask) "VNC client pixel format red state=%p ioc=%p max=%u bits=%u shift=%u mask=%u"
+vnc_client_pixel_format_green(void *state, void *ioc, int max, int bits, int shift, int mask) "VNC client pixel format green state=%p ioc=%p max=%u bits=%u shift=%u mask=%u"
+vnc_client_pixel_format_blue(void *state, void *ioc, int max, int bits, int shift, int mask) "VNC client pixel format blue state=%p ioc=%p max=%u bits=%u shift=%u mask=%u"
 vnc_client_throttle_threshold(void *state, void *ioc, size_t oldoffset, size_t offset, int client_width, int client_height, int bytes_per_pixel, void *audio_cap) "VNC client throttle threshold state=%p ioc=%p oldoffset=%zu newoffset=%zu width=%d height=%d bpp=%d audio=%p"
 vnc_client_throttle_incremental(void *state, void *ioc, int job_update, size_t offset) "VNC client throttle incremental state=%p ioc=%p job-update=%d offset=%zu"
 vnc_client_throttle_forced(void *state, void *ioc, int job_update, size_t offset) "VNC client throttle forced state=%p ioc=%p job-update=%d offset=%zu"
ui/vnc.c +52 -0

109 lines not on this page · raw message

Signature · 1 line
2.49.0
#3 lore raw

[PULL 3/4] crypto/x509-utils: Check for error from gnutls_x509_crt_init()

In reply to Daniel P. Berrangé

From: Peter Maydell <[email protected]>

Coverity notes that in qcrypto_get_x509_cert_fingerprint() we call gnutls_x509_crt_init() but don't check for an error return. Add the missing check.

Coverity: CID 1593155

Fixes 10a1d34fc0d ("crypto: Introduce x509 utils")
---
 crypto/x509-utils.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
crypto/x509-utils.c +5 -1
index 8bad00a51b..39bb6d4d8c 100644
@@ -46,7 +46,11 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
         return -1;
     }
 
-    gnutls_x509_crt_init(&crt);
+    if (gnutls_x509_crt_init(&crt) < 0) {
+        error_setg(errp, "Unable to initialize certificate: %s",
+                   gnutls_strerror(ret));
+        return -1;
+    }
 
     if (gnutls_x509_crt_import(crt, &datum, GNUTLS_X509_FMT_PEM) != 0) {
         error_setg(errp, "Failed to import certificate");
Signature · 1 line
2.49.0
#4 lore raw

[PULL 1/4] ui: fix setting client_endian field defaults

In reply to Daniel P. Berrangé

When a VNC client sends a "set pixel format" message, the 'client_endian' field will get initialized, however, it is valid to omit this message if the client wants to use the server's native pixel format. In the latter scenario nothing is initializing the 'client_endian' field, so it remains set to 0, matching neither G_LITTLE_ENDIAN nor G_BIG_ENDIAN. This then results in pixel format conversion routines taking the wrong code paths.

This problem existed before the 'client_be' flag was changed into the 'client_endian' value, but the lack of initialization meant it semantically defaulted to little endian, so only big endian systems would potentially be exposed to incorrect pixel translation.

The 'virt-viewer' / 'remote-viewer' apps always send a "set pixel format" message so aren't exposed to any problems, but the classical 'vncviewer' app will show the problem easily.

---
 ui/vnc.c | 1 +
 1 file changed, 1 insertion(+)
ui/vnc.c +1 -0
index e9c30aad62..a16be468b9 100644
@@ -2329,6 +2329,7 @@ static void pixel_format_message (VncState *vs) {
     char pad[3] = { 0, 0, 0 };
 
     vs->client_pf = qemu_default_pixelformat(32);
+    vs->client_endian = G_BYTE_ORDER;
 
     vnc_write_u8(vs, vs->client_pf.bits_per_pixel); /* bits-per-pixel */
     vnc_write_u8(vs, vs->client_pf.depth); /* depth */
Signature · 1 line
2.49.0
#5 lore raw
In reply to Daniel P. Berrangé
Quoted 25 lines · Daniel P. Berrangé

The following changes since commit c079d3a31e45093286c65f8ca5350beb3a4404a9:

Merge tag 'pull-10.1-rc0-maintainer-140725-1' of https://gitlab.com/stsquad/qemu into staging (2025-07-15 00:12:07 -0400)

are available in the Git repository at:

https://gitlab.com/berrange/qemu tags/misc-next-pull-request

for you to fetch changes up to def71a6b12d817b95a81b622bad2ca096ed5a3ab:

crypto: load all certificates in X509 CA file (2025-07-16 11:27:30 +0100)

----------------------------------------------------------------
* Fix endian defaults when no VNC pixel format message is set
* Add more trace events for VNC messages
* Fix checking of certificate loading
* Eliminate cert limit on loading CA certificates

----------------------------------------------------------------

Daniel P. Berrangé (2):
ui: fix setting client_endian field defaults
ui: add trace events for all client messages

Quoted 5 lines

Henry Kleynhans (1):
crypto: load all certificates in X509 CA file

Peter Maydell (1):
crypto/x509-utils: Check for error from gnutls_x509_crt_init()

Please take a look at the following test failure:

stderr:
../crypto/tlscredsx509.c:526:5: runtime error: control flow integrity check for type 'void (void *)' failed during indirect function call (/lib64/libc.so.6+0xa8e90): note: cfree@GLIBC_2.2.5 defined here ../crypto/tlscredsx509.c:526:5: note: check failed in /builds/qemu-project/qemu/build/qemu-system-x86_64, destination function located in /lib64/libc.so.6
#0 0x562e710ee7e0 in qcrypto_tls_creds_x509_load (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xc037e0) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#1 0x562e710c719a in user_creatable_add_type (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xbdc19a) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#2 0x562e710c74d0 in user_creatable_add_qapi (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xbdc4d0) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#3 0x562e712f634b in qmp_marshal_object_add.cfi (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xe0b34b) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#4 0x562e7135dfac in do_qmp_dispatch_bh.cfi (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xe72fac) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#5 0x562e71387d9e in aio_bh_call (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xe9cd9e) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#6 0x562e71387f8b in aio_bh_poll (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xe9cf8b) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#7 0x562e7136c0fb in aio_dispatch (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xe810fb) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#8 0x562e71388f0a in aio_ctx_dispatch.cfi (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xe9df0a) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#9 0x7f06fbde602b (/lib64/libglib-2.0.so.0+0x5d02b) (BuildId:
c1b2ab1d795f60de663adaf74140f09f2b2fd034)
#10 0x7f06fbde62f4 in g_main_context_dispatch (/lib64/libglib-2.0.so.0+0x5d2f4) (BuildId:
c1b2ab1d795f60de663adaf74140f09f2b2fd034)
#11 0x562e7138a648 in main_loop_wait (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xe9f648) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#12 0x562e70d92b56 in qemu_main_loop (/builds/qemu-project/qemu/build/qemu-system-x86_64+0x8a7b56) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#13 0x562e7122510b in qemu_default_main.cfi (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xd3a10b) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#14 0x562e71225074 in main (/builds/qemu-project/qemu/build/qemu-system-x86_64+0xd3a074) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
#15 0x7f06f9e01087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId:
fc3b3c4da3283cd44c006682a30b9df3242de053)
#16 0x7f06f9e0114a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14a) (BuildId:
fc3b3c4da3283cd44c006682a30b9df3242de053)
#17 0x562e709d9524 in _start (/builds/qemu-project/qemu/build/qemu-system-x86_64+0x4ee524) (BuildId: 62905ce6fa45c21d61eea8ffdcee6ca6b6a2af3d)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../crypto/tlscredsx509.c:526:5
Broken pipe
../tests/qtest/libqtest.c:208: kill_qemu() detected QEMU death from signal 6 (Aborted) (core dumped)
(test program exited with status code -6)

https://gitlab.com/qemu-project/qemu/-/jobs/10717452444#L69

Thanks!

Stefan

Quoted 11 lines
 crypto/tlscredsx509.c | 23 +++++++++----------
 crypto/x509-utils.c   |  6 ++++-
 ui/trace-events       | 14 ++++++++++++
 ui/vnc.c              | 53 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 13 deletions(-)

--
2.49.0