Commit 2a0b3bd
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 4c75aad commit 2a0b3bd
1 file changed
+25
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16086 | 16086 | | |
16087 | 16087 | | |
16088 | 16088 | | |
16089 | | - | |
| 16089 | + | |
| 16090 | + | |
| 16091 | + | |
| 16092 | + | |
| 16093 | + | |
| 16094 | + | |
| 16095 | + | |
| 16096 | + | |
16090 | 16097 | | |
16091 | 16098 | | |
16092 | 16099 | | |
16093 | | - | |
| 16100 | + | |
16094 | 16101 | | |
16095 | 16102 | | |
16096 | 16103 | | |
| |||
16101 | 16108 | | |
16102 | 16109 | | |
16103 | 16110 | | |
16104 | | - | |
16105 | | - | |
| 16111 | + | |
| 16112 | + | |
| 16113 | + | |
| 16114 | + | |
| 16115 | + | |
16106 | 16116 | | |
16107 | | - | |
16108 | | - | |
16109 | | - | |
16110 | | - | |
16111 | | - | |
16112 | | - | |
| 16117 | + | |
| 16118 | + | |
| 16119 | + | |
| 16120 | + | |
| 16121 | + | |
| 16122 | + | |
| 16123 | + | |
16113 | 16124 | | |
16114 | 16125 | | |
16115 | 16126 | | |
| |||
16122 | 16133 | | |
16123 | 16134 | | |
16124 | 16135 | | |
16125 | | - | |
16126 | | - | |
| 16136 | + | |
| 16137 | + | |
| 16138 | + | |
16127 | 16139 | | |
16128 | 16140 | | |
| 16141 | + | |
16129 | 16142 | | |
16130 | 16143 | | |
16131 | 16144 | | |
| |||
0 commit comments