Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
profiling/rules: Improve dynamic rule handling
Issue: 6861 Without this commit, disabling rule profiling via suricatasc's command 'ruleset-profile-stop' may crash because profiling_rules_entered becomes negative. This can happen because - There can be multiple rules evaluated for a single packet - Each rule is profiled individually. - Starting profiling is gated by a configuration setting and rule profiling being active - Ending profiling is gated by the same configuration setting and whether the packet was marked as profiling. The crash can occur when a rule is being profiled and rule profiling is then disabled after one at least one rule was profiled for the packet (which marks the packet as being profiled). In this scenario, the value of profiling_rules_entered was not incremented so the BUG_ON in the end profiling macro trips because it is 0. The changes to fix the problem are: - In the profiling end macro, gate the actions taken there by the same configuration setting and use the profiling_rues_entered (instead of the per-packet profiling flag). Since the start and end macros are tightly coupled, this will permit profiling to "finish" if started. - Modify SCProfileRuleStart to only check the sampling values if the packet hasn't been marked for profiling already. This change makes all rules for a packet (once selected) to be profiled (without this change sampling is applied to each *rule* that applies to the packet.
- Loading branch information