[BUG] system/vncviewer: `rfb_negotiate_security` never bounds the server-supplied security-type count against `sizeof(types)`, overflowing the 16-byte stack array `types[16]` (pre-auth stack buffer overflow)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- networking
Direzione di ricerca
Inizia da system/vncviewer/rfb_protocol.c, in particolare da rfb_negotiate_security() e rfb_recv_exact(), per seguire come il conteggio fornito dal server viene usato come lunghezza di lettura. Verifica come rfb_discard_exact() gestisce i byte in eccesso. Rifiuta un conteggio troppo grande oppure consumalo in modo sicuro senza scrivere oltre types[16]; il lavoro è completato quando i conteggi troppo grandi non possono causare un overflow del buffer e gli handshake validi continuano a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description / Steps to reproduce the issue
During the RFB 3.7+ security handshake the server sends a one-byte count of security types,
followed by that many type bytes. rfb_negotiate_security() reads the count straight off the
socket into a uint8_t and uses it as the length of a recv into the fixed 16-byte stack array
types[16], with no upper-bound check (only the == 0 case is special-cased).
system/vncviewer/rfb_protocol.c, rfb_negotiate_security():
521 static int rfb_negotiate_security(int sockfd, const char *password)
522 {
523 uint8_t num_types;
524 uint8_t types[16]; /* 16-byte stack buffer */
...
532 ret = rfb_recv_exact(sockfd, &num_types, 1); /* server-supplied 1..255 */
...
538 if (num_types == 0) { ... return -ECONNREFUSED; } /* ONLY the ==0 case handled */
...
551 ret = rfb_recv_exact(sockfd, types, num_types); /* SINK: writes num_types bytes */
rfb_recv_exact() writes exactly len bytes into the caller buffer:
383 static int rfb_recv_exact(int sockfd, void *buf, size_t len)
...
388 while (len > 0)
390 n = recv(sockfd, p, len, 0);
406 p += n;
407 len -= n;
So line 551 can recv up to 255 bytes into types[16], a 239-byte stack overflow of
attacker-chosen content that smashes the saved-register / return-address region of the frame.
There is no bound at all (not even a DEBUGASSERT) between the 1-byte read of num_types and
its use as the copy length.
This runs before authentication: vncviewer_main.c:191 rfb_connect() →
vncviewer_main.c:208 rfb_handshake() → rfb_protocol.c:772 rfb_negotiate_security(). A
malicious VNC server (the server a viewer connects to) or an on-path attacker injecting into the
TCP stream triggers it on the first handshake, with no credentials.
Steps:
- Build and run the vncviewer app and connect to an attacker-controlled / MITM'd VNC server.
- In the RFB 3.7+ security handshake, have the server send a security-type count of e.g.
0xff
followed by that many bytes. rfb_negotiate_security()writes those bytes pasttypes[16].
An AddressSanitizer build reports a stack-buffer-overflow WRITE past the 16-byte types array.
Expected: a count larger than the viewer's buffer is rejected or read in capped chunks.
Actual: up to 255 attacker bytes are written past types[16] on the stack, before auth.
Suggested fix: reject or clamp num_types to sizeof(types) before the recv — the viewer
only needs to know whether None / VNC Auth is offered, so it can read in capped chunks and
discard the remainder like rfb_discard_exact already does elsewhere.
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
ubuntu 22
NuttX Version
a09fb84a9b5f274add52cc0b6d803b77d44306c1
Issue Architecture
[Arch: all]
Issue Area
[Area: Networking]
Host information
No response
Verification
- I have verified before submitting the report.
- Lingua principale
- C
- Stelle
- 472
- Fork
- 793
- Merge medio
- 1g 19h
- PR unite (30g)
- 116
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/nuttx-apps
-
[FEATURE] Shrink getprime runs for OSTestForse già presa @linguini1 l’ha presa 19 giorni fa. ApertaType: Enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
apache/nuttx-apps#3620 · 6 commenti · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Type: Enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
apache/nuttx-apps#3816 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[FEATURE] `pthread_sigqueue` testing implementationForse già presa @Swatantra-66 l’ha presa 3 giorni fa. ApertaType: Enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
apache/nuttx-apps#3796 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] testing/sched/timerjitter: unexpected results under normal usageForse già presa @RogerNext l’ha presa 93 giorni fa. ApertaType: Bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
apache/nuttx-apps#3634 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[TODO] move graphics/input -> input.Forse di nuovo libera @cederom l’ha presa 219 giorni fa e non c’è nessuna pull request aperta. Aperta
apache/nuttx-apps#3436 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/nuttx-apps
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
area:docs area:stdlib found-by:duet-audit kind:docs-drift
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
InauguralSystems/EigenScript#2251 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
flux-framework/flux-coral2#513 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ly05010419/MacNativeGames#1420 ·
I maintainer di solito rispondono entro 1 giorno
-
Isaac workingAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
seedds/nxnative#763 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno