Skip to content
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

pcre: creates a match structure per match run #6425

Closed
wants to merge 1 commit into from

Conversation

catenacyber
Copy link
Contributor

Link to redmine ticket:
https://redmine.openinfosecfoundation.org/issues/4720

Describe changes:

  • Creates a pcre2_match_data for each call of DetectPcrePayloadMatch

I am not sure this is the problem.

But if there are two threads which can call concurrently DetectPcrePayloadMatch with the same DetectPcreData (ie SigMatchData context), that is indeed a problem

TODO

  • check this is the bug
  • check if there are other places with the same problem
  • assess performance impact

So that DetectPcrePayloadMatch is thread safe
and does not rewrite a shared parse_regex.match structure
@codecov
Copy link

codecov bot commented Sep 30, 2021

Codecov Report

Merging #6425 (c878014) into master (9b3c355) will decrease coverage by 0.00%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##           master    #6425      +/-   ##
==========================================
- Coverage   76.92%   76.91%   -0.01%     
==========================================
  Files         613      613              
  Lines      186677   186681       +4     
==========================================
- Hits       143597   143589       -8     
- Misses      43080    43092      +12     
Flag Coverage Δ
fuzzcorpus 53.04% <0.00%> (-0.01%) ⬇️
suricata-verify 51.61% <75.00%> (-0.03%) ⬇️
unittests 62.99% <75.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@@ -199,7 +200,8 @@ int DetectPcrePayloadMatch(DetectEngineThreadCtx *det_ctx, const Signature *s,
}

/* run the actual pcre detection */
ret = DetectPcreExec(det_ctx, pe, (char *)ptr, len, start_offset, 0);
pcre2_match_data *match = pcre2_match_data_create_from_pattern(pe->parse_regex.regex, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use thread specific data with DetectRegisterThreadCtxFuncs, DetectThreadCtxGetKeywordThreadCtx. See src/detect-lua.c for an example implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Victor.
I gathered from your answer that

  • this was indeed one bug
  • the performance impact could be avoided

@catenacyber
Copy link
Contributor Author

Replaced by #6427

catenacyber added a commit to catenacyber/suricata that referenced this pull request Nov 6, 2023
victorjulien pushed a commit to victorjulien/suricata that referenced this pull request Nov 7, 2023
catenacyber added a commit to catenacyber/suricata that referenced this pull request Nov 9, 2023
catenacyber added a commit to catenacyber/suricata that referenced this pull request Nov 9, 2023
catenacyber added a commit to catenacyber/suricata that referenced this pull request Nov 9, 2023
catenacyber added a commit to catenacyber/suricata that referenced this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants