]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
3 years agodetect/dataset: cleanup dead code 7227/head
Shivani Bhardwaj [Fri, 28 Jan 2022 13:43:04 +0000 (19:13 +0530)] 
detect/dataset: cleanup dead code

(cherry picked from commit 7366396011227b5e51ca810d86ebf7d310e98f34)

3 years agodetect/dataset: fix space condition in rule lang
Shivani Bhardwaj [Fri, 28 Jan 2022 20:17:17 +0000 (01:47 +0530)] 
detect/dataset: fix space condition in rule lang

If there is a space following a keyword that does not expect a value,
the rule fails to load due to improper value evaluation.
e.g. Space after "set" command
alert http any any -> any any (http.user_agent; dataset:set  ,ua-seen,type string,save datasets.csv; sid:1;)

gives error
[ERRCODE: SC_ERR_UNKNOWN_VALUE(129)] - dataset action "" is not supported.

Fix this by handling values correctly for such cases.

(cherry picked from commit 6d2a2a073120906304f70c0e120565eae96e36b8)

3 years agoflow: fix and simplify locking
Victor Julien [Fri, 8 Apr 2022 20:06:09 +0000 (22:06 +0200)] 
flow: fix and simplify locking

Since:

9551cd053579 ("threading: don't pass locked flow between threads")

`MoveToWorkQueue()` unconditionally unlocks the flow. This allows simpler
locking handling, including of tcp reuse flows.

The simpler logic also fixes a scenario where TCP reuse flows got "unlocked"
twice, once in `FlowGetFlowFromHash()` and once in `MoveToWorkQueue()`.

Bug: #5248.
Coverity: 1494354.
(cherry picked from commit 57533d3e47315e6b96c941fe5fd64149cbeb8b1a)

3 years agolog/stack: Propagate original signal 7215/head
Jeff Lucovsky [Fri, 11 Feb 2022 15:38:45 +0000 (10:38 -0500)] 
log/stack: Propagate original signal

Issue: 4550

This commit modifies the "stack trace on signal" to propagate the
original signal received instead of always raising SIGABRT.

(cherry picked from commit a3443845fbaf5c01bb8758817490bc93b5c039a5)

3 years agoconfig: Make libunwind use configurable for 6.0
Jeff Lucovsky [Thu, 27 Jan 2022 14:00:23 +0000 (09:00 -0500)] 
config: Make libunwind use configurable for 6.0

Issue: 4973

This commit makes stack-trace on fault configurable by
adding "--enable-libunwind" as a configure option.

By default, or if "--enable-libunwind=no" is specified, the libunwind
library will not be configured.

When "--enable-libunwind=yes" is specified, libunwind will be used iff
it can be found in one of the standard library locations.

3 years agodoc/yaml: Signal-termination option description
Jeff Lucovsky [Thu, 17 Jun 2021 13:24:46 +0000 (09:24 -0400)] 
doc/yaml: Signal-termination option description

(cherry picked from commit 93842aa14a67ed1e7acfc6bbdacbffef8bd6bae0)

3 years agologging/diag: Enable stacktrace diagnostic if config'd
Jeff Lucovsky [Thu, 17 Jun 2021 13:07:29 +0000 (09:07 -0400)] 
logging/diag: Enable stacktrace diagnostic if config'd

This commit adds a signal handler for SIGSEGV when configured. The
signal handler emits a one line stack trace using SCLogError. The intent
is to provide diagnostic information in deployments where core files are
not possible.

The diagnostic message is from the offending thread and includes the
stack trace; each frame includes the symbol + offset.

(cherry picked from commit 7f0f463b6475bbf69b24664485fc5b3b3bd8004b)

3 years agologging: Stacktrace on signal term setting
Jeff Lucovsky [Thu, 17 Jun 2021 13:04:56 +0000 (09:04 -0400)] 
logging: Stacktrace on signal term setting

This commit adds a configuration setting to enable a stack trace message
if Suricata receives a signal that terminates execution, such as
SIGSEGV, SIGABRT.

(cherry picked from commit 163f70be9d87960fb260eb5c03383799f78b46b5)

3 years agoerror: Add error code for sig-related diagnostics
Jeff Lucovsky [Thu, 17 Jun 2021 12:54:30 +0000 (08:54 -0400)] 
error: Add error code for sig-related diagnostics

This commit adds an error code for the diagnostic code used for
diagnostic messages following unexpected termination due to signals..

(cherry picked from commit 501c870a2c176a053f090f7f2535dd989153db4c)

3 years agoconfigure.ac: Support libunwind configuration
Jeff Lucovsky [Thu, 17 Jun 2021 12:52:17 +0000 (08:52 -0400)] 
configure.ac: Support libunwind configuration

This commit adds support for enabling libunwind -- a library that can be
used to display stack information.

Libunwind is enabled and used by Suricata if present during
configuration.  A diagnostic message is displayed if libunwind
cannot be found.

(cherry picked from commit 303dd29b501d9f27b60d1b400986f04b99df2453)

3 years agonss: use 'atexit()' to cleanup
Victor Julien [Thu, 7 Apr 2022 12:44:26 +0000 (14:44 +0200)] 
nss: use 'atexit()' to cleanup

This avoids ASAN to report leaks in case of fatal errors in tests.

3 years agoflow-manager: fix off-by-one in flow_hash row allocation 7206/head
Arne Welzel [Sat, 12 Feb 2022 16:49:07 +0000 (17:49 +0100)] 
flow-manager: fix off-by-one in flow_hash row allocation

The current code doesn't cover all rows when more than one flow manager is
used. It leaves a single row between ftd->max and ftd->min of the next
manager orphaned. As an example:

    hash_size=1000
    flowmgr_number=3
    range=333

    instance  ftd->min  ftd->max
    0         0         333
    1         334       666
    2         667       1000

    Rows not covered: 333, 666

(cherry picked from commit 8ef066318d7c4dd9b6686dbebd621c790828c384)

3 years agossl: first pass limit when allocating buffer for certificates
Philippe Antoine [Thu, 10 Mar 2022 14:09:57 +0000 (15:09 +0100)] 
ssl: first pass limit when allocating buffer for certificates

With this check, on the first packet of a certificate presenting
a length of 16Mbytes, we only allocate up to 65Kb

When we get to the point where need more than 65Kb, we realloc
to the true size.

With this check, it makes it more expensive for an attacket to use
this allocation as a way to trigger ressource exhaustion...

(cherry picked from commit 862e84877ff262cd4b8c4b191a8710f94f63fcf7)

3 years agofuzz: use fuzzing confyaml for protodetect target 7199/head
Philippe Antoine [Wed, 15 Dec 2021 19:48:47 +0000 (20:48 +0100)] 
fuzz: use fuzzing confyaml for protodetect target

As is done for other targets,
so that all app-layer protocols are enabled,
even the ones disabled by default such as enip

And resets protocol detection every time we try
so that probing_parser_toserver_alproto_masks are fresh.

(cherry picked from commit 09c84d0c26d58e4750ef2114699c9324b561bf4e)

3 years agosmtp: check if we have a current transaction 7193/head
Philippe Antoine [Tue, 25 Jan 2022 20:10:37 +0000 (21:10 +0100)] 
smtp: check if we have a current transaction

Ticket: 4948

This is not the perfect solution, but it prevents to trigger
the assert, and keep the assert.
A better solution would need to create transaction from
the reponse parsing, in case a later command was buffered and
not answered. But this would not be enough as NoNewTx prevents
the creation of a new transaction for RSET...

(cherry picked from commit 4247605d874113ef13003816007e0575219d065e)

3 years agosmb1: apply close to direction 7190/head
Victor Julien [Fri, 25 Mar 2022 10:17:23 +0000 (11:17 +0100)] 
smb1: apply close to direction

Instead of closing files in both direction when receiving a close request,
close only toserver files for the request and close toclient on receiving
a response.

(cherry picked from commit b336882008d3640973fa71be6f36f3de33d3cd25)

3 years agopppoe: fix protocol field length variation 7189/head
Steven Ottenhoff [Thu, 13 Jan 2022 13:05:58 +0000 (13:05 +0000)] 
pppoe: fix protocol field length variation

Detect when protocol field is not a 16 bit field.
Added tests to prove logic

Ticket: 4810
(cherry picked from commit 6bf2117056e8c2e9448a02d2198384935b1d5b70)

3 years agosmtp: check if there is a transaction to close
Philippe Antoine [Tue, 22 Feb 2022 12:10:59 +0000 (13:10 +0100)] 
smtp: check if there is a transaction to close

Ticket: 4948

When parsing the response for starttls

(cherry picked from commit 99b3443369703ba69d962019edeca8f1c7c7896e)

3 years agodoc/xbits: clarify noalert usage 7127/head
Shivani Bhardwaj [Fri, 28 Jan 2022 12:13:10 +0000 (17:43 +0530)] 
doc/xbits: clarify noalert usage

3 years agodetect/xbits: parse keywords w strtok_r
Shivani Bhardwaj [Thu, 27 Jan 2022 18:52:25 +0000 (00:22 +0530)] 
detect/xbits: parse keywords w strtok_r

Ticket: 4820

3 years agodetect/ipproto: Use builtin protocol table
Jeff Lucovsky [Sat, 12 Feb 2022 14:46:29 +0000 (09:46 -0500)] 
detect/ipproto: Use builtin protocol table

Issue 5072

This commit causes the built-in protocol table to be used for protocol
name and number validation.

(cherry picked from commit 4f2f745bed4858c6441b1b936f66453e87b715bb)

3 years agodetect/tests: Register protoname tests
Jeff Lucovsky [Thu, 17 Feb 2022 16:06:16 +0000 (11:06 -0500)] 
detect/tests: Register protoname tests

Issue: 5072

This commit registers the proto-name unit tests.

(cherry picked from commit 3bd1d258a98c7e6f6fa45feb111f3297f1a527e7)

3 years agodetect/ipproto: Add init/release functions
Jeff Lucovsky [Thu, 17 Feb 2022 16:05:22 +0000 (11:05 -0500)] 
detect/ipproto: Add init/release functions

Issue: 5072

This commit insures that the protocol name hashtables are initialized
and released.

(cherry picked from commit b52496725771c0a4bc98e1fe5c246bca77e8da03)

3 years agoutil/proto: Protocol-name functions
Jeff Lucovsky [Sat, 12 Feb 2022 14:44:13 +0000 (09:44 -0500)] 
util/proto: Protocol-name functions

Issue: 5072

This commit adds utility functions handling protocol names.

(cherry picked from commit ff0cf89738d7b947a3d7d8d0c6c5dc7adb95e6af)

3 years agoerror/hash: Add error code for hash add failures
Jeff Lucovsky [Fri, 18 Feb 2022 12:41:13 +0000 (07:41 -0500)] 
error/hash: Add error code for hash add failures

Issue: 5072
(cherry picked from commit 1e2883602b8d95d96fa9c31e5ebbcb68ceeaa14a)

3 years agoutil: export Djb2 hash string function
Philippe Antoine [Thu, 18 Feb 2021 10:44:24 +0000 (11:44 +0100)] 
util: export Djb2 hash string function

(cherry picked from commit 5cb996efcf2248a6a04abfe2bde1dc5115bdfac2)

3 years agoproto: Remove dependency on /etc/protocols
Jeff Lucovsky [Thu, 6 May 2021 13:49:55 +0000 (09:49 -0400)] 
proto: Remove dependency on /etc/protocols

This commit eliminates the dependency on /etc/protocols and equivalent
on other platforms by using a static table of IANA assigned protocol
values (names, description).

(cherry picked from commit e77e8dbe18bdb70e42713abe4e90ec724adab5ca)

3 years agothreads: Honor per-thread stack size setting
Jeff Lucovsky [Fri, 11 Feb 2022 14:02:39 +0000 (09:02 -0500)] 
threads: Honor per-thread stack size setting

Issue: 4550

This commit adjusts the per-thread stack size if a size has been
configured. If the setting has not been configured, the default
per-thread stack size provided by the runtime mechanisms are used.

(cherry picked from commit 6232c94235a60f2f89d444dfd5a9e20efc0a5a60)

3 years agoconfig/thread: Use config'd per-thread stack size
Jeff Lucovsky [Fri, 11 Feb 2022 13:36:28 +0000 (08:36 -0500)] 
config/thread: Use config'd per-thread stack size

Issue: 4550

This commit checks if there's a config setting for threading.stack-size
and assigns the value to a global variable for use during thread
creation.

(cherry picked from commit e4d60f451b8a226e32a3df8e232efe437b11e2e3)

3 years agosuricata.yaml: Add per-thread stack size setting
Jeff Lucovsky [Fri, 11 Feb 2022 13:35:36 +0000 (08:35 -0500)] 
suricata.yaml: Add per-thread stack size setting

Issue: 4550
(cherry picked from commit d79a317cea900e60166068c4d6703caab7218509)

3 years agoconfig/debug: Debug probe for getattr_np
Jeff Lucovsky [Tue, 15 Feb 2022 15:50:33 +0000 (10:50 -0500)] 
config/debug: Debug probe for getattr_np

This commit adds a probe for a non-portable function to be used in
diagnostic debug display of a thread's stack size.

(cherry picked from commit deb49862cd6734ccb15c1cc91e430c8ee01292aa)

3 years agodoc: Describe per-thread stack size config setting
Jeff Lucovsky [Fri, 11 Feb 2022 13:34:12 +0000 (08:34 -0500)] 
doc: Describe per-thread stack size config setting

Issue: 4550

This commit documents the new per-thread stack-size setting. Some
systems have a small default value that is not suitable for Suricata's
multi-threaded architecture and adjustment may be required.

(cherry picked from commit 117e11b0ae0c64d8c8b61d3d343957be3b9eb128)

3 years agogeneral: Fix typo
Jeff Lucovsky [Thu, 27 Jan 2022 17:30:14 +0000 (12:30 -0500)] 
general: Fix typo

(cherry picked from commit b53fced45254ca267e75ea7e8c60afab82ea1e08)

3 years agoconfig/ref: Raise errors for ref.config parsing
Jeff Lucovsky [Wed, 26 Jan 2022 21:35:12 +0000 (16:35 -0500)] 
config/ref: Raise errors for ref.config parsing

This commit raises an error in configuration test mode if there was an
error parsing reference.config.

Issue: 4659
(cherry picked from commit be2155b4edb712913166cb5e8c10b36fb4362f2a)

3 years agologging: change ownership of application log if needed
Jason Ish [Thu, 20 Jan 2022 18:08:33 +0000 (12:08 -0600)] 
logging: change ownership of application log if needed

When running with privilege dropping, the application log file
is opened before privileges are dropped resulting in Suricata
failing to re-open the file for file rotation.

If needed, chown the application to the run-as user/group after
opening.

Ticker #4523

(cherry picked from commit 59ac1fe277b0dc2fc2b6c1739c10eb58a0d48cba)

3 years agostartup: initialize run as user info sooner
Jason Ish [Thu, 20 Jan 2022 17:40:24 +0000 (11:40 -0600)] 
startup: initialize run as user info sooner

Initialize the run-as user info after loading the config, but
before setting up logging (previously it was done while initializing
signal handlers). This will allow the log file to be given the
correct permissions if Suricata is configured to run as a non-root
user.

(cherry picked from commit 08518df373625eed25d03108bd24b9e389295c81)

3 years agoswf: fix coverity warnings
Victor Julien [Tue, 15 Feb 2022 06:56:57 +0000 (07:56 +0100)] 
swf: fix coverity warnings

*** CID 1499365:    (UNINIT)
/src/util-file-swf-decompression.c: 98 in FileSwfZlibDecompression()
92         infstream.avail_in = (uInt)compressed_data_len;
93         infstream.next_in = (Bytef *)compressed_data;
94         infstream.avail_out = (uInt)decompressed_data_len;
95         infstream.next_out = (Bytef *)decompressed_data;
96
97         inflateInit(&infstream);

>>>     CID 1499365:    (UNINIT)
>>>     Using uninitialized value "infstream.total_out" when calling "inflate".
98         int result = inflate(&infstream, Z_NO_FLUSH);
99         switch(result) {
100             case Z_STREAM_END:
101                 break;
102             case Z_OK:
103                 break;

/src/util-file-swf-decompression.c: 98 in FileSwfZlibDecompression()
92         infstream.avail_in = (uInt)compressed_data_len;
93         infstream.next_in = (Bytef *)compressed_data;
94         infstream.avail_out = (uInt)decompressed_data_len;
95         infstream.next_out = (Bytef *)decompressed_data;
96
97         inflateInit(&infstream);

>>>     CID 1499365:    (UNINIT)
>>>     Using uninitialized value "infstream.total_out" when calling "inflate".
98         int result = inflate(&infstream, Z_NO_FLUSH);
99         switch(result) {
100             case Z_STREAM_END:
101                 break;
102             case Z_OK:
103                 break;

*** CID 1499363:  Error handling issues  (CHECKED_RETURN)
/src/util-file-swf-decompression.c: 97 in FileSwfZlibDecompression()
91
92         infstream.avail_in = (uInt)compressed_data_len;
93         infstream.next_in = (Bytef *)compressed_data;
94         infstream.avail_out = (uInt)decompressed_data_len;
95         infstream.next_out = (Bytef *)decompressed_data;
96
>>>     CID 1499363:  Error handling issues  (CHECKED_RETURN)
>>>     Calling "inflateInit_(&infstream, "1.2.11", 112)" without checking return value. This library function may fail and return an error code.
97         inflateInit(&infstream);
98         int result = inflate(&infstream, Z_NO_FLUSH);
99         switch(result) {
100             case Z_STREAM_END:
101                 break;
102             case Z_OK:

Bug: #5079.
(cherry picked from commit e1f7c63fa8ed9ee787f89776162ca221573ef227)

3 years agodoc: add usage of flowbits OR op
Shivani Bhardwaj [Sat, 19 Feb 2022 06:33:10 +0000 (12:03 +0530)] 
doc: add usage of flowbits OR op

Ticket 5130

(cherry picked from commit 015c9fe1e3aebd2a2f01b91d4e5f81d977bbdd9d)

3 years agounittests: clean up packet clear logic
Victor Julien [Wed, 23 Feb 2022 12:41:42 +0000 (13:41 +0100)] 
unittests: clean up packet clear logic

(cherry picked from commit 0437ca61ff81e3597a00e1e11311f4e9dc7182a5)

3 years agoapplayer: fix clang formatting
Shivani Bhardwaj [Mon, 7 Mar 2022 14:41:14 +0000 (20:11 +0530)] 
applayer: fix clang formatting

3 years agodecode: release refs from PacketFree
Victor Julien [Wed, 23 Feb 2022 12:40:59 +0000 (13:40 +0100)] 
decode: release refs from PacketFree

Mostly helps unittests.

(cherry picked from commit f07d5b2d89ed27d075e9f9328fd678d6ea701889)

3 years agodetect/iprep: fix host locking issues
Victor Julien [Wed, 23 Feb 2022 10:08:45 +0000 (11:08 +0100)] 
detect/iprep: fix host locking issues

Separate the code paths between reusing a Packet stored host reference
and fetching a new reference from the host hash.

This addresses the issue where in some conditions use_cnt could get
desync'd.

Bug: #2802.
(cherry picked from commit 49a36bb323d44a3ef453f284c35780523c9d3bd7)

3 years agoiprep: unify free handling
Victor Julien [Wed, 23 Feb 2022 10:05:40 +0000 (11:05 +0100)] 
iprep: unify free handling

Introduce a new util function to free a Hosts iprep code. It also
handles the Host use_cnt decrement.

This change makes sure we also decrement the use_cnt when cleaning
up when shutting down the host table.

Move the BUG_ON check for use_cnt into the HostClearMemory() func
to check it in more cases.

(cherry picked from commit 172d2b28a58d923ddbc5644dd3bfb52e353b8a55)

3 years agodetect/iponly: add tests for 5170 7104/head
Victor Julien [Tue, 1 Mar 2022 11:44:01 +0000 (12:44 +0100)] 
detect/iponly: add tests for 5170

(cherry picked from commit 935ea745f5e38b49713ae77d86b57ce7260917a4)

3 years agodetect/address: minor unittest cleanup
Victor Julien [Tue, 1 Mar 2022 11:43:25 +0000 (12:43 +0100)] 
detect/address: minor unittest cleanup

(cherry picked from commit 053b2b3b5b1197064bba5d59d4731c5789ff7239)

3 years agodetect/iponly: validate netmask
Victor Julien [Tue, 1 Mar 2022 11:42:49 +0000 (12:42 +0100)] 
detect/iponly: validate netmask

Only accept netmask in dotted quad notation if they can be turned
into a CIDR.

According to rfc 4632, CIDR (compat) netmasks are all that should be
used.

Bug: #5168.
(cherry picked from commit 79b7b7a0ddfdcd7664ca328a41d24fbca75e3e54)

3 years agodetect/address: validate netmasks
Victor Julien [Tue, 1 Mar 2022 11:41:04 +0000 (12:41 +0100)] 
detect/address: validate netmasks

Only accept netmask in dotted quad notation if they can be turned
into a CIDR.

According to rfc 4632, CIDR (compat) netmasks are all that should be
used.

Bug: #5168.
(cherry picked from commit 259bd8aa92c7bc8ca8c74b3f429f321935493828)

3 years agodetect/iponly: break out range insert code
Victor Julien [Mon, 28 Feb 2022 21:31:58 +0000 (22:31 +0100)] 
detect/iponly: break out range insert code

So we can reuse it.

(cherry picked from commit 4020e2faa7ee93dfed663b4b0795644572ddfd79)

3 years agoutil/cidr: add util to convert netmask to cidr
Victor Julien [Tue, 1 Mar 2022 11:41:49 +0000 (12:41 +0100)] 
util/cidr: add util to convert netmask to cidr

(cherry picked from commit a67b97e14c08f46f50c1acd989f0dc049a8e4cba)

3 years agonfs: clean up partial record handling
Victor Julien [Mon, 21 Feb 2022 17:10:44 +0000 (18:10 +0100)] 
nfs: clean up partial record handling

There should be no remaining data after parsing the partial
RPC record, so don't handle it but instead add a debug validation
bug on.

Successful processing for NFSv3 read/write records returns
AppLayerResult::ok() directly as all data is consumed.

(cherry picked from commit 07b110071331f5023a70710a90f50b9a500a518b)

3 years agonfs3: improve read validation; fix partial handling
Victor Julien [Mon, 21 Feb 2022 19:30:45 +0000 (20:30 +0100)] 
nfs3: improve read validation; fix partial handling

(cherry picked from commit d85b77cad064bd88c921b2f3d520fe526ad8ff82)

3 years agonfs3: fix partial write record handling
Victor Julien [Mon, 21 Feb 2022 19:30:35 +0000 (20:30 +0100)] 
nfs3: fix partial write record handling

Comment from Jason Ish: This was a bit more than a cherry pick as some
of the modifications weren't directly portable to the nom macros. So
instead bring in some of the nom function based parsers as they work
fine with nom 5.

(cherry picked from commit 4418fc1b02f47533439fe00789d9c850a24271b2)

3 years agonfs3: enforce more values
Victor Julien [Sun, 20 Feb 2022 22:02:13 +0000 (23:02 +0100)] 
nfs3: enforce more values

Enforce values of a number of u32's that are used as bools or for
really low values.

(cherry picked from commit 5baf94e40ddeb3deab97a897b9da2e93ece4c654)

3 years agorpc: enforce various field values
Victor Julien [Mon, 21 Feb 2022 09:08:41 +0000 (10:08 +0100)] 
rpc: enforce various field values

Minimal frag_len. Correct msgtype and others.

(cherry picked from commit 1c57e3c18d746743bc2cbcaba35f78b5f9b15675)

3 years agonfs/rpc: update full record parsers to be more exact
Victor Julien [Sun, 20 Feb 2022 09:00:48 +0000 (10:00 +0100)] 
nfs/rpc: update full record parsers to be more exact

Instead of 'take'ing all data for the RPC prog_data and then
letting the higher level parsers figure out which part to use
take the exact amount.

Comments from Shivani Bhardwaj: This is was more than a cherry pick and
some of the modifications were not directly portable to the nom macros.
So, parsers were changed to make sure the functionality remained same while
making the transition to nom5 while keeping the diff minimal.

(cherry picked from commit 64d8a1e16e07148a8b5839452be3f7481e4e3623)

3 years agonfs: break out partial record handling
Victor Julien [Sun, 20 Feb 2022 07:59:05 +0000 (08:59 +0100)] 
nfs: break out partial record handling

(cherry picked from commit bfb5ae867e083f4146b2455309387f77fac5623c)

3 years agonfs/rpc: enforce length field limits
Victor Julien [Sat, 19 Feb 2022 07:42:35 +0000 (08:42 +0100)] 
nfs/rpc: enforce length field limits

Limits based on the Linux kernel limits. Then multiplied a few times
to allow for other implementations to have higher limits.

(cherry picked from commit fe76ab1803bea02f47f691b5944ba319a3bc0300)

3 years agonfs4: verify bool fields
Victor Julien [Mon, 21 Feb 2022 11:20:13 +0000 (12:20 +0100)] 
nfs4: verify bool fields

(cherry picked from commit 5ecb626e50048cfa43ad67cdd80307377e90926c)

3 years agooutput: fix timestamp missing usecs
Victor Julien [Fri, 18 Feb 2022 09:19:04 +0000 (10:19 +0100)] 
output: fix timestamp missing usecs

On ARM 32bit with Musl `tv_usecs` is defined as `int64_t` which lead to
CreateIsoTimeString() printing all zeros on the usecs. Work around this
by first assigning to a `int64_t` and then updating the expected format
string to accept `int64_t`.

Bug: #5094.
(cherry picked from commit a0c0471f1f51af0171ed5df1e2de0b900651bc19)

3 years agodetect/address: use common cidr code
Victor Julien [Thu, 17 Feb 2022 15:53:43 +0000 (16:53 +0100)] 
detect/address: use common cidr code

(cherry picked from commit 8a73b242e389a5dbc223de83e2e7542bc46903d8)

3 years agoradix: fix unittests after stict checks
Victor Julien [Thu, 17 Feb 2022 12:35:45 +0000 (13:35 +0100)] 
radix: fix unittests after stict checks

(cherry picked from commit 38aec1439c7fffc49144ae5ccb38da2d462c85d9)

3 years agoradix: improve address range handling
Victor Julien [Thu, 17 Feb 2022 12:32:17 +0000 (13:32 +0100)] 
radix: improve address range handling

Handle non-exact address ranges from string. This can come directly
from user input, so here it is accepted but the address is converted
to the address range start. A warning will be issued.

Debug validation checks are added to catch this.

This issue could lead to bad input from iprep (with cidr), defrag config
and htp server personalities to produce a bad radix tree.

Bug: #5084.
Bug: #5085.
Bug: #5086.
(cherry picked from commit 7fd6fe732b360d4f1de4483b539af2eda813b966)

3 years agodetect/iponly: fix netmask handling
Victor Julien [Tue, 15 Feb 2022 19:43:27 +0000 (20:43 +0100)] 
detect/iponly: fix netmask handling

If the ipaddress was not the address range start, it was not masked to turn
it into that. So 1.2.3.4/24 was not stored as address 1.2.3.0 with netmask 24,
but as 1.2.3.4 with netmask 24. This was then propagated into the radix tree,
where it was used as an exact key in exact lookups, giving unexpected results.

This patch implements the netmask handling for IPv4 and IPv6, and adds a set
of tests for it.

Bug: #5081.
Bug: #5066.
(cherry picked from commit 51d4e0dced9cac7463ee924b00bc8666c68b20c3)

3 years agoradix: fix unittest not cleaning up
Victor Julien [Tue, 15 Feb 2022 13:44:08 +0000 (14:44 +0100)] 
radix: fix unittest not cleaning up

(cherry picked from commit 311085dd34c445b8d9195c8517475b764a61eb3b)

3 years agodetect/iponly: update SigNumArray comment
Victor Julien [Sat, 12 Feb 2022 07:23:03 +0000 (08:23 +0100)] 
detect/iponly: update SigNumArray comment

(cherry picked from commit 860daceb04301850bc059e73c7344cb843248bf9)

3 years agoradix: cleanup test
Victor Julien [Fri, 11 Feb 2022 14:53:41 +0000 (15:53 +0100)] 
radix: cleanup test

(cherry picked from commit d04dface20657e781f683c30f159afcefa5ac1ea)

3 years agoradix: add tests for Bug #5066
Victor Julien [Fri, 11 Feb 2022 14:52:51 +0000 (15:52 +0100)] 
radix: add tests for Bug #5066

Bug: #5066.
(cherry picked from commit 89b7ac0a60bf83c69bbd9f4f45be128524ff3999)

3 years agoradix: fix FP/FN issue in IP-only
Victor Julien [Fri, 11 Feb 2022 14:50:01 +0000 (15:50 +0100)] 
radix: fix FP/FN issue in IP-only

A bug was reported about the IP-only rules not correctly matching. This was
traced to the rules in question not getting recorded into the IP-only radix
tree correctly.

Sequence:

- 100.117.241.0/25 inserted into the tree

- 100.117.241.0/26 inserted into the tree

Both are part of the same radix node, but recorded by their different netmasks
in the user data portion.

Then faulty insert happens:

- 100.117.241.64/26

For reference, these net blocks compute to:

- 100.117.241.0/25:  100.117.241.0  - 100.117.241.127
- 100.117.241.0/26:  100.117.241.0  - 100.117.241.63
- 100.117.241.64/26: 100.117.241.64 - 100.117.241.127

The IP-only engine first does a search to get to the user data it may need to
include. It does so for with `SCRadixFindKeyIPV4ExactMatch` for single IPs, or
using `SCRadixFindKeyIPV4Netblock` in case of a netblock. Any "match" from
either of these is considered an "exact match" by the IP-only setup code.

This exact match expectation turned out to be wrong and
`SCRadixFindKeyIPV4Netblock` behaved more like "best match" instead, which is
a non-exact match, but its the next best match if no exact match is found.

The way the look up for 100.117.241.64/26 went wrong, is that it returned
the user data for 100.117.241.0/26. This happens as follows:

- first it would do an exact find, which didn't give a result

- then it removed bits from the keystream until it found a matching node
  and explore if any of the netmasks it contained matched. Here the first
  step of the bug started:

  it considered the netmask (with user data) a match that matched the
  number of bits of the matching key, but not of the actual range netmask cidr
  value.

  So in this case the number of shared bits between `100.117.241.0/25` and
  `100.117.241.64/26` was 25, so it assumed that the user data for the
  netmask 25 was the match.

  To summarize this step, there are 2 problems with this:
  1. it returns a match on something that isn't an exact match
  2. it considered the wrong netmask value

- the radix code then took the returned node, and did the netmask check
  again. This time it did use its own netmask value, so this time
  it did find the netmask 26 (+ user data). However because of the node that
  was returned, this netmask (+user data) belongs to `100.117.241.0`, not to
  `100.117.241.64`.

- the IP-only detection code was satisfied with what it assumed to be
  "exact match" and just updated the user data to include the user data that
  should have been associated with `100.117.241.64/26` to `100.117.241.0/26`.

This patch addresses the issue as follows:

It makes `SCRadixFindKeyIPV4Netblock` also return an exact match by propagating
the netmask in the search and in the evaluation of the stored netmasks.

It does away with the secondary netmask (+user data) evaluation.
`SCRadixFindKeyIPV4Netblock` is expected to handle this correctly.

The IP-only engine will fall back to the "not found" path, which does an explicit
"best match" lookup and then insert a new entry into the radix tree based on
the user data of the "best match".

Issue was present for IPv6 as well.

Bug: #5066.
(cherry picked from commit 6aa6e3f95372e256006b78e921391d88c1010f15)

3 years agodetect/iponly: cleanups
Victor Julien [Thu, 10 Feb 2022 08:04:23 +0000 (09:04 +0100)] 
detect/iponly: cleanups

(cherry picked from commit 6381b1a643bb9cc4ea8860def42b633a70c35e3e)

3 years agodetect/iponly: minor debug 'Print' improvements
Victor Julien [Thu, 10 Feb 2022 07:50:07 +0000 (08:50 +0100)] 
detect/iponly: minor debug 'Print' improvements

(cherry picked from commit de4354abcbbce376bc3047311561d0fbf16e4569)

3 years agoradix: minor debug 'Print' improvements
Victor Julien [Thu, 10 Feb 2022 07:49:17 +0000 (08:49 +0100)] 
radix: minor debug 'Print' improvements

(cherry picked from commit 3ca3c9dfbee112cc061ee0f3f7bbd5bde92a849d)

3 years agoutil/cidr: simplify IPv4 CIDR handling; add IPv6
Victor Julien [Thu, 17 Feb 2022 09:56:53 +0000 (10:56 +0100)] 
util/cidr: simplify IPv4 CIDR handling; add IPv6

Instead of building a table at init just calculate it on demand.

Callsites are all during init, so its not performance critical.

Add similar function for IPv6.

(cherry picked from commit e04d378e587d99fa40e1b237c0ef4db5cfde1902)

3 years agomqtt: parse properties with the right buffer's length
Philippe Antoine [Sun, 23 Jan 2022 20:30:22 +0000 (21:30 +0100)] 
mqtt: parse properties with the right buffer's length

(cherry picked from commit f0e869b26b6e913714db03b85039a0af38094419)

3 years agodcerpc: remove prev_tx_call_id and clear_bind_cache from DCERPCState
Eloy Pérez González [Thu, 4 Nov 2021 14:20:14 +0000 (15:20 +0100)] 
dcerpc: remove prev_tx_call_id and clear_bind_cache from DCERPCState

remove those fields since are not used because of the removal of
handle_bind_cache.

(cherry picked from commit 15f493f516a452ca810f77595fb57f8e2e96d6e3)

3 years agodcerpc: avoid delete the rpc state interface context
Eloy Pérez González [Fri, 22 Oct 2021 13:32:41 +0000 (15:32 +0200)] 
dcerpc: avoid delete the rpc state interface context

The bug:
The dcerpc dce_iface keyword just match the packet following the bind. Only the
next request after the rpc is sent will match. However the expected behaviour it
that all the rpc requests/responses sent under the context of the given
interface would match.

In the Open Group c706 the following is indicated:

In 2.2.1 Binding-related Operations, indicates that one category of binding
operations are those that "operations that establish internal call routing
information for the server." (The other are to establish the protocol which is
not relevant here). And the following statement can be found:

Operations in the second category establish a set of mappings that the server
can use to route calls internally to the appropriate manager routine. This
routing is based on the interface and version, operation and any object
requested by the call.

It indicates that server routes (to call methods) are based on the operation,
interface and object.

- Operation: To indicate the method to call, and operation number is
             specified as indicated in the second step of 2.3.3.2 (Client
             Binding Steps).
- Interface: An interface is a set of remotely callable operations offered by a
             server and invokable by clients. (2.1.1.1)
- Object: Is the manager that implements the interface, as stated in section
          Interface and Manager Selection of 2.3.3.3. It is not mandatory, can
          be nil.

To call a method, a client must send a request message as defined in 2.6.4.9,
that contains these identifiers:

- opnum: The opnum field identifies the operation being invoked within the
         interface.
- p_cont_id (Context ID in Wireshark): The p_cont_id field holds a presentation
                                       context identifier that identifies the
                                       data representation and interface, as
                                       defined in 12.6.3.4 (Context Identifiers).
- object: The object field is contained if the PFC_OBJECT_UUID is set. (Could be
          interesting to create a keyword dce_object for matching this UUID)

Therefore, to get the correct method to invoke, the server must map the context
to the correct interface. This is negotiated by the bind request

Interfaces are first negotiated using the bind message (12.6.4.3), contained in
the p_context_elem array. Then they are accepted or rejected using the bind_ack
message (12.6.4.4).

Once these contexts are established, both client and server can use the context
id, which is the index of the p_context_elem array, to refer the interface they
are using.

Moreover, in the middle of the connection, the context can be changed with the
alter_context message.

This is way suricata shouldn't delete the bindack attribute, that contains
the contexts, used by match_backuuid. This is the only way to know the interface
a request message is referring to.

ticket: 4769
https://redmine.openinfosecfoundation.org/issues/4769

(cherry picked from commit 1aca2676a6965056582c3da85e4bb2058aca43b0)

3 years agosmb/dce_iface: avoid deleting current ifaces from state
Eloy Pérez González [Fri, 22 Oct 2021 11:53:39 +0000 (13:53 +0200)] 
smb/dce_iface: avoid deleting current ifaces from state

The smb dce_iface keyword must match for all those dcerpc requests
and responses sent in the context of the given interface. They are
not matching as the current bind interfaces are deleted by any
non bind message.

Ticket: 4767
(cherry picked from commit bff0774767757b0ccab8165e293024fa39d0a952)

3 years agosmb/dce_iface: use DCERPC_TYPE_REQUEST
Eloy Pérez González [Fri, 22 Oct 2021 11:52:14 +0000 (13:52 +0200)] 
smb/dce_iface: use DCERPC_TYPE_REQUEST

The smb dce_iface keyword must match for all those dcerpc requests and
responses sent in the context of the given interface. They are not
matching because in rs_smb_tx_get_dce_iface, x.req_cmd is erroneously
compared with 1. Fix this by comparing with DCERPC_TYPE_REQUEST instead.

Ticket: 4767
(cherry picked from commit 1ae22fd5de3155c356c1191759cb7c066498a93e)

3 years agosmb/dce_opnum: move range if to outer context
Eloy Pérez González [Fri, 22 Oct 2021 13:01:39 +0000 (15:01 +0200)] 
smb/dce_opnum: move range if to outer context

The smb dce_opnum matches all the opnums that are higher that the
indicated opnum. This is due the range comparison if was put in the
exact comparison context, and in case the opnum doesn't match exactly,
then the range comparison is triggered (the upper limit is always true).

Move the erroneus if to the outer context, as else option of the block
checks if comparison should be exact or range.

Ticket: 4767
(cherry picked from commit 333db3b3852899885f1c2a251b4643b124e3cb18)

3 years agosmb/dce_opnum: use DCERPC_TYPE_REQUEST
Eloy Pérez González [Fri, 22 Oct 2021 13:00:11 +0000 (15:00 +0200)] 
smb/dce_opnum: use DCERPC_TYPE_REQUEST

The smb dce_opnum keyword doesn't match the dcerpc requests/responses.
This occurs because in the rs_smb_tx_match_dce_opnum function, the
x.req_cmd is matched against the erroneous code 1. Fix this by using
DCERPC_TYPE_REQUEST for the comparison instead.

Ticket: 4767
(cherry picked from commit 8dca3d0416f539f5086f72f69d71cfc418355a2f)

3 years agogithub-ci: replace failing CentOS 8 by AlmaLinux 8.4
Victor Julien [Mon, 31 Jan 2022 10:42:10 +0000 (11:42 +0100)] 
github-ci: replace failing CentOS 8 by AlmaLinux 8.4

(cherry picked from commit 6c240938b51daadb6c869d2339c2e7cc29ebde68)

3 years agogithub-ci: use curl -L for npcap: follow redirects 6883/head
Jason Ish [Fri, 21 Jan 2022 05:21:08 +0000 (23:21 -0600)] 
github-ci: use curl -L for npcap: follow redirects

(cherry picked from commit 90996958aa32ef3ff789c28b6efcb8ded2cef342)

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

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

(cherry picked from commit 41a139b590a059171d0517a455c562486e1a21c2)

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

Issue: #4895

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

file_data doesn't support the NFS protocol.

(cherry picked from commit 215335fdc6431e1c5de6155aa64c152bda507b72)

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

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

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

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

Issue: 4947

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

(cherry picked from commit fc6fdef07006e5382839ef88873e90754b30e6e0)

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

(cherry picked from commit 2a5d79e42609bd5ae0d0456cd5c458e20670160e)

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

Ticket #4515

(cherry picked from commit 0861b66e152c6d2a0517a4a043ef56bdb1be4d76)

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

[Edit by Jason Ish: fix flag bit value]

Ticket #4515

(cherry picked from commit dfb6f105e8b104bf27cce24b650d047d0925c145)

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

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

Ticket #4924

(cherry picked from commit fcbdc304265aaba724b245a5c3f02e00c8059a1a)

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

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

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

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

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

To hide the ifdefs for capture offload.

(cherry picked from commit b19d1df69f47b4b85337f1695bc770f4b0703bac)

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

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

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

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

Ticket 4744

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

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

Ticket 4978

(cherry picked from commit 286c510ece27c8fd408434c1786df26aba0c5581)

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

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

(cherry picked from commit 7be793f7b479d66977ff68ea1ca3c832c744b3d2)

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

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

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

Ticket 4239

(cherry picked from commit 92eb14c5adc985433dd44bdcac18fa6e67440043)

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

It differentiates memory error than regular ones.

(cherry picked from commit 0e70958e67398f599b77ba991dc631e025cae5f4)

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

Ticket: 4812

When adding many sequence nodes

(cherry picked from commit 15649424a76d01eb332d85620ffc4956d4f3d9be)