Commit Graph

524 Commits (cb174e4fd99e6cf8840f6962f880815501913451)

Author SHA1 Message Date
Victor Julien ceebd6e904 stream: reuse TCP session after TFO SYN+data reject 3 years ago
Victor Julien 7ef57cc7cb stream: support SYN/ACK with TFO only ack'ing ISN
Not ack'ing the data.
3 years ago
Victor Julien 7e6154a26f stream: add counter for acks for unseen data
This is another indicator for packet loss or strange captures.
3 years ago
Victor Julien b7739bfdba stream: flag ACKs that ack segments after next_seq
Avoid this for async streams.
3 years ago
Victor Julien a0f0a3b48b stream: fix spurious retransmission handling
Fix spurious retransmissions getting dropped, stalling connections in IPS
mode.

There are several reasons why benign spurious retransmissions can happen,
with the most obvious one that an ACK is lost so the sender retransmits
while the receiver has ACK'd it. If Suricata sees the ACK but afterwards
it gets lost, we can get in this condition. Packet loss can have a wide
range of causes here, including packets reaching a host but getting
dropped in the NIC queue or kernel queues due to resource constraints.

So these packets are no longer an "error" in this patch.

Next to this, the accuracy of the spurious retransmission has been
improved. Use SEQ macros to compare sequence numbers. Only use base_seq
if reassembly is still enabled for a stream.

A special case is added for cases where a segment is before last_ack
but after base_seq, which can happen when protocol detection isn't
finished yet. In this case the segment is tagged as spurious, but still
processed. This way we can check for overlaps.

Bug: #5875.
3 years ago
Victor Julien 01b7ccc224 stream: add liberal timetamps option
Linux is slightly more permissive wrt timestamps than many
other OS'. To avoid many events/issues with linux hosts, add an
option to allow for this slightly more permissive behavior.

Ideally the host-os config would be used, but in practice this
setting is rarely set up correctly, if at all.

This option is enabled by default.
3 years ago
Victor Julien 6a2fdc456b stream: Dup-ACK detection
Modeled after Wiresharks Dup-ACK detection.
3 years ago
Victor Julien 76225bf9ac stream: fix next_seq updates after temporary gap
On every accepted packet in established state, update next_seq if
packet seq+len is larger than existing next_seq. This allows it to
catch up after large gaps that are filled again a bit later.

Bug: #5877.
3 years ago
Victor Julien 3948b160c7 stream: implement config option for SYN queue
Default to allowing 10 SYNs to not trigger an event on a connection
attempt that times out.
3 years ago
Victor Julien d03773840b stream: track packet flags in packet
These flags can then later be used by stream logging.
3 years ago
Victor Julien 551fb80150 stream: improve first FIN next_seq update
For accepted FIN packets, always update next_seq. This helps track the
FIN sequence.

Bug: #5877.
3 years ago
Victor Julien 80a012a787 stream: improve FIN next_seq handling
Update next_seq to SEQ + payload_len + 1, so retransmission checks
work better.

Bug: #5877.
3 years ago
Victor Julien 20df715e64 stream: set next_seq before last_ack
next_seq sometimes depends on last_ack in cases of packet loss
catch up, so first update it.

Bug: #5877.
3 years ago
Victor Julien 67af94f2e0 stream/tcp: fix wrong ACK trigger FIN1 to FIN2
An ACK that ACK'd older data while still being in-window could
lead to FIN_WAIT1 to FIN_WAIT2 state transition. Detect this
case and generally harden the check.

Bug: #5877.
3 years ago
Victor Julien 7bfee147ef stream: SYN queue support
Support case where there are multiple SYN retransmits, where
each has a new timestamp.

Before this patch, Suricata would only accept a SYN/ACK that
matches the last timestamp. However, observed behavior is that
the server may choose to only respond to the first. In IPS mode
this could lead to a connection timing out as Suricata drops
the SYN/ACK it considers wrong, and the server continues to
retransmit it.

This patch reuses the SYN/ACK queuing logic to keep a list
of SYN packets and their window, timestamp, wscale and sackok
settings. Then when the SYN/ACK arrives, it is first evaluated
against the normal session state. But if it fails due to a
timestamp mismatch, it will look for queued SYN's and see if
any of them match the timestamp. If one does, the ssn is updated
to use that SYN and the SYN/ACK is accepted.

Bug: #5856.
3 years ago
Victor Julien 3bbed8c1d4 stream: minor code cleanup 3 years ago
Victor Julien 65f28b075f stream: turn session bool into flag 3 years ago
Victor Julien 23dd34dd8a stream/config: turn async_oneside into bool 3 years ago
Victor Julien 0a831b5ea2 stream: minor code cleanups in ACK validation 3 years ago
Victor Julien 15637ecce4 stream: remove unused macros 3 years ago
Victor Julien 58c1f14f17 stream: remove usused thread pseudo packet queue 3 years ago
Victor Julien 435ca5bbf0 stream: remove unused packetqueue argument 3 years ago
Philippe Antoine 3365ef72c3 tcp: pick up a midstream session even with FIN flag
Ticket: #5437
4 years ago
Victor Julien 4ad5e040af stream: minor cleanups 4 years ago
Victor Julien b31617c060 stream: reduce scope of inline drop check 4 years ago
Victor Julien 288086af3f stream: move state queue code into util func 4 years ago
Victor Julien fc376f8145 stream: set event on bad timestamp on syn_sent state 4 years ago
Victor Julien c3ecf63b1e stream: remove unnecessary ssn checks
Add debug validation to catch any change.
4 years ago
Victor Julien 93c9594dd8 stream/tcp: allow tcp session reuse on null sessions
When a "stream starter" packet finds an existing TCP flow, the flow will be
evaluated for reuse.

The following scenario wasn't handled well:

1. Suricata starts after a tool has just stopped using lots of connections
   (e.g. ab stress testing a webserver)
2. even though the client is closed already, the server is still doing
   connection cleanup sending many FINs and later RSTs
3. Suricata creates flows for these packets, but no TCP sessions
4. client resumes testing, creating flows that have the same 5 tuple as the
   flows created for the FIN/RST packets
5. Suricata refuses to "reuse" the flows as the condition "tcp flow w/o session"
   is not considered valid for session reuse
6. new TCP connection is not properly tracked and evaluated in parsing and
   detection

There may be other vectors into this, like a flow w/o session because of
memcap issues.

Bug: #5843.
4 years ago
Victor Julien a5547564b6 stream/midstream: add bug number to policy warning 4 years ago
Victor Julien 7951d8a14f flow: remove use_cnt
Packets only ever reference the flow while holding its lock. This
means than any code possibly evicting the flow will have to wait
for the existing users to complete their work. Therefore the use_cnt
serves no function anymore and can be removed.
4 years ago
Victor Julien 3ca37008d7 stream: remove unused pseudo packet function 4 years ago
Victor Julien 420351eda2 time: fix various time issues
Found by Coverity Scan.
4 years ago
Juliana Fajardini 416f7522e7 stream/tcp: fix typos, update copyright year
Bug #5765
4 years ago
Juliana Fajardini 8e9905e0d8 exceptions: ignore policy if stream.midstream=true
Set the engine to ignore the stream.midstream-policy if stream.midstream
is enabled.

If we had both stream.midstream AND stream.midstream_policy enabled,
this could lead to midstream flows being dropped (or bypassed, or...)
instead of being accepted by the engine, as it was probably meant when
the user enabled midstream flows.

Bug #5765
4 years ago
Juliana Fajardini 0d9289014b exceptions: add master switch config option
This allows all traffic Exception Policies to be set from one
configuration point. All exception policy options are available in IPS
mode. Bypass, pass and auto (disabled) are also available in iDS mode

Exception Policies set up individually will overwrite this setup for the
given traffic exception.

Task #5219
4 years ago
Jeff Lucovsky 31793aface time: Replace struct timeval with scalar value
Issue: 5718

This commit switches the majority of time handling to a new type --
SCTime_t -- which is a 64 bit container for time:
- 44 bits -- seconds
- 20 bits -- useconds
4 years ago
Victor Julien c79c0ca347 streaming: remove config pointer from struct 4 years ago
Victor Julien ff882cd73f streaming: add sbcfg to StreamingBufferClear 4 years ago
Victor Julien af211cbfad debug: add pkt_src to detect/stream entry log 4 years ago
Victor Julien ef2ed35311 stream: add debug statements 4 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 4 years ago
Victor Julien 8ef95c10a8 pool: use errno style error reporting 4 years ago
Philippe Antoine 62352ad030 src: fix remaining cppclean warnings 4 years ago
Victor Julien cd2a5ec84f packet: move action functions to packet files 4 years ago
Victor Julien 235f369ab9 stream: reduce pool locking overhead
Add thread local cache to avoid locking overhead for ssns and segments.

A thread will return segments/ssns to a local cache first, and if that
is full, to a return queue where the actual return to the pool returns
a batch, to amortize locking overhead.

Adds segment and session pool/cache counters to see where how effective
the cache is.
4 years ago
Victor Julien b06c0579f5 stream: fix reachable assertion
Fix `Flow::thread_id` not always getting properly set up, leading to
a reachable assertion.

Bug #4582.
4 years ago
Juliana Fajardini 9d9bc04886 stream/tcp: typo fix 4 years ago
Victor Julien e250ef6402 debug: remove empty header 4 years ago
Juliana Fajardini aa5bb2c329 stream: add exception policy for midstream flows
This allows to set a midstream-policy that can:
- fail closed (stream.midstream-policy=drop-flow)
- fail open (stream.midstream-policy=pass-flow)
- bypass stream (stream.midstream-policy=bypass)
- do nothing (default behavior)

Usage and behavior:

If stream.midstream-policy is set then if Suricata identifies a midstream flow
it will apply the corresponding action associated with the policy.

No setting means Suricata will not apply such policies, either inspecting the
flow (if stream.midstream=true) or ignoring it stream.midstream=false.

Task #5468
4 years ago