ui/vnc: fix multiple OOB memory accesses
cover ui/vnc: fix multiple OOB memory accesses
The following VNC patches are in response to recent disclosures to the qemu-security list.
Daniel P. Berrangé (4):
ui/vnc: fix OOB read access in VNC SASL mechname array ui/vnc: fix OOB write in VNC stats array ui/vnc: fix OOB write in lossy rect worker code ui/vnc: fix OOB read updating VNC update frequency stats
ui/vnc-auth-sasl.c | 2 ++ ui/vnc.c | 14 ++++++++------ ui/vnc.h | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/4 ui/vnc: fix OOB read access in VNC SASL mechname array
When reading the SASL mechname array off the VNC connection, if malicious, the received data may contain embedded NULs. If this happens the memory buffer returned by g_strndup may be shorter than the original data. Unfortunately the code continued to index into this buffer with an offset equal to the original length. This is a potential OOB read of the array.
--- ui/vnc-auth-sasl.c | 2 ++ 1 file changed, 2 insertions(+)
ui/vnc-auth-sasl.c +2 -0
@@ -489,6 +489,8 @@ static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_char *mechname =g_strndup ((const char *) data, len);trace_vnc_auth_sasl_mech_choose (vs, mechname); +/* If 'data' had embedded NUL the dup'd string might now be shorter */ + len =strlen (mechname);if (strncmp (vs->sasl.mechlist, mechname, len) ==0 ) {if (vs->sasl.mechlist[len] !='\0' && vs->sasl.mechlist[len] !=',' ) {
Signature · 1 line
2.54.0
PATCH 2/4 ui/vnc: fix OOB write in VNC stats array
In reply to Daniel P. BerrangéThe VncSurface struct maintains update statistics in an array:
VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
where the dimensions are defined as:
#define VNC_STAT_RECT 64 #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT) #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)
If VNC_MAX_WIDTH / VNC_MAX_HEIGHT are not an exact multiple of VNC_STAT_REC, the COLS/ROWS will be undersized by 1.
Unfortunately:
#define VNC_MAX_HEIGHT 2160
is not a multiple of 64, so there is potential for OOB reads and writes in the 'stats' array, if the guest surface is over 2112 pixels in height. An array overflow occurs when vnc_update_stats() records new statistics, either scribbling over data later in the VncDisplay struct that 'stats' is embedded in, or performing an OOB write on the allocated struct memory.
--- ui/vnc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ui/vnc.h +2 -2
@@ -85,8 +85,8 @@ typedef void VncSendHextileTile(VncState *vs,#define VNC_DIRTY_BPL (x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE)#define VNC_STAT_RECT 64 -#define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT) -#define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT) +#define VNC_STAT_COLS DIV_ROUND_UP(VNC_MAX_WIDTH, VNC_STAT_RECT) +#define VNC_STAT_ROWS DIV_ROUND_UP(VNC_MAX_HEIGHT, VNC_STAT_RECT)#define VNC_AUTH_CHALLENGE_SIZE 16
Signature · 1 line
2.54.0
PATCH 3/4 ui/vnc: fix OOB write in lossy rect worker code
In reply to Daniel P. BerrangéIncorrect calculation of the boundary condition when tracking lossy rectangles in the worker thread will result in an OOB write which can corrupt further worker state, and/or trigger any guard pages that may lie beyond the VncWorker struct. This can be triggered through careful choice of the display resolution in the guest OS by an unprivileged user.
--- ui/vnc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
ui/vnc.c +4 -4
@@ -2982,13 +2982,13 @@ void vnc_sent_lossy_rect(VncWorker *worker, int x, int y, int w, int h) {int i, j; - w = (x + w) /VNC_STAT_RECT ; - h = (y + h) /VNC_STAT_RECT ; + w =DIV_ROUND_UP ((x + w),VNC_STAT_RECT ); + h =DIV_ROUND_UP ((y + h),VNC_STAT_RECT ); x /=VNC_STAT_RECT ; y /=VNC_STAT_RECT ; -for (j = y; j <= h; j++) { -for (i = x; i <= w; i++) { +for (j = y; j < h; j++) { +for (i = x; i < w; i++) { worker->lossy_rect[j][i] =1 ; } }
Signature · 1 line
2.54.0
Re: [PATCH 3/4] ui/vnc: fix OOB write in lossy rect worker code
Quoted 20 lines · Daniel P. Berrangé
Incorrect calculation of the boundary condition when tracking lossy rectangles in the worker thread will result in an OOB write which can corrupt further worker state, and/or trigger any guard pages that may lie beyond the VncWorker struct. This can be triggered through careful choice of the display resolution in the guest OS by an unprivileged user.
Fixes CVE-2026-48002Reported-by Marc-André Lureau <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>Signed-off-by Daniel P. Berrangé <[email protected]>--- ui/vnc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)ui/vnc.c +0
-0
ui/vnc.c void vnc_sent_lossy_rect(VncWorker *worker, int x, int y, int w, int h) · line 2986
Quoted 7 lines
ui/vnc.c +2
-2@@ -2982,13 +2982,13 @@ void vnc_sent_lossy_rect(VncWorker *worker, int x, int y, int w, int h) {int i, j; - w = (x + w) /VNC_STAT_RECT ; - h = (y + h) /VNC_STAT_RECT ; + w =DIV_ROUND_UP ((x + w),VNC_STAT_RECT ); + h =DIV_ROUND_UP ((y + h),VNC_STAT_RECT );
assert(h < VNC_STAT_ROWS);
assert(w < VNC_STAT_COLS);Quoted 10 lines
ui/vnc.c +2
-2x /=VNC_STAT_RECT ; y /=VNC_STAT_RECT ; -for (j = y; j <= h; j++) { -for (i = x; i <= w; i++) { +for (j = y; j < h; j++) { +for (i = x; i < w; i++) { worker->lossy_rect[j][i] =1 ; } }
Re: [PATCH 3/4] ui/vnc: fix OOB write in lossy rect worker code
Hi
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Daniel P. Berrangé
Incorrect calculation of the boundary condition when tracking lossy rectangles in the worker thread will result in an OOB write which can corrupt further worker state, and/or trigger any guard pages that may lie beyond the VncWorker struct. This can be triggered through careful choice of the display resolution in the guest OS by an unprivileged user.
Fixes CVE-2026-48002Reported-by Marc-André Lureau <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>Signed-off-by Daniel P. Berrangé <[email protected]>--- ui/vnc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)ui/vnc.c +0
-0@@ -2982,13 +2982,13 @@ void vnc_sent_lossy_rect(VncWorker *worker, int x, int y, int w, int h) {int i, j;
Quoted 8 lines
ui/vnc.c void vnc_sent_lossy_rect(VncWorker *worker, int x, int y, int w, int h) · line 2986
Quoted 4 lines
ui/vnc.c +2
-2- w = (x + w) /VNC_STAT_RECT ; - h = (y + h) /VNC_STAT_RECT ; + w =DIV_ROUND_UP ((x + w),VNC_STAT_RECT ); + h =DIV_ROUND_UP ((y + h),VNC_STAT_RECT );assert(h < VNC_STAT_ROWS); assert(w < VNC_STAT_COLS);
with <=, yes, I can add this while taking.
Quoted 12 lines
Quoted 10 lines
ui/vnc.c +2
-2x /=VNC_STAT_RECT ; y /=VNC_STAT_RECT ; -for (j = y; j <= h; j++) { -for (i = x; i <= w; i++) { +for (j = y; j < h; j++) { +for (i = x; i < w; i++) { worker->lossy_rect[j][i] =1 ; } }
PATCH 4/4 ui/vnc: fix OOB read updating VNC update frequency stats
In reply to Daniel P. BerrangéIncorrect loop bounds in vnc_update_freq result in iterating past the last row and past the last column in the VNC stats array. With suitably chosen dimensions this could be a OOB read that accesses memory beyond the VncDisplay struct that the stats array is embedded in.
Should this hit a guard page, it could trigger a guest crash. If it does not, then the VNC frequency stats will be updated with garbage.
--- ui/vnc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
ui/vnc.c +4 -2
@@ -3091,12 +3091,14 @@ double vnc_update_freq(VncState *vs, int x, int y, int w, int h)int i, j;double total =0 ;int num =0 ; +int x_end = x + w; +int y_end = y + h; x =QEMU_ALIGN_DOWN (x,VNC_STAT_RECT ); y =QEMU_ALIGN_DOWN (y,VNC_STAT_RECT ); -for (j = y; j <= y + h; j +=VNC_STAT_RECT ) { -for (i = x; i <= x + w; i +=VNC_STAT_RECT ) { +for (j = y; j < y_end; j +=VNC_STAT_RECT ) { +for (i = x; i < x_end; i +=VNC_STAT_RECT ) { total +=vnc_stat_rect (vs->vd, i, j)->freq; num++; }
Signature · 1 line
2.54.0