From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Marcelo Tosatti" <mtosatti@redhat.com>,
kvm@vger.kernel.org, "Daniel P. Berrangé" <berrange@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH 3/5] ui/vnc: validate color shifts in SetPixelFormat
Date: Mon, 06 Jul 2026 16:53:50 +0400 [thread overview]
Message-ID: <20260706-fix-v1-3-4b83a70e9f3b@redhat.com> (raw)
In-Reply-To: <20260706-fix-v1-0-4b83a70e9f3b@redhat.com>
A malicious VNC client can send a SetPixelFormat message with shift
values >= 32, causing UB mask computation
(e.g. red_max << red_shift where red_shift is 255). Apparently, this is
not covered by -fwrapv.
Reject color shifts >= bits_per_pixel before computing masks, and cast
the max values to uint32_t to avoid signed integer overflow when a
valid shift (e.g. 24) would set bit 31 of a signed int.
Fixes: 9f64916da20 ("pixman/vnc: use pixman images in vnc.")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3948
Reported-by: huntr bubble
Signed-off-by: Marc-Andre Lureau <marcandre.lureau@redhat.com>
---
ui/vnc.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/ui/vnc.c b/ui/vnc.c
index 559d3954b87..94a38242c56 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2276,18 +2276,25 @@ static void set_pixel_format(VncState *vs, int bits_per_pixel,
return;
}
+ if (red_shift >= bits_per_pixel ||
+ green_shift >= bits_per_pixel ||
+ blue_shift >= bits_per_pixel) {
+ 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;
- vs->client_pf.rmask = red_max << red_shift;
+ vs->client_pf.rmask = (uint32_t)red_max << red_shift;
vs->client_pf.gmax = green_max ? green_max : 0xFF;
vs->client_pf.gbits = ctpopl(green_max);
vs->client_pf.gshift = green_shift;
- vs->client_pf.gmask = green_max << green_shift;
+ vs->client_pf.gmask = (uint32_t)green_max << green_shift;
vs->client_pf.bmax = blue_max ? blue_max : 0xFF;
vs->client_pf.bbits = ctpopl(blue_max);
vs->client_pf.bshift = blue_shift;
- vs->client_pf.bmask = blue_max << blue_shift;
+ vs->client_pf.bmask = (uint32_t)blue_max << blue_shift;
vs->client_pf.bits_per_pixel = bits_per_pixel;
vs->client_pf.bytes_per_pixel = bits_per_pixel / 8;
vs->client_pf.depth = bits_per_pixel == 32 ? 24 : bits_per_pixel;
--
2.55.0
next prev parent reply other threads:[~2026-07-06 12:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 12:53 [PATCH 0/5] Various UI/security-related fixes Marc-André Lureau
2026-07-06 12:53 ` [PATCH 1/5] i386/tdx: fix uninitialized variable warning in tdx_check_features Marc-André Lureau
2026-07-06 12:53 ` [PATCH 2/5] ui/vnc: fix OOB write in vnc_refresh_lossy_rect Marc-André Lureau
2026-07-06 12:53 ` Marc-André Lureau [this message]
2026-07-06 12:53 ` [PATCH 4/5] ui/vnc: use RFB wire types for client message handlers Marc-André Lureau
2026-07-06 12:53 ` [PATCH 5/5] ui/input-barrier: fix off-by-one in keycode bounds check Marc-André Lureau
2026-07-10 13:43 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260706-fix-v1-3-4b83a70e9f3b@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=berrange@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox