-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Packet alerts/v7 #6999
Packet alerts/v7 #6999
Conversation
Some unittests used SCMalloc for allocating new Packet the unittests. While this is valid, it leads to segmentation faults when we move to dynamic allocation of the maximum alerts allowed to be triggered by a single packet. This massive patch uses PacketGetFromAlloc, which initializes a Packet in such a way that any dynamic allocated structures within will also be initialized. Related to Task OISF#4207
The maximum of possible alerts triggered by a unique packet was hardcoded to 15. With usage of 'noalert' rules, that limit could be reached somewhat easily. Make that configurable via suricata.yaml. Conf Bug#4941 Task OISF#4207
Plus small clang formatting change.
When appending a new alert, there is no need to check if alerts.cnt > 0 since alerts.cnt is unsigned.
with the implementation of configurable packet-alert-max, a bug was found in the way we added alerts to the packet queue. But the new logic exposed a possible bug case when the same signature generated more than one alert for the same packet (from different transactions). This would lead to Suri call memmove with size 0.
Codecov Report
@@ Coverage Diff @@
## master #6999 +/- ##
==========================================
- Coverage 77.70% 77.61% -0.09%
==========================================
Files 628 628
Lines 185656 185557 -99
==========================================
- Hits 144270 144028 -242
- Misses 41386 41529 +143
Flags with carried forward coverage won't be shown. Click here to find out more. |
@@ -189,8 +189,10 @@ int PacketAlertAppend(DetectEngineThreadCtx *det_ctx, const Signature *s, | |||
SCLogDebug("sid %"PRIu32"", s->id); | |||
|
|||
/* It should be usually the last, so check it before iterating */ | |||
if (p->alerts.cnt == 0 || p->alerts.alerts[p->alerts.cnt - 1].num < s->num) { | |||
/* Same signatures can generate more than one alert, if it's a diff tx */ | |||
if (p->alerts.cnt == 0 || p->alerts.alerts[p->alerts.cnt - 1].num <= s->num) { |
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.
Q: how do we know here if the alerts came from diff txs?
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.
Since this wasn't checked before, I assumed it was not needed...
{ | ||
intmax_t max = 0; | ||
if (ConfGetInt("packet-alert-max", &max) == 1) { | ||
if (max < 0 || max > UINT8_MAX) { |
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.
Q: What happens in a case when max == 0?
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 think we decided that if the user chose that, that was up to them... 🤔
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.
change behavior to Warning and default
Followed by: #7000 |
#6943 addressing comments done on #6896
Describe changes:
BUG_ON
to check if we're not callingmemmove
with size 0Link to redmine ticket:
https://redmine.openinfosecfoundation.org/issues/4207
suricata-verify-pr: 694