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

dcerpc: prevent integer underflow #12528

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

catenacyber
Copy link
Contributor

Link to ticket: https://redmine.openinfosecfoundation.org/issues/
None, oss-fuzz https://issues.oss-fuzz.com/u/1/issues/393414238

Describe changes:

  • DCERPC: prevent int underflow
  • DCERPC: use different header for both directions

@inashivb what do you think ?

in case a fragment has a length lesser than DCERPC_HDR_LEN

Fixes: 9daf852 ("dcerpc: tidy up code")
@catenacyber catenacyber requested a review from jasonish as a code owner February 3, 2025 16:41
Comment on lines 941 to 876
if cur_i.len() < (fraglen - frag_bytes_consumed) as usize {
if (cur_i.len() + frag_bytes_consumed as usize) < fraglen as usize {
Copy link
Member

Choose a reason for hiding this comment

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

This does appear to restore correct behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@inashivb what do you think of the behavior when fraglen < 16 ?

I think we should set an event

Copy link
Member

Choose a reason for hiding this comment

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

@inashivb what do you think of the behavior when fraglen < 16 ?

I think we should set an event

Agreed.

@jasonish
Copy link
Member

jasonish commented Feb 3, 2025

For commit dcerpc: use different header for different directions, there is no reason why, or ticket, about why this commit is being done.

Copy link
Member

@jasonish jasonish left a comment

Choose a reason for hiding this comment

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

Looks like a CI error with an SCLogDebug.

@suricata-qa
Copy link

ERROR:

ERROR: QA failed on ASAN_TLPR1_suri.

Pipeline 24561

@catenacyber
Copy link
Contributor Author

For commit dcerpc: use different header for different directions, there is no reason why, or ticket, about why this commit is being done.

I guess we need one or more tickets, but wanted Shivani's opinion first ;-)

@catenacyber catenacyber marked this pull request as draft February 3, 2025 19:43
@catenacyber
Copy link
Contributor Author

catenacyber commented Feb 3, 2025

TODOs :

  • fix header handling (by removing it from persistent DCERPC state)
  • take fraglen into account like &cur_i[parsed as usize..] should be &cur_i[parsed as usize..fraglen]
  • how to handle DCERPC headers having a fraglen < 16 ?
  • handle multiple PDUs in one call of handle_input_data

Header handling was wrong in the case

  • packet A to server is fragmented (return AppLayerResult::incomplete)
  • packet B is to client, but uses the header of the to_server packet

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 98.41270% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.69%. Comparing base (d4330ef) to head (323bf95).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12528   +/-   ##
=======================================
  Coverage   80.68%   80.69%           
=======================================
  Files         925      925           
  Lines      258914   258858   -56     
=======================================
- Hits       208914   208880   -34     
+ Misses      50000    49978   -22     
Flag Coverage Δ
fuzzcorpus 56.83% <98.18%> (+<0.01%) ⬆️
livemode 19.41% <0.00%> (+<0.01%) ⬆️
pcap 44.19% <90.90%> (+<0.01%) ⬆️
suricata-verify 63.38% <94.54%> (-0.01%) ⬇️
unittests 58.38% <88.88%> (-0.01%) ⬇️

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

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 24577

1 similar comment
@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 24577

@inashivb
Copy link
Member

inashivb commented Feb 4, 2025

TODOs :

* fix header handling (by removing it from persistent DCERPC state)

Indeed. This surfaced while doing the work recently.

* take fraglen into account like `&cur_i[parsed as usize..]` should be `&cur_i[parsed as usize..fraglen]`

sounds reasonable.

* how to handle DCERPC headers having a fraglen < 16 ?

you suggested setting an event and that sounds good to me.

* handle multiple PDUs in one call of `handle_input_data`

There's a ticket for this already. If you're working on it, please assign it to yourself: https://redmine.openinfosecfoundation.org/issues/7254

Header handling was wrong in the case

* packet A to server is fragmented (return AppLayerResult::incomplete)

* packet B is to client, but uses the header of the to_server packet

Sounds correct. This case is not covered with the current header reuse approach. This explanation should go in the commit and there should be another ticket for this.

Thank you for improving this parser! :)

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