* [PATCH] ui/vnc: validate SetPixelFormat field ranges
@ 2026-07-13 10:00 marcandre.lureau
2026-07-13 10:07 ` Daniel P. Berrangé
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: marcandre.lureau @ 2026-07-13 10:00 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc-André Lureau
From: Marc-André Lureau <marcandre.lureau@redhat.com>
The VNC SetPixelFormat message carries red/green/blue_max as 16-bit
values, but PixelFormat stores them as uint8_t. A client sending a
max value above 255 (e.g. 0x0100) passes the existing non-zero check
but silently truncates to 0 on assignment, leading to a division by
zero in the Tight PNG palette path.
Similarly, the shift values are read as uint8_t from the wire but
used in left-shift expressions (red_max << red_shift). Shifts >= 32
are undefined behavior in C for 32-bit operands.
Add explicit range checks for both: reject the connection if any
channel max exceeds UINT8_MAX, or any shift is >= 32.
Fixes: CVE-2026-15578
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3976
Reported-by: dong ling
Signed-off-by: Marc-Andre Lureau <marcandre.lureau@redhat.com>
---
ui/vnc.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/ui/vnc.c b/ui/vnc.c
index dfc8262d42a..c4ee4738b28 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2276,6 +2276,16 @@ static void set_pixel_format(VncState *vs, int bits_per_pixel,
return;
}
+ if (red_max > UINT8_MAX || green_max > UINT8_MAX || blue_max > UINT8_MAX) {
+ vnc_client_error(vs);
+ return;
+ }
+
+ if (red_shift >= 32 || green_shift >= 32 || blue_shift >= 32) {
+ vnc_client_error(vs);
+ return;
+ }
+
vs->client_pf.rmax = red_max ? red_max : 0xFF;
vs->client_pf.rbits = ctpopl(red_max);
vs->client_pf.rshift = red_shift;
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ui/vnc: validate SetPixelFormat field ranges
2026-07-13 10:00 [PATCH] ui/vnc: validate SetPixelFormat field ranges marcandre.lureau
@ 2026-07-13 10:07 ` Daniel P. Berrangé
2026-07-13 10:49 ` Philippe Mathieu-Daudé
2026-07-13 11:06 ` Marc-André Lureau
2 siblings, 0 replies; 4+ messages in thread
From: Daniel P. Berrangé @ 2026-07-13 10:07 UTC (permalink / raw)
To: marcandre.lureau; +Cc: qemu-devel
On Mon, Jul 13, 2026 at 02:00:56PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> The VNC SetPixelFormat message carries red/green/blue_max as 16-bit
> values, but PixelFormat stores them as uint8_t. A client sending a
> max value above 255 (e.g. 0x0100) passes the existing non-zero check
> but silently truncates to 0 on assignment, leading to a division by
> zero in the Tight PNG palette path.
>
> Similarly, the shift values are read as uint8_t from the wire but
> used in left-shift expressions (red_max << red_shift). Shifts >= 32
> are undefined behavior in C for 32-bit operands.
>
> Add explicit range checks for both: reject the connection if any
> channel max exceeds UINT8_MAX, or any shift is >= 32.
>
> Fixes: CVE-2026-15578
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3976
> Reported-by: dong ling
> Signed-off-by: Marc-Andre Lureau <marcandre.lureau@redhat.com>
> ---
> ui/vnc.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index dfc8262d42a..c4ee4738b28 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -2276,6 +2276,16 @@ static void set_pixel_format(VncState *vs, int bits_per_pixel,
> return;
> }
>
> + if (red_max > UINT8_MAX || green_max > UINT8_MAX || blue_max > UINT8_MAX) {
> + vnc_client_error(vs);
> + return;
> + }
> +
> + if (red_shift >= 32 || green_shift >= 32 || blue_shift >= 32) {
> + vnc_client_error(vs);
> + return;
> + }
> +
> vs->client_pf.rmax = red_max ? red_max : 0xFF;
> vs->client_pf.rbits = ctpopl(red_max);
> vs->client_pf.rshift = red_shift;
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ui/vnc: validate SetPixelFormat field ranges
2026-07-13 10:00 [PATCH] ui/vnc: validate SetPixelFormat field ranges marcandre.lureau
2026-07-13 10:07 ` Daniel P. Berrangé
@ 2026-07-13 10:49 ` Philippe Mathieu-Daudé
2026-07-13 11:06 ` Marc-André Lureau
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-07-13 10:49 UTC (permalink / raw)
To: marcandre.lureau, qemu-devel
On 13/7/26 12:00, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> The VNC SetPixelFormat message carries red/green/blue_max as 16-bit
> values, but PixelFormat stores them as uint8_t. A client sending a
> max value above 255 (e.g. 0x0100) passes the existing non-zero check
> but silently truncates to 0 on assignment, leading to a division by
> zero in the Tight PNG palette path.
>
> Similarly, the shift values are read as uint8_t from the wire but
> used in left-shift expressions (red_max << red_shift). Shifts >= 32
> are undefined behavior in C for 32-bit operands.
>
> Add explicit range checks for both: reject the connection if any
> channel max exceeds UINT8_MAX, or any shift is >= 32.
>
> Fixes: CVE-2026-15578
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3976
> Reported-by: dong ling
> Signed-off-by: Marc-Andre Lureau <marcandre.lureau@redhat.com>
> ---
> ui/vnc.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ui/vnc: validate SetPixelFormat field ranges
2026-07-13 10:00 [PATCH] ui/vnc: validate SetPixelFormat field ranges marcandre.lureau
2026-07-13 10:07 ` Daniel P. Berrangé
2026-07-13 10:49 ` Philippe Mathieu-Daudé
@ 2026-07-13 11:06 ` Marc-André Lureau
2 siblings, 0 replies; 4+ messages in thread
From: Marc-André Lureau @ 2026-07-13 11:06 UTC (permalink / raw)
To: qemu-devel
Hi
On Mon, Jul 13, 2026 at 2:02 PM <marcandre.lureau@redhat.com> wrote:
>
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> The VNC SetPixelFormat message carries red/green/blue_max as 16-bit
> values, but PixelFormat stores them as uint8_t. A client sending a
> max value above 255 (e.g. 0x0100) passes the existing non-zero check
> but silently truncates to 0 on assignment, leading to a division by
> zero in the Tight PNG palette path.
>
> Similarly, the shift values are read as uint8_t from the wire but
> used in left-shift expressions (red_max << red_shift). Shifts >= 32
> are undefined behavior in C for 32-bit operands.
>
> Add explicit range checks for both: reject the connection if any
> channel max exceeds UINT8_MAX, or any shift is >= 32.
>
> Fixes: CVE-2026-15578
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3976
> Reported-by: dong ling
> Signed-off-by: Marc-Andre Lureau <marcandre.lureau@redhat.com>
> ---
> ui/vnc.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index dfc8262d42a..c4ee4738b28 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -2276,6 +2276,16 @@ static void set_pixel_format(VncState *vs, int bits_per_pixel,
> return;
> }
>
> + if (red_max > UINT8_MAX || green_max > UINT8_MAX || blue_max > UINT8_MAX) {
> + vnc_client_error(vs);
> + return;
> + }
> +
> + if (red_shift >= 32 || green_shift >= 32 || blue_shift >= 32) {
> + vnc_client_error(vs);
> + return;
> + }
I am dropping this block, it's already covered by earlier patch:
https://patchew.org/QEMU/20260706-fix-v1-0-4b83a70e9f3b@redhat.com/20260706-fix-v1-3-4b83a70e9f3b@redhat.com/
> +
> vs->client_pf.rmax = red_max ? red_max : 0xFF;
> vs->client_pf.rbits = ctpopl(red_max);
> vs->client_pf.rshift = red_shift;
> --
> 2.55.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-13 11:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13 10:00 [PATCH] ui/vnc: validate SetPixelFormat field ranges marcandre.lureau
2026-07-13 10:07 ` Daniel P. Berrangé
2026-07-13 10:49 ` Philippe Mathieu-Daudé
2026-07-13 11:06 ` Marc-André Lureau
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.