Commit Graph

13451 Commits (1b24f4d357fd922a5c3202fce2904da29a04ed12)
 

Author SHA1 Message Date
Victor Julien fc566037b4 eve/schema: add new flow fields 2 years ago
Victor Julien 1594e41b06 stream: remove unused TCP_LISTEN
Keep the values the same so we might be able to bring it back
w/o issues.
2 years ago
Victor Julien e05b6f44e3 counter: tcp liberal counter 2 years ago
Victor Julien 0ebe372607 stream: after missing segments, be liberal on RST
This avoids long lasting inactive flows because in the most likely
case the RST did in fact end the connection. However Suricata may
still consider it to be "established".
2 years ago
Victor Julien b0993d6fd8 flow: add various flow counters
Add flow.end state counters

Add active TCP sessions counter

Add flow.active counter

Add flow.total counter

Ticket: #1478.
2 years ago
Victor Julien aa31d2193f counters: add StatsDecr 2 years ago
Victor Julien 88edc8630c flow/manager: add flow.mgr.rows_sec counter 2 years ago
Victor Julien f271fb4575 flow/recycler: bring back pthread_cond_t sleep
Bug #4379.
2 years ago
Victor Julien 633e6cf09e flow/recycler: minor code cleanups 2 years ago
Victor Julien 73138809e2 flow/manager: move counters into util func 2 years ago
Victor Julien 0c048d3e5c flow/manager: minor code cleanups 2 years ago
Victor Julien 7f4e120a97 flow/manager: remove debug and dead code 2 years ago
Victor Julien e6ac2e4e8a flow/manager: sleep handled by pthread_cond_t again
Use only in live mode to allow FM to respond quickly to time
increases in offline mode.

Bug #4379.
2 years ago
Victor Julien 39141a8836 time: add timeradd implementation
timeradd isn't available on MinGW.
2 years ago
Victor Julien e9d2417e0f flow/manager: adaptive hash eviction timing
The flow manager scans the hash table in chunks based on the flow timeout
settings. In the default config this will lead to a full hash pass every
240 seconds. Under pressure, this will lead to a large amount of memory
still in use by flows waiting to be evicted, or evicted flows waiting to
be freed.

This patch implements a new adaptive logic to the timing and amount of
work that is done by the flow manager. It takes the memcap budgets and
calculates the proportion of the memcap budgets in use. It takes the max
in-use percentage, and adapts the flow manager behavior based on that.

The memcaps considered are:
    flow, stream, stream-reassembly and app-layer-http

The percentage in use, is inversely applies to the time the flow manager
takes for a full hash pass. In addition, it is also applied to the chunk
size and the sleep time.

Example: tcp.reassembly_memuse is at 90% of the memcap and normal flow
hash pass is 240s. Hash pass time will be:

    240 * (100 - 90) / 100 = 24s

Chunk size and sleep time will automatically be updated for this.

Adds various counters.

Bug: #4650.
Bug: #4808.
2 years ago
Michael Tremer f50af12068 stream: tcp: Handle retransmitted SYN with TSval
For connections that use TCP timestamps for which the first SYN packet
does not reach the server, any replies to retransmitted SYNs will be
tropped.

This is happening in StateSynSentValidateTimestamp, where the timestamp
value in a SYN-ACK packet must match the one from the SYN packet.
However, since the server never received the first SYN packet, it will
respond with an updated timestamp from any of the following SYN packets.

The timestamp value inside suricata is not being updated at any time
which should happen. This patch fixes that problem.

Bug: #4376.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years ago
Victor Julien 8109b0017e detect/dcerpc: simplify keyword validation
Now that the engine understands the relation between SMB and DCERPC better
we can get rid of some of the special case handling in keywords.
2 years ago
Victor Julien 8d20b40cdd detect/content: fix FNs due to bad depth calc
When trying to propegate the depth/offset, within/distance chains
a logic error would set too a restrictive depth on a pattern that
followed more than one "unchained" patterns.

Bug: #5162.
2 years ago
Victor Julien 50d02ebc05 detect/content: simplify int bounds checking
Use a macro to validate the ranges for overflows. This removes
the clutter of all the checks and warnings, and also no longer
puts the state machine in an undefined state when hitting such
a condition.
2 years ago
Victor Julien a83f02d4cd detect/dcerpc: apply dcerpc to smb as well
So 'alert dcerpc' also matches if the DCERPC is over SMB.

Explicitly refuse smb keywords for the 'dcerpc' app proto setting:
`alert dceprc ... smb.share; ...` is rejected.

Remove a now useless special case in the stateless rule processing
matching for dcerpc/smb.

Bug: #5208.
2 years ago
Philippe Antoine e692530021 event: only sets APPLAYER_UNEXPECTED_PROTOCOL once
If f->alproto == ALPROTO_UNKNOWN, we do not know the new protocol
yet, so we do not set the event yet.
2 years ago
Philippe Antoine b0298dd046 events: reset logged event
Otherwise, if we log a first app_layer_event, then reset
with AppLayerDecoderEventsResetEvents for a new packet,
then get another event, it does not get logged

Ticket: #5391
2 years ago
Philippe Antoine eb1c2a6083 smb: use default stream-depth 0 by default
As broken by commit e5c948df87

Ticket: #5390
2 years ago
Victor Julien 2ba9da4815 eve/schema: add missing magic from files array 2 years ago
dependabot[bot] 130dffed8c github-actions: bump actions/cache from 3.0.3 to 3.0.4
Bumps [actions/cache](https://github.com/actions/cache) from 3.0.3 to 3.0.4.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](30f413bfed...c3f1317a9e)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
Philippe Antoine c585be338c nfs: fix arbitrary allocation
Bug introduced by https://github.com/OISF/suricata/pull/7111

Nom's count begins by allocating a Vector, which leads to arbitrary
allocation due to flavors_cnt coming from network, and not even
being checked against i.len()

Ticket: #5237
2 years ago
Philippe Antoine 7acdece7d0 util: fix integer warnings in mime decoding
Ticket: #4516
2 years ago
Philippe Antoine 9d6e5558f1 defrag: do not cast pkt len to u16
as it can overflow
2 years ago
Philippe Antoine b8524e70d9 detect: change InspectEngineFuncPtr2 to return uint8_t 2 years ago
Philippe Antoine 49f92d0b94 ci: adds warning flag about integer conversions 2 years ago
Philippe Antoine c5cf2967b3 detect: fix integer warnings
Ticket: #4516
2 years ago
Philippe Antoine ac8fb553a1 detect: fix integer warnings for content
Ticket: #4516
2 years ago
Philippe Antoine 57fb183d32 detect: fix integer warnings for app-layer-event
Ticket: #4516
2 years ago
Philippe Antoine 79d7edb3e0 ftp: fix integer warning
Ticket: #4516
2 years ago
Philippe Antoine 26dc70648c dns: remove unused events field from state
found overflowing by oss-fuzz
2 years ago
Victor Julien df2e408d96 detect/threshold: fix offline time handling issue
Due to the TIMEVAL_DIFF_SEC calculating the delta into an unsigned
integer, it would underflow to a high positive value leading to
and incorrect result if the packet timestamp was below the timestamp
for the threshold entry. In normal conditions this shouldn't happen,
but in offline mode each thread has its own concept of time which
might differ significantly based on the pcap. In this case the
overflow would be very common.

Changing it to a signed value calculation triggered fuzz undefined
behavior if the packet timeval was very high, so this patch takes a
new approach where it no longer calculates a diff but sets up the
"seconds" value we compare against as a timeval itself, and uses
that to compare.

Fixes: 9fafc1031c ("time: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.")
Fixes: 82dc61f4c3 ("detect/threshold: Refactor threshold calculation to handle by_rule and by_both.")

Uses add `timeradd` specific version where available.

Bug: #5386.
2 years ago
Victor Julien fea374626a stream/midstream: fix double flow reverse case
In the case of midstream SYN/ACK pickup, we reverse the flow based on
the SYN/ACK. If we then later get traffic that appears to be in the
reverse direction based on the app-layer, we would reverse it again.
This isn't correct. When we have the SYN/ACK we know the flow's real
direction.
2 years ago
Victor Julien 2a7349406c eve/schema: add missing capture_file field 2 years ago
Victor Julien 42adaf5627 eve/schema: add missing http fields 2 years ago
Victor Julien d58f9e54d0 eve/schema: add missing alert fields 2 years ago
Victor Julien 2abce12b5b eve/schema: add missing smb fields 2 years ago
Victor Julien b24e1f1e46 eve/schema: add missing drop fields for ipv6 2 years ago
Victor Julien 6ad5d6a148 eve/schema: add profiling detect fields 2 years ago
Lukas Sismis 8845c07a90 bypass: af-packet: fix memory leak - reassign of EBPFBypassData
AF-Packet bypass function in some situations allocates EBPF bypass data
for an already bypassed flow and assigns it to the flow without any checks

Issue: #5368
2 years ago
Lukas Sismis 05797c45bb bypass: fix memory leak - reassign of FlowBypassInfo
In some situations bypass callback is called on already bypassed
flow. This allocates FlowBypassInfo structure for the flow but
does not check if the flow already has one.

Issue: #5368
2 years ago
Victor Julien 2486d29adb napatech: fix conf API call 2 years ago
Victor Julien 8580499ded exceptions: initial exception-policy implementation
Adds a framework for setting exception policies. These would be called
when the engine reaches some kind of exception condition, like hitting
a memcap or some traffic processing error.

The policy gives control over what should happen next: drop the packet,
drop the packet and flow, bypass, etc.

Implements the policy for:

    stream: If stream session or reassembly memcaps are hit call the
    memcap policy on the packet and flow.

    flow: Apply policy when memcap is reached and no flow could be
    freed up.

    defrag: Apply policy when no tracker could be picked up.

    app-layer: Apply ppolicy if a parser reaches an error state.

All options default to 'ignore', which means the default behavior
is unchanged.

Adds commandline options: add simulation options for exceptions. These
are only exposed if compiled with `--enable-debug`.

Ticket: #5214.
Ticket: #5215.
Ticket: #5216.
Ticket: #5218.
Ticket: #5194.
2 years ago
Victor Julien 4567995678 decode: add pass action wrapper 2 years ago
Victor Julien d81ad78444 decode: turn no payload/packet inspect macros into funcs
Remove unused unset macros.
2 years ago
Victor Julien 0035673208 eve/drop: log drop reason
Ticket: #5202.
2 years ago