-
Notifications
You must be signed in to change notification settings - Fork 1.8k
detect: guard rate filter callback registration #15380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5122,12 +5122,18 @@ void DetectLowerSetupCallback( | |
| } | ||
| } | ||
|
|
||
| void SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg) | ||
| bool SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg) | ||
| { | ||
| DetectEngineCtx *de_ctx = DetectEngineGetCurrent(); | ||
| if (de_ctx == NULL) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm really curious how we would get here with a NULL de_ctx. The only call site: if (de_ctx->RateFilterCallback && original_action != pa->action) {
pa->action = de_ctx->RateFilterCallback(p, sid, gid, rev, original_action,
pa->action, de_ctx->rate_filter_callback_arg);So there a detect engine when this is called. It's also a full engine as this is only called on a signature match AFAICS.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is also called in plugins see cc @jasonish
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this actually a scenario a plugin could end up in?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if it can, where should a plugin attempt to reregister these callbacks again?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The runtime call-site that @victorjulien points to (inside the signature-match Where should a plugin reregister? That is a fair follow-up. The current fix (guard + log + early return) prevents Two options, in order of invasiveness:
|
||
| SCLogError("no detection engine available for rate filter callback registration"); | ||
| return false; | ||
| } | ||
|
|
||
| de_ctx->RateFilterCallback = fn; | ||
| de_ctx->rate_filter_callback_arg = arg; | ||
| DetectEngineDeReference(&de_ctx); | ||
| return true; | ||
| } | ||
|
|
||
| int DetectEngineThreadCtxGetJsonContext(DetectEngineThreadCtx *det_ctx) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would look a warning here, and in the other plugin as well on failure, just for completeness of the examples.