Commit a46a2f6
committed
tls: fix ECH heap buffer overflow via publicName SNI pollution
In TLSX_EchChangeSNI, the ctx->extensions branch set extensions
unconditionally even when TLSX_Find returned NULL. This caused
TLSX_UseSNI to attach the attacker-controlled publicName to the shared
WOLFSSL_CTX when no inner SNI was configured. TLSX_EchRestoreSNI then
failed to clean it up because its removal was gated on serverNameX !=
NULL. The inner ClientHello was sized before the pollution but written
after it, causing TLSX_SNI_Write to memcpy 255 bytes past the
allocation boundary.
Fix by mirroring the guarded pattern of the ssl->extensions branch:
only set extensions when TLSX_Find returns non-NULL, and only perform
the SNI swap when extensions is non-NULL. Also move TLSX_Remove in
TLSX_EchRestoreSNI outside the serverNameX guard so any injected
publicName SNI is always cleaned up.
Also return BAD_FUNC_ARG when ECH is used without an inner SNI,
preventing ECH ClientHello construction in an invalid configuration.
Reported by: Nicholas Carlini (Anthropic) & Thai Duong (Calif.io)1 parent 0c54199 commit a46a2f6
1 file changed
+25
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16088 | 16088 | | |
16089 | 16089 | | |
16090 | 16090 | | |
16091 | | - | |
| 16091 | + | |
| 16092 | + | |
| 16093 | + | |
| 16094 | + | |
| 16095 | + | |
| 16096 | + | |
| 16097 | + | |
| 16098 | + | |
16092 | 16099 | | |
16093 | 16100 | | |
16094 | 16101 | | |
16095 | | - | |
| 16102 | + | |
16096 | 16103 | | |
16097 | 16104 | | |
16098 | 16105 | | |
| |||
16103 | 16110 | | |
16104 | 16111 | | |
16105 | 16112 | | |
16106 | | - | |
16107 | | - | |
| 16113 | + | |
| 16114 | + | |
| 16115 | + | |
| 16116 | + | |
| 16117 | + | |
16108 | 16118 | | |
16109 | | - | |
16110 | | - | |
16111 | | - | |
16112 | | - | |
16113 | | - | |
16114 | | - | |
| 16119 | + | |
| 16120 | + | |
| 16121 | + | |
| 16122 | + | |
| 16123 | + | |
| 16124 | + | |
| 16125 | + | |
16115 | 16126 | | |
16116 | 16127 | | |
16117 | 16128 | | |
| |||
16124 | 16135 | | |
16125 | 16136 | | |
16126 | 16137 | | |
16127 | | - | |
16128 | | - | |
| 16138 | + | |
| 16139 | + | |
| 16140 | + | |
16129 | 16141 | | |
16130 | 16142 | | |
| 16143 | + | |
16131 | 16144 | | |
16132 | 16145 | | |
16133 | 16146 | | |
| |||
0 commit comments