mirror of https://github.com/OISF/suricata
detect/alert: release the alert context not carried by the packet
PacketAlertSetContext() allocates the "alert:" pcre capture context for every alert a detection thread queues, but only alerts copied into the packet were ever freed. Entries the queue dropped instead kept owning it: threshold and suppression hits, alerts over packet_alert_max, skip_td and skip_fw bypasses, and everything after a pass rule broke out of the loop. Under ASAN, 500 suppressed packets leaked 19461 bytes in 998 allocations. The copy AlertQueueAppend() keeps in `p->alerts.drop` owns a context of its own and is not an alerts[] slot, so the packet side recycler never reached it. Two sites invalidate that slot: PacketReinit() and the per packet reset in DetectRunSetup(). Both only cleared `action`, and the second is the worse one: a slot that reads as empty while it still owns memory lets the next drop alert overwrite the pointer and lose the chain. The assignment in AlertQueueAppend() needs no release of its own, as its `p->alerts.drop.action == 0` guard only passes for a slot one of the two reset sites already emptied. Clear the queue entry where the alert is handed to the packet, and release whatever the remaining entries own at the end of PacketAlertFinalizeProcessQueue() so every exit path runs through it. Route both drop-slot reset sites through PacketAlertDropReset(), which releases the chain first: the slot's own pointer is the guard, not PKT_ALERT_CTX_USED, a whole packet hint set at PacketAlertFinalize() and stale at the reset sites. Packets that are freed rather than recycled (PacketFree() -> PacketDestructor(), e.g. at pool teardown) release their drop copy only via the PacketDestructor site. Ticket: #9116.pull/16329/head
parent
9a37bb659b
commit
32ccee91c3
Loading…
Reference in New Issue