]> git.ipfire.org Git - people/ms/suricata.git/log
people/ms/suricata.git
2 years agodhcp: use generic tx iterator
Jason Ish [Wed, 10 Nov 2021 18:03:53 +0000 (12:03 -0600)] 
dhcp: use generic tx iterator

2 years agohttp2: use generic tx iterator
Jason Ish [Wed, 10 Nov 2021 18:00:50 +0000 (12:00 -0600)] 
http2: use generic tx iterator

2 years agotemplate: use generic tx iterator
Jason Ish [Wed, 10 Nov 2021 17:58:19 +0000 (11:58 -0600)] 
template: use generic tx iterator

2 years agonfs: use generic tx iterator
Jason Ish [Wed, 10 Nov 2021 17:54:23 +0000 (11:54 -0600)] 
nfs: use generic tx iterator

2 years agorfb: use generic tx iterator
Jason Ish [Wed, 10 Nov 2021 17:24:14 +0000 (11:24 -0600)] 
rfb: use generic tx iterator

2 years agomqtt: use generic tx iterator
Jason Ish [Wed, 10 Nov 2021 17:20:13 +0000 (11:20 -0600)] 
mqtt: use generic tx iterator

2 years agomodbus: use generic tx iterator
Jason Ish [Mon, 25 Oct 2021 23:18:59 +0000 (17:18 -0600)] 
modbus: use generic tx iterator

2 years agosmb: use generic tx iterator
Jason Ish [Mon, 25 Oct 2021 23:01:20 +0000 (17:01 -0600)] 
smb: use generic tx iterator

2 years agorust/app-layer: provide generic implementation of iterator
Jason Ish [Thu, 14 Oct 2021 18:37:03 +0000 (12:37 -0600)] 
rust/app-layer: provide generic implementation of iterator

Create traits for app-layer State and Transaction that allow
a generic implementation of a transaction iterator that parser
can use when the follow the common pattern for iterating
transactions.

Also convert DNS to use the generic for testing purposes.

2 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.

2 years agodetect: file_data keyword works on nfs protocol
Philippe Antoine [Fri, 19 Nov 2021 11:33:06 +0000 (12:33 +0100)] 
detect: file_data keyword works on nfs protocol

Ticket: #4839

2 years agohttp2: remove needless borrows
Shivani Bhardwaj [Wed, 8 Sep 2021 01:44:25 +0000 (07:14 +0530)] 
http2: remove needless borrows

2 years agocore: Remove unneeded consts
Shivani Bhardwaj [Thu, 12 Aug 2021 16:43:31 +0000 (22:13 +0530)] 
core: Remove unneeded consts

2 years agossh: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 16:41:38 +0000 (22:11 +0530)] 
ssh: use Direction enum

2 years agosnmp: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 16:36:09 +0000 (22:06 +0530)] 
snmp: use Direction enum

2 years agosmb: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 16:29:53 +0000 (21:59 +0530)] 
smb: use Direction enum

2 years agosip: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 13:22:13 +0000 (18:52 +0530)] 
sip: use Direction enum

2 years agonfs: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 13:11:12 +0000 (18:41 +0530)] 
nfs: use Direction enum

2 years agomqtt: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 12:41:42 +0000 (18:11 +0530)] 
mqtt: use Direction enum

2 years agokrb: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 12:39:15 +0000 (18:09 +0530)] 
krb: use Direction enum

2 years agoike: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 12:30:53 +0000 (18:00 +0530)] 
ike: use Direction enum

2 years agohttp2: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 11:57:53 +0000 (17:27 +0530)] 
http2: use Direction enum

2 years agofiles: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 12:21:07 +0000 (17:51 +0530)] 
files: use Direction enum

2 years agodns: use Direction enum
Shivani Bhardwaj [Thu, 12 Aug 2021 09:54:51 +0000 (15:24 +0530)] 
dns: use Direction enum

2 years agodcerpc: use Direction enum
Shivani Bhardwaj [Wed, 11 Aug 2021 11:29:48 +0000 (16:59 +0530)] 
dcerpc: use Direction enum

2 years agocore: add Direction enum
Shivani Bhardwaj [Fri, 11 Sep 2020 18:48:21 +0000 (00:18 +0530)] 
core: add Direction enum

Ticket: 3832

2 years agodoc: Fix typo in documentation of rule keyword flow
Andreas Dolp [Thu, 28 Oct 2021 04:56:27 +0000 (06:56 +0200)] 
doc: Fix typo in documentation of rule keyword flow

2 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.

2 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.

2 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.

2 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.

2 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.

2 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

2 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.

2 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.

2 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.

2 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

2 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.

2 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.

2 years agoaf-packet: simplify tpacket-v2 setup code
Victor Julien [Fri, 5 Nov 2021 10:31:58 +0000 (11:31 +0100)] 
af-packet: simplify tpacket-v2 setup code

Setup can no longer fail, so make the function void and remove dead
error checking code.

2 years agoaf-packet: PacketSetData can't fail; remove check
Victor Julien [Thu, 4 Nov 2021 06:52:59 +0000 (07:52 +0100)] 
af-packet: PacketSetData can't fail; remove check

PacketSetData() can't fail unless the input pointer is NULL, which is
impossible from the af-packet paths calling it. Remove error check to
avoid possible branching.

2 years agoaf-packet: fix if/down issues with tpacket-v2/autofp
Victor Julien [Wed, 3 Nov 2021 20:32:46 +0000 (21:32 +0100)] 
af-packet: fix if/down issues with tpacket-v2/autofp

The AFPSwitchState function would close the socket and free the
other resources when the interface went down _and_ the ref cnt was
0. However in autofp mode it was common to get to this point while
packets were still processed in the autofp worker threads, meaning
the ref cnt would not be 0. On the interface coming back up the
initialization code would overwrite the socket and rings, leading
to resource leaks.

Socket ref cnt is decremented from the v2 release callback. If the
callback would get to ref cnt 0, the packet would not be released
in the kernel, but it would (possibly) close the socket if the
iface was down, but not free other resources.

This patch changes the logic to first release the packet to the
kernel and then decrement the ref cnt and it makes the main receive
loop the only one responsible for opening and closing sockets. Wait
with closing the socket and rings until the ref count is 0, which can
happen after AFPSwitchState is called due to packets still being
processed by autofp worker threads.

Bug: #4803.

2 years agoaf-packet: packet checks into debug validate check
Victor Julien [Wed, 3 Nov 2021 14:02:12 +0000 (15:02 +0100)] 
af-packet: packet checks into debug validate check

2 years agoaf-packet: hide all ebpf/bypass logic behind guards
Victor Julien [Sun, 31 Oct 2021 20:47:21 +0000 (21:47 +0100)] 
af-packet: hide all ebpf/bypass logic behind guards

Leave no runtime checks for bypass/ebpf/xdp if not compiled in.

2 years agoaf-packet: minor code cleanups
Victor Julien [Sun, 31 Oct 2021 20:34:31 +0000 (21:34 +0100)] 
af-packet: minor code cleanups

2 years agoaf-packet: simplify socket handling in tpacket v3
Victor Julien [Wed, 3 Nov 2021 20:09:46 +0000 (21:09 +0100)] 
af-packet: simplify socket handling in tpacket v3

Tpacket v3 only supports workers mode, which means the packet that would
reference a socket won't leave the thread. Therefore keeping a ref count
on the socket is not needed.

This patch removes the per packet reference count increment. The decrement
was missing, so this fixes the ref cnt handling so that after a iface up/
down capture can recover.

It should also lead to a minor performance increase as we avoid a round
of atomic operations per packet.

Bug: #4804.
Bug: #4801.

2 years agoaf-packet: minor config parsing cleanup
Victor Julien [Fri, 5 Nov 2021 14:39:17 +0000 (15:39 +0100)] 
af-packet: minor config parsing cleanup

2 years agoaf-packet: remove obsolete define
Victor Julien [Sun, 31 Oct 2021 20:17:41 +0000 (21:17 +0100)] 
af-packet: remove obsolete define

2 years agoaf-packet: remove zero copy flag
Victor Julien [Sun, 31 Oct 2021 21:36:29 +0000 (22:36 +0100)] 
af-packet: remove zero copy flag

Flag was always set for tpacket v2 and v3, which meant the check
for it in the packet setup paths were useless.

2 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.

2 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.

2 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

2 years agodetect-rfb-secresult: convert unittest to FAIL/PASS APIs
Modupe Falodun [Tue, 2 Nov 2021 21:18:51 +0000 (22:18 +0100)] 
detect-rfb-secresult: convert unittest to FAIL/PASS APIs

Bug: #4055

2 years agodetect-sameip: convert unittests to FAIL/PASS APIs
Modupe Falodun [Mon, 1 Nov 2021 20:19:47 +0000 (21:19 +0100)] 
detect-sameip: convert unittests to FAIL/PASS APIs

Bug: #4057

2 years agodetect/event: convert unittests to FAIL/PASS APIs
Sam Muhammed [Mon, 1 Nov 2021 12:18:55 +0000 (14:18 +0200)] 
detect/event: convert unittests to FAIL/PASS APIs

Task #4025

2 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.

2 years agodetect/payload: convert unittests to FAIL/PASS APIs
Sam Muhammed [Wed, 3 Nov 2021 13:10:52 +0000 (15:10 +0200)] 
detect/payload: convert unittests to FAIL/PASS APIs

Task #4026

2 years agodetect-gid: convert unittests to FAIL/PASS APIs
Modupe Falodun [Thu, 4 Nov 2021 20:35:06 +0000 (21:35 +0100)] 
detect-gid: convert unittests to FAIL/PASS APIs

Bug: #4041

2 years agoutil/unittests: delete PASS_IF macro
Juliana Fajardini [Tue, 2 Nov 2021 18:22:51 +0000 (18:22 +0000)] 
util/unittests: delete PASS_IF macro

The logic flow we want to achieve with unittests, where first we have
all FAIL statements and then just one PASS statement could become more
convoluted with the existence of the PASS_IF macro. Besides, what could
be written as a FAIL_IF might in some cases be written in not so clear
ways with the PASS_IF option available.

Also: fix inverted check values in documentation, update copyright year

Optimization: #4795

2 years agodetect/dsize: convert unittests to FAIL/PASS API
Juliana Fajardini [Tue, 2 Nov 2021 18:27:42 +0000 (18:27 +0000)] 
detect/dsize: convert unittests to FAIL/PASS API

Also: change them to comply with the deletion of PASS_IF macro &
condense checks for invalid dsizes in one test, have all checks on same
valid dsize happen in a single test.

Task: #4021

2 years agounittests (assorted): remove PASS_IF macro
Juliana Fajardini [Thu, 28 Oct 2021 19:39:45 +0000 (20:39 +0100)] 
unittests (assorted): remove PASS_IF macro

Also small documentation clean up and test adjusments where that
was needed.

affected: counters, decode-vntag, detect-mark

Related to #4795

2 years agodevguide: add page about rust unittests
Juliana Fajardini [Wed, 3 Nov 2021 11:20:36 +0000 (11:20 +0000)] 
devguide: add page about rust unittests

Part of the task to offer better guidance on how and when to write
unit tests or suricata-verify tests
Also updated linking and index files, as well as testing page to refer
to the unit tests pages

Doc: #4590

2 years agodevguide: repurpose unittests page to unittests-c
Juliana Fajardini [Wed, 3 Nov 2021 10:59:20 +0000 (10:59 +0000)] 
devguide: repurpose unittests page to unittests-c

Part of ongoing task to add more guidance on how to create unittests
and suricata-verify tests for suri. There will also be a unittests-rust
page.

Doc: #4590

2 years agodevguide: add page about testing
Juliana Fajardini [Wed, 29 Sep 2021 13:40:14 +0000 (14:40 +0100)] 
devguide: add page about testing

This page offers guidance about when to use unittests or s-v tests,
and how to create input for those. Also lists other common ways to test
Suri, such as fuzzing and the CI checks.

Doc: #4590

2 years agorust/tftp: convert parser to nom7 functions
Pierre Chifflier [Mon, 1 Nov 2021 13:34:34 +0000 (14:34 +0100)] 
rust/tftp: convert parser to nom7 functions

2 years agorust/dns: convert parser to nom7 functions
Pierre Chifflier [Sat, 30 Oct 2021 14:38:51 +0000 (16:38 +0200)] 
rust/dns: convert parser to nom7 functions

2 years agorust/ssh: convert parser to nom7 functions
Pierre Chifflier [Sat, 30 Oct 2021 14:32:38 +0000 (16:32 +0200)] 
rust/ssh: convert parser to nom7 functions

2 years agorust/mqtt: convert parser to nom7 functions
Pierre Chifflier [Sat, 30 Oct 2021 14:30:04 +0000 (16:30 +0200)] 
rust/mqtt: convert parser to nom7 functions

2 years agorust/sip: convert parser to nom7 functions
Pierre Chifflier [Thu, 2 Sep 2021 08:00:09 +0000 (10:00 +0200)] 
rust/sip: convert parser to nom7 functions

2 years agorust/ftp: convert parser to nom7 functions
Pierre Chifflier [Wed, 1 Sep 2021 15:49:27 +0000 (17:49 +0200)] 
rust/ftp: convert parser to nom7 functions

2 years agorust/dhcp: convert parser to nom7 functions
Pierre Chifflier [Wed, 1 Sep 2021 15:09:42 +0000 (17:09 +0200)] 
rust/dhcp: convert parser to nom7 functions

2 years agorust: add nom7 dependency
Pierre Chifflier [Wed, 1 Sep 2021 14:38:51 +0000 (16:38 +0200)] 
rust: add nom7 dependency

2 years agorust: remove unnecessary nested match
Modupe Falodun [Sun, 31 Oct 2021 16:59:53 +0000 (17:59 +0100)] 
rust: remove unnecessary nested match

Bug: #4605

2 years agorust: fix inherent to string
Modupe Falodun [Sun, 31 Oct 2021 16:31:52 +0000 (17:31 +0100)] 
rust: fix inherent to string

Bug: OISF#4618

2 years agorust(lint): use is_null() instead of ptr::null_mut()
Sam Muhammed [Tue, 19 Oct 2021 02:02:42 +0000 (04:02 +0200)] 
rust(lint): use is_null() instead of ptr::null_mut()

Bug: #4594

2 years agorust(lint): use is_null() instead of ptr::null()
Sam Muhammed [Sun, 17 Oct 2021 23:26:41 +0000 (01:26 +0200)] 
rust(lint): use is_null() instead of ptr::null()

Bug: #4594

2 years agorust(lint): use let for binding single value
Sam Muhammed [Sun, 24 Oct 2021 03:36:11 +0000 (05:36 +0200)] 
rust(lint): use let for binding single value

`match` is better used with binding to multiple variables,
for binding to a single value, `let` statement is recommended.

Bug: #4616

2 years agodetect-engine: convert unittests to FAIL/PASS APIs
Sam Muhammed [Thu, 28 Oct 2021 02:42:38 +0000 (04:42 +0200)] 
detect-engine: convert unittests to FAIL/PASS APIs

2 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.

2 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.

2 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.

2 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.

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

2 years agoflow/bypass: use_cnt desync'd on bypassed flows
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.

2 years agopcrexform: use substring and not whole match
Philippe Antoine [Thu, 21 Oct 2021 13:28:17 +0000 (15:28 +0200)] 
pcrexform: use substring and not whole match

2 years agotftp: StringToAppProto case
Philippe Antoine [Wed, 20 Oct 2021 08:56:44 +0000 (10:56 +0200)] 
tftp: StringToAppProto case

So, fuzz_applayerparserparse_tftp will fuzz tftp

2 years agorange: checks that end is after start for HTTP2
Philippe Antoine [Tue, 19 Oct 2021 10:38:49 +0000 (12:38 +0200)] 
range: checks that end is after start for HTTP2

As was done only for HTTP1 in previous commit

The verification part stays separated from the parsing part,
as we want to keep on logging invalid ranges values.

2 years agoqueue.h: suppress scan-build warnings
Jason Ish [Tue, 12 Oct 2021 14:41:42 +0000 (08:41 -0600)] 
queue.h: suppress scan-build warnings

If running under scan-build, use our own implementations of all
the macros which include some code to satisfy scan-build
warnings.

2 years agorange: move back files ownership in one case
Philippe Antoine [Thu, 14 Oct 2021 19:31:13 +0000 (21:31 +0200)] 
range: move back files ownership in one case

In the case, we receive a range request with expected
overlap then new bytes, but the response does not get to the
new bytes, we are still skipping, but the HttpRangeContainerBlock
had the ownership of the files, and need to give it back

2 years agorange: checks that end is after start
Philippe Antoine [Wed, 13 Oct 2021 19:07:27 +0000 (21:07 +0200)] 
range: checks that end is after start

Otherwise, we end up allocating too much memory

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

As does wireshark

2 years agoike: do not keep server transforms in state
Philippe Antoine [Mon, 21 Jun 2021 08:50:12 +0000 (10:50 +0200)] 
ike: do not keep server transforms in state

Fixes #4534

Now, only the tx with the transforms will match
with ike.chosen_sa_attribute

2 years agomodbus: tx iterator
Philippe Antoine [Thu, 7 Oct 2021 12:31:29 +0000 (14:31 +0200)] 
modbus: tx iterator

When there are a lot of open transactions, as is possible with
modbus, the default tx_iterator will loop for the whole
transacations vector to find each transaction, that means
quadratic complexity.

Reusing the tx_iterator from the template, and keeping as a state
the last index where to start looking avoids this quadratic
complexity.

2 years agoutil: avoid calling snprintf in PrintStringsToBuffer
Philippe Antoine [Thu, 7 Oct 2021 12:30:56 +0000 (14:30 +0200)] 
util: avoid calling snprintf in PrintStringsToBuffer

As we print only one character

2 years agohttp2: enable by default, even if not in config
Philippe Antoine [Sun, 10 Oct 2021 20:17:48 +0000 (22:17 +0200)] 
http2: enable by default, even if not in config

2 years agohttp2: enable by default
Philippe Antoine [Thu, 30 Sep 2021 13:32:42 +0000 (15:32 +0200)] 
http2: enable by default

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

2 years agoapp-layer: disable by default if not in configuration
Philippe Antoine [Wed, 6 Oct 2021 18:57:09 +0000 (20:57 +0200)] 
app-layer: disable by default if not in configuration

DNP3, ENIP, HTTP2 and Modbus are supposed to be disabled
by default. That means the default configuration does it,
but that also means that, if they are not in suricata.yaml,
the protocol should stay disabled.

2 years agoqueue.h: wrap the system sys/queue.h
Jason Ish [Wed, 6 Oct 2021 16:53:46 +0000 (10:53 -0600)] 
queue.h: wrap the system sys/queue.h

Instead of using local implementations for the queue.h macro,
wrap the system provided queue.h and then adding missing
features as needed.

The idea is that Suricata when integrated with another library
that includes sys/queue.h can look at the same source of truth
for these macros.

But not all operating systems include a queue.h with the same
features, and some don't include it at all, like Windows. So
on Windows this will be a full implementation of all the queue.h
features Suricata needs.

2 years agoalert: fixes leak in ThresholdHandlePacketRule
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