]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
3 years agogithub-ci: use curl -L for npcap: follow redirects 6883/head
Jason Ish [Fri, 21 Jan 2022 05:21:08 +0000 (23:21 -0600)] 
github-ci: use curl -L for npcap: follow redirects

(cherry picked from commit 90996958aa32ef3ff789c28b6efcb8ded2cef342)

3 years agostream-tcp-reassemble: fix reassembly direction for FIN packets
Angelo Mirabella [Thu, 20 Jan 2022 14:52:33 +0000 (14:52 +0000)] 
stream-tcp-reassemble: fix reassembly direction for FIN packets

Suricata invokes the stream reassembly logic only for the current packet
direction if the packet contains a FIN flag. However, this does not
handle the case in which the packet ACKs data from the opposing direction.
This patch forces the invocation of the stream reassembly logic
on both direction when Suricata sees a FIN packet.

(cherry picked from commit 41a139b590a059171d0517a455c562486e1a21c2)

3 years agodetect/file_data: Reject invalid protocols 6824/head
Jeff Lucovsky [Thu, 13 Jan 2022 15:39:12 +0000 (10:39 -0500)] 
detect/file_data: Reject invalid protocols

Issue: #4895

This commit causes Suricata to reject signatures that combine TCP-based
alerts using file_data with NFS keywords.

file_data doesn't support the NFS protocol.

(cherry picked from commit 215335fdc6431e1c5de6155aa64c152bda507b72)

3 years agostream: fix stream pruning being too aggressive
Victor Julien [Thu, 13 Jan 2022 11:13:43 +0000 (12:13 +0100)] 
stream: fix stream pruning being too aggressive

Pruning of StreamBufferBlocks could remove blocks that fell entirely
after the target offset due to a logic error. This could lead to data
being evicted that was still meant to be processed in theapp-layer
parsers.

Bug: #4953.
(cherry picked from commit 78f5e082f5188204606ab9ceb5044447e49aaca2)

3 years agosuricatasc: Handle incomplete/empty recv values
Jeff Lucovsky [Tue, 11 Jan 2022 19:16:24 +0000 (14:16 -0500)] 
suricatasc: Handle incomplete/empty recv values

Issue: 4947

Improve handling of values returned by recv. Sometimes, recv returns an
empty string if suricata terminates asynchronously.

(cherry picked from commit fc6fdef07006e5382839ef88873e90754b30e6e0)

3 years agodoc/eve-json-format/dns: Describing Z-bit
Odin Jenseg [Tue, 8 Jun 2021 19:56:41 +0000 (21:56 +0200)] 
doc/eve-json-format/dns: Describing Z-bit

(cherry picked from commit 2a5d79e42609bd5ae0d0456cd5c458e20670160e)

3 years agodns: add dns flag to dns request logging
Jason Ish [Tue, 21 Dec 2021 22:49:21 +0000 (16:49 -0600)] 
dns: add dns flag to dns request logging

Ticket #4515

(cherry picked from commit 0861b66e152c6d2a0517a4a043ef56bdb1be4d76)

3 years agodns: Logging of Z-bit
Odin Jenseg [Tue, 8 Jun 2021 19:55:36 +0000 (21:55 +0200)] 
dns: Logging of Z-bit

[Edit by Jason Ish: fix flag bit value]

Ticket #4515

(cherry picked from commit dfb6f105e8b104bf27cce24b650d047d0925c145)

3 years agodns: create transaction even if z-bit was set
Jason Ish [Tue, 21 Dec 2021 22:34:05 +0000 (16:34 -0600)] 
dns: create transaction even if z-bit was set

It appears that DNS servers will still process a DNS request even if the
z-bit is set, our parser will fail the transaction. So create the
transaction, but still set the event.

Ticket #4924

(cherry picked from commit fcbdc304265aaba724b245a5c3f02e00c8059a1a)

3 years agoflow/bypass: clear memory on bypass
Victor Julien [Mon, 25 Oct 2021 17:15:23 +0000 (19:15 +0200)] 
flow/bypass: clear memory on bypass

Previously the flow would hold on to the app-layer and segment data
until the end of the flow, even though it would never be accessed again.

This patch clears app-layer and stream data, but not stream ssn as its
used in flow logging.

Bug: #4778.
(cherry picked from commit 536291054c9694070beac1d19b41bf8a1f9c1d4e)

3 years agoflow/bypass: add util func to check if flow is bypassed
Victor Julien [Mon, 25 Oct 2021 18:25:39 +0000 (20:25 +0200)] 
flow/bypass: add util func to check if flow is bypassed

To hide the ifdefs for capture offload.

(cherry picked from commit b19d1df69f47b4b85337f1695bc770f4b0703bac)

3 years agoflow/worker: run housekeeping for bypassed packets
Victor Julien [Mon, 25 Oct 2021 17:14:49 +0000 (19:14 +0200)] 
flow/worker: run housekeeping for bypassed packets

Run flow eviction and flow inject queues for bypassed packets as well,
to avoid a scenario where these won't get run at all if too much of the
traffic is bypassed.

Bug: #4779.
(cherry picked from commit ab8f289bb652a2aa83bdd476708a5f297cbec83c)

3 years agodetect/proto: Warn if proto not found in config
Shivani Bhardwaj [Tue, 18 Jan 2022 07:31:41 +0000 (13:01 +0530)] 
detect/proto: Warn if proto not found in config

Ticket 4744

3 years agoflow: immediately evict tcp reused flows
Victor Julien [Tue, 26 Oct 2021 09:09:51 +0000 (11:09 +0200)] 
flow: immediately evict tcp reused flows

Since we already know we're going to no longer use it, might as well
evict it right away.

Ticket 4978

(cherry picked from commit 286c510ece27c8fd408434c1786df26aba0c5581)

3 years agoci: remove eol Fedora 32 & 33
Shivani Bhardwaj [Tue, 18 Jan 2022 07:17:43 +0000 (12:47 +0530)] 
ci: remove eol Fedora 32 & 33

3 years agoci: add fedora 35 to builds
Corey Thomas [Wed, 10 Nov 2021 13:21:38 +0000 (08:21 -0500)] 
ci: add fedora 35 to builds

(cherry picked from commit 7be793f7b479d66977ff68ea1ca3c832c744b3d2)

3 years agoci: add Fedora 34 to builds
Shivani Bhardwaj [Thu, 13 Jan 2022 17:11:19 +0000 (22:41 +0530)] 
ci: add Fedora 34 to builds

3 years agodatasets: initialize after dropping privileges
Jason Ish [Thu, 9 Dec 2021 22:59:04 +0000 (16:59 -0600)] 
datasets: initialize after dropping privileges

Move initialization of datasets to a point after privileges
have been dropped.

Ticket 4239

(cherry picked from commit 92eb14c5adc985433dd44bdcac18fa6e67440043)

3 years agoutil/streaming: improve error handling
Eric Leblond [Thu, 19 Aug 2021 09:21:21 +0000 (11:21 +0200)] 
util/streaming: improve error handling

It differentiates memory error than regular ones.

(cherry picked from commit 0e70958e67398f599b77ba991dc631e025cae5f4)

3 years agoconf: avoid quadratic complexity
Philippe Antoine [Mon, 8 Nov 2021 13:18:30 +0000 (14:18 +0100)] 
conf: avoid quadratic complexity

Ticket: 4812

When adding many sequence nodes

(cherry picked from commit 15649424a76d01eb332d85620ffc4956d4f3d9be)

3 years agoaf-packet: use configured cluster-id when checking for fanout
Jason Ish [Fri, 16 Oct 2020 15:43:29 +0000 (09:43 -0600)] 
af-packet: use configured cluster-id when checking for fanout

When testing for fanout support a cluster-id of 1 was always being
used instead of the configured cluster-id. This limited fanout
support to only one Suricata instance.

Instead of hardcoding an ID of 1, use the configured cluster-id.

Also make cluster_id a uint16_t instead of an int in AFPThreadVars.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/3419

(cherry picked from commit df0ed6fda47fc80a397710316ae78cc3967e29bb)

3 years agoprofiling: fix profiling with sample rate
Eric Leblond [Wed, 17 Nov 2021 15:43:23 +0000 (16:43 +0100)] 
profiling: fix profiling with sample rate

Rules profiling was returning invalid results when used with sample
rate. The problem was that the sample condition was run twice in the
packet flow. As a result, the second pass was not initializing the
variable storing the initial CPU ticks and the resulting performance
counters were reporting invalid values.

Bug: #4836.
(cherry picked from commit 6d5f59696dda77e1e7b2c45f51413b76690da4e9)

3 years agosmtp: log transaction even if no email present 6765/head
Jason Ish [Wed, 10 Nov 2021 22:38:35 +0000 (16:38 -0600)] 
smtp: log transaction even if no email present

The SMTP transaction logger was not writing the log if the email
portion of the logger failed, such as in the case of STARTTLS
where this is no email decoded.

Ticket #4817

(cherry picked from commit 52b9c12f41d890cda340fe3b1c7e7e3e9d673d73)

3 years agorust: bump MSRV to 1.41.1
Shivani Bhardwaj [Tue, 14 Dec 2021 15:44:30 +0000 (21:14 +0530)] 
rust: bump MSRV to 1.41.1

Ticket: #4902.

3 years agomingw: add bcrypt to LDADD for rust compilation 6703/head
Victor Julien [Tue, 7 Dec 2021 08:56:51 +0000 (09:56 +0100)] 
mingw: add bcrypt to LDADD for rust compilation

(cherry picked from commit e93dc24383443398d6a2e888931d7000b392c09a)

3 years agoalert: fixes leak in ThresholdHandlePacketRule 6701/head
Philippe Antoine [Tue, 5 Oct 2021 19:14:18 +0000 (21:14 +0200)] 
alert: fixes leak in ThresholdHandlePacketRule

ThresholdHandlePacketRule may take ownership of an allocated
DetectThresholdEntry, and places it in a position of the
array th_entry. But it never got released

(cherry picked from commit 6fadb97d5ded5805745bca02bfb962de975ec122)

3 years agomqtt: fix transaction completion 6700/head
Philippe Antoine [Thu, 2 Dec 2021 09:29:40 +0000 (10:29 +0100)] 
mqtt: fix transaction completion

Ticket: 4862

A transaction to client is always considered
complete in the direction to server and vice versa.
Otherwise, transactions are never complete for
AppLayerParserTransactionsCleanup

(cherry picked from commit 1b10848d84f6417a4030e5814db246b369b77593)

3 years agodhcp: fix url in comment 6635/head
Jason Ish [Wed, 17 Nov 2021 01:34:11 +0000 (19:34 -0600)] 
dhcp: fix url in comment

rustdoc was complaining about the format of the URL in a comment
while trying to generate documentation. Convert the comment to a
non-rustdoc comment for now to satisfy rustdoc.

(cherry picked from commit eb6cc6293717e10f881edd6713fb8dc6ef78d3b7)

3 years agoci: update Ubuntu 16.04 test to 20.04 with MSRV
Jason Ish [Mon, 22 Nov 2021 21:05:19 +0000 (15:05 -0600)] 
ci: update Ubuntu 16.04 test to 20.04 with MSRV

Update the Ubuntu 16.04 test to Ubuntu 20.04 and make it clear
that it is also testing the minimum supported Rust version for 6.0.

Note: Ubuntu 16.04 is now EOL.

3 years agoversion: start development towards 6.0.5
Victor Julien [Thu, 18 Nov 2021 08:57:14 +0000 (09:57 +0100)] 
version: start development towards 6.0.5

3 years agorelease: 6.0.4; update changelog; require htp 0.5.39 suricata-6.0.4
Victor Julien [Tue, 16 Nov 2021 12:15:35 +0000 (13:15 +0100)] 
release: 6.0.4; update changelog; require htp 0.5.39

3 years agotcp: rejects FIN+SYN packets as invalid
Philippe Antoine [Thu, 16 Sep 2021 14:54:37 +0000 (16:54 +0200)] 
tcp: rejects FIN+SYN packets as invalid

Ticket: #4569

If a FIN+SYN packet is sent, the destination may keep the
connection alive instead of starting to close it.
In this case, a later SYN packet will be ignored by the
destination.

Previously, Suricata considered this a session reuse, and thus
used the sequence number of the last SYN packet, instead of
using the one of the live connection, leading to evasion.

This commit errors on FIN+SYN so that they do not get
processed as regular FIN packets.

(cherry picked from commit 6cb6225b28c5d8e616a420b7d05b129ba2845dc0)

3 years agostream/tcp: handle RST with MD5 or AO header
Victor Julien [Tue, 5 Oct 2021 12:48:27 +0000 (14:48 +0200)] 
stream/tcp: handle RST with MD5 or AO header

Special handling for RST packets if they have an TCP MD5 or AO header option.
The options hash can't be validated. The end host might be able to validate
it, as it can have a key/password that was communicated out of band.

The sender could use this to move the TCP state to 'CLOSED', leading to
a desync of the TCP session.

This patch builds on top of
843d0b7a10bb ("stream: support RST getting lost/ignored")

It flags the receiver as having received an RST and moves the TCP state
into the CLOSED state. It then reverts this if the sender continues to
send traffic. In this case it sets the following event:

    stream-event:suspected_rst_inject;

Bug: #4710.
(cherry picked from commit 50e2b973eeec7172991bf8f544ab06fb782b97df)

3 years agontp: fixes leak of de_state
Philippe Antoine [Tue, 12 Oct 2021 11:29:39 +0000 (13:29 +0200)] 
ntp: fixes leak of de_state

Bug: #4752.
(cherry picked from commit 3212fa7d2bc514f4e759dbb9e0002203c814a9b5)

3 years agosnmp: fixes leak of de_state
Philippe Antoine [Tue, 12 Oct 2021 11:29:25 +0000 (13:29 +0200)] 
snmp: fixes leak of de_state

Bug: #4752.
(cherry picked from commit 28a3181a2de0101b0796058eeffac0180eef35d6)

3 years agosmb: midstream probing checks for netbios message type
Philippe Antoine [Mon, 23 Aug 2021 15:31:51 +0000 (17:31 +0200)] 
smb: midstream probing checks for netbios message type

If it is available

Bug: #4620.
(cherry picked from commit f37240a3e2758756f345a237b6d348ab38fb758b)

3 years agoprotodetect: opposing side cannot change protocol
Philippe Antoine [Fri, 16 Jul 2021 12:22:28 +0000 (14:22 +0200)] 
protodetect: opposing side cannot change protocol

Ticket: #4562

As the data which triggered the opposing side
was the same protocol and not another one,
that means the protocol change failed.

Prevents a memory leak in later call of AppLayerParserParse
which would allocate a new state and leak the old one

(cherry picked from commit be617a3c1b25a7a4b1acdc7b65d3733d4f48a1f9)

3 years agosmtp: completes RSET transaction on last multiline
Philippe Antoine [Wed, 14 Jul 2021 17:40:42 +0000 (19:40 +0200)] 
smtp: completes RSET transaction on last multiline

Bug: #4561.
(cherry picked from commit f44bbbb9ada39893279965a98831620074205871)

3 years agoswf: right input length for decompression
Philippe Antoine [Thu, 1 Jul 2021 13:04:58 +0000 (15:04 +0200)] 
swf: right input length for decompression

Also when compress_depth reaches buffer_len

Bug: #4536.
(cherry picked from commit f211a330ddfbac8a6d0b85ea5f2ee0fcc1ccad3d)

3 years agorust: right condition for both uint to be zero
Philippe Antoine [Mon, 13 Sep 2021 09:22:36 +0000 (11:22 +0200)] 
rust: right condition for both uint to be zero

Theay can overflow leading to their addition to be zero

If a NFS read reply indicates a count of 0xFFFFFFFF

Bug: #4680.
(cherry picked from commit 8f8823b6f2b0a26b551397b8b574104bfd37e9f5)

3 years agoinspect: debug validation to ensure correct argument
Philippe Antoine [Mon, 13 Sep 2021 10:27:51 +0000 (12:27 +0200)] 
inspect: debug validation to ensure correct argument

(cherry picked from commit 689ac97d7225fd43b64c103034b1fdf63fa4d324)

3 years agodetect: fixes InspectionBuffer id with transforms
Philippe Antoine [Mon, 13 Sep 2021 10:18:34 +0000 (12:18 +0200)] 
detect: fixes InspectionBuffer id with transforms

When InspectionBufferGet gets called with base_id
Later InspectionBufferSetup must also be called with base_id

In case there were transforms, we had base_id != list_id

Not calling InspectionBufferSetup with the right id
resulted in leaving a dangling pointer,
because it was not added to det_ctx->inspect.to_clear_queue

Bug: #4681.
(cherry picked from commit c3339c853e3b35d896db68644ee7557fb725da18)

3 years agoloopback: decodes IPv6 from all OSes 6609/head
Philippe Antoine [Tue, 12 Oct 2021 07:04:59 +0000 (09:04 +0200)] 
loopback: decodes IPv6 from all OSes

As does wireshark

(cherry picked from commit 27b4f165b17499cc765ccb770f1cf994992e10f6)

3 years agoflow/bypass: use_cnt desync'd on bypassed flows 6603/head
Victor Julien [Wed, 20 Oct 2021 11:20:32 +0000 (13:20 +0200)] 
flow/bypass: use_cnt desync'd on bypassed flows

Locally bypassed flows had unsafe updates to `Flow::use_cnt` leading to a race
issue. For a packet it would do the flow lookup, attach the flow to the packet,
increment the `use_cnt`. Then it would detect that the flow is in the bypass
state, and unlock it while holding a reference (so alos not decrementing the
`use_cnt`). When the packet was then returned to the packet pool, the flow would
be disconnected from the packet, which would decrement `use_cnt` without holding
the flow lock.

This patch addresses this issue by disconnecting the flow from the packet
immediately when the bypassed state is detected. This moves the `use_cnt`
decrement to within the lock.

Bug: #4766.
(cherry picked from commit ec7e0561e8356371c7ec1c2b285f267424558f81)

3 years agopacketpool: reset PacketRelease on return to pool
Victor Julien [Fri, 5 Nov 2021 19:05:43 +0000 (20:05 +0100)] 
packetpool: reset PacketRelease on return to pool

Reset PacketRelease callback to make sure its not set to a capture
specific callback.

As an example:

  0x000055e00af09d35 in AFPReleaseDataFromRing (p=0x7f1d884cb830) at source-af-packet.c:653
  0x000055e00af09dd0 in AFPReleasePacket (p=0x7f1d884cb830) at source-af-packet.c:678
  0x000055e00ab53d7e in TmqhOutputPacketpool (t=0x55e00fb79250, p=0x7f1d884cb830) at tmqh-packetpool.c:465
  0x000055e00af08dec in TmThreadsSlotProcessPkt (tv=0x55e00fb79250, s=0x55e012134790, p=0x7f1d884cb830) at tm-threads.h:201
  0x000055e00af08e70 in TmThreadsCaptureInjectPacket (tv=0x55e00fb79250, p=0x7f1d884cb830) at tm-threads.h:221
  0x000055e00af08f2e in TmThreadsCaptureHandleTimeout (tv=0x55e00fb79250, p=0x0) at tm-threads.h:245
  0x000055e00af0ba76 in ReceiveAFPLoop (tv=0x55e00fb79250, data=0x7f1d884ccb60, slot=0x55e01198e4b0) at source-af-packet.c:1321
  0x000055e00ab55257 in TmThreadsSlotPktAcqLoop (td=0x55e00fb79250) at tm-threads.c:312
  0x00007f1dca9d5609 in start_thread (arg=<optimized out>) at pthread_create.c:477
  0x00007f1dca7c6293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Here the packet was a pseudo packet to handle a timeout condition. But
the ReleasePacket callback was still set to AFPReleasePacket from a
previous use of the Packet.

Bug: #4807.
(cherry picked from commit 07ce871da4b385f6f1d86310f5dcdf00e6c79692)

3 years agoaf-packet: avoid flag colision with kernel
Victor Julien [Sun, 31 Oct 2021 09:28:18 +0000 (10:28 +0100)] 
af-packet: avoid flag colision with kernel

Avoid colision of TP_STATUS_USER_BUSY with TP_STATUS_TS_RAW_HARDWARE,
both were using bit 31.

Bug: #4800.
(cherry picked from commit ad862fff371cddd19329d9ac0ddb106e1ad6b1b3)

3 years agoaf-packet: fix soft lockup issues
Victor Julien [Sun, 31 Oct 2021 21:13:19 +0000 (22:13 +0100)] 
af-packet: fix soft lockup issues

The Suricata AF_PACKET code opens a socket per thread, then after some minor
setup enters a loop where the socket is poll()'d with a timeout. When the
poll() call returns a non zero positive value, the AF_PACKET ring will be
processed.

The ringbuffer processing logic has a pointer into the ring where we last
checked the ring. From this position we will inspect each frame until we
find a frame with tp_status == TP_STATUS_KERNEL (so essentially 0). This
means the frame is currently owned by the kernel.

There is a special case handling for starting the ring processing but
finding a TP_STATUS_KERNEL immediately. This logic then skip to the next
frame, rerun the check, etc until it either finds an initialized frame or
the last frame of the ringbuffer.

The problem was, however, that the initial uninitialized frame was possibly
(likely?) still being initialized by the kernel. A data race between the
notification through the socket (the poll()) and the updating of the
`tp_status` field in the frame could lead to a valid frame getting skipped.

Of note is that for example libpcap does not do frame scanning. Instead it
simply exits it ring processing loop. Also interesting is that libpcap uses
atomic loads and stores on the tp_status field.

This skipping of frames had 2 bad side effects:

1. in most cases, the buffer would be full enough that the frame would
   be processed in the next pass of the ring, but now the frame would
   out of order. This might have lead to packets belong to the same
   flow getting processed in the wrong order.

2. more severe is the soft lockup case. The skipped frame sits at ring
   buffer index 0. The rest of the ring has been cleared, after the
   initial frame was skipped. As our pass of the ring stops at the end
   of the ring (ptv->frame_offset + 1 == ptv->req.v2.tp_frame_nr) the code
   exits the ring processing loop at goes back to poll(). However, poll()
   will not indicate that there is more data, as the stale frame in the
   ring blocks the kernel from populating more frames beyond it. This
   is now a dead lock, as the kernel waits for Suricata and Suricata
   never touches the ring until it hears from the kernel.

   The scan logic will scan the whole ring at most once, so it won't
   reconsider the stale frame either.

This patch addresses the issues in several ways:

1. the startup "discard" logic was fixed to not skip over kernel
   frames. Doing so would get us in a bad state at start up.

2. Instead of scanning the ring, we now enter a busy wait loop
   when encountering a kernel frame where we didn't expect one. This
   means that if we got a > 0 poll() result, we'll busy wait until
   we get at least one frame.

3. Error handling is unified and cleaned up. Any frame error now
   returns the frame to the kernel and progresses the frame pointer.

4. If we find a frame that is owned by us (TP_STATUS_USER_BUSY) we
   yield to poll() immediately, as the next expected status of that
   frame is TP_STATUS_KERNEL.

5. the ring is no longer processed until the "end" of the ring (so
   highest index), but instead we process at most one full ring size
   per run.

6. Work with a copy of `tp_status` instead of accessing original touched
   also by the kernel.

Bug: #4785.
(cherry picked from commit a022648b9e6910ca05a0564c2ead9344a4c34312)

3 years agoaf-packet: define all current TP_STATUS_* flags
Victor Julien [Tue, 2 Nov 2021 16:16:31 +0000 (17:16 +0100)] 
af-packet: define all current TP_STATUS_* flags

(cherry picked from commit 8b08b0343d8a5a6b3d7d2ccb22fa4c4707400932)

3 years agoflow/manager: fix flows not evicted & freed in time
Victor Julien [Sun, 7 Nov 2021 05:25:31 +0000 (06:25 +0100)] 
flow/manager: fix flows not evicted & freed in time

Flows have been shown to linger for a long time w/o giving up their
resources. This would lead to higher memory use and memcaps getting
reached.

Three main causes have been identified:

Slow passes hash passes. By default the flow manager will scan the
flow hash slowly. It is based on the flow timeout settings, and with
the default config it will take 4 minutes for a full scan to be
complete. This leaves a window for flows that are timed out to linger
for minutes longer than expected.

Flow Manager yields under pressure. The per row TryLock causes work
to be delayed more. The Flow manager will use trylock on a hash row
and will yield immediately if the row is busy. This means that it will
take a full pass before the row is revisited again. If the row holds
busy flows, this could happen many times in a row.

Flow Manager favors evicted flows over active flows. The Flow Manager
will only process the evicted flows if they are present. These flows
have been evicted by workers. The active flows on that hash row will
have to wait until the next hash pass. Of course by then there could
be more evicted flows.

Combined these factors could lead to flows not being considered for
freeing and logging for a very long time, potentially even indefinitly.

The patch addresses the latter two flow manager issues by no longer
using TryLock. It will now simply wait for the lock to be released and
then do its work on it. Additionally for each row both the evicted list
and the active flow list will be processed.

Bug: #4650.
(cherry picked from commit 244dd11c34152fbdb01636da8a9fa4a9fa0de050)

3 years agoflow/manager: remove obsolete code
Victor Julien [Mon, 25 Oct 2021 20:12:01 +0000 (22:12 +0200)] 
flow/manager: remove obsolete code

(cherry picked from commit 41fee417229feed7636f95acb3c3d7309b9d3122)

3 years agostyle: remove latest warnings 6528/head
Philippe Antoine [Fri, 24 Sep 2021 13:42:50 +0000 (15:42 +0200)] 
style: remove latest warnings

about unused variables

(cherry picked from commit cb30772372234b88787676eff865e43ce6793cad)

3 years agoflowint: same analysis warnings as flowbits
Philippe Antoine [Fri, 24 Sep 2021 13:42:41 +0000 (15:42 +0200)] 
flowint: same analysis warnings as flowbits

(cherry picked from commit f6ba3699bb8a790956b645e3c47cc159811ab677)

3 years agohttp2: null check during upgrade 6465/head
Philippe Antoine [Mon, 23 Aug 2021 13:03:51 +0000 (15:03 +0200)] 
http2: null check during upgrade

(cherry picked from commit fa4c7626bde98f20700172984f7bd07c285406ba)

3 years agodnp3: regenerate object decoding code 6462/head
Philippe Antoine [Thu, 8 Jul 2021 13:02:50 +0000 (15:02 +0200)] 
dnp3: regenerate object decoding code

Ticket: #4558
So as to avoid intra-structure overflow

(cherry picked from commit 44bd3169eb1ab0501d909fe261b3dafde6375400)

3 years agodnp3: adds bounds check for prefix chararray
Philippe Antoine [Thu, 8 Jul 2021 13:01:15 +0000 (15:01 +0200)] 
dnp3: adds bounds check for prefix chararray

Ticket: #4558
Avoids intra structure overflow

(cherry picked from commit 126a7dcb4f1818a806c882c54da864992bb304d5)

3 years agodnp3: use base64 macro in gen script
Philippe Antoine [Thu, 8 Jul 2021 12:57:56 +0000 (14:57 +0200)] 
dnp3: use base64 macro in gen script

As is done already in C
cf commit ea0936199d142fc52ec69baf7984cbdd92dd4705

(cherry picked from commit 5ec9688f03eb611b8ec3108a4f20db2baf87b225)

3 years agossh: fix match on ssh banner
Shivani Bhardwaj [Fri, 8 Oct 2021 00:35:29 +0000 (06:05 +0530)] 
ssh: fix match on ssh banner

Default detection handling of SSH should not be to pass in case the
direction was not a match but to treat it like it was meant to server.

3 years agodetect: suppress error message for pcre only rules 6457/head
Victor Julien [Fri, 19 Feb 2021 10:45:00 +0000 (11:45 +0100)] 
detect: suppress error message for pcre only rules

(cherry picked from commit 9dd1444f4431731bf4917488e0abec0d9a46fdcc)

3 years agohttp2: better rust lifetimes 6453/head
Philippe Antoine [Tue, 7 Sep 2021 12:44:25 +0000 (14:44 +0200)] 
http2: better rust lifetimes

so that borrow check gets happy

(cherry picked from commit 56fae072b225d1c175116efe117c264afbdbf4a3)

3 years agohttp2: better rust style
Philippe Antoine [Fri, 4 Jun 2021 13:18:32 +0000 (15:18 +0200)] 
http2: better rust style

(cherry picked from commit 596a4a9d6edf43c73de85356b2e0cec3cb91e471)

3 years agohttp2: concatenate one headers multiple values
Philippe Antoine [Mon, 31 May 2021 14:17:22 +0000 (16:17 +0200)] 
http2: concatenate one headers multiple values

For detection, as is done with HTTP1

(cherry picked from commit 48ed874ddad4bbe7321191712263086f4567a5ab)

3 years agohttp2: generic http2_header_blocks
Philippe Antoine [Mon, 31 May 2021 09:40:42 +0000 (11:40 +0200)] 
http2: generic http2_header_blocks

so as not to forget continuation and push promise
when iterating over headers

(cherry picked from commit e3ff0e7731e8d652ee7f22945311674e65455a74)

3 years agohttp2: http.header keyword now works for HTTP2
Philippe Antoine [Mon, 31 May 2021 08:50:38 +0000 (10:50 +0200)] 
http2: http.header keyword now works for HTTP2

As well as http.header.raw

(cherry picked from commit 0b0649d98e07eb7dc8da60100c80fbcfe6cdd9e8)

3 years agohttp2: http.header_names keyword now works for HTTP2
Philippe Antoine [Mon, 31 May 2021 08:11:27 +0000 (10:11 +0200)] 
http2: http.header_names keyword now works for HTTP2

(cherry picked from commit 9b9f909d7db9ba4485bf50577868fa7072998487)

3 years agohttp2: http.host normalized keyword now works for HTTP2
Philippe Antoine [Wed, 26 May 2021 19:45:30 +0000 (21:45 +0200)] 
http2: http.host normalized keyword now works for HTTP2

(cherry picked from commit 547e9f4ab42fb4a67dc67f85fa58e0c9a7e4c634)

3 years agohttp2: turn Host header into authority during upgrade
Philippe Antoine [Wed, 26 May 2021 18:54:01 +0000 (20:54 +0200)] 
http2: turn Host header into authority during upgrade

HTTP1 uses Host, but HTTP2 uses rather :authority cf HPACK

(cherry picked from commit 75f75e1eb09c208a42e58b2babbc55027cd79e28)

3 years agogithub-ci: pin macos build to 10.15 6450/head
Jason Ish [Tue, 5 Oct 2021 16:44:03 +0000 (10:44 -0600)] 
github-ci: pin macos build to 10.15

There is currently a build failure with macos-latest (recently updated)
to 11 in the libhtp test suite code. Not sure if there are other
build issues in libhtp or Suricata at this time.

(cherry picked from commit 8b9721b2652790354e619c77622cf84c766915a3)

3 years agohttp2: do not try to upgrade if http2 is disabled in config 6443/head
Philippe Antoine [Wed, 15 Sep 2021 14:22:00 +0000 (16:22 +0200)] 
http2: do not try to upgrade if http2 is disabled in config

(cherry picked from commit 8536048443a30907ec4c96958374d782d7e656c6)

3 years agohttp2: flatten code style
Philippe Antoine [Wed, 15 Sep 2021 14:20:56 +0000 (16:20 +0200)] 
http2: flatten code style

(cherry picked from commit 42ba421ca975920bd753cbbf44a5bf9d118d4a3b)

3 years agoprotodetect: handle all gaps, even when depth is reached
Philippe Antoine [Mon, 23 Aug 2021 14:31:42 +0000 (16:31 +0200)] 
protodetect: handle all gaps, even when depth is reached

(cherry picked from commit 527415dba08f6f2af7fb93fdef19e3029cef88bd)

3 years agoapp-layer/pd: review bailout conditions
Philippe Antoine [Wed, 9 Jun 2021 10:09:23 +0000 (12:09 +0200)] 
app-layer/pd: review bailout conditions

To take TCP window into account
And to actually bail out if we received too much data
where the limit is configured by stream.reassembly.depth

(cherry picked from commit f77b027ada0436855109f422bfa4d491dba846c7)

3 years agoapp-layer/pd: only consider actual available data
Victor Julien [Wed, 21 Apr 2021 13:20:49 +0000 (15:20 +0200)] 
app-layer/pd: only consider actual available data

For size limit checks consider only available data at the stream start
and before any GAPS.

The old check would consider too much data if there were temporary gaps,
like when a data packet was in-window but (far) ahead of the expected
segment.

(cherry picked from commit 7a114e506a27fcb2a3b5ed28b1c10fe100cf78c6)

3 years agostreaming/buffer: account sbb data size
Victor Julien [Fri, 4 Jun 2021 13:31:33 +0000 (15:31 +0200)] 
streaming/buffer: account sbb data size

When tracking data track the size of the blocks so that in case
of gaps we can still know how much data we hold.

(cherry picked from commit be1baa8cab1bc51228d2d882b15880a36c377be4)

3 years agoipv6: simpler generic overlap condition
Philippe Antoine [Fri, 10 Sep 2021 12:16:57 +0000 (14:16 +0200)] 
ipv6: simpler generic overlap condition

This also changes the behavior, as the condition is checked in
every case cf ipv6-malformed-fragments-8

(cherry picked from commit 3a230c2208046d001b386979663a6c565691794b)

3 years agoflow: free spare pool more aggressively
Victor Julien [Mon, 4 Oct 2021 14:01:47 +0000 (16:01 +0200)] 
flow: free spare pool more aggressively

The flows exceeding the spare pools config setting would be freed
per at max 100 flows a second. After a high speed test this would
lead to excessive memory use for a long time.

This patch updates the logic to free 10% of the excess flows per
run, freeing multiple blocks of flows as needed.

Bug: #4731.
(cherry picked from commit fa72a5add8d9ebdcc4da5e05a8cd4259ede572d7)

3 years agothreading: force break loop on flow inject
Victor Julien [Mon, 4 Oct 2021 07:24:51 +0000 (09:24 +0200)] 
threading: force break loop on flow inject

Track availability of break loop callback to avoid overhead.

(cherry picked from commit ff97d7c15da0a8a7b8ea1a0d461f4f56ca2052d6)

3 years agoflow: process evicted flows on low/no traffic
Victor Julien [Fri, 1 Oct 2021 11:20:02 +0000 (13:20 +0200)] 
flow: process evicted flows on low/no traffic

In a scenario where there was suddenly no more traffic flowing, flows
in a threads `flow_queue` would not be processed. The easiest way to
see this would be in a traffic replay scenario. After the replay is done
no more packets come in and these evicted flows got stuck.

In workers mode, the capture part handles timeout this was updated to
take the `ThreadVars::flow_queue` into account.

The autofp mode the logic that puts a flow into a threads `flow_queue`
would already wake a thread up, but the `flow_queue` was then ignored.
This has been updated to take the `flow_queue` into account.

In both cases a "capture timeout" packet is pushed through the pipeline
to "flush" the queues.

Bug: #4722.
(cherry picked from commit b788d3345cd4e4c467672bb6bfb90d2b8620e068)

3 years agothreading: minor cleanups
Victor Julien [Sun, 3 Oct 2021 12:54:17 +0000 (14:54 +0200)] 
threading: minor cleanups

(cherry picked from commit 31977170a8a44290fd8f501ef1018b7696644040)

3 years agodetect: track prefilter by progress, not engine 6416/head
Victor Julien [Tue, 14 Sep 2021 08:35:18 +0000 (10:35 +0200)] 
detect: track prefilter by progress, not engine

Fix FNs in case of too many prefilter engines. A transaction was tracking
which engines have run using a u64 bit array. The engines 'local_id' was
used to set and check this bit. However the bit checking code didn't
handle int types correctly, leading to an incorrect left shift result of
a u32 to a u64 bit value.

This commit addresses that by fixing the int handling, but also by
changing how the engines are tracked.

To avoid wasting prefilter engine tracking bit space, track what
ran by the progress they are registered at, instead of the individual
engine id's. While we can have many engines, the protocols use far
fewer unique progress values. So instead of tracking for dozens of
prefilter id's, we track for the handful of progress values.

To allow for this the engine array is sorted by tx_min_progress, then
app_proto and finally local_id. A new field is added to "know" when
the last relevant engine for a progress value is reached, so that we
can set the prefilter bit then.

A consquence is that the progress values have a ceiling now that
needs to fit in a 64 bit bitarray. The values used by parsers currently
does not exceed 5, so that seems to be ok.

Bug: #4685.
(cherry picked from commit 932cf0b6a6ad1d34fffe8dd92c14b5bc32c9f6fe)

3 years agodetect: unify alert handling; fix bugs
Victor Julien [Fri, 3 Sep 2021 15:04:02 +0000 (17:04 +0200)] 
detect: unify alert handling; fix bugs

Unify handling of signature matches between various rule types and
between noalert and regular rules.

"noalert" sigs are added to the alert queue initially, but removed
from it after handling their actions. This way all actions are applied
from a single place.

Make sure flow drop and pass are mutually exclusive.

The above addresses issue with pass and drops not getting applied
correctly in various cases.

Bug: #4663
Bug: #4670

(cherry picked from commit aa93984b7e58d3d8c1323f86bdaff937f8b8bd1e)

3 years agodetect: remove dead code
Victor Julien [Fri, 10 Sep 2021 08:19:50 +0000 (10:19 +0200)] 
detect: remove dead code

(cherry picked from commit ae89874b066c91675b809e8cf992d780331efb1c)

3 years agodns: improve probing parser 6411/head
Philippe Antoine [Tue, 9 Mar 2021 20:00:36 +0000 (21:00 +0100)] 
dns: improve probing parser

Checks opcode is valid
Checks additional_rr do not exceed message length
Better logic for incomplete cases

(cherry picked from commit 9e7ea631b2a067609c500539cd3a7a139f39c3e4)

3 years agonfs: improve probing parser
Philippe Antoine [Tue, 16 Mar 2021 12:07:16 +0000 (13:07 +0100)] 
nfs: improve probing parser

Checks credentials flavor is known

(cherry picked from commit b3c1f2ab489c22494900476426fd5cad9ba08cd1)

3 years agoenip: improve probing parser
Philippe Antoine [Tue, 9 Mar 2021 14:54:16 +0000 (15:54 +0100)] 
enip: improve probing parser

Strict length for register sessions
NOP command must have options=0

(cherry picked from commit 0c948142b93a2de0ede0a65e6ddb650f2a2239bc)

3 years agoutil/lua-common: use lua_pushnumber for SCFileInfo
Juliana Fajardini [Thu, 16 Sep 2021 13:48:09 +0000 (14:48 +0100)] 
util/lua-common: use lua_pushnumber for SCFileInfo

(cherry picked from commit b3f447a0df0d389184febc06dc7445ddcae940e2)

3 years agoutil/lua-common: use pushinteger w/ byte & pkt cnt
Juliana Fajardini [Tue, 7 Sep 2021 09:37:19 +0000 (10:37 +0100)] 
util/lua-common: use pushinteger w/ byte & pkt cnt

LuaCallbackStatsPushToStackFromFlow tuple is composed of integer values
not all of them had been converted to lua_pushinteger yet.

(cherry picked from commit 8b53468d32e5b14817a41c6b0656cd3569a87749)

3 years agoutil/lua-common: update copyright year
Juliana Fajardini [Mon, 26 Jul 2021 14:35:40 +0000 (15:35 +0100)] 
util/lua-common: update copyright year

(cherry picked from commit 82cd125c62ac349c529582455eae19455fe2d50f)

3 years agoutil-lua-common: use lua_pushinteger w/ int values
Juliana Fajardini [Mon, 26 Jul 2021 12:24:02 +0000 (13:24 +0100)] 
util-lua-common: use lua_pushinteger w/ int values

replace lua_pushnumber with lua_pushinteger for SCFlowStats and
SCRuleIds.

(cherry picked from commit 9b6ce274877ca825dbcbda0a7e540660004b5390)

3 years agolua/output: fix typo
Juliana Fajardini [Thu, 22 Jul 2021 19:58:01 +0000 (20:58 +0100)] 
lua/output: fix typo

(cherry picked from commit 00d7a152eb730158be4840d224430bd0331e8ec6)

3 years agolua: use pushinteger for int in flow/packet tuples
Juliana Fajardini [Mon, 5 Jul 2021 11:18:41 +0000 (12:18 +0100)] 
lua: use pushinteger for int in flow/packet tuples

(cherry picked from commit 7592a9be433b9decba1c40928e6840d0a5071ace)

3 years agodoc/lua-functions: add sha items to SCFileInfo doc 6403/head
Juliana Fajardini [Tue, 14 Sep 2021 09:04:38 +0000 (10:04 +0100)] 
doc/lua-functions: add sha items to SCFileInfo doc

(cherry picked from commit 751906b71d95380e64779f569b08195d6f388a2e)

3 years agoutil/lua-common: fix SCFileInfo bug & doc comment
Juliana Fajardini [Tue, 14 Sep 2021 08:49:07 +0000 (09:49 +0100)] 
util/lua-common: fix SCFileInfo bug & doc comment

The callback for FileInfo was returning the wrong value, resulting
in loss of some tuple values for one calling SCFileInfo in a script.

The documentation comment wasn't mentioning the sha items that are
pushed.

(cherry picked from commit 1315cb793b884140b51e9934ebbdc7493be22db5)

3 years agohttp2: better file tracking 6392/head
Philippe Antoine [Thu, 2 Sep 2021 14:31:20 +0000 (16:31 +0200)] 
http2: better file tracking

If an HTTP2 file was within only ont DATA frame, the filetracker
would open it and close it in the same call, preventing the
firther call to incr_files_opened

Also includes rustfmt again for all HTTP2 files

(cherry picked from commit bb98a18b3d6d104d11a105aea3886d3daa5956cf)

3 years agoftp: support per-tx file accounting 6379/head
Victor Julien [Thu, 18 Mar 2021 12:47:26 +0000 (13:47 +0100)] 
ftp: support per-tx file accounting

(cherry picked from commit 04ba6dc1384410517a8450a47221e72d22fbc801)

3 years agosmb: add debug validation on file counts
Victor Julien [Thu, 18 Mar 2021 12:06:22 +0000 (13:06 +0100)] 
smb: add debug validation on file counts

(cherry picked from commit c9cee7af4985d569b34dc080be615b19eb5180a9)

3 years agosmb: count files in tx
Victor Julien [Thu, 18 Mar 2021 07:37:08 +0000 (08:37 +0100)] 
smb: count files in tx

(cherry picked from commit 114d3ba7307db7ab449bffae2c2dcb48e6b8f08d)

3 years agohttp2: support per-tx file accounting
Victor Julien [Thu, 18 Mar 2021 07:36:22 +0000 (08:36 +0100)] 
http2: support per-tx file accounting

(cherry picked from commit c1dfb619c4313f66322f89969e54c4ea01bbb9dc)

3 years agonfs: add debug validation on file counts
Victor Julien [Thu, 18 Mar 2021 12:06:34 +0000 (13:06 +0100)] 
nfs: add debug validation on file counts

(cherry picked from commit 1b3c3225cdc9d834d3a96aa239fb76b228859492)

3 years agonfs: support per-tx file accounting
Victor Julien [Thu, 18 Mar 2021 10:09:01 +0000 (11:09 +0100)] 
nfs: support per-tx file accounting

(cherry picked from commit 1d48601c258e944c1c3f9510b2707a6a2415a671)

3 years agonfs: don't reuse file transactions
Victor Julien [Thu, 18 Mar 2021 10:05:35 +0000 (11:05 +0100)] 
nfs: don't reuse file transactions

After a file has been closed (CLOSE, COMMIT command or EOF/SYNC part of
READ/WRITE data block) mark it as such so that new file commands on that
file do not reuse the transaction.

When a file transfer is completed it will be flagged as such and not be
found anymore by the NFSState::get_file_tx_by_handle() method. This forces
a new transaction to be created.

(cherry picked from commit 67759795c6405e449a80b282d290f84dc0fcd778)