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

pgsql: don't error out with PDU parsing errors - v3 #12614

Closed
wants to merge 12 commits into from

Conversation

jufajardini
Copy link
Contributor

Previous PR: #12609

Link to ticket: https://redmine.openinfosecfoundation.org/issues/
https://redmine.openinfosecfoundation.org/issues/5524
https://redmine.openinfosecfoundation.org/issues/5566

Describe changes:
#12609, fixing:

  • remove leftover commented code
  • fix rust error

Provide values to any of the below to override the defaults.

SV_BRANCH=OISF/suricata-verify#2299

jufajardini and others added 11 commits February 17, 2025 16:52
Some backend messages can be the shortest pgsql length possible,
4 bytes, but the parser expectd all messages to be longer than that.

Related to
Bug OISF#5524
The initial parsing for message type checking was more complex than
needed be.

Related to
Bug OISF#5524
Building on top of work done by Jason Ish.

Related to
Bug OISF#5524
Some inner parsers were using it, some weren't. Better to standardize
this. Also take the time to avoid magic numbers for representing the
expected lengths for pgsql PDUs.
Also throwing PgsqlParseError and allowing for incomplete results.

Related to
Task OISF#5566
Bug OISF#5524
Even if unknown, if the message is properly parsed, allow the parser to
proceed.

Related to
Bug OISF#5524
This allows the app-proto to continue onto parsing next PDUs, if
possible.

Bug OISF#5524
Events for:
- parsing error when parsing pgsql packet length
- parsing error for pgsql requests (post length parsing)
- parsing error for pgsql responses (post length parsing)
- too many transactions

Include `pgsql-events.rules` file, and PGSQL events SID range definition

Task OISF#5566
No state change, but since we added Unknown responses, we should handle
that case -- should we have a specific state for such cases?

Related to
Bug OISF#5524
Task OISF#5566
This may happen in some situations if the app-layer parser only sees
unknown messages and sets an event: there will be an empty transaction,
but nothing to log.

Related to
Task OISF#5566
@jufajardini jufajardini requested a review from a team as a code owner February 18, 2025 19:50
@jufajardini jufajardini marked this pull request as draft February 18, 2025 20:05
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 81.87500% with 29 lines in your changes missing coverage. Please review.

Project coverage is 80.75%. Comparing base (10ede91) to head (7d24770).
Report is 19 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12614      +/-   ##
==========================================
+ Coverage   80.74%   80.75%   +0.01%     
==========================================
  Files         931      931              
  Lines      259144   259208      +64     
==========================================
+ Hits       209242   209328      +86     
+ Misses      49902    49880      -22     
Flag Coverage Δ
fuzzcorpus 56.99% <82.85%> (+0.02%) ⬆️
livemode 19.37% <1.42%> (-0.01%) ⬇️
pcap 44.15% <1.42%> (-0.01%) ⬇️
suricata-verify 63.45% <79.85%> (+0.02%) ⬆️
unittests 58.34% <63.75%> (+<0.01%) ⬆️

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

@jufajardini jufajardini marked this pull request as ready for review February 18, 2025 21:48
@suricata-qa
Copy link

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.uptime 648 626 96.6%

Pipeline 24779

@victorjulien victorjulien added this to the 8.0 milestone Feb 19, 2025
@victorjulien
Copy link
Member

Merged in #12625, thanks!

@jufajardini jufajardini deleted the 5524-pgsql/v3 branch February 19, 2025 17:27
if let PgsqlFEMessage::UnknownMessageType(_) = request {
return ALPROTO_FAILED;
}
Ok((_, _)) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not look right to me : the code does not match the commit message : this is probing, not parsing

I do not think we want to detect pgsql when we see unknown messages

// TODO Log anomaly event instead?
js.set_bool("request", false)?;
js.set_bool("response", false)?;
// TODO Log anomaly event?
Copy link
Contributor

Choose a reason for hiding this comment

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

return Error so that caller returns false ?

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.

4 participants