* [PATCH] drm/qxl: Fix out-of-bounds read in qxl_update_offset_props()
@ 2026-10-08 12:43 Julio Faracco
2026-10-08 12:55 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Julio Faracco @ 2026-10-08 12:43 UTC (permalink / raw)
To: Dave Airlie, Gerd Hoffmann, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, virtualization,
spice-devel, dri-devel, linux-kernel
Function qxl_update_offset_props() dereferences
qdev->client_monitors_config->heads[output->index] for every connector.
The connector list holds qxl_num_crtc entries (default 4), but heads[] is
only allocated for client_monitors_config->count entries. When the client
reports fewer monitors than qxl_num_crtc (e.g. a guest started with
heads=1), output->index exceeds count and the read runs off the end:
BUG: KASAN: slab-out-of-bounds in
qxl_display_read_client_monitors_config+0x61e/0x6f0 [qxl]
Read of size 4 ... located 16 bytes to the right of allocated
32-byte region
Factor the index-vs-count check already open-coded in
qxl_add_monitors_config_modes() and qxl_conn_detect() into a
qxl_output_get_client_head() helper that returns the head or NULL when
the config is absent or does not cover the output's index, and use it
in all three places.
Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
drivers/gpu/drm/qxl/qxl_display.c | 34 +++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c
index 75d47e6b9142..92cc240dc9c2 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -147,6 +147,21 @@ static int qxl_display_copy_rom_client_monitors_config(struct qxl_device *qdev)
return status;
}
+/*
+ * Return the client monitors config head for @output, or NULL when the
+ * client monitors config is absent or does not cover this output's index.
+ */
+static struct qxl_head *qxl_output_get_client_head(struct qxl_output *output)
+{
+ struct qxl_device *qdev = to_qxl(output->base.dev);
+ struct qxl_monitors_config *cfg = qdev->client_monitors_config;
+
+ if (!cfg || output->index >= cfg->count)
+ return NULL;
+
+ return &cfg->heads[output->index];
+}
+
static void qxl_update_offset_props(struct qxl_device *qdev)
{
struct drm_device *dev = &qdev->ddev;
@@ -157,7 +172,9 @@ static void qxl_update_offset_props(struct qxl_device *qdev)
list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
output = drm_connector_to_qxl_output(connector);
- head = &qdev->client_monitors_config->heads[output->index];
+ head = qxl_output_get_client_head(output);
+ if (!head)
+ continue;
drm_object_property_set_value(&connector->base,
dev->mode_config.suggested_x_property, head->x);
@@ -262,12 +279,11 @@ static int qxl_add_monitors_config_modes(struct drm_connector *connector)
return 0;
if (h >= qxl_num_crtc)
return 0;
- if (!qdev->client_monitors_config)
- return 0;
- if (h >= qdev->client_monitors_config->count)
+
+ head = qxl_output_get_client_head(output);
+ if (!head)
return 0;
- head = &qdev->client_monitors_config->heads[h];
DRM_DEBUG_KMS("head %d is %dx%d\n", h, head->width, head->height);
return qxl_add_mode(connector, head->width, head->height, true);
@@ -1103,15 +1119,17 @@ static enum drm_connector_status qxl_conn_detect(
drm_connector_to_qxl_output(connector);
struct drm_device *ddev = connector->dev;
struct qxl_device *qdev = to_qxl(ddev);
+ struct qxl_head *head;
bool connected = false;
/* The first monitor is always connected */
if (!qdev->client_monitors_config) {
if (output->index == 0)
connected = true;
- } else
- connected = qdev->client_monitors_config->count > output->index &&
- qxl_head_enabled(&qdev->client_monitors_config->heads[output->index]);
+ } else {
+ head = qxl_output_get_client_head(output);
+ connected = head && qxl_head_enabled(head);
+ }
DRM_DEBUG("#%d connected: %d\n", output->index, connected);
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/qxl: Fix out-of-bounds read in qxl_update_offset_props()
2026-10-08 12:43 [PATCH] drm/qxl: Fix out-of-bounds read in qxl_update_offset_props() Julio Faracco
@ 2026-10-08 12:55 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-10-08 12:55 UTC (permalink / raw)
To: Julio Faracco
Cc: dri-devel, Eugenio Perez, virtualization, Michael S. Tsirkin
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] drm/qxl: Incomplete fix leaves out-of-bounds read in qxl_conn_get_modes()
- [High] drm/qxl: Lockless reallocation of client_monitors_config causes Use-After-Free
--
commit 3364903c8ea46fb8e3ab3b182d79c5b5a9cc250d
Author: Julio Faracco <jcfaracco@gmail.com>
drm/qxl: Fix out-of-bounds read in qxl_update_offset_props()
This patch introduces a helper to safely validate bounds when the client
reports fewer monitors than configured, preventing an out-of-bounds read.
The helper is applied to several functions across the qxl display driver.
> diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c
> --- a/drivers/gpu/drm/qxl/qxl_display.c
> +++ b/drivers/gpu/drm/qxl/qxl_display.c
> @@ -148,6 +148,21 @@ static int qxl_display_copy_rom_client_monitors_config(struct qxl_device *qdev)
> return status;
> }
>
> +/*
> + * Return the client monitors config head for @output, or NULL when the
> + * client monitors config is absent or does not cover this output's index.
> + */
> +static struct qxl_head *qxl_output_get_client_head(struct qxl_output *output)
> +{
> + struct qxl_device *qdev = to_qxl(output->base.dev);
> + struct qxl_monitors_config *cfg = qdev->client_monitors_config;
> +
> + if (!cfg || output->index >= cfg->count)
> + return NULL;
> +
> + return &cfg->heads[output->index];
[Severity: High]
Does this code create a use-after-free race condition?
The qxl_client_monitors_config_work_func() workqueue asynchronously executes
qxl_display_copy_rom_client_monitors_config() and
qxl_alloc_client_monitors_config(), which frees and reallocates
qdev->client_monitors_config before acquiring the DRM modeset locks.
Since this helper reads qdev->client_monitors_config into cfg without any
synchronization locks, if the background workqueue frees the configuration
array immediately after this fetch:
kfree(qdev->client_monitors_config);
could the subsequent bounds check (cfg->count) and array access
(&cfg->heads[output->index]) dereference freed memory?
> +}
> +
> static void qxl_update_offset_props(struct qxl_device *qdev)
[ ... ]
> @@ -1111,15 +1127,17 @@ static enum drm_connector_status qxl_conn_detect(
> drm_connector_to_qxl_output(connector);
> struct drm_device *ddev = connector->dev;
> struct qxl_device *qdev = to_qxl(ddev);
> + struct qxl_head *head;
> bool connected = false;
>
> /* The first monitor is always connected */
> if (!qdev->client_monitors_config) {
> if (output->index == 0)
> connected = true;
> - } else
> - connected = qdev->client_monitors_config->count > output->index &&
> - qxl_head_enabled(&qdev->client_monitors_config->heads[output->index]);
> + } else {
> + head = qxl_output_get_client_head(output);
> + connected = head && qxl_head_enabled(head);
> + }
[Severity: High]
Does qxl_conn_get_modes() remain vulnerable to the same out-of-bounds read?
This patch fixes the issue here and in a few other places, but
qxl_conn_get_modes() has an identical pattern that was not updated:
if (qdev->client_monitors_config) {
struct qxl_head *head;
head = &qdev->client_monitors_config->heads[output->index];
if (head->width)
...
If output->index exceeds qdev->client_monitors_config->count during a mode
probe, won't this still trigger the KASAN slab-out-of-bounds memory read?
>
> DRM_DEBUG("#%d connected: %d\n", output->index, connected);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261008124317.32199-1-jcfaracco@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-08 12:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08 12:43 [PATCH] drm/qxl: Fix out-of-bounds read in qxl_update_offset_props() Julio Faracco
2026-10-08 12:55 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox