Bug #9065
closedlua/tls: GetCertInfo strlen(cert0_fingerprint) NULL deref (main lacks the 7.0.x/8.0.x fix)
Description
- Status: present in
main(9b7938aec); fixed on 7.0.x/8.0.x (20fa5d773/82d763a48, Ticket 6286) but not in main - backport/merge gap - Class: NULL pointer dereference (worker crash) from a TLS certificate with no fingerprint
- Component:
src/util-lua-tls.c:179(GetCertInfo)
Description¶
GetCertInfo() checks only cert0_subject and then calls strlen() on cert0_fingerprint (src/util-lua-tls.c:169-180):
if (connp->cert0_subject == NULL)
return LuaCallbackError(luastate, "error: no cert");
...
r += LuaPushStringBuffer(luastate, (uint8_t *)connp->cert0_fingerprint,
strlen(connp->cert0_fingerprint));
cert0_fingerprint is a separate allocation (src/app-layer-ssl.c:442-444) that can stay NULL while subject/issuerdn/serial are set:
- allocation failure of the fingerprint buffer (
SCCalloc(1, SHA1_STRING_LENGTH)returns NULL) ->goto error(:535-539,:552-558) frees onlyx509, leaving the other fields set; - SAN-array allocation failure (
:510-514, attacker-influenced size up toTLS_MAX_SAN=4096) takes the same error path before the fingerprint is computed; - on platforms where
calloc(0, 16)returns NULL, a certificate with zero SANs takes that path too.
The failed parse does not abort detection (SSLv3ParseHandshakeTypeCertificate, app-layer-ssl.c:1562-1575).
Trigger: TLS ServerHello with such a certificate; rule alert tls any any -> any any (lua:tlsinfo.lua; sid:1;) with tls.get_tx():get_server_cert_info() (or an output script bound to the TLS logger) -> strlen(NULL) -> worker crash. OOM/platform-gated, but a DoS in the detection path.
Fix direction¶
Guard all four fields like src/output-json-tls.c:184 does (e.g. cert0_fingerprint ? strlen(...) : 0), matching the 7.0.x/8.0.x fix. Port the backport to main.
Test¶
lua-tls-cert-info (normal server+client cert info, return arity 4) plus a unit test that forces subject-set/fingerprint-NULL and asserts no crash.