Commit Graph

8468 Commits (suricata-4.0.6)
 

Author SHA1 Message Date
Victor Julien ab751da633 changelog: update for 4.0.6 7 years ago
Victor Julien 7abaf30979 smtp/mime: fix null ptr deref on bad traffic
Due to missing error handling, a bad mime message could put the
mime parser in an error state, without the SMTP layer taking this
into account. So the SMTP layer would continue to pass data to the
mime parser, even though it was in an error state.

When the parser would be fed a very long line while in this state,
it would try to set an error flag in the state. However, due to
the error state, this setting of the flag would dereference a null
pointer.

This patch fixes this issue by updating the mime parser to check
the state it is in when receiving new input. It will refuse to
process futher data while in the error state. It will also return
a new error code to indicate to the SMTP layer that the parser
was in an error state.
7 years ago
Eric Leblond b5f5ef7eba af-packet: improve error handling
Stress condition in Suricata could lead to interface to disconnect
when it is not necessary. This patch updates the error handling
code to try to continue reading when such a case occurs.
7 years ago
Victor Julien 3fdc6183b0 storage: don't leak memory for unittests 7 years ago
Victor Julien 0f767ac20a radix: fix a memleak when removing the last node 7 years ago
Victor Julien 15973b01e6 detect/address: minor memory handling cleanups 7 years ago
Victor Julien 2710c0bd21 detect: suppress scan-build warnings 7 years ago
Victor Julien e83915a6aa detect/flags: cleanup parsing to not alloc temp strings 7 years ago
Victor Julien b5669c1775 mpm: fix minor scan-build warning 7 years ago
Victor Julien b09fa8f088 pool: avoid possible double free in error path
Should be impossible as a double free, but scan-build-7 thinks it
is possible.
7 years ago
Victor Julien 1a0d7deb9b pool: small code cleanups 7 years ago
Victor Julien fe45726635 stream: don't assume malformed TCP packets
This deep in the stream engine packets are valid, so don't check
for the tcph header in a packet as it confuses scan-build.

Do add a DEBUG_VALIDATE_BUG_ON so in QA we double check.
7 years ago
Victor Julien b3cd2e7e81 decode/tcp: rewrite options decoding to assist scan-build 7 years ago
Victor Julien beaf041e58 smb/c: don't accept null input 7 years ago
Victor Julien 0b08605868 htp: fix potential (but unlikely) memleak in uri normalization 7 years ago
Victor Julien 1470b436b9 thresholds: remove dead code in parsing 7 years ago
Victor Julien a7161316a2 radix: fix memory leak in error path 7 years ago
Victor Julien 1f7f136748 coverity: suppress warnings 7 years ago
Victor Julien 07ffb7db53 host/os/info: fix lookup memleak 7 years ago
Victor Julien 6bf423959b debug/log: suppress coverity checked_return warning 7 years ago
Victor Julien b94e372633 bpf: suppress coverity toctou warning 7 years ago
Victor Julien 6a73e17fc4 pcap: fix buffer size validation logic 7 years ago
Victor Julien d5267c3020 uricontent: move debug func into unittests
Cleanup header, which lead to the app-layer-htp.h header needing to
be added in a few other places.
7 years ago
Victor Julien f502a52407 detect/replace: fix mem leak in error path 7 years ago
Victor Julien c66091cbb7 isdataat: fix mem leak in error path 7 years ago
Victor Julien ead1e9830b bits: avoid memory leak in case of adding types 7 years ago
Victor Julien f000b70b9a ipproto: fix memleak in error case 7 years ago
Victor Julien 985b6198d4 bytetest: don't leak memory in error condition 7 years ago
Victor Julien b60c469e7d yaml: fix potential memleak and suppress coverity issue 7 years ago
Victor Julien 39d6551437 outputs: fix memleaks in the error paths reported by coverity 7 years ago
Victor Julien 8433e9a8b1 coverity: suppress warning for intentional code 7 years ago
Victor Julien 6eba849068 rust/dns: don't compile unused C code if Rust is enabled 7 years ago
Victor Julien 8702fb9bea coverity: don't warn on fall back random 7 years ago
Victor Julien 7c4f0ac901 http: implement min size stream logic
Update HTTP parser to set the min inspect depth per transaction. This
allows for signatures to have their fast_pattern in the HTTP body,
while still being able to inspect the raw stream reliably with it.

The inspect depth is set per transaction as it:
- depends on the per personality config for min inspect size
- is set to the size of the actual body if it is smaller

After the initial inspection is done, it is set to 0 which disables
the feature for the rest of the transaction.

This removes the rescanning flush logic in commit
7e004f52c6 and provides an alternative
fix for bug #2522. The old approach caused too much rescanning of
HTTP body data leading to a performance degradation.

Bug #2522
7 years ago
Victor Julien a0734cf7e1 stream: introduce min inspect depth logic
Some rules need to inspect both raw stream data and higher level
buffers together. When this higher level buffer is a streaming
buffer itself, the risk of mismatch exists.

This patch allows an app-layer parser to set a 'min inspect depth'.
The value is used by the stream engine to keep at least this
depth worth of data, so that the detection engine can request
all of it for inspection.

For rules that have the SIG_FLAG_FLUSH flag set, data is inspected
not from offset raw_progress, but from raw_progress minus
min_inspect_depth.

At this time this is only used for sigs that have their fast_pattern
in a HTTP body and have raw stream match as well.
7 years ago
Victor Julien 005d876365 gcc8: fix format truncation warnings 7 years ago
Victor Julien 96869a367a stream/tcp: be more liberal in last_ack
Don't set even if seq is before next_seq, as this could still be
a valid packet that was sent before the state was reached.
7 years ago
Victor Julien 22a6372226 stream/tcp: add debug statements to state dispatcher 7 years ago
Victor Julien ad0794015a unittests: fix format-truncation warning 7 years ago
Victor Julien a0c37ff82d flow/timeout: code simplification and cleanup 7 years ago
Victor Julien 78345cc887 flow-manager: fix unittest initialization 7 years ago
Eric Leblond 37d10d3537 af-packet: close the socket in case of early fail 7 years ago
Eric Leblond 6d2fc70190 log-filestore: fix file descriptor leak
In the case we exceed the number of simultaneously open
file we can reach a state were we will not close the file
after writing.

Thanks to Steve Grubb <sgrubb@redhat.com> for the analysis.
7 years ago
Victor Julien 530203bfd5 detect/prefilter: speed up setup
If the global detect.prefilter.default setting is not "auto", it is
wasteful to run each prefilter setup routine. This patch tracks which
of the engines have been explicitly enabled in the rules and only
runs those.
7 years ago
Victor Julien df6b985f3c detect/prefilter: fix prefilter when setting is 'mpm'
When prefilter is not enabled globally, it is still possible to
enable it per signature. This was broken however, as the setup
code would never be called.

This commit always call the setup code and lets that sort out
which signatures (if any) to enable prefiltering for.
7 years ago
Victor Julien c80aae1b5b detect: limit flush logic to sigs that need it
Limit the early 'flush' logic to sigs that actually need to match
on both stream and http bodies.
7 years ago
Victor Julien 4fc04f17d8 detect/prefilter: fix alias for fast_pattern
If prefilter is used on a content keyword, it acts as a simple
fast_pattern statement. This was broken because the SIG_FLAG_PREFILTER
flag bypasses MPM for a sig. This commits fixes this by not setting
the flag when it should act as fast_pattern.
7 years ago
Victor Julien 4ca131d9bc detect/http: flush bodies when inspecting stream
The HTTP bodies (http_client_body and http_server_body/file_data) use
settings to control how much data we have before doing first inspection:

    request-body-minimal-inspect-size
    response-body-minimal-inspect-size

These settings default to 32k as quite some existing rules need this.

At the same time, the 'raw stream' inspection uses its own limits. By
default it inspects the data in blocks of about 2.5k. This could lead
to a situation where rules would not match.

For example, with 2 rules like this:

    content:"abc"; content:"data="; http_client_body; depth:5; sid:1;
    content:"xyz"; sid:2;

Sid 1 would only be inspected when the POST body reached the 32k limit
or when it was complete. Observed case shows the POST body to be 18k.
Sid 2 is inspected as soon as the 2.5k limit is reached, and then again
for each 2.5k increment. This moves the raw stream tracker forward.

So by the time sid 1 is inspected, some 18/19k into the stream, the
raw stream tracker is actually already moved forward for approximately
17.5k, this leads to the stream match of sid 1 possibly not matching.
Since the body match is at the start of the buffer, it makes sense
that the body and stream are inspected together.

The body inspection uses a tracker 'body_inspected', that keeps track
of how far into the body both MPM and per signature inspection has
moved.

This patch updates the logic in 2 ways:

1. it triggers earlier HTTP body inspection, which is matched to the
   stream inspection. When the detection engine finds it has stream
   data available for inspection, it passes the new 'STREAM_FLUSH'
   flag to the HTTP body inspection code. Which will then do an
   early inspection, even if still before the min inspect size.

2. to still somewhat adhere to the min inspect size, the body
   tracker is not updated until the min inspect size is reached.
   This will lead to some re-evaluation of the same body data.

If raw stream reassembly is disabled, this 'STREAM_FLUSH' flag is
never set, and the old behavior is used.

Bug #2522.
7 years ago
Victor Julien 36dacde025 stream: improve TCP CLOSED handling
Trigger app layer reassembly in both directions as soon as we've set
the TCP state to closed.

In IDS mode, if a toserver packet would close the state, the app layer
would not get updated until the next toclient packet. However, in
detection, the raw stream inspection would already use all available
stream data in detection and move the 'raw stream progress' tracker
forward. When in later (a) packet(s) the app layer was updated and
inspection ran on the app layer, the stream progress was already
moved too far forward. This would lead to signatures that matched
on both stream and app layer to not match.

By triggering the app layer reassembly as soon as the TCP state is
set to closed, the inspection as both the stream and app layer data
available at the same time so these rules can match.

Bug: #2570
Bug: #2554
7 years ago
Victor Julien d58f81d01b detect/files: don't prune files for bad packets
A bad packet (rejected by stream engine) could still trigger a file
prune, even though (most of the) detection wouldn't happen for the
packet. The next valid packet would then not be able to match on the
file, as it was already freed.

This patch uses the same logic before file pruning as in the detect
engine.

Bug: 2576
7 years ago