Skip to content

system/vncviewer: scan security types in chunks to prevent stack overflow - #3949

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:vncviewer/security-types-bound
Nov 1, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:vncviewer/security-types-bound

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Fixes #3942 by bounding stack usage when reading security types during the RFB handshake.

During the RFB 3.7+ security handshake, rfb_negotiate_security() received the 1-byte server-supplied count num_types (1..255) and called rfb_recv_exact(sockfd, types, num_types) into a fixed 16-byte stack buffer types[16]. A malicious or malfunctioning server could send up to 255 bytes, causing an unauthenticated 239-byte stack buffer overflow.

This fix:

  1. Receives and scans the security types in bounded chunks of up to sizeof(types) (16 bytes) at a time, preventing stack buffer overflow regardless of num_types.
  2. Inspects all server-offered security types across all chunks so supported types placed after the 16th entry are not dropped.
  3. Preserves preference order (None > VNC Auth).
  4. If None is selected, drains any remaining types via rfb_discard_exact(sockfd, remaining) to keep the RFB stream synchronized.

Impact

  • Security: Fixes a pre-authentication stack buffer overflow vulnerability in vncviewer.
  • Compatibility: Fully compatible with RFC 6143 / RFB 3.7+ specifications.
  • User: No user-facing API or configuration changes.

Testing

  • Host: Linux / x86_64
  • Style: Verified with nuttx/tools/checkpatch.sh (0 warnings, 0 errors).
  • Logic Verification: Tested chunking boundaries and stream drainage logic when num_types is smaller than, equal to, and larger than sizeof(types).

Comment thread system/vncviewer/rfb_protocol.c Resolved
Comment thread system/vncviewer/rfb_protocol.c Resolved
…flow

During the RFB security handshake, the server sends a 1-byte count of
supported security types (num_types, up to 255). rfb_negotiate_security()
previously passed num_types directly to rfb_recv_exact() into a fixed
16-byte stack array types[16], allowing a malicious server or network
attacker to overflow the stack buffer by up to 239 bytes before
authentication.

Rather than truncating the list or rejecting counts greater than 16,
receive and scan the security types in chunks of up to sizeof(types).
This inspects all server-offered security types without unbounded stack
growth. If RFB_SEC_NONE is found, any remaining unread types are drained
via rfb_discard_exact() to keep the stream synchronized.

Fixes apache#3942.

Assisted-by: Google Gemini
Signed-off-by: Swatantra Yadav <[email protected]>
@Swatantra-66
Swatantra-66 force-pushed the vncviewer/security-types-bound branch from 4eae928 to 6222975 Compare October 31, 2026 09:07
@xiaoxiang781216
xiaoxiang781216 merged commit 15a6f29 into apache:master Nov 1, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants