qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/7] Ui patches
@ 2024-02-16 13:31 marcandre.lureau
  2024-02-16 13:31 ` [PULL 1/7] ui: reject extended clipboard message if not activated marcandre.lureau
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: marcandre.lureau @ 2024-02-16 13:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, peter.maydell, Marc-André Lureau

From: Marc-André Lureau <marcandre.lureau@redhat.com>

The following changes since commit 3ff11e4dcabe2b5b4c26e49d741018ec326f127f:

  Merge tag 'pull-target-arm-20240215' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2024-02-15 17:36:30 +0000)

are available in the Git repository at:

  https://gitlab.com/marcandre.lureau/qemu.git tags/ui-pull-request

for you to fetch changes up to 186acfbaf7f325833702f50f75ef5116dc29e233:

  tests/qtest: Depend on dbus_display1_dep (2024-02-16 17:27:22 +0400)

----------------------------------------------------------------
UI-related fixes

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

Akihiko Odaki (3):
  audio: Depend on dbus_display1_dep
  meson: Explicitly specify dbus-display1.h dependency
  tests/qtest: Depend on dbus_display1_dep

Daniel P. Berrangé (1):
  ui: reject extended clipboard message if not activated

Fiona Ebner (2):
  ui/clipboard: mark type as not available when there is no data
  ui/clipboard: add asserts for update and request

Tianlan Zhou (1):
  ui/console: Fix console resize with placeholder surface

 ui/clipboard.c          | 26 +++++++++++++++++++++++---
 ui/console.c            |  2 +-
 ui/vnc.c                |  5 +++++
 audio/meson.build       |  3 ++-
 tests/qtest/meson.build |  2 +-
 ui/meson.build          |  2 +-
 6 files changed, 33 insertions(+), 7 deletions(-)

-- 
2.43.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PULL 1/7] ui: reject extended clipboard message if not activated
  2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
@ 2024-02-16 13:31 ` marcandre.lureau
  2024-02-16 13:31 ` [PULL 2/7] ui/clipboard: mark type as not available when there is no data marcandre.lureau
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre.lureau @ 2024-02-16 13:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, peter.maydell, Daniel P. Berrangé,
	Marc-André Lureau

From: Daniel P. Berrangé <berrange@redhat.com>

The extended clipboard message protocol requires that the client
activate the extension by requesting a psuedo encoding. If this
is not done, then any extended clipboard messages from the client
should be considered invalid and the client dropped.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20240115095119.654271-1-berrange@redhat.com>
---
 ui/vnc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/ui/vnc.c b/ui/vnc.c
index 3db87fd89c..af20d24534 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2445,6 +2445,11 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
         }
 
         if (read_s32(data, 4) < 0) {
+            if (!vnc_has_feature(vs, VNC_FEATURE_CLIPBOARD_EXT)) {
+                error_report("vnc: extended clipboard message while disabled");
+                vnc_client_error(vs);
+                break;
+            }
             if (dlen < 4) {
                 error_report("vnc: malformed payload (header less than 4 bytes)"
                              " in extended clipboard pseudo-encoding.");
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 2/7] ui/clipboard: mark type as not available when there is no data
  2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
  2024-02-16 13:31 ` [PULL 1/7] ui: reject extended clipboard message if not activated marcandre.lureau
@ 2024-02-16 13:31 ` marcandre.lureau
  2024-02-16 13:31 ` [PULL 3/7] ui/clipboard: add asserts for update and request marcandre.lureau
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre.lureau @ 2024-02-16 13:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, peter.maydell, Fiona Ebner, qemu-stable,
	Marc-André Lureau

From: Fiona Ebner <f.ebner@proxmox.com>

With VNC, a client can send a non-extended VNC_MSG_CLIENT_CUT_TEXT
message with len=0. In qemu_clipboard_set_data(), the clipboard info
will be updated setting data to NULL (because g_memdup(data, size)
returns NULL when size is 0). If the client does not set the
VNC_ENCODING_CLIPBOARD_EXT feature when setting up the encodings, then
the 'request' callback for the clipboard peer is not initialized.
Later, because data is NULL, qemu_clipboard_request() can be reached
via vdagent_chr_write() and vdagent_clipboard_recv_request() and
there, the clipboard owner's 'request' callback will be attempted to
be called, but that is a NULL pointer.

In particular, this can happen when using the KRDC (22.12.3) VNC
client.

Another scenario leading to the same issue is with two clients (say
noVNC and KRDC):

The noVNC client sets the extension VNC_FEATURE_CLIPBOARD_EXT and
initializes its cbpeer.

The KRDC client does not, but triggers a vnc_client_cut_text() (note
it's not the _ext variant)). There, a new clipboard info with it as
the 'owner' is created and via qemu_clipboard_set_data() is called,
which in turn calls qemu_clipboard_update() with that info.

In qemu_clipboard_update(), the notifier for the noVNC client will be
called, i.e. vnc_clipboard_notify() and also set vs->cbinfo for the
noVNC client. The 'owner' in that clipboard info is the clipboard peer
for the KRDC client, which did not initialize the 'request' function.
That sounds correct to me, it is the owner of that clipboard info.

Then when noVNC sends a VNC_MSG_CLIENT_CUT_TEXT message (it did set
the VNC_FEATURE_CLIPBOARD_EXT feature correctly, so a check for it
passes), that clipboard info is passed to qemu_clipboard_request() and
the original segfault still happens.

Fix the issue by handling updates with size 0 differently. In
particular, mark in the clipboard info that the type is not available.

While at it, switch to g_memdup2(), because g_memdup() is deprecated.

Cc: qemu-stable@nongnu.org
Fixes: CVE-2023-6683
Reported-by: Markus Frank <m.frank@proxmox.com>
Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Markus Frank <m.frank@proxmox.com>
Message-ID: <20240124105749.204610-1-f.ebner@proxmox.com>
---
 ui/clipboard.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/ui/clipboard.c b/ui/clipboard.c
index 3d14bffaf8..b3f6fa3c9e 100644
--- a/ui/clipboard.c
+++ b/ui/clipboard.c
@@ -163,9 +163,15 @@ void qemu_clipboard_set_data(QemuClipboardPeer *peer,
     }
 
     g_free(info->types[type].data);
-    info->types[type].data = g_memdup(data, size);
-    info->types[type].size = size;
-    info->types[type].available = true;
+    if (size) {
+        info->types[type].data = g_memdup2(data, size);
+        info->types[type].size = size;
+        info->types[type].available = true;
+    } else {
+        info->types[type].data = NULL;
+        info->types[type].size = 0;
+        info->types[type].available = false;
+    }
 
     if (update) {
         qemu_clipboard_update(info);
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 3/7] ui/clipboard: add asserts for update and request
  2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
  2024-02-16 13:31 ` [PULL 1/7] ui: reject extended clipboard message if not activated marcandre.lureau
  2024-02-16 13:31 ` [PULL 2/7] ui/clipboard: mark type as not available when there is no data marcandre.lureau
@ 2024-02-16 13:31 ` marcandre.lureau
  2024-02-16 13:31 ` [PULL 4/7] ui/console: Fix console resize with placeholder surface marcandre.lureau
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre.lureau @ 2024-02-16 13:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, peter.maydell, Fiona Ebner, Marc-André Lureau

From: Fiona Ebner <f.ebner@proxmox.com>

Should an issue like CVE-2023-6683 ever appear again in the future,
it will be more obvious which assumption was violated.

Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20240124105749.204610-2-f.ebner@proxmox.com>
---
 ui/clipboard.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/ui/clipboard.c b/ui/clipboard.c
index b3f6fa3c9e..4264884a6c 100644
--- a/ui/clipboard.c
+++ b/ui/clipboard.c
@@ -65,12 +65,24 @@ bool qemu_clipboard_check_serial(QemuClipboardInfo *info, bool client)
 
 void qemu_clipboard_update(QemuClipboardInfo *info)
 {
+    uint32_t type;
     QemuClipboardNotify notify = {
         .type = QEMU_CLIPBOARD_UPDATE_INFO,
         .info = info,
     };
     assert(info->selection < QEMU_CLIPBOARD_SELECTION__COUNT);
 
+    for (type = 0; type < QEMU_CLIPBOARD_TYPE__COUNT; type++) {
+        /*
+         * If data is missing, the clipboard owner's 'request' callback needs to
+         * be set. Otherwise, there is no way to get the clipboard data and
+         * qemu_clipboard_request() cannot be called.
+         */
+        if (info->types[type].available && !info->types[type].data) {
+            assert(info->owner && info->owner->request);
+        }
+    }
+
     notifier_list_notify(&clipboard_notifiers, &notify);
 
     if (cbinfo[info->selection] != info) {
@@ -132,6 +144,8 @@ void qemu_clipboard_request(QemuClipboardInfo *info,
         !info->owner)
         return;
 
+    assert(info->owner->request);
+
     info->types[type].requested = true;
     info->owner->request(info, type);
 }
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 4/7] ui/console: Fix console resize with placeholder surface
  2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
                   ` (2 preceding siblings ...)
  2024-02-16 13:31 ` [PULL 3/7] ui/clipboard: add asserts for update and request marcandre.lureau
@ 2024-02-16 13:31 ` marcandre.lureau
  2024-02-16 13:31 ` [PULL 5/7] audio: Depend on dbus_display1_dep marcandre.lureau
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre.lureau @ 2024-02-16 13:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, peter.maydell, Tianlan Zhou,
	Marc-André Lureau

From: Tianlan Zhou <bobby825@126.com>

In `qemu_console_resize()`, the old surface of the console is keeped if the new
console size is the same as the old one. If the old surface is a placeholder,
and the new size of console is the same as the placeholder surface (640*480),
the surface won't be replace.
In this situation, the surface's `QEMU_PLACEHOLDER_FLAG` flag is still set, so
the console won't be displayed in SDL display mode.
This patch fixes this problem by forcing a new surface if the old one is a
placeholder.

Signed-off-by: Tianlan Zhou <bobby825@126.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20240207172024.8-1-bobby825@126.com>
---
 ui/console.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui/console.c b/ui/console.c
index 7db921e3b7..832055675c 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1577,7 +1577,7 @@ void qemu_console_resize(QemuConsole *s, int width, int height)
     assert(QEMU_IS_GRAPHIC_CONSOLE(s));
 
     if ((s->scanout.kind != SCANOUT_SURFACE ||
-         (surface && surface->flags & QEMU_ALLOCATED_FLAG)) &&
+         (surface && !is_buffer_shared(surface) && !is_placeholder(surface))) &&
         qemu_console_get_width(s, -1) == width &&
         qemu_console_get_height(s, -1) == height) {
         return;
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 5/7] audio: Depend on dbus_display1_dep
  2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
                   ` (3 preceding siblings ...)
  2024-02-16 13:31 ` [PULL 4/7] ui/console: Fix console resize with placeholder surface marcandre.lureau
@ 2024-02-16 13:31 ` marcandre.lureau
  2024-02-16 13:31 ` [PULL 6/7] meson: Explicitly specify dbus-display1.h dependency marcandre.lureau
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre.lureau @ 2024-02-16 13:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, peter.maydell, Akihiko Odaki,
	Marc-André Lureau

From: Akihiko Odaki <akihiko.odaki@daynix.com>

dbusaudio needs dbus_display1_dep.

Fixes: 739362d4205c ("audio: add "dbus" audio backend")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20240214-dbus-v7-1-7eff29f04c34@daynix.com>
---
 audio/meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/audio/meson.build b/audio/meson.build
index c8f658611f..608f35e6af 100644
--- a/audio/meson.build
+++ b/audio/meson.build
@@ -30,7 +30,8 @@ endforeach
 
 if dbus_display
     module_ss = ss.source_set()
-    module_ss.add(when: [gio, pixman], if_true: files('dbusaudio.c'))
+    module_ss.add(when: [gio, dbus_display1_dep, pixman],
+                  if_true: files('dbusaudio.c'))
     audio_modules += {'dbus': module_ss}
 endif
 
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 6/7] meson: Explicitly specify dbus-display1.h dependency
  2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
                   ` (4 preceding siblings ...)
  2024-02-16 13:31 ` [PULL 5/7] audio: Depend on dbus_display1_dep marcandre.lureau
@ 2024-02-16 13:31 ` marcandre.lureau
  2024-02-16 13:31 ` [PULL 7/7] tests/qtest: Depend on dbus_display1_dep marcandre.lureau
  2024-02-20 15:26 ` [PULL 0/7] Ui patches Peter Maydell
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre.lureau @ 2024-02-16 13:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, peter.maydell, Akihiko Odaki,
	Marc-André Lureau

From: Akihiko Odaki <akihiko.odaki@daynix.com>

Explicitly specify dbus-display1.h as a dependency so that files
depending on it will not get compiled too early.

Fixes: 1222070e7728 ("meson: ensure dbus-display generated code is built before other units")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20240214-dbus-v7-2-7eff29f04c34@daynix.com>
---
 ui/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui/meson.build b/ui/meson.build
index 376e0d771b..0b7e2b6f6b 100644
--- a/ui/meson.build
+++ b/ui/meson.build
@@ -91,7 +91,7 @@ if dbus_display
                                           '--c-namespace', 'QemuDBus',
                                           '--generate-c-code', '@BASENAME@'])
   dbus_display1_lib = static_library('dbus-display1', dbus_display1, dependencies: gio)
-  dbus_display1_dep = declare_dependency(link_with: dbus_display1_lib, include_directories: include_directories('.'))
+  dbus_display1_dep = declare_dependency(link_with: dbus_display1_lib, sources: dbus_display1[0])
   dbus_ss.add(when: [gio, dbus_display1_dep],
               if_true: [files(
                 'dbus-chardev.c',
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 7/7] tests/qtest: Depend on dbus_display1_dep
  2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
                   ` (5 preceding siblings ...)
  2024-02-16 13:31 ` [PULL 6/7] meson: Explicitly specify dbus-display1.h dependency marcandre.lureau
@ 2024-02-16 13:31 ` marcandre.lureau
  2024-02-20 15:26 ` [PULL 0/7] Ui patches Peter Maydell
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre.lureau @ 2024-02-16 13:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, peter.maydell, Akihiko Odaki, Thomas Huth,
	Laurent Vivier, Paolo Bonzini

From: Akihiko Odaki <akihiko.odaki@daynix.com>

It ensures dbus-display1.c will not be recompiled.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20240214-dbus-v7-3-7eff29f04c34@daynix.com>
---
 tests/qtest/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 2b89e8634b..430d49b409 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -344,7 +344,7 @@ if vnc.found()
 endif
 
 if dbus_display
-  qtests += {'dbus-display-test': [dbus_display1, gio]}
+  qtests += {'dbus-display-test': [dbus_display1_dep, gio]}
 endif
 
 qtest_executables = {}
-- 
2.43.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PULL 0/7] Ui patches
  2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
                   ` (6 preceding siblings ...)
  2024-02-16 13:31 ` [PULL 7/7] tests/qtest: Depend on dbus_display1_dep marcandre.lureau
@ 2024-02-20 15:26 ` Peter Maydell
  7 siblings, 0 replies; 9+ messages in thread
From: Peter Maydell @ 2024-02-20 15:26 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: qemu-devel, Gerd Hoffmann

On Fri, 16 Feb 2024 at 13:31, <marcandre.lureau@redhat.com> wrote:
>
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> The following changes since commit 3ff11e4dcabe2b5b4c26e49d741018ec326f127f:
>
>   Merge tag 'pull-target-arm-20240215' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2024-02-15 17:36:30 +0000)
>
> are available in the Git repository at:
>
>   https://gitlab.com/marcandre.lureau/qemu.git tags/ui-pull-request
>
> for you to fetch changes up to 186acfbaf7f325833702f50f75ef5116dc29e233:
>
>   tests/qtest: Depend on dbus_display1_dep (2024-02-16 17:27:22 +0400)
>
> ----------------------------------------------------------------
> UI-related fixes
>
> ----------------------------------------------------------------


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/9.0
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-02-20 15:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-16 13:31 [PULL 0/7] Ui patches marcandre.lureau
2024-02-16 13:31 ` [PULL 1/7] ui: reject extended clipboard message if not activated marcandre.lureau
2024-02-16 13:31 ` [PULL 2/7] ui/clipboard: mark type as not available when there is no data marcandre.lureau
2024-02-16 13:31 ` [PULL 3/7] ui/clipboard: add asserts for update and request marcandre.lureau
2024-02-16 13:31 ` [PULL 4/7] ui/console: Fix console resize with placeholder surface marcandre.lureau
2024-02-16 13:31 ` [PULL 5/7] audio: Depend on dbus_display1_dep marcandre.lureau
2024-02-16 13:31 ` [PULL 6/7] meson: Explicitly specify dbus-display1.h dependency marcandre.lureau
2024-02-16 13:31 ` [PULL 7/7] tests/qtest: Depend on dbus_display1_dep marcandre.lureau
2024-02-20 15:26 ` [PULL 0/7] Ui patches Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).