]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
2 years agohttp: complete multipart until request.body-limit 8648/head
Philippe Antoine [Thu, 26 Jan 2023 08:28:46 +0000 (09:28 +0100)] 
http: complete multipart until request.body-limit

In the case we are truncating a multipart file because of reaching
request.body-limit, we used to not consume the whole buffer, but
keep expected_boundary_len bytes in case a new boundary begins
in these bytes.
Even if we cannot check the complete boundary, we can still check
the first bytes, as will be done in the rust version.

Ticket: #5952

2 years agostream: handle zero window probe acks 8638/head
Victor Julien [Mon, 6 Mar 2023 15:06:25 +0000 (16:06 +0100)] 
stream: handle zero window probe acks

These can be skipped for the most part.

2 years agoeve/stream: add output warning about experimental state
Victor Julien [Mon, 6 Mar 2023 15:05:56 +0000 (16:05 +0100)] 
eve/stream: add output warning about experimental state

2 years agostream: accept and flag ack of ZWP data
Victor Julien [Fri, 3 Mar 2023 07:02:35 +0000 (08:02 +0100)] 
stream: accept and flag ack of ZWP data

Tcp Zero Window Probes try to send a single byte payload to "probe" if
the window has reopened. This single byte is, if accepted, not retransmitted.

2 years agostream: harden tcp reuse check against RST/FIN
Victor Julien [Fri, 3 Mar 2023 12:30:55 +0000 (13:30 +0100)] 
stream: harden tcp reuse check against RST/FIN

2 years agostream: improve SYN and SYN/ACK handling with ECN/CWR flags
Victor Julien [Fri, 3 Mar 2023 12:30:14 +0000 (13:30 +0100)] 
stream: improve SYN and SYN/ACK handling with ECN/CWR flags

2 years agostream: fix TFO overlap detection with ECN/CWR flags
Victor Julien [Fri, 3 Mar 2023 12:02:48 +0000 (13:02 +0100)] 
stream: fix TFO overlap detection with ECN/CWR flags

2 years agostream: flag zero window probe packets
Victor Julien [Thu, 2 Mar 2023 10:51:37 +0000 (11:51 +0100)] 
stream: flag zero window probe packets

2 years agoconf: deprecate multiple "include" statements at same level
Jason Ish [Fri, 24 Mar 2023 05:51:11 +0000 (23:51 -0600)] 
conf: deprecate multiple "include" statements at same level

The YAML spec considers duplicate keys to be an error, as do some YAML
implementations, most notably Rust's serde_yaml which would be nice to
use in the future.

Multiple include lines at the same level will still work, but a warning
will be emitted.

These can be fixed by moving to an "include" array:

include:
  - file1.yaml
  - file2.yaml

Ticket: #5939

2 years agoconf: fatal error if "include" is a mapping
Jason Ish [Fri, 24 Mar 2023 05:49:55 +0000 (23:49 -0600)] 
conf: fatal error if "include" is a mapping

If a field named "include" is mapping it is not processed correctly.
Instead return a fatal error.

In our YAML, "include" has always been a reserved word, so this should
not break any known configuration.

Ticket: #5939

2 years agoconf: allow "include" to be a list of files
Jason Ish [Fri, 24 Mar 2023 05:49:00 +0000 (23:49 -0600)] 
conf: allow "include" to be a list of files

In preparation for deprecating multiple "include" fields at the same
level, allow "include" to be a list of filenames.

Ticket: #5939

2 years agodocs: clarify exception policy's supported values
Juliana Fajardini [Wed, 22 Mar 2023 19:05:40 +0000 (16:05 -0300)] 
docs: clarify exception policy's supported values

As flow.memcap-policy and defrag.memcap-policy do not support flow
actions, clarify that in the documentation. Also fix some typos, and
add missing values in some places where the exception policies were
explained.

Related to
Bug #5940

2 years agoexception/policy: use pkt action if no flow support
Juliana Fajardini [Fri, 24 Mar 2023 14:15:14 +0000 (11:15 -0300)] 
exception/policy: use pkt action if no flow support

Defrag memcap and flow memcap do not support flow action for the
exception policies, as there is no flow when the exception condition is
hit. In such cases, the exception policy must be considered for the
packet only, when that makes sense, or should be ignored, in case of
`bypass`.

Bug #5940

2 years agodetect: bump detect engine version for tenant reload 8635/head
Philippe Antoine [Fri, 10 Mar 2023 10:28:26 +0000 (11:28 +0100)] 
detect: bump detect engine version for tenant reload

Because the engine version is used to free the old
variables and not the new ones.
As is done in DetectEngineReload.

Ticket: #5866

2 years agodetect: bytemath do not left shift more than 64
Philippe Antoine [Tue, 14 Mar 2023 11:17:05 +0000 (12:17 +0100)] 
detect: bytemath do not left shift more than 64

As it is undefined behavior by C standard.
In this case, zeroes the value.

Ticket: #5900

2 years agorust: don't suppress vendor output
Jason Ish [Wed, 22 Mar 2023 16:03:30 +0000 (10:03 -0600)] 
rust: don't suppress vendor output

There appears to be some errors happening in CI and this may be hiding
the source of the error.

2 years agorust: bundle Cargo.lock
Jason Ish [Sat, 18 Mar 2023 18:20:12 +0000 (12:20 -0600)] 
rust: bundle Cargo.lock

Cargo.lock has to be provided as template, Cargo.lock.in so it can
live beside Cargo.lock in out of tree automake builds, like distcheck.

This will pin Rust dependencies even for git builds, updating
Cargo.lock will now be a manual process that we'll have to take care
of periodically.

2 years agoflow/manager: fix coverity divide_by_zero warning
Juliana Fajardini [Fri, 24 Mar 2023 20:04:57 +0000 (17:04 -0300)] 
flow/manager: fix coverity divide_by_zero warning

Updated all cases where flow_config.prealloc was used in a division.

*** CID 1524506:  Integer handling issues  (DIVIDE_BY_ZERO)
/src/flow-manager.c: 858 in FlowManager()
852                                "flow_spare_q status: %" PRIu32 "%% flows at the queue",
853                             spare_pool_len, flow_config.prealloc,
854                             spare_pool_len * 100 / flow_config.prealloc);
855
856                     /* only if we have pruned this "emergency_recovery" percentage
857                      * of flows, we will unset the emergency bit */
>>>     CID 1524506:  Integer handling issues  (DIVIDE_BY_ZERO)
>>>     In expression "spare_pool_len * 100U / flow_config.prealloc", division by expression "flow_config.prealloc" which may be zero has undefined behavior.
858                     if (spare_pool_len * 100 / flow_config.prealloc > flow_config.emergency_recovery) {
859                         emerg_over_cnt++;
860                     } else {
861                         emerg_over_cnt = 0;
862                     }

Related to
Bug #5919

2 years agocontent: Constrain distance/within values
Jeff Lucovsky [Wed, 7 Dec 2022 15:20:06 +0000 (10:20 -0500)] 
content: Constrain distance/within values

Ticket: 5740

This commit constrains the values for distance and limit to 1MB. The
constraint is enforced while parsing the keyword values.

2 years agodoc/content: Add limits for distance/within
Jeff Lucovsky [Wed, 7 Dec 2022 15:10:18 +0000 (10:10 -0500)] 
doc/content: Add limits for distance/within

Ticket: 5740

2 years agoprofiling: updated switch block to fix gcc warning 8625/head
jason taylor [Tue, 21 Mar 2023 14:51:13 +0000 (14:51 +0000)] 
profiling: updated switch block to fix gcc warning

This fixes a warning emitted by Fedora 37 when compiling
with gcc 12.2.1

Signed-off-by: jason taylor <jtfas90@gmail.com>
2 years agoprofiling: minor reformatting
Victor Julien [Fri, 24 Mar 2023 08:25:44 +0000 (09:25 +0100)] 
profiling: minor reformatting

2 years agoflow/manager: fix prealloc unhandled division by 0 8624/head
Juliana Fajardini [Mon, 20 Mar 2023 14:56:58 +0000 (11:56 -0300)] 
flow/manager: fix prealloc unhandled division by 0

If flow.prealloc was set to zero in our yaml config, this led to
a floating point exception in the flow manager.

Bug: #5919.

2 years agoenip: optimized tx iterator
Philippe Antoine [Thu, 23 Mar 2023 08:00:42 +0000 (09:00 +0100)] 
enip: optimized tx iterator

As for SMTP, having a linked list.

Ticket: #5927

2 years agodnp3: optimized tx iterator
Philippe Antoine [Thu, 23 Mar 2023 07:57:53 +0000 (08:57 +0100)] 
dnp3: optimized tx iterator

As for SMTP, having a linked list.

Ticket: #5927

2 years agosmtp: optimized tx iterator
Philippe Antoine [Wed, 22 Mar 2023 16:24:40 +0000 (17:24 +0100)] 
smtp: optimized tx iterator

To be more efficient with larger number of transactions.
As was done for FTP.

Ticket: #5927

2 years agosource-xf-xdp: update for deprecated function in libbpf
Jason Ish [Wed, 22 Mar 2023 21:13:46 +0000 (15:13 -0600)] 
source-xf-xdp: update for deprecated function in libbpf

libbpf 0.8 deprecates bpf_get_link_xpd_id, and 1.0 removes it. Add
./configure check to see if this method is available and use it if so,
otherwise use the deprecated method which is not available on older
but still supported Linux distributions.

Ticket: #5924

2 years agorust: update aes and aes-gcm crates
Jason Ish [Wed, 22 Mar 2023 17:58:33 +0000 (11:58 -0600)] 
rust: update aes and aes-gcm crates

Addresses RUSTSEC-2021-0059, RUSTSEC-2021-0060.

2 years agodetect/urilen: fix applying urilen as depth
Victor Julien [Thu, 23 Mar 2023 14:42:18 +0000 (15:42 +0100)] 
detect/urilen: fix applying urilen as depth

If urilen induced depth was set, later DetectContentPropagateLimits()
would apply a wrong depth setting, leading to a false negative in
some cases.

Bug: #5929.

2 years agodetect/urilen: support HTTP/2
Victor Julien [Thu, 23 Mar 2023 10:31:49 +0000 (11:31 +0100)] 
detect/urilen: support HTTP/2

Ticket: #5931.

2 years agoeve/drop: don't log drops unless packet is dropped
Victor Julien [Tue, 21 Mar 2023 19:20:48 +0000 (20:20 +0100)] 
eve/drop: don't log drops unless packet is dropped

In pass/drop combinations where the pass rule took precendence over
the drop, a "drop" false positive could still be logged due to the
storing of the drop record in the packet drop alert store.

Bug: #5867.

2 years agodetect/mpm: minor code cleanups
Victor Julien [Mon, 20 Mar 2023 13:25:41 +0000 (14:25 +0100)] 
detect/mpm: minor code cleanups

2 years agodetect: apply within as depth where possible
Victor Julien [Sun, 19 Mar 2023 16:46:02 +0000 (17:46 +0100)] 
detect: apply within as depth where possible

The rule lang allows for within and distance to act as depth/offset,
but internally this was not handle the same way. This patch converts
within/distance w/o a prior pattern to depth/within.

2 years agodetect/offset: minor code cleanups
Victor Julien [Sun, 19 Mar 2023 18:25:09 +0000 (19:25 +0100)] 
detect/offset: minor code cleanups

2 years agodetect/content: refactor limit propagation
Victor Julien [Sun, 19 Mar 2023 15:39:32 +0000 (16:39 +0100)] 
detect/content: refactor limit propagation

2 years agodetect/distance: minor code cleanups
Victor Julien [Sun, 19 Mar 2023 15:30:00 +0000 (16:30 +0100)] 
detect/distance: minor code cleanups

2 years agodetect/within: minor code cleanups
Victor Julien [Sun, 19 Mar 2023 15:24:40 +0000 (16:24 +0100)] 
detect/within: minor code cleanups

2 years agodetect/analyzer: fix lists names
Victor Julien [Thu, 16 Mar 2023 05:38:48 +0000 (06:38 +0100)] 
detect/analyzer: fix lists names

Simpler names that lead to cleaner json.

2 years agodetect/analyzer: add byte_test/byte_jump detail
Victor Julien [Wed, 15 Mar 2023 21:16:40 +0000 (22:16 +0100)] 
detect/analyzer: add byte_test/byte_jump detail

2 years agodetect/analyzer: add content relative_next flag
Victor Julien [Mon, 13 Mar 2023 13:48:19 +0000 (14:48 +0100)] 
detect/analyzer: add content relative_next flag

2 years agodetect/analyzer: add more pcre detail
Victor Julien [Mon, 13 Mar 2023 12:53:32 +0000 (13:53 +0100)] 
detect/analyzer: add more pcre detail

2 years agodetect: split mpm per alproto for file.data & others
Victor Julien [Sat, 18 Mar 2023 18:05:07 +0000 (19:05 +0100)] 
detect: split mpm per alproto for file.data & others

Instead of a shared mpm context for just "file.data" or "file.magic"
use per alproto mpms. This way http file.data rules won't affect smb
file.data performance.

Ticket: #4378.

2 years agompm factory: include alproto
Victor Julien [Sat, 18 Mar 2023 18:56:07 +0000 (19:56 +0100)] 
mpm factory: include alproto

In preparation of spliting out mpm's for keywords shared by
multiple protocols, like file.data.

2 years agojsonschema: do not enforce keys for alert metadata 8605/head
Philippe Antoine [Mon, 26 Dec 2022 10:54:54 +0000 (11:54 +0100)] 
jsonschema: do not enforce keys for alert metadata

As this is a free field and can have any key based on a rule

2 years agodoc: security.limit-noproc upgrade note
Philippe Antoine [Mon, 13 Mar 2023 10:28:40 +0000 (11:28 +0100)] 
doc: security.limit-noproc upgrade note

Ticket: #5621

2 years agogithub-ci: Add Netmap build to GH actions
Lukas Sismis [Fri, 10 Mar 2023 17:25:44 +0000 (18:25 +0100)] 
github-ci: Add Netmap build to GH actions

Issue: #5803

2 years agosmtp: apply suricata.yaml defaults to in-code defaults
Jason Ish [Tue, 14 Mar 2023 22:11:25 +0000 (16:11 -0600)] 
smtp: apply suricata.yaml defaults to in-code defaults

Currently the default suricata.yaml sets some values that do not
reflect the default values in the code. As most users are probably
using a default suricata.yaml, make the code have the same defaults as
in suricata.yaml:

- mime.decode-mime: false -> true
- mime.decode-base64: false -> true
- mime.decode-quoted-printable: false -> true
- mime.extract-urls: false -> true

Issue: #5823

2 years agoschema: add "message_id" to email
Jason Ish [Tue, 14 Mar 2023 22:11:07 +0000 (16:11 -0600)] 
schema: add "message_id" to email

2 years agoconf: document ConfGetChildValueBool
Jason Ish [Mon, 13 Mar 2023 23:27:04 +0000 (17:27 -0600)] 
conf: document ConfGetChildValueBool

2 years agodetect-lua: Convert unittests to FAIL/PASS API
Gabriel Lima Luz [Fri, 3 Feb 2023 15:02:56 +0000 (12:02 -0300)] 
detect-lua: Convert unittests to FAIL/PASS API

Ticket: 4051

2 years agosource-xdp: only allow busy poll if headers support it
Jason Ish [Thu, 9 Feb 2023 17:16:18 +0000 (11:16 -0600)] 
source-xdp: only allow busy poll if headers support it

Wrap the enabling of busy poll in a compile time conditional checking
for the required defines to be set. While we have runtime support for
kernels less than 5.11, we also need a compile time check as the headers
may be old as well.

Issue: 5855

2 years agogithub-ci: add Debian 11 builder with XDP
Jason Ish [Thu, 9 Feb 2023 15:39:37 +0000 (09:39 -0600)] 
github-ci: add Debian 11 builder with XDP

2 years agoschema: fix optional 8587/head
Jason Ish [Mon, 6 Mar 2023 17:51:03 +0000 (11:51 -0600)] 
schema: fix optional

"optional" is not part of jsonschema. Instead an array named "required"
is used to list all field names that are required.

2 years agoschema: fix engines section
Jason Ish [Mon, 6 Mar 2023 17:48:45 +0000 (11:48 -0600)] 
schema: fix engines section

The definition of items is an object, not an array.

2 years agonflog/time: Fixup timestamp handling
Jeff Lucovsky [Tue, 7 Mar 2023 13:59:12 +0000 (08:59 -0500)] 
nflog/time: Fixup timestamp handling

Issue: 5818

This commit corrects the timestamp handling for the packet to work with
the SCTime_t struct.

2 years agorust/clippy: allow derivable impls
Jason Ish [Thu, 9 Mar 2023 17:48:53 +0000 (11:48 -0600)] 
rust/clippy: allow derivable impls

The latest Rust will automatically "fix" derivable default
implementation, which is nice, but makes changes that don't meet our
current MSRV, so allow derivable impls for now.

2 years agodetect/app-layer-event: simplify parsing code
Victor Julien [Wed, 8 Mar 2023 09:09:26 +0000 (10:09 +0100)] 
detect/app-layer-event: simplify parsing code

Simpler and fully local parsing code.

Remove unittests that relied on previous implementation. Code
is tested by SV tests.

2 years agodetect/analyzer: add transform names
Victor Julien [Mon, 6 Mar 2023 16:31:54 +0000 (17:31 +0100)] 
detect/analyzer: add transform names

2 years agoutil/mime: use uint32_t for consumed bytes 8581/head
Shivani Bhardwaj [Wed, 8 Mar 2023 15:46:03 +0000 (21:16 +0530)] 
util/mime: use uint32_t for consumed bytes

In a case of the line buffer being over 255 bytes, the consumed bytes
would reset to 0 as it was uint8_t. Fix this integer overflow by setting
the type to uint32_t.

Redmine ticket: 5883

2 years agodoc: add dataset examples 8572/head
Shivani Bhardwaj [Mon, 27 Feb 2023 13:17:16 +0000 (18:47 +0530)] 
doc: add dataset examples

2 years agodetect: add comments for DETECT_SM_LIST_* types
Shivani Bhardwaj [Thu, 2 Mar 2023 07:28:17 +0000 (12:58 +0530)] 
detect: add comments for DETECT_SM_LIST_* types

2 years agoconfig: put version in configuration as a proper value
Jason Ish [Mon, 30 Jan 2023 23:13:04 +0000 (17:13 -0600)] 
config: put version in configuration as a proper value

Adds a new field, "suricata-version" to the configuration file with
the major and minor version of the Suricata that generated the
configuration file.

This may be useful in the future for presenting warnings about
important changes, or even providing different defaults based on what
the user might expect.

Ticket: 5822

2 years agopfring: Packet structure for ts fix
Jeff Lucovsky [Fri, 17 Feb 2023 14:18:24 +0000 (09:18 -0500)] 
pfring: Packet structure for ts fix

Issue: 5818

This commit addresses the issue with using the address of a packed
member of a structure. The pfring timeval is within a packed structure.

2 years agopfring/time: Track stat output with SCTime_t
Jeff Lucovsky [Sun, 29 Jan 2023 14:28:38 +0000 (09:28 -0500)] 
pfring/time: Track stat output with SCTime_t

Issue: 5818

This commit changes the datatype of the tracking value for the last time
stats were dumped.

Changing the type also eliminates a comparison between values with
different signs.

2 years agotime: SCTime additions -- neq, initializer
Jeff Lucovsky [Sun, 29 Jan 2023 13:36:42 +0000 (08:36 -0500)] 
time: SCTime additions -- neq, initializer

Issue: 5818

This commit adds an initializer for the SCTime_t type and a comparison
macro for "not equal".

Use them as follows:
    SCTime_t my_var = SCTIME_INITIALIZER;
    if (SCTIME_CMP_NEQ(sctime1_val, sctime2_val)) {
    }

2 years agoeve: add version and warning in ntlmssp
Lancer Cheng [Tue, 14 Feb 2023 11:33:35 +0000 (11:33 +0000)] 
eve: add version and warning in ntlmssp

Bug OISF#5783

2 years agodoc: add version filed in NTLMSSP documentation
Lancer Cheng [Tue, 14 Feb 2023 11:27:29 +0000 (11:27 +0000)] 
doc: add version filed in NTLMSSP documentation

Bug OISF#5783

2 years agosmb: fix parser of ntlmssp negotiateflags
Lancer Cheng [Tue, 14 Feb 2023 11:26:57 +0000 (11:26 +0000)] 
smb: fix parser of ntlmssp negotiateflags

Fix endian-conversion bug in function parse_ntlm_auth_nego_flags

Bug OISF#5783

2 years agolog/thread: Consolidate threaded file tracking
Jeff Lucovsky [Sat, 11 Feb 2023 16:42:55 +0000 (11:42 -0500)] 
log/thread: Consolidate threaded file tracking

Issue: 5836

This commit removes the duplicate threaded file tracking from the log
file mechanisms.

Tracking is now consolidated with the threaded hash table.

2 years agolog: Stop if log initialization fails at startup
Jeff Lucovsky [Sat, 4 Feb 2023 15:08:37 +0000 (10:08 -0500)] 
log: Stop if log initialization fails at startup

Issue: 5836

This commit modifies Suricata to fail if log initialization errors occur
during startup.

2 years agostream: add seq min and max; use in segment compare 8563/head
Victor Julien [Tue, 28 Feb 2023 14:00:09 +0000 (15:00 +0100)] 
stream: add seq min and max; use in segment compare

2 years agostream: fix overlap detection
Victor Julien [Tue, 28 Feb 2023 10:41:59 +0000 (11:41 +0100)] 
stream: fix overlap detection

If a in-tree segment was partly before base_seq the overlap detection
miscalculated the data offset. This lead to memcmp comparing the wrong
data.

Bug: #5881.

2 years agostream: reuse TCP session after TFO SYN+data reject 8562/head
Victor Julien [Mon, 27 Feb 2023 14:42:37 +0000 (15:42 +0100)] 
stream: reuse TCP session after TFO SYN+data reject

2 years agoeve/stream: log tcp reuse flag in packets
Victor Julien [Mon, 27 Feb 2023 14:42:15 +0000 (15:42 +0100)] 
eve/stream: log tcp reuse flag in packets

2 years agoflow: remove unused tcp reuse flow flag
Victor Julien [Mon, 27 Feb 2023 14:41:36 +0000 (15:41 +0100)] 
flow: remove unused tcp reuse flow flag

2 years agostream: support SYN/ACK with TFO only ack'ing ISN
Victor Julien [Sat, 25 Feb 2023 09:10:29 +0000 (10:10 +0100)] 
stream: support SYN/ACK with TFO only ack'ing ISN

Not ack'ing the data.

2 years agostream: add counter for acks for unseen data
Victor Julien [Thu, 23 Feb 2023 09:29:06 +0000 (10:29 +0100)] 
stream: add counter for acks for unseen data

This is another indicator for packet loss or strange captures.

2 years agoeve/stream: ack unseen data
Victor Julien [Wed, 22 Feb 2023 20:14:52 +0000 (21:14 +0100)] 
eve/stream: ack unseen data

2 years agostream: flag ACKs that ack segments after next_seq
Victor Julien [Wed, 22 Feb 2023 20:14:23 +0000 (21:14 +0100)] 
stream: flag ACKs that ack segments after next_seq

Avoid this for async streams.

2 years agostream: fix spurious retransmission handling
Victor Julien [Sat, 18 Feb 2023 09:48:51 +0000 (10:48 +0100)] 
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.

2 years agostream: add liberal timetamps option
Victor Julien [Wed, 22 Feb 2023 14:17:53 +0000 (15:17 +0100)] 
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.

2 years agostream: D-SACK detection and logging
Victor Julien [Tue, 21 Feb 2023 09:47:13 +0000 (10:47 +0100)] 
stream: D-SACK detection and logging

RFC 2883 specifies a special use of SACKs to indicate a host has
received a segment it considers a spurious retransmission.

2 years agostream: Dup-ACK detection
Victor Julien [Tue, 21 Feb 2023 09:08:31 +0000 (10:08 +0100)] 
stream: Dup-ACK detection

Modeled after Wiresharks Dup-ACK detection.

2 years agostream: fix next_seq updates after temporary gap
Victor Julien [Sat, 18 Feb 2023 14:36:55 +0000 (15:36 +0100)] 
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.

2 years agoeve/stream: per packet stream engine logging
Victor Julien [Thu, 16 Feb 2023 07:59:31 +0000 (08:59 +0100)] 
eve/stream: per packet stream engine logging

Debug facility to get a per packet view into the stream engine's state.

Logs after a packet has been processed in the stream engine, so the view
into the state includes the updates based on the current packet.

Marked as experimental so it can be changed w/o notice.

Bug: #5876.

2 years agostream: implement config option for SYN queue
Victor Julien [Fri, 17 Feb 2023 12:03:41 +0000 (13:03 +0100)] 
stream: implement config option for SYN queue

Default to allowing 10 SYNs to not trigger an event on a connection
attempt that times out.

2 years agostream: track packet flags in packet
Victor Julien [Thu, 16 Feb 2023 05:17:24 +0000 (06:17 +0100)] 
stream: track packet flags in packet

These flags can then later be used by stream logging.

2 years agostream: improve first FIN next_seq update
Victor Julien [Tue, 14 Feb 2023 14:36:56 +0000 (15:36 +0100)] 
stream: improve first FIN next_seq update

For accepted FIN packets, always update next_seq. This helps track the
FIN sequence.

Bug: #5877.

2 years agostream: improve FIN next_seq handling
Victor Julien [Wed, 15 Feb 2023 10:56:47 +0000 (11:56 +0100)] 
stream: improve FIN next_seq handling

Update next_seq to SEQ + payload_len + 1, so retransmission checks
work better.

Bug: #5877.

2 years agostream: set next_seq before last_ack
Victor Julien [Wed, 15 Feb 2023 10:56:01 +0000 (11:56 +0100)] 
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.

2 years agostream/tcp: fix wrong ACK trigger FIN1 to FIN2
Victor Julien [Sat, 11 Feb 2023 12:14:53 +0000 (13:14 +0100)] 
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.

2 years agostream: SYN queue support
Victor Julien [Thu, 9 Feb 2023 16:11:21 +0000 (17:11 +0100)] 
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.

2 years agostream: fix direction macro to be used in conditions
Victor Julien [Mon, 13 Feb 2023 07:53:03 +0000 (08:53 +0100)] 
stream: fix direction macro to be used in conditions

2 years agostream: minor code cleanup
Victor Julien [Sun, 12 Feb 2023 20:34:56 +0000 (21:34 +0100)] 
stream: minor code cleanup

2 years agoflow: fix comment typo
Victor Julien [Sun, 12 Feb 2023 20:34:33 +0000 (21:34 +0100)] 
flow: fix comment typo

2 years agostream: turn session bool into flag
Victor Julien [Sat, 11 Feb 2023 18:22:26 +0000 (19:22 +0100)] 
stream: turn session bool into flag

2 years agostream: turn session flags into u32
Victor Julien [Sat, 11 Feb 2023 18:16:28 +0000 (19:16 +0100)] 
stream: turn session flags into u32

Due to gaps/padding the size of the struct won't change.

2 years agostream/config: optimize stream config structure layout
Victor Julien [Sat, 11 Feb 2023 13:27:00 +0000 (14:27 +0100)] 
stream/config: optimize stream config structure layout

2 years agostream/config: turn async_oneside into bool
Victor Julien [Sat, 11 Feb 2023 13:20:21 +0000 (14:20 +0100)] 
stream/config: turn async_oneside into bool

2 years agostream: minor code cleanups in ACK validation
Victor Julien [Sat, 11 Feb 2023 07:09:17 +0000 (08:09 +0100)] 
stream: minor code cleanups in ACK validation