]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
3 years agoloopback: decodes IPv6 from all OSes 6610/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 agoaf-packet: avoid flag colision with kernel 6604/head
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 agosources: fix pipeline failure handling
Victor Julien [Mon, 11 Nov 2019 14:26:32 +0000 (15:26 +0100)] 
sources: fix pipeline failure handling

When TmThreadsSlotProcessPkt fails it will return the packet that was
passed to it to the packetpool.

Some of the packet sources were doing this manually as well. This patch
fixes those sources.

(cherry picked from commit 7c83cb585e634fab7f94a5b4ebddbc54365325d9)

3 years agocapture: optimize checksum handling
Victor Julien [Fri, 29 May 2020 11:04:47 +0000 (13:04 +0200)] 
capture: optimize checksum handling

Don't use a flag in the livedev, but overwrite the config setting after
'auto' mode has determined checksums should be disabled.

(cherry picked from commit 3957750731e6699fcb1f2a4c777f7892f0556ab4)

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 agoaf-packet: fix warnings by undefined sanitizer
Victor Julien [Fri, 29 May 2020 12:27:24 +0000 (14:27 +0200)] 
af-packet: fix warnings by undefined sanitizer

(cherry picked from commit d8c82d4f39e6696a4bf63efaf76544722ad1bd97)

3 years agoflow/manager: fix emergency timed wait handling
Victor Julien [Fri, 12 Nov 2021 06:46:47 +0000 (07:46 +0100)] 
flow/manager: fix emergency timed wait handling

In emergency mode the time set to wait could be in the past.

Bug: #4816.

3 years agotime: add timeradd implementation
Victor Julien [Wed, 10 Nov 2021 14:40:26 +0000 (15:40 +0100)] 
time: add timeradd implementation

timeradd isn't available on MinGW.

3 years agotime: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.
Todd Mortimer [Mon, 30 Mar 2020 23:38:24 +0000 (23:38 +0000)] 
time: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.

Make it easy to compare 'struct timeval's and get their difference.

(cherry picked from commit 9fafc1031c0c9c11e5d98a286535b6b18af7cd3d)

3 years agostyle: remove latest warnings 6530/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 agodatasets: better err msg if type not defined
Shivani Bhardwaj [Fri, 8 Oct 2021 06:00:44 +0000 (11:30 +0530)] 
datasets: better err msg if type not defined

3 years agogithub-ci: pin macos build to 10.15 6452/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 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 agodetect: suppress error message for pcre only rules
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 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 agodetect: fix FNs in case of too many prefilter engines 6415/head
Victor Julien [Tue, 28 Sep 2021 10:28:54 +0000 (12:28 +0200)] 
detect: fix FNs in case of too many prefilter engines

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.

This is only a partial fix however. It's not hard to craft a ruleset that
exceeds the 63-bit space available. A more complete fix is in:

932cf0b6a6ad ("detect: track prefilter by progress, not engine")

However this seems like a too high risk change for a backport into
5.0.

This patch does issue a warning if the condition is detected at start
up, and `-T` does error out on it.

Bug: #4688.

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 agoutil/lua-common: use lua_pushnumber for SCFileInfo 6412/head
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
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 agodetect: fix multi-inspect buffer issue
Jeff Lucovsky [Sat, 18 Sep 2021 14:17:28 +0000 (10:17 -0400)] 
detect: fix multi-inspect buffer issue

Fix multi-inspect buffer issue caused by setting up for multi but not
using it for inspection.

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 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 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 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 agodnp3: regenerate object decoding code
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 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 agothreading: respect SC_MAX_CPUS envvar 6373/head
Victor Julien [Sat, 11 Sep 2021 13:43:29 +0000 (15:43 +0200)] 
threading: respect SC_MAX_CPUS envvar

3 years agogithub-ci: run suricata-verify in quiet mode 6370/head
Jason Ish [Fri, 10 Sep 2021 16:49:42 +0000 (10:49 -0600)] 
github-ci: run suricata-verify in quiet mode

Makes it easier to pick out the failing tests.

3 years agogithub-ci: prepare cbindgen in its own job
Jason Ish [Fri, 10 Sep 2021 16:14:47 +0000 (10:14 -0600)] 
github-ci: prepare cbindgen in its own job

We already do this in master. For 5.0.x it should clear up any
issues where our MSRV isn't suitable to build cbindgen.

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)

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

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 agoikev2: remove transforms fields
Shivani Bhardwaj [Fri, 25 Jun 2021 10:29:31 +0000 (15:59 +0530)] 
ikev2: remove transforms fields

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 agosmtp: null terminate before calling strtoul
Philippe Antoine [Thu, 22 Apr 2021 08:28:15 +0000 (10:28 +0200)] 
smtp: null terminate before calling strtoul

by copying in a temporary buffer
as is done in ByteExtractString

(cherry picked from commit 33fa7ab5969d3fc5ca088c003bd4dbfe76d77b6b)

4 years agostream/tcp: avoid evasion linked to ACK handling
Eric Leblond [Fri, 28 May 2021 09:38:18 +0000 (11:38 +0200)] 
stream/tcp: avoid evasion linked to ACK handling

Actual code will completely discard TCP analysis of a packet that
don't have the ACK bit set but have a ACK value set. This will be
for example the case of all SYN packets that have a ACK value.

Problem is that these type of packets are legit for the operating
systems and for the RFC. The consequence is that an attacker
sending a SYN packet with a non null ACK value will open succesfully
a TCP session to its target and this session will have no protocol
discovery, no TCP streaming and no application layer analysis.
Result is  a quasi full evasion of the TCP stream that will only
appear in the flow log if this log is enable or alert on tcp-pkt
signature that are uncommon.

The patch is updating the code to only discard packets that do not
have the SYN flag set. This prevents the evasion and complies with the
RFC that states that the ACK bit should always be set once the
TCP session is established.

This addresses CVE-2021-35063.

Fixes: fa692df37 ("stream: reject broken ACK packets")
Bug: #4513.

4 years agodetect: track base id for xform buffers
Victor Julien [Thu, 25 Feb 2021 19:06:40 +0000 (20:06 +0100)] 
detect: track base id for xform buffers

Buffers with transforms are based on the non-transformed "base"
buffer, with a new ID assigned and the transform callbacks added.

This patch stores the id of the original buffer in the new buffer
inspect and prefilter structures. This way the buffers with and
without transforms can share some of the logic are progression
of file and body inspection trackers.

Related tickets: #4361 #4199 #3616

(cherry picked from commit 975062cf401f79c00abf728d923c65aabd143af2)

4 years agodetect/file.data: fix mixing transforms (file api)
Victor Julien [Thu, 25 Feb 2021 19:07:41 +0000 (20:07 +0100)] 
detect/file.data: fix mixing transforms (file api)

Fix handling of file progress tracking for regular file.data along
with transform combinations for the part of the implementation that
uses the File API.

This is done by implementing the 'base id' logic.

Related tickets: #4361 #4199 #3616

(cherry picked from commit 54ad7de9cea22b9a3c3e7cc64145155126f4dada)

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 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 agodoc: update sphinx api to use add_css_file
Philippe Antoine [Mon, 17 May 2021 14:27:49 +0000 (16:27 +0200)] 
doc: update sphinx api to use add_css_file

instead of deprecated add_stylesheet

(cherry picked from commit 95f225e8fbd5d352a8ca86cd317f908034966ed4)

4 years agomodbus: fix memory leak in signature parsing 6223/head
Philippe Antoine [Tue, 22 Jun 2021 06:16:40 +0000 (08:16 +0200)] 
modbus: fix memory leak in signature parsing

Bug: #4538.

4 years agorules/decoder-events: fix duplicate sid
Corey Thomas [Tue, 2 Mar 2021 16:16:21 +0000 (11:16 -0500)] 
rules/decoder-events: fix duplicate sid

4 years agoftp: completely parses pasv and epsv responses 6174/head
Philippe Antoine [Tue, 27 Apr 2021 07:03:45 +0000 (09:03 +0200)] 
ftp: completely parses pasv and epsv responses

(cherry picked from commit ca6e434e0b84dc8478763dc0a8716c5e3686a99a)

4 years agounix-socket: reset to ready state on startup
Jason Ish [Thu, 25 Feb 2021 17:16:28 +0000 (11:16 -0600)] 
unix-socket: reset to ready state on startup

As part of commit ea15282f47c6ff781533e3a063f9c903dd6f1afb,
some initialization was moved to happen even in unix socket mode,
however, this initialization does setup some loggers that can only have
one instance enabled (anomaly, drop, file-store).

This will cause these loggers to error out on the first pcap, but work
on subsequent runs of the pcap as some deinitialization is done after
each pcap.

This fix just runs the post pcap-file deinitialization routine to
reset some of the initialization done on startup, like is done after
running each pcap in unix socket mode.

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

Additionally this prevents alerts from being logged two times
on the first run of a pcap through the unix socket:

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

(cherry picked from commit 488d5fb34284f7e5be760edeca7607209cfa4b5e)

4 years agodetect/prefilter: fix null ptr deref on invalid rule 6100/head
Victor Julien [Wed, 3 Mar 2021 12:41:26 +0000 (13:41 +0100)] 
detect/prefilter: fix null ptr deref on invalid rule

A bad rule 'icode:<0; prefilter;' would trigger a null ptr deref
in ApplyToU8Hash.

Bug #4375.

(cherry picked from commit 7d6835958bbb6ddf2931c9e20f409eadfc8ca068)

4 years agoeve/drop: use highest priority drop
Victor Julien [Fri, 12 Mar 2021 09:22:01 +0000 (10:22 +0100)] 
eve/drop: use highest priority drop

When adding the alert to a drop record make sure the add the highest
priority.

It would until now add all drops from high to low prio, effectively
overwriting the record each time.

Ticket #4397

(cherry picked from commit 398ebf934509a8d27a1c8b858eae061b89d5c44a)

4 years agodetect/alert: apply pd only actions to flow
Victor Julien [Wed, 10 Mar 2021 12:25:55 +0000 (13:25 +0100)] 
detect/alert: apply pd only actions to flow

Ticket #4394

(cherry picked from commit 6cf44fc839e8f1da820095928b5b25e7fc0a8521)

4 years agodetect/alert: minor code refactor
Victor Julien [Tue, 9 Mar 2021 19:56:14 +0000 (20:56 +0100)] 
detect/alert: minor code refactor

Use a simpler reject check and move logic into util func.

(cherry picked from commit 6c594d29db55bb0d6f28f0a5fa758c3e00a86ca1)

4 years agodetect/iponly: don't check & set flow flags twice
Victor Julien [Tue, 9 Mar 2021 15:25:14 +0000 (16:25 +0100)] 
detect/iponly: don't check & set flow flags twice

Per flow IP-only flags are checked and set by IP-only engine, so
no need to set/check them per alert.

(cherry picked from commit fbcdd2ec267d49040ca178f8562767d8fb00aa73)

4 years agokerberos: fix probing parser tag condition
Philippe Antoine [Thu, 11 Mar 2021 15:12:36 +0000 (16:12 +0100)] 
kerberos: fix probing parser tag condition

according to the comment

(cherry picked from commit cb150e97d09baea09a738388426eafad3cccff2a)

4 years agogeneral: Typo cleanup
Jeff Lucovsky [Mon, 29 Mar 2021 12:33:02 +0000 (08:33 -0400)] 
general: Typo cleanup

(cherry picked from commit 2893b04ab014c4dcc0bfc4c6f9dbf83fd44717a1)

4 years agodetect/threshold: Improve threshold.config perf
Jeff Lucovsky [Mon, 29 Mar 2021 12:30:59 +0000 (08:30 -0400)] 
detect/threshold: Improve threshold.config perf

This commit improves performance when parsing threshold.config by
removing a loop-invariant to create a one-time object with the parsed
address(es).

Then, as needed, copies of this object are made as the suppression
rule(s) are processed.

(cherry picked from commit 02ceac8b8d4473de5f373a4785a1c143778b06e1)

4 years agodetect/threshold: Function to deep-copy thresh obj
Jeff Lucovsky [Mon, 29 Mar 2021 12:28:50 +0000 (08:28 -0400)] 
detect/threshold: Function to deep-copy thresh obj

This commit adds a function to make a deep copy of a DetectThresholdData
object.

The function is used when parsing threshold.config items to make a
one-time object and then add copies as needed.

(cherry picked from commit e873632a2811be4cd370336d43fcc5619bcd28e2)

4 years agodetect/address: Expose DetectAddressCopy function
Jeff Lucovsky [Mon, 29 Mar 2021 12:26:40 +0000 (08:26 -0400)] 
detect/address: Expose DetectAddressCopy function

(cherry picked from commit 11f9cc6524958d11b6d9ab1f0785bfe16237096f)

4 years agoflow/bypass: Properly set the ICMP emergency-bypassed value
Luke Coughlan [Mon, 26 Apr 2021 12:05:15 +0000 (13:05 +0100)] 
flow/bypass: Properly set the ICMP emergency-bypassed value

Currently the ICMP emergency-bypassed value defined in suricata.conf is
overwriting the UDP value rather than correctly setting it for ICMP.
This commit corrects this bug so that the ICMP value can be set as
expected.

(cherry picked from commit 7fb56a9075a97cd9781d08efd0f949b0bfca2719)

4 years agoftp: fixes leak with duplicate expectation
Philippe Antoine [Thu, 8 Apr 2021 15:44:01 +0000 (17:44 +0200)] 
ftp: fixes leak with duplicate expectation

(cherry picked from commit 68d6922e3cc47c2608e1ac3614c6bd3a48185a12)

4 years agorelease: 5.0.6; update changelog; require htp 0.5.37 suricata-5.0.6
Victor Julien [Mon, 1 Mar 2021 13:30:41 +0000 (14:30 +0100)] 
release: 5.0.6; update changelog; require htp 0.5.37

4 years agoapp-layer: fix transaction cleanup
Victor Julien [Mon, 1 Feb 2021 21:23:47 +0000 (22:23 +0100)] 
app-layer: fix transaction cleanup

Fix a 'skipped' transaction early in the list leading to all further
transactions getting skipped, even if they were fully processed and
ready to be cleaned up.

(cherry picked from commit 8baef60d600c5254662633d8275f321a6dafb82c)

4 years agodetect/prefilter: fix handling of prefilter as fast_pattern alias
Victor Julien [Sat, 20 Feb 2021 14:53:51 +0000 (15:53 +0100)] 
detect/prefilter: fix handling of prefilter as fast_pattern alias

(cherry picked from commit 0dd5921bc9791ac733c8d264212d69e661309df1)

4 years agoclassification: sync and update
Victor Julien [Wed, 24 Feb 2021 15:30:13 +0000 (16:30 +0100)] 
classification: sync and update

Sync to latest ET open and introduce inappropriate as a classification
to replace something some find inappropriate.

(cherry picked from commit f037f6f4ff08ed0442b3bbc1623dfb7ecb23c716)

4 years agosmb: relax probing parser to handle first NBSS message
Philippe Antoine [Wed, 17 Feb 2021 14:36:12 +0000 (15:36 +0100)] 
smb: relax probing parser to handle first NBSS message

cf dcerpc-udp S-V test :
First message is Message Type: Session request (0x81)
Second message is SMB

(cherry picked from commit 83070102557d2755b9ffc67bb14b9b4d48b039e9)

4 years agodetect: fix overflows in SetupU8Hash
Philippe Antoine [Wed, 17 Feb 2021 16:02:35 +0000 (17:02 +0100)] 
detect: fix overflows in SetupU8Hash

For instance ">255" resulted in overflow

(cherry picked from commit 2d765d6c686449e78e29759b07c4852ebab3c46e)

4 years agomodbus: stop allocating transactions when flooded
Philippe Antoine [Thu, 17 Dec 2020 20:48:54 +0000 (21:48 +0100)] 
modbus: stop allocating transactions when flooded

cf #4224

(cherry picked from commit 89030d3e59e23d4850ac9a7db5763c3d4d4fd537)

4 years agossl: reset state when breaking out of SSLV3_HANDSHAKE_PROTOCOL
Philippe Antoine [Fri, 18 Dec 2020 21:12:23 +0000 (22:12 +0100)] 
ssl: reset state when breaking out of SSLV3_HANDSHAKE_PROTOCOL

So that we cannot resumt it with corrupted values

(cherry picked from commit eb460cf78dadc874633a57571245acf2911a6b6e)

4 years agodetect: forbids unsupported prefilters
Philippe Antoine [Sun, 7 Feb 2021 20:34:12 +0000 (21:34 +0100)] 
detect: forbids unsupported prefilters

(cherry picked from commit b7fd01c86e0d0f3c341031d62ec89e305859aa0b)

4 years agodecode: limits the number of decoded layers
Philippe Antoine [Thu, 28 Jan 2021 16:48:48 +0000 (17:48 +0100)] 
decode: limits the number of decoded layers

so as to avoid overrecursion leading to stack exhaustion

(cherry picked from commit 7500c29300dcef8716d87461842e7d7c3e5101ac)

4 years agofilestore: fix global counter init in unix socket mode
Jason Ish [Fri, 18 Dec 2020 17:34:30 +0000 (11:34 -0600)] 
filestore: fix global counter init in unix socket mode

Move initialization of filestore global counter to PreRunInit,
so they get registered during program initialization, or as
required in unix-socket mode, initialized for each file run.

Fixes Redmine issue:
https://redmine.openinfosecfoundation.org/issues/4216

(cherry picked from commit 0aed5e188b214d56107e66ea8e38dfb7d5a13758)

4 years agogithub-ci: use suricata-update master-1.1.x branch
Jason Ish [Wed, 24 Feb 2021 22:53:06 +0000 (16:53 -0600)] 
github-ci: use suricata-update master-1.1.x branch

Suricata 5.0.x tracks the Suricata-Update 1.1.x branch.

4 years agostream/tcp: fix stream side after direction change 5912/head
Ilya Bakhtin [Tue, 28 Jul 2020 14:33:23 +0000 (16:33 +0200)] 
stream/tcp: fix stream side after direction change

(cherry picked from commit 1ecea0f44c0050feb57c6b26a5a94c8ad8f1b85d)

4 years agohttp: makes decompression time limit configurable
Philippe Antoine [Wed, 17 Feb 2021 08:37:57 +0000 (09:37 +0100)] 
http: makes decompression time limit configurable

(cherry picked from commit a04b5566a62d9d6967587f83dfaca89b5c33eb66)

4 years agoprotodetect: improve midstream handling 5895/head
Ilya Bakhtin [Mon, 15 Feb 2021 17:36:46 +0000 (18:36 +0100)] 
protodetect: improve midstream handling

Set "done flag" only if parsers for both directions are not found in a
case of midstream parsers from other direction are tried if nothing is found
for the initial one. "done flag" must be set if nothing is found in both
directions. Otherwise processing of incomplete data is terminated at the very
first try.

(cherry picked from commit 5285163d8f31dc89a4ab96b0842099f9792e29be)

4 years agotcp: remove debug asserts about large windows 5890/head
Philippe Antoine [Wed, 17 Feb 2021 14:43:17 +0000 (15:43 +0100)] 
tcp: remove debug asserts about large windows

Completes 00d7c9034be7470177c01e8805831c258b016d0e

(cherry picked from commit 7264f58f2cbf266ba44efd32c5031b692b57967d)

4 years agodetct/pcre: Correct capture group count check 5887/head
Jeff Lucovsky [Mon, 8 Feb 2021 13:05:41 +0000 (08:05 -0500)] 
detct/pcre: Correct capture group count check

This commit corrects the validation check between the number of
variables used and the number of specified capture groups.

(cherry picked from commit 469d5bb214195d8939be467c66ef1e6d25ad3e1f)

4 years agoalert/syslog: fix minor compile warning 5867/head
Victor Julien [Thu, 22 Oct 2020 14:10:14 +0000 (16:10 +0200)] 
alert/syslog: fix minor compile warning

(cherry picked from commit 62cc0c7acf2270d63e0e164d9e39f47b811e1fb3)

4 years agoproto/names: add SCTP if not defined in system
Victor Julien [Mon, 18 Jan 2021 12:56:32 +0000 (13:56 +0100)] 
proto/names: add SCTP if not defined in system

If SCTP is missing from /etc/protocols, add it manually.

(cherry picked from commit bf00285d0acf87c794f6569eb51d1f7d1247a0da)

4 years agohost: improve compare logic
Victor Julien [Sat, 13 Feb 2021 16:10:15 +0000 (17:10 +0100)] 
host: improve compare logic

The old compare macro would compare all bytes of an address, even
when for IPv4 addresses the additional bytes were not in use. This
made the logic vulnerable to mistakes like in issue #4280.

(cherry picked from commit 6bfc5afa2301cc416e2fced23ec1accdfdea0daf)

4 years agodetect/iprep: fix loading of mixed ipv4/ipv6 lists 5864/head
Victor Julien [Sat, 13 Feb 2021 15:54:56 +0000 (16:54 +0100)] 
detect/iprep: fix loading of mixed ipv4/ipv6 lists

Improper reuse of the address data structure between loading
different lines in the iprep file would lead to the host using
a malformed address.

(cherry picked from commit 7b03e6837e5a7366f546e7a2b681d2921ded1ab1)

4 years agosuricata: avoid at exit crash in nfq mode
Eric Leblond [Sun, 24 Jan 2021 21:40:02 +0000 (22:40 +0100)] 
suricata: avoid at exit crash in nfq mode

When Suricata was build with ebpf support and when it was started
in NFQ mode, it was crashing at exit because it was trying to free
the device extension.

This patch fixes the issue by only trigger the eBPF related code
when Suricata is running in AFP_PACKET mode.

(cherry picked from commit 85327890f5bb3b9521a2dfb8268ace6645d02f72)

4 years agodataset: fix dataset string lookup
Eric Leblond [Wed, 20 Jan 2021 20:17:04 +0000 (21:17 +0100)] 
dataset: fix dataset string lookup

The data was unlocked but the use_cnt was not decreased resulting
in the data entry not being removable.

(cherry picked from commit 64f994f753b9109c8f788e3a6dbe4c72f6e69d94)

4 years agodetect-fast-pattern: Mark as OPTIONAL_OPT, instead of NOOPT 5861/head
Gianni Tedesco [Sun, 13 Dec 2020 14:50:23 +0000 (23:50 +0900)] 
detect-fast-pattern: Mark as OPTIONAL_OPT, instead of NOOPT

Also update the erroneous comment about it.

(cherry picked from commit cebe15c23b48e92df5181b3f0b0e6ac7195d717b)

4 years agodetect: Validate that NOOPT options don't have optvals
Gianni Tedesco [Sun, 13 Dec 2020 14:54:13 +0000 (23:54 +0900)] 
detect: Validate that NOOPT options don't have optvals

Without this, a simple typo between : and ; is able to hide actual bugs
in rules.

I discovered 2 bugs in ET open ruleset this way.

(cherry picked from commit 10ea60a237cf41ddd10f7a887e2824b4b8e1c419)

4 years agodns: initialize log flags as an unsigned long long
Jason Ish [Mon, 7 Dec 2020 21:31:34 +0000 (15:31 -0600)] 
dns: initialize log flags as an unsigned long long

On 64 bit all 64 bits were being initialized, but on 32 bit
only 32 bits were as it was being initialized as a long.

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

(cherry picked from commit f2ab5803fbd88ae613429a382f28e81841832d0d)

4 years agogithub-ci: use python3 in debian builds
Jason Ish [Fri, 8 Jan 2021 16:32:47 +0000 (10:32 -0600)] 
github-ci: use python3 in debian builds

(cherry picked from commit 18a1fd22c2dfd0613b190a656574077c1230e309)

4 years agogithub-ci/macos: use brew to install Python 3
Jason Ish [Fri, 8 Jan 2021 15:39:19 +0000 (09:39 -0600)] 
github-ci/macos: use brew to install Python 3

The default Python on MacOS is Python 2. Suricata-Verify now
depends on Python 3, so install it with Brew.

(cherry picked from commit 7904ef82d0b2478694025ca0d9043f2ae98be73a)

4 years agorust/json: Rework scope for short-lived vars 5733/head
Jeff Lucovsky [Sat, 16 Jan 2021 14:34:20 +0000 (09:34 -0500)] 
rust/json: Rework scope for short-lived vars

This commit corrects scope issues identified during CI with
FC32/strict-rust:
"this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
"

4 years agorust: lock major versions of crates 5732/head
Victor Julien [Sat, 16 Jan 2021 09:17:35 +0000 (10:17 +0100)] 
rust: lock major versions of crates

4 years agorust: lock to byteorder ~1.3.4 to avoid MSRV bump
Victor Julien [Sat, 16 Jan 2021 08:59:31 +0000 (09:59 +0100)] 
rust: lock to byteorder ~1.3.4 to avoid MSRV bump