]> git.ipfire.org Git - thirdparty/suricata.git/commit
var-names: reimplement var name handling
authorVictor Julien <vjulien@oisf.net>
Wed, 2 Aug 2023 06:37:45 +0000 (08:37 +0200)
committerVictor Julien <vjulien@oisf.net>
Fri, 11 Aug 2023 05:02:06 +0000 (07:02 +0200)
commitb130234b2639842619da4c156ce5164a652202ec
tree224254ed4cd3ec42905a5442b10affa0233f3a09
parent575fbdfbf38f75561b0d40c668c81d0d041bb359
var-names: reimplement var name handling

Implement a new design for handling var name id's. The old logic
was aware of detection engine versions and generally didn't work
well for multi-tenancy cases. Other than memory leaks and crashes,
logging of var names worked or failed based on which tenant was
loaded last.

This patch implements a new approach, where there is a global store
of vars and their id's for the lifetime of the program.

Overall Design:

Base Store: "base"

Used during keyword registration. Operates under lock. Base is shared
between all detect engines, detect engine versions and tenants.
Each variable name is ref counted.

During the freeing of a detect engine / tenant, unregistration decreases
the ref cnt.

Base has both a string to id and a id to string hash table. String to
id is used during parsing/registration. id to string during unregistration.

Active Store Pointer (atomic)

The "active" store atomic pointer points to the active lookup store. The call
to `VarNameStoreActivate` will build a new lookup store and hot swap
the pointer.

Ensuring memory safety. During the hot swap, the pointer is replaced, so
any new call to the lookup functions will automatically use the new store.
This leaves the case of any lookup happening concurrently with the pointer
swap. For this case we add the old store to a free list. It gets a timestamp
before which it cannot be freed.

Free List

The free list contains old stores that are waiting to get removed. They
contain a timestamp that is checked before they are freed.

Bug: #6044.
Bug: #6201.
14 files changed:
src/detect-engine-build.c
src/detect-engine.c
src/detect-flowbits.c
src/detect-flowint.c
src/detect-flowvar.c
src/detect-flowvar.h
src/detect-hostbits.c
src/detect-lua.c
src/detect-pcre.c
src/detect-pktvar.c
src/detect-xbits.c
src/suricata.c
src/util-var-name.c
src/util-var-name.h