]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
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)

3 years agohttp: support per-tx file accounting
Victor Julien [Thu, 18 Mar 2021 09:57:48 +0000 (10:57 +0100)] 
http: support per-tx file accounting

(cherry picked from commit d74c18ee28fbda3a5b6d2ddb157cae90b70da0bf)

3 years agofilestore: store chunks in packet direction
Victor Julien [Thu, 18 Mar 2021 13:38:33 +0000 (14:38 +0100)] 
filestore: store chunks in packet direction

Storing too early can lead to files being considered TRUNCATED if the
TCP state is not yet CLOSED when logging is triggered. This has been
observed with FTP-DATA and might also be an issue with simple HTTP.

(cherry picked from commit ca124b033ef408501897e0517eaf79d2196c68d9)

3 years agofilestore: track files getting stored per tx
Victor Julien [Tue, 23 Mar 2021 10:08:33 +0000 (11:08 +0100)] 
filestore: track files getting stored per tx

Avoid evicting a tx before the filedata logger has decided it is
done.

(cherry picked from commit 56d3e28a3a122178270e81b73783e0f126486232)

3 years agoapp-layer/transactions: track files opens and logs
Victor Julien [Thu, 18 Mar 2021 09:55:50 +0000 (10:55 +0100)] 
app-layer/transactions: track files opens and logs

To make sure a transaction is not evicted before all file logging is complete.

(cherry picked from commit c78f5ac3169e8b4539c49fde9d9aa8fa8465f40e)

3 years agoeve/files: log in packet direction only
Victor Julien [Thu, 18 Mar 2021 09:52:44 +0000 (10:52 +0100)] 
eve/files: log in packet direction only

Bug: #3703.

Don't log files too soon.

(cherry picked from commit 45dc4cdeece538c6f383b6658deca7dc1e825181)

3 years agorules: add newer rule files to makefile for release tarball 6363/head
Andreas Herz [Tue, 6 Apr 2021 15:29:03 +0000 (17:29 +0200)] 
rules: add newer rule files to makefile for release tarball

(cherry picked from commit c93073c246cfabb091270dba8eb55b0c6e17d67a)

3 years agostream: update memcaps in code to match config
Victor Julien [Thu, 1 Jul 2021 14:31:35 +0000 (16:31 +0200)] 
stream: update memcaps in code to match config

(cherry picked from commit b08a7b9a66d04f21241e8d1b75e0c6ff9ae69d8c)

3 years agohttp2: support deflate decompression 6348/head
Philippe Antoine [Mon, 5 Jul 2021 09:18:26 +0000 (11:18 +0200)] 
http2: support deflate decompression

cf #4556

(cherry picked from commit 1378b2f45144676d98f3430728dcca3e09540921)

3 years agohttp2: set Debug on structs
Victor Julien [Thu, 10 Jun 2021 19:03:31 +0000 (21:03 +0200)] 
http2: set Debug on structs

(cherry picked from commit 20e8f90981a1a0dca448b00c897c1c583513c25f)

3 years agohttp2: document HTTP1 keywords enabling 6344/head
Philippe Antoine [Mon, 5 Jul 2021 07:40:23 +0000 (09:40 +0200)] 
http2: document HTTP1 keywords enabling

For HTTP signatures to match on HTTP2 traffic if configure
option app-layer.protocols.http2.http1-rules is enabled

3 years agoipv6: decoder event on invalid length
Philippe Antoine [Mon, 19 Jul 2021 15:31:32 +0000 (17:31 +0200)] 
ipv6: decoder event on invalid length

From RFC 2460, section 4.5,
each fragment, except the last one, must have a length
which is a multiple of 8

(cherry picked from commit ca760e305cd74933b685b1bd5be795b24a7d94a7)

3 years agorust: bump bitflags dependency version
Philippe Antoine [Sun, 28 Mar 2021 15:53:50 +0000 (17:53 +0200)] 
rust: bump bitflags dependency version

So that lexical-core, needed by nom, and using bitflags
is used with version 0.7.5 instead of version 0.7.0
which fixed the fact that BITS is now a reserved keyword
in nightly version

(cherry picked from commit 0105d4f017127f9696646e7d0176caec47a7c169)

3 years agoci: dummy git configuration for rebase
Philippe Antoine [Fri, 27 Aug 2021 15:36:50 +0000 (17:36 +0200)] 
ci: dummy git configuration for rebase

(cherry picked from commit 7fa3e8df615215a1628fc1e37f4913d93ced3a92)

3 years agoci: rebase specified s-v pr
Philippe Antoine [Mon, 5 Jul 2021 14:37:03 +0000 (16:37 +0200)] 
ci: rebase specified s-v pr

So that CI does not fail, if suricata PR got upgraded in a new
version, but S-V PR did not get upgraded, and S-V changed
in master

(cherry picked from commit 3e81d20a71deb2a061d3f86430b88b8bdd4b7d6d)

3 years agogithub-ci: enable hiredis on fedora 33 build
Jason Ish [Tue, 4 May 2021 21:47:53 +0000 (15:47 -0600)] 
github-ci: enable hiredis on fedora 33 build

(cherry picked from commit def636383ec2f917e3bdb20ee6619de226afca52)

3 years agoci: update known rust version
Simon Dugas [Mon, 1 Feb 2021 01:58:26 +0000 (20:58 -0500)] 
ci: update known rust version

Update RUST_VERSION_KNOWN to the latest stable known to succeed. Also
updates the documentation to avoid confusion around the use of this
variable.

(cherry picked from commit f629321de06043214e69a56d8259a1e781535293)

3 years agotravis: remove ci file as we switched to github-ci
Victor Julien [Tue, 4 May 2021 08:40:09 +0000 (10:40 +0200)] 
travis: remove ci file as we switched to github-ci

(cherry picked from commit 28548b072b8ebd3e40ec8e0c6b96ebb794522a96)

3 years agothreading: don't pass locked flow between threads
Victor Julien [Wed, 18 Aug 2021 18:14:48 +0000 (20:14 +0200)] 
threading: don't pass locked flow between threads

Previously the flow manager would share evicted flows with the workers
while keeping the flows mutex locked. This reduced the number of unlock/
lock cycles while there was guaranteed to be no contention.

This turns out to be undefined behavior. A lock is supposed to be locked
and unlocked from the same thread. It appears that FreeBSD is stricter on
this than Linux.

This patch addresses the issue by unlocking before handing a flow off
to another thread, and locking again from the new thread.

Issue was reported and largely analyzed by Bill Meeks.

Bug: #4478
(cherry picked from commit 9551cd05357925e8bec8e0030d5f98fd07f17839)

3 years agocounters: only print alerts if stats are enabled
Shivani Bhardwaj [Mon, 21 Jun 2021 18:35:06 +0000 (00:05 +0530)] 
counters: only print alerts if stats are enabled

(cherry picked from commit a17da8374a905ad31a4fa66f85ee1cc73b857389)

3 years agomacset: adjust test to pass after fix
Victor Julien [Mon, 30 Aug 2021 19:56:24 +0000 (21:56 +0200)] 
macset: adjust test to pass after fix

(cherry picked from commit cd40fcdea710349bb998fbc4323c94394bf69c98)

3 years agomacset: fix memory size check
Eric Leblond [Fri, 20 Aug 2021 12:41:20 +0000 (14:41 +0200)] 
macset: fix memory size check

(cherry picked from commit 328bdf2c61a2b04ce1b3cde3063a07f170134717)

3 years agoflow: be sure to check hash till the end
Eric Leblond [Fri, 20 Aug 2021 08:42:13 +0000 (10:42 +0200)] 
flow: be sure to check hash till the end

(cherry picked from commit d7468c55ca4a8375ca6ca12396a4c61af6465041)

3 years agoflow: add comment on flow handling
Eric Leblond [Thu, 19 Aug 2021 14:30:50 +0000 (16:30 +0200)] 
flow: add comment on flow handling

(cherry picked from commit e531530a67789f895360200fa9d5874d3dcd7511)

3 years agostream: increase memcap on memory errors
Eric Leblond [Thu, 19 Aug 2021 09:22:06 +0000 (11:22 +0200)] 
stream: increase memcap on memory errors

(cherry picked from commit c1bffa9545b8aa9d0fc64ac6511edd34919135d7)

3 years agoflow: fix a debug assert
Eric Leblond [Sun, 15 Aug 2021 10:17:23 +0000 (12:17 +0200)] 
flow: fix a debug assert

As the FlowBypassedTimeout function is interacting with the capture
method it is possible that the return changes between the call that
did trigger the timeout and the actual state (ie if packets arrive
in between the two calls). So we should not use the call to
FlowBypassedTimeout in the assert.

(cherry picked from commit cce7e4f4cb28485f2e43630b4baf7a77449af707)

3 years agoflow: more accurate flow counters
Eric Leblond [Sat, 14 Aug 2021 21:05:03 +0000 (23:05 +0200)] 
flow: more accurate flow counters

Don't increment the flow timeout counter for flows that are not
really timeout (as use_cnt is non zero). And also don't take into
account bypassed flows in the counter for flow timeout in use.

(cherry picked from commit 9a4ef6b8fc290a83ad0d17c036d8a93b5c02689c)

3 years agoflow/worker: handle timeout edge case
Victor Julien [Mon, 30 Aug 2021 08:53:49 +0000 (10:53 +0200)] 
flow/worker: handle timeout edge case

In the flow worker timeout path it is assumed that we can hand off
flows to the recycler after processing, implying that `Flow::use_cnt` is 0.
However, there was a case where this assumption was incorrect.

When during flow timeout handling the last processed data would trigger a
protocol upgrade, two additional pseudo packets would be created that were
then pushed all the way through the engine packet paths. This would mean
they both took a flow reference and would hold that until after the flow
was handed off to the recycler. Thread safety implementation would make
sure this didn't lead to crashes.

This patch handles this case returning these packets to the pool from
the timeout handling.

(cherry picked from commit c51042e0934fd328010d41d9405fd643855aba89)

3 years agoflow/worker: set proper end flag
Victor Julien [Fri, 30 Jul 2021 19:15:28 +0000 (21:15 +0200)] 
flow/worker: set proper end flag

(cherry picked from commit c5556b5dd9b9430bddd7a79917db6bc14642b090)

3 years agoflow/manager: set proper end flag
Victor Julien [Fri, 30 Jul 2021 18:12:05 +0000 (20:12 +0200)] 
flow/manager: set proper end flag

(cherry picked from commit 61f6fe037df2b1cabd1a763f099ca62714c6c3da)

3 years agodetect/analyzer: suggest modern keywords
Victor Julien [Fri, 5 Feb 2021 21:01:26 +0000 (22:01 +0100)] 
detect/analyzer: suggest modern keywords

(cherry picked from commit b55b327db1590ae7e8ccb1a9ada9ddaa29a900bb)

3 years agodetect/analyzer: fix json output for warnings/notes
Victor Julien [Fri, 5 Feb 2021 20:33:35 +0000 (21:33 +0100)] 
detect/analyzer: fix json output for warnings/notes

(cherry picked from commit 57f7612ffd6de650943607f2fb168015e45a39e1)

4 years agorelease: 6.0.3; update changelog; require htp 0.5.38 suricata-6.0.3
Jason Ish [Wed, 30 Jun 2021 14:44:39 +0000 (08:44 -0600)] 
release: 6.0.3; update changelog; require htp 0.5.38

4 years agorust/ike: suppress some compile warnings when not debug
Jason Ish [Wed, 30 Jun 2021 16:03:35 +0000 (10:03 -0600)] 
rust/ike: suppress some compile warnings when not debug

Due to ef5755338fa6404b60e7f90bfbaca039b2bfda1e, the variables
that are only used for debug output now emit unused variable
warnings when Suricata is not built with debug. Prefix these
variables with _ to suppress these warnings.

4 years agoikev2: remove transforms fields
Shivani Bhardwaj [Fri, 25 Jun 2021 10:29:31 +0000 (15:59 +0530)] 
ikev2: remove transforms fields

4 years agoswf: right input length for decompression
Philippe Antoine [Thu, 29 Apr 2021 09:57:15 +0000 (11:57 +0200)] 
swf: right input length for decompression

(cherry picked from commit 4d2f9cc8a0409bb03f5d285bb83d64afec08ba2a)

4 years agodetect: set event if max inspect buffers exceeded
Victor Julien [Thu, 13 May 2021 06:06:11 +0000 (08:06 +0200)] 
detect: set event if max inspect buffers exceeded

If a parser exceeds 1024 buffers we stop processing them and
set a detect event instead. This is to avoid parser bugs as well as
crafted bad traffic leading to resources starvation due to excessive
loops.

(cherry picked from commit e611adf3dc5b531a9d0ef9b861b4dbe0e150eae6)

4 years agodetect: fix multi inspect buffer issue; clean up
Victor Julien [Thu, 13 May 2021 05:50:12 +0000 (07:50 +0200)] 
detect: fix multi inspect buffer issue; clean up

Fix multi inspect buffer API causing cleanup logic in the single
inspect buffer paths. This could lead to a buffer overrun in the
"to clear" logic.

Multi buffers now use InspectionBufferSetupMulti instead of
InspectionBuffer. This is enforced by a check in debug validation.

Simplify the multi inspect buffer setup code and update the callers.

(cherry picked from commit 3dc50322db0efb92683b9578c7dccd1fae4b5cb2)

4 years agorust: SCLogDebug is real nop when built as release
Philippe Antoine [Thu, 6 May 2021 11:30:49 +0000 (13:30 +0200)] 
rust: SCLogDebug is real nop when built as release

Before, even if there were no outputs, all the arguments
were evaluated, which could turn expensive

All variables which are used only in certain build configurations
are now prefixed by underscore to avoid warnings

(cherry picked from commit ef5755338fa6404b60e7f90bfbaca039b2bfda1e)

4 years agomqtt: move sub/unsub limits into app-layer config
Victor Julien [Mon, 21 Jun 2021 19:10:55 +0000 (21:10 +0200)] 
mqtt: move sub/unsub limits into app-layer config

(cherry picked from commit 3c1cc1e345bc9f78988411efa8461351d24efe98)

4 years agodetect/mqtt: add topic inspection limit
Sascha Steinbiss [Mon, 10 May 2021 12:54:47 +0000 (14:54 +0200)] 
detect/mqtt: add topic inspection limit

We add a new 'mqtt.(un)subscribe-topic-match-limit' option
to allow a user to specify the maximum number of topics in
a MQTT SUBSCRIBE or UNSUBSCRIBE message to be evaluated
in detection.

(cherry picked from commit 4c0ef73bf21f5b07c5c34fd2dc5f6d9c166bc6da)

4 years agodetect: use u32 for InspectionBufferMultipleForList
Philippe Antoine [Thu, 6 May 2021 07:25:49 +0000 (09:25 +0200)] 
detect: use u32 for InspectionBufferMultipleForList

So that we do not have an endless loop casting index to
u16 and having more than 65536 buffers in one transaction

Changes for all protocols, even ones where it is impossible
to have such a pattern, so as to avoid bad pattern copy/paste
in the future

(cherry picked from commit 7d0a39412bb451443a4e19e6571ab86a0583214c)

4 years agodcerpc: handles bigger inputs than 2^16
Philippe Antoine [Mon, 12 Apr 2021 14:56:33 +0000 (16:56 +0200)] 
dcerpc: handles bigger inputs than 2^16

By comparing integers with the largest size

(cherry picked from commit 6f03ee2e47d331aa29524d81777c970415b817f1)