reference: fix multi-tenant loading issues

Bug: #4797.
pull/9240/head
Victor Julien 2 years ago
parent 2859eeae81
commit e2f4c751aa

@ -2523,6 +2523,7 @@ static DetectEngineCtx *DetectEngineCtxInitReal(enum DetectEngineType type, cons
if (ActionInitConfig() < 0) { if (ActionInitConfig() < 0) {
goto error; goto error;
} }
SCReferenceConfInit(de_ctx);
if (SCRConfLoadReferenceConfigFile(de_ctx, NULL) < 0) { if (SCRConfLoadReferenceConfigFile(de_ctx, NULL) < 0) {
if (RunmodeGetCurrent() == RUNMODE_CONF_TEST) if (RunmodeGetCurrent() == RUNMODE_CONF_TEST)
goto error; goto error;
@ -2660,6 +2661,7 @@ void DetectEngineCtxFree(DetectEngineCtx *de_ctx)
/* freed our var name hash */ /* freed our var name hash */
VarNameStoreFree(de_ctx->version); VarNameStoreFree(de_ctx->version);
SCClassConfDeinit(de_ctx); SCClassConfDeinit(de_ctx);
SCReferenceConfDeinit(de_ctx);
SCFree(de_ctx); SCFree(de_ctx);
//DetectAddressGroupPrintMemory(); //DetectAddressGroupPrintMemory();

@ -853,9 +853,6 @@ typedef struct DetectEngineCtx_ {
/* used by the signature ordering module */ /* used by the signature ordering module */
struct SCSigOrderFunc_ *sc_sig_order_funcs; struct SCSigOrderFunc_ *sc_sig_order_funcs;
/* hash table used for holding the reference config info */
HashTable *reference_conf_ht;
/* main sigs */ /* main sigs */
DetectEngineLookupFlow flow_gh[FLOW_STATES]; DetectEngineLookupFlow flow_gh[FLOW_STATES];
@ -1016,6 +1013,14 @@ typedef struct DetectEngineCtx_ {
HashTable *class_conf_ht; HashTable *class_conf_ht;
pcre2_code *class_conf_regex; pcre2_code *class_conf_regex;
pcre2_match_data *class_conf_regex_match; pcre2_match_data *class_conf_regex_match;
/* reference config parsing */
/* hash table used for holding the reference config info */
HashTable *reference_conf_ht;
pcre2_code *reference_conf_regex;
pcre2_match_data *reference_conf_regex_match;
} DetectEngineCtx; } DetectEngineCtx;
/* Engine groups profiles (low, medium, high, custom) */ /* Engine groups profiles (low, medium, high, custom) */

@ -253,7 +253,6 @@ void RunUnittests(int list_unittests, const char *regex_arg)
TmqhSetup(); TmqhSetup();
TagInitCtx(); TagInitCtx();
SCReferenceConfInit();
UtInitialize(); UtInitialize();

@ -383,9 +383,6 @@ static void GlobalsDestroy(SCInstance *suri)
FeatureTrackingRelease(); FeatureTrackingRelease();
SCProtoNameRelease(); SCProtoNameRelease();
TimeDeinit(); TimeDeinit();
if (!suri->disabled_detect) {
SCReferenceConfDeinit();
}
TmqhCleanup(); TmqhCleanup();
TmModuleRunDeInit(); TmModuleRunDeInit();
ParseSizeDeinit(); ParseSizeDeinit();
@ -2549,7 +2546,6 @@ void PostConfLoadedDetectSetup(SCInstance *suri)
{ {
DetectEngineCtx *de_ctx = NULL; DetectEngineCtx *de_ctx = NULL;
if (!suri->disabled_detect) { if (!suri->disabled_detect) {
SCReferenceConfInit();
SetupDelayedDetect(suri); SetupDelayedDetect(suri);
int mt_enabled = 0; int mt_enabled = 0;
(void)ConfGetBool("multi-detect.enabled", &mt_enabled); (void)ConfGetBool("multi-detect.enabled", &mt_enabled);

@ -28,7 +28,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
SpmTableSetup(); SpmTableSetup();
EngineModeSetIDS(); EngineModeSetIDS();
SigTableSetup(); SigTableSetup();
SCReferenceConfInit();
} }
if (cnt++ == 1024) { if (cnt++ == 1024) {
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);

@ -41,9 +41,6 @@
/* Default path for the reference.conf file */ /* Default path for the reference.conf file */
#define SC_RCONF_DEFAULT_FILE_PATH CONFIG_DIR "/reference.config" #define SC_RCONF_DEFAULT_FILE_PATH CONFIG_DIR "/reference.config"
static pcre2_code *regex = NULL;
static pcre2_match_data *regex_match = NULL;
/* the hash functions */ /* the hash functions */
uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen); uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen);
char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1, char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
@ -53,14 +50,15 @@ void SCRConfReferenceHashFree(void *ch);
/* used to get the reference.config file path */ /* used to get the reference.config file path */
static const char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx); static const char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx);
void SCReferenceConfInit(void) void SCReferenceConfInit(DetectEngineCtx *de_ctx)
{ {
int en; int en;
PCRE2_SIZE eo; PCRE2_SIZE eo;
int opts = 0; int opts = 0;
regex = pcre2_compile((PCRE2_SPTR8)SC_RCONF_REGEX, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL); de_ctx->reference_conf_regex =
if (regex == NULL) { pcre2_compile((PCRE2_SPTR8)SC_RCONF_REGEX, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
if (de_ctx->reference_conf_regex == NULL) {
PCRE2_UCHAR errbuffer[256]; PCRE2_UCHAR errbuffer[256];
pcre2_get_error_message(en, errbuffer, sizeof(errbuffer)); pcre2_get_error_message(en, errbuffer, sizeof(errbuffer));
SCLogWarning("pcre2 compile of \"%s\" failed at " SCLogWarning("pcre2 compile of \"%s\" failed at "
@ -68,20 +66,20 @@ void SCReferenceConfInit(void)
SC_RCONF_REGEX, (int)eo, errbuffer); SC_RCONF_REGEX, (int)eo, errbuffer);
return; return;
} }
regex_match = pcre2_match_data_create_from_pattern(regex, NULL); de_ctx->reference_conf_regex_match =
pcre2_match_data_create_from_pattern(de_ctx->reference_conf_regex, NULL);
return; return;
} }
void SCReferenceConfDeinit(void) void SCReferenceConfDeinit(DetectEngineCtx *de_ctx)
{ {
if (regex != NULL) { if (de_ctx->reference_conf_regex != NULL) {
pcre2_code_free(regex); pcre2_code_free(de_ctx->reference_conf_regex);
regex = NULL; de_ctx->reference_conf_regex = NULL;
} }
if (regex_match != NULL) { if (de_ctx->reference_conf_regex_match != NULL) {
pcre2_match_data_free(regex_match); pcre2_match_data_free(de_ctx->reference_conf_regex_match);
regex_match = NULL; de_ctx->reference_conf_regex_match = NULL;
} }
} }
@ -235,7 +233,8 @@ int SCRConfAddReference(DetectEngineCtx *de_ctx, const char *line)
int ret = 0; int ret = 0;
ret = pcre2_match(regex, (PCRE2_SPTR8)line, strlen(line), 0, 0, regex_match, NULL); ret = pcre2_match(de_ctx->reference_conf_regex, (PCRE2_SPTR8)line, strlen(line), 0, 0,
de_ctx->reference_conf_regex_match, NULL);
if (ret < 0) { if (ret < 0) {
SCLogError("Invalid Reference Config in " SCLogError("Invalid Reference Config in "
"reference.config file"); "reference.config file");
@ -244,7 +243,8 @@ int SCRConfAddReference(DetectEngineCtx *de_ctx, const char *line)
/* retrieve the reference system */ /* retrieve the reference system */
size_t copylen = sizeof(system); size_t copylen = sizeof(system);
ret = pcre2_substring_copy_bynumber(regex_match, 1, (PCRE2_UCHAR8 *)system, &copylen); ret = pcre2_substring_copy_bynumber(
de_ctx->reference_conf_regex_match, 1, (PCRE2_UCHAR8 *)system, &copylen);
if (ret < 0) { if (ret < 0) {
SCLogError("pcre2_substring_copy_bynumber() failed"); SCLogError("pcre2_substring_copy_bynumber() failed");
goto error; goto error;
@ -252,7 +252,8 @@ int SCRConfAddReference(DetectEngineCtx *de_ctx, const char *line)
/* retrieve the reference url */ /* retrieve the reference url */
copylen = sizeof(url); copylen = sizeof(url);
ret = pcre2_substring_copy_bynumber(regex_match, 2, (PCRE2_UCHAR8 *)url, &copylen); ret = pcre2_substring_copy_bynumber(
de_ctx->reference_conf_regex_match, 2, (PCRE2_UCHAR8 *)url, &copylen);
if (ret < 0) { if (ret < 0) {
SCLogError("pcre2_substring_copy_bynumber() failed"); SCLogError("pcre2_substring_copy_bynumber() failed");
goto error; goto error;

@ -53,7 +53,7 @@ FILE *SCRConfGenerateValidDummyReferenceConfigFD01(void);
FILE *SCRConfGenerateInvalidDummyReferenceConfigFD02(void); FILE *SCRConfGenerateInvalidDummyReferenceConfigFD02(void);
FILE *SCRConfGenerateInvalidDummyReferenceConfigFD03(void); FILE *SCRConfGenerateInvalidDummyReferenceConfigFD03(void);
void SCReferenceConfInit(void); void SCReferenceConfInit(DetectEngineCtx *de_ctx);
void SCReferenceConfDeinit(void); void SCReferenceConfDeinit(DetectEngineCtx *de_ctx);
#endif /* __UTIL_REFERENCE_CONFIG_H__ */ #endif /* __UTIL_REFERENCE_CONFIG_H__ */

Loading…
Cancel
Save