
Lettura fuori dai limiti in html2xhtml : CVE-2022-44311
Html2xhtml v1.3 è stato scoperto contenere una lettura fuori dai limiti nella funzione static void elm_close(tree_node_t *nodo) in procesador.c. Questa vulnerabilità consente agli attaccanti di accedere a file sensibili o causare una Denial of Service (DoS) tramite un file html appositamente predisposto.
CWE-125 Out-of-Bounds Read è un tipo di errore software che può verificarsi quando si leggono dati dalla memoria. Ciò può accadere se il programma tenta di leggere oltre la fine di un array, ad esempio. Le letture fuori dai limiti possono portare a crash o altre vulnerabilità impreviste e possono consentire a un attaccante di leggere informazioni sensibili a cui non dovrebbe avere accesso.
html2xhtml/src/procesador.c. (GHSA-28fm-qh2h-3mch)Html2xhtml è uno strumento a riga di comando che converte file HTML in file XHTML. Html2xhtml può generare output XHTML conforme a uno dei seguenti tipi di documento: XHTML 1.0 (Transitional, Strict e Frameset), XHTML 1.1, XHTML Basic e XHTML Mobile Profile.
La vulnerabilità è stata scoperta a causa di un errore di segmentazione (segfault) che si verificava quando si utilizzava l'opzione -t frameset. Un errore di segmentazione o segfault è un tipo specifico di errore causato dall'accesso a memoria che non ti appartiene. È un meccanismo di supporto che impedisce di corrompere la memoria e introdurre bug di memoria difficili da debuggare.
Con l'uso di Valgrind, uno strumento per trovare errori di accesso alla memoria heap (memoria allocata dinamicamente con new o malloc) in programmi C e C++, l'errore di segmentazione è stato debuggato e ha riportato una lettura non valida di 4 byte nel caso di test:
==1040381== Memcheck, a memory error detector
==1040381== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1040381== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==1040381== Command: ./src/html2xhtml -t frameset report/vuln/id:000000,sig:11,src:001386+001369,time:12081510,execs:2336913,op:splice,rep:16
==1040381==
==1040381== Invalid read of size 4
==1040381== at 0x40E911: elm_close (procesador.c:944)
==1040381== by 0x410617: err_html_struct (procesador.c:1889)
==1040381== by 0x40F20A: err_content_invalid (procesador.c:0)
==1040381== by 0x40F20A: elm_close (procesador.c:959)
==1040381== by 0x40E7C4: saxEndDocument (procesador.c:233)
==1040381== by 0x40DF7A: main (html2xhtml.c:117)
==1040381== Address 0x6f20d4 is not stack'd, malloc'd or (recently) free'd
==1040381==
==1040381==
==1040381== Process terminating with default action of signal 11 (SIGSEGV)
==1040381== Access not within mapped region at address 0x6F20D4
==1040381== at 0x40E911: elm_close (procesador.c:944)
==1040381== by 0x410617: err_html_struct (procesador.c:1889)
==1040381== by 0x40F20A: err_content_invalid (procesador.c:0)
==1040381== by 0x40F20A: elm_close (procesador.c:959)
==1040381== by 0x40E7C4: saxEndDocument (procesador.c:233)
==1040381== by 0x40DF7A: main (html2xhtml.c:117)
==1040381== If you believe this happened as a result of a stack
==1040381== overflow in your program's main thread (unlikely but
==1040381== possible), you can try to increase the size of the
==1040381== main thread stack using the --main-stacksize= flag.
==1040381== The main thread stack size used in this run was 8388608.
==1040381==
==1040381== HEAP SUMMARY:
==1040381== in use at exit: 88,190 bytes in 13 blocks
==1040381== total heap usage: 22 allocs, 9 frees, 2,218,413 bytes allocated
==1040381==
==1040381== LEAK SUMMARY:
==1040381== definitely lost: 0 bytes in 0 blocks
==1040381== indirectly lost: 0 bytes in 0 blocks
==1040381== possibly lost: 0 bytes in 0 blocks
==1040381== still reachable: 88,190 bytes in 13 blocks
==1040381== suppressed: 0 bytes in 0 blocks
==1040381== Rerun with --leak-check=full to see details of leaked memory
==1040381==
==1040381== For lists of detected and suppressed errors, rerun with: -s
==1040381== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==1040419== Memcheck, a memory error detector
Il log degli errori di Valgrind ci ha portato alla seguente funzione in cui si è verificato il segfault:

È stato riscontrato che manca un controllo di tipo nella funzione. L'utente passava un nodo di tipo comment invece di element alla funzione e questo comporta un errore di lettura fuori dai limiti. Un utente potrebbe fornire un documento malformato con un ELM_PTR(nodo).contenttype[doctype] non valido, risultando nel seguente confronto in assembly:
cmp dword ptr [rbp + rax*4 + 0xc], 4
Questa vulnerabilità può essere sfruttata dagli attaccanti per leggere file sensibili, memoria o locazioni utilizzando un file alterato.
| Gravità | Alta 8.1 / 10 |
|---|
| Complessità dell'attacco | Bassa |
| Privilegi richiesti | Nessuno |
| Interazione dell'utente | Richiesta |
| Ambito | Invariato |
| Riservatezza | Alta |
| Integrità | Nessuna |
| Disponibilità | Alta |