]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
13 months agodetect/snmp: do not bother to free a null pointer 11419/head 11432/head
Philippe Antoine [Tue, 2 Jul 2024 07:26:23 +0000 (09:26 +0200)] 
detect/snmp: do not bother to free a null pointer

Ticket: 7134

13 months agogithub-actions: remove build for EOL centos:7 11405/head
Victor Julien [Tue, 2 Jul 2024 18:02:49 +0000 (20:02 +0200)] 
github-actions: remove build for EOL centos:7

13 months agodetect/noalert: point noalert/alert to new doc
Victor Julien [Fri, 7 Jun 2024 19:02:00 +0000 (21:02 +0200)] 
detect/noalert: point noalert/alert to new doc

(cherry picked from commit d02054fa3168c05de7eb87ae5ce0120b44aba8b4)

13 months agodoc/userguide: add noalert/alert keyword docs
Victor Julien [Thu, 6 Jun 2024 10:25:51 +0000 (12:25 +0200)] 
doc/userguide: add noalert/alert keyword docs

(cherry picked from commit 50ef646d4524d9e53554b618bc0e4bede3745dde)

13 months agodoc/userguide: give pcre1 to pcre2 proper heading
Victor Julien [Thu, 6 Jun 2024 09:46:55 +0000 (11:46 +0200)] 
doc/userguide: give pcre1 to pcre2 proper heading

(cherry picked from commit c83e3285ae6f5dfd01a750e83ccfd4d9e57b7d47)

13 months agodetect: implement 'alert' keyword as a companion to 'noalert'
Victor Julien [Fri, 12 Jan 2024 13:00:37 +0000 (14:00 +0100)] 
detect: implement 'alert' keyword as a companion to 'noalert'

This can be used to implement alert then pass logic.

Add support for alert-then-pass to alert handling routines.

Ticket: #5466.
(cherry picked from commit d5fb8204b6b30b9617ebd95dd12c87a812b2cb5a)

13 months agodetect: set ACTION_ALERT for rules that should alert
Victor Julien [Fri, 12 Jan 2024 10:14:27 +0000 (11:14 +0100)] 
detect: set ACTION_ALERT for rules that should alert

Replaces default "alert" logic and removed SIG_FLAG_NOALERT.

Instead, "noalert" unsets ACTION_ALERT. Same for flowbits:noalert and
friends.

In signature ordering rules w/o action are sorted as if they have 'alert',
which is the same behavior as before, but now implemented explicitly.

Ticket: #5466.
(cherry picked from commit 92581dbc0669464e2e3ed2b84c8e0695418879c3)

13 months agodetect/flowbits: remove DETECT_FLOWBITS_CMD_NOALERT
Shivani Bhardwaj [Sat, 9 Dec 2023 07:19:31 +0000 (12:49 +0530)] 
detect/flowbits: remove DETECT_FLOWBITS_CMD_NOALERT

DETECT_FLOWBITS_CMD_NOALERT is misleading as it gives an impression that
noalert is a flowbit specific command that'll be used and dealt with at
some point but as soon as noalert is found in the rule lang, signature
flag for noalert is set and control is returned. It never gets added to
cmd of the flowbits object.

(cherry picked from commit 75471dd69b78d0915819b978e937483dca8b4a04)

13 months agodetect/alert: minor loop cleanup
Victor Julien [Fri, 12 Jan 2024 12:41:17 +0000 (13:41 +0100)] 
detect/alert: minor loop cleanup

(cherry picked from commit 8f72a04973764ea849096cec3ee828e7ce4891ec)

13 months agodetect/noalert: minor cleanup
Victor Julien [Fri, 12 Jan 2024 08:51:02 +0000 (09:51 +0100)] 
detect/noalert: minor cleanup

(cherry picked from commit 44e7fdc3ca9add50e254f4c87fad63e8d0fe246f)

13 months agochangelog: update 7.0.6 CVEs and titles 11391/head
Shivani Bhardwaj [Fri, 28 Jun 2024 02:59:47 +0000 (08:29 +0530)] 
changelog: update 7.0.6 CVEs and titles

13 months agoversion: start development towards 7.0.7 11378/head 11385/head
Shivani Bhardwaj [Thu, 27 Jun 2024 11:02:04 +0000 (16:32 +0530)] 
version: start development towards 7.0.7

13 months agorelease: 7.0.6; update changelog suricata-7.0.6
Shivani Bhardwaj [Wed, 26 Jun 2024 07:02:03 +0000 (12:32 +0530)] 
release: 7.0.6; update changelog

13 months agohttp2: do not expand duplicate headers
Philippe Antoine [Mon, 17 Jun 2024 14:30:49 +0000 (16:30 +0200)] 
http2: do not expand duplicate headers

Ticket: 7104

As this can cause a big mamory allocation due to the quadratic
nature of the HPACK compression.

(cherry picked from commit 5bd17934df321b88f502d48afdd6cc8bad4787a7)

13 months agomodbus: abort flow parsing on flood
Philippe Antoine [Thu, 25 Apr 2024 19:24:33 +0000 (21:24 +0200)] 
modbus: abort flow parsing on flood

Ticket: 6987

Let's not spend more resources for a flow which is trying to
make us do it...

(cherry picked from commit 37509e8e0ed097f8e0174df754835ac60584fc72)

13 months agodefrag: don't use completed tracker
Victor Julien [Tue, 4 Jun 2024 12:43:22 +0000 (14:43 +0200)] 
defrag: don't use completed tracker

When a Tracker is set up for a IPID, frags come in for it and it's
reassembled and complete, the `DefragTracker::remove` flag is set. This
is mean to tell the hash cleanup code to recyle the tracker and to let
the lookup code skip the tracker during lookup.

A logic error lead to the following scenario:

1. there are sufficient frag trackers to make sure the hash table is
   filled with trackers
2. frags for a Packet with IPID X are processed correctly (X1)
3. frags for a new Packet that also has IPID X come in quickly after the
   first (X2).
4. during the lookup, the frag for X2 hashes to a hash row that holds
   more than one tracker
5. as the trackers in hash row are evaluated, it finds the tracker for
   X1, but since the `remove` bit is not checked, it is returned as the
   tracker for X2.
6. reassembly fails, as the tracker is already complete

The logic error is that only for the first tracker in a row the `remove`
bit was checked, leading to reuse to a closed tracker if there were more
trackers in the hash row.

Ticket: #7042.

13 months agodetect: add to signature mask for decode events 11361/head 11364/head
Philippe Antoine [Wed, 19 Jun 2024 11:42:32 +0000 (13:42 +0200)] 
detect: add to signature mask for decode events

Ticket: 6291
(cherry picked from commit 0a953fe1ce2a030916b094aac7618d039ecff485)

13 months agodetect: fix check for app_layer events
Philippe Antoine [Wed, 19 Jun 2024 11:39:08 +0000 (13:39 +0200)] 
detect: fix check for app_layer events

Ticket: 7106
(cherry picked from commit 4e584ed20165f2af32f13f75d71f64ff24bafc5b)

13 months agodoc: port user install and build instruction from master-6.0.x 11352/head 11354/head
Lukas Sismis [Tue, 16 Jan 2024 14:27:56 +0000 (15:27 +0100)] 
doc: port user install and build instruction from master-6.0.x

Ticket: #6685
(cherry picked from commit bd9608771e7392800b7526a3bffce438e5271d4c)

13 months agogithub-ci: add minimal build for Ubuntu and AlmaLinux
Lukas Sismis [Thu, 11 Apr 2024 20:55:22 +0000 (22:55 +0200)] 
github-ci: add minimal build for Ubuntu and AlmaLinux

(cherry picked from commit cd7c35eb5a047d7bf10c2abadb458b4140db9676)

13 months agogithub-ci: remove gosu from installed packages
Lukas Sismis [Thu, 11 Apr 2024 20:54:43 +0000 (22:54 +0200)] 
github-ci: remove gosu from installed packages

(cherry picked from commit 6d663ec8852cf0db6a12cc6d1c581b2b5610d63d)

13 months agodoc: update eBPF compilation instructions
Lukas Sismis [Tue, 16 Jan 2024 13:47:08 +0000 (14:47 +0100)] 
doc: update eBPF compilation instructions

Ticket: #6599
(cherry picked from commit 521d1cb8e70d2a0ace2b50b130e56874b502425d)

13 months agorust/ike: prefix never read field names with _ 11348/head
Jason Ish [Thu, 20 Jun 2024 16:27:24 +0000 (10:27 -0600)] 
rust/ike: prefix never read field names with _

New warning from rustc.

The other option is to allow dead code, however this is more explicit,
and when they are read, its obvious they should be renamed.

13 months agorust: fix clippy lint for legacy_numeric_constants
Jason Ish [Thu, 20 Jun 2024 16:23:31 +0000 (10:23 -0600)] 
rust: fix clippy lint for legacy_numeric_constants

https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants

13 months agorust: rename .cargo/config to .cargo/config.toml
Jason Ish [Thu, 16 May 2024 16:42:53 +0000 (10:42 -0600)] 
rust: rename .cargo/config to .cargo/config.toml

Addresses this warning from the Rust compiler:

warning: `../rust/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
(cherry picked from commit 8560564657735a4c22004d51db9775ca2f1d9645)

13 months agocargo: use default-features instead of default_features
Jason Ish [Thu, 20 Jun 2024 16:18:24 +0000 (10:18 -0600)] 
cargo: use default-features instead of default_features

"default_features" is being deprecated in Rust 2024.

13 months agorust: simply matches with unwrap_or_default
Jason Ish [Thu, 20 Jun 2024 16:17:27 +0000 (10:17 -0600)] 
rust: simply matches with unwrap_or_default

New default clippy warning:
https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default

13 months agoprofiling: check packet flag first
Eric Leblond [Wed, 8 Nov 2023 20:20:28 +0000 (21:20 +0100)] 
profiling: check packet flag first

This fixes the state handling and simplify the logic.

(cherry picked from commit b128a75973a2a73d28a4bd5b0a8c12cce4fc7d8f)

13 months agoprofiling: add option to active rules profiling at start
Eric Leblond [Wed, 8 Nov 2023 20:18:33 +0000 (21:18 +0100)] 
profiling: add option to active rules profiling at start

When replaying a pcap file, it is not possible to get rules
profiling because it has to be activated from the unix socket.
This patch adds a new option to be able to activate profiling
collection at start so a pcap run can get rules profiling
information.

(cherry picked from commit eecb3440e21c428e86bc60e1bbe5808ef4c27a6c)

13 months agosmtp: respect quotes for to and cc logging
Philippe Antoine [Tue, 4 Jun 2024 13:24:18 +0000 (15:24 +0200)] 
smtp: respect quotes for to and cc logging

When splitting the field over commas, skip the commas
which are innside quotes

Ticket: 7060

Not a direct backport, but heavily inspired by new rust code
handling it

13 months agoeve/schema: complete and reorder smtp fields
Philippe Antoine [Thu, 23 May 2024 12:52:46 +0000 (14:52 +0200)] 
eve/schema: complete and reorder smtp fields

received and cc were missing

(cherry picked from commit 8d4699fbba46ff1e75a21be3701776bd936afb9e)

13 months agosmtp: exit data mode if data command was rejected
Philippe Antoine [Sat, 30 Mar 2024 14:05:26 +0000 (15:05 +0100)] 
smtp: exit data mode if data command was rejected

And the server was advertising pipelining.

Ticket: 6906
(cherry picked from commit ed895c04ff1239bd75f97a1fd7a4b53706f7f25c)

13 months agooutput/ja4: Log ja4 hashes iff configured 11276/head 11288/head
Jeff Lucovsky [Wed, 5 Jun 2024 13:06:39 +0000 (09:06 -0400)] 
output/ja4: Log ja4 hashes iff configured

This commit allows ja4 hashes to be logged iff enabled in the tls/quic
section of the outputs.

With the default setting ("off"), ja4 hashes will only be logged in
alerts when the signatures uses the ja4.hash keyword.

When enabled, ja4 hashes will be inclued in quic and tls logs.

- tls:
     ja4: on
- quic:
     ja4: on

Issue: 7010

13 months agooutput/ja4: Restrict ja4 hashes to alerts
Jeff Lucovsky [Sat, 1 Jun 2024 12:52:27 +0000 (08:52 -0400)] 
output/ja4: Restrict ja4 hashes to alerts

This commit restricts ja4 hash output to alerts; ja4 hashes will not be
in tls or quic events.

Issue: 7010

13 months agotests/ja4: config message when ja4 auto enabled
Jeff Lucovsky [Wed, 8 May 2024 14:08:13 +0000 (10:08 -0400)] 
tests/ja4: config message when ja4 auto enabled

Issue: 7010

This commit displays a config message when JA4 is enabled due to rule
usage.

13 months agoja4: implement for TLS and QUIC
Sascha Steinbiss [Sat, 24 Feb 2024 10:10:47 +0000 (11:10 +0100)] 
ja4: implement for TLS and QUIC

Ticket: OISF#6379
(cherry picked from commit 120313f4daf2b2501f7ab098954e91f550413c96)

13 months agoja3: make feature compile time configurable
Sascha Steinbiss [Fri, 12 Apr 2024 17:54:23 +0000 (19:54 +0200)] 
ja3: make feature compile time configurable

(cherry picked from commit 9d0db71ebf65919215b9e09a1b8fbbbc27560388)

13 months agosuricata: initialize feature tracking earlier
Sascha Steinbiss [Sat, 24 Feb 2024 09:34:50 +0000 (10:34 +0100)] 
suricata: initialize feature tracking earlier

This gives app layer code a chance to access feature
information.

(cherry picked from commit 32f23b6d2f71a289e78e67b9121dfa661c78aef3)

14 months agodoc: add source verification docs 11256/head
jason taylor [Wed, 22 May 2024 01:04:09 +0000 (21:04 -0400)] 
doc: add source verification docs

Ticket: #6908

Signed-off-by: jason taylor <jtfas90@gmail.com>
(cherry picked from commit 47d6c3a3ab632dca72e60b753afa60521f0ea079)

14 months agogithub-actions: bump scan-build to Ubuntu 24.04 / clang 18
Victor Julien [Sat, 25 May 2024 05:04:29 +0000 (07:04 +0200)] 
github-actions: bump scan-build to Ubuntu 24.04 / clang 18

(cherry picked from commit e0411878fc1ba790bdce13f59f7bf1bfa211bdaf)

14 months agodetect/tls.store: fix direction check
Victor Julien [Sat, 25 May 2024 07:36:48 +0000 (09:36 +0200)] 
detect/tls.store: fix direction check

STREAM_* flags are invalid for `Flow::flags`.

Fixes: dfcb4295240f ("detect/cert: Use client side certs")
(cherry picked from commit 032bc04a1e8a5fe099327e74ef15143a1cf78024)

14 months agoutil/radix-tree: fix potential dereference of nullptr
Alexey Simakov [Tue, 28 May 2024 16:36:58 +0000 (19:36 +0300)] 
util/radix-tree: fix potential dereference of nullptr

Fix potential dereferece of nullptr in case of
unsuccessful allocation of memory leak for tree nodes

Bug: #7049
(cherry picked from commit a8217d288afe91efe8d6e222fd5b1788cec6c976)

14 months agooutput/lua: handle registration error
Victor Julien [Sat, 1 Jun 2024 14:11:10 +0000 (16:11 +0200)] 
output/lua: handle registration error

Use error message instead of info message.

(cherry picked from commit 621fe38dbfe64e834557a6374144dce8bbf89630)

14 months agooutput/streaming: suppress noisy start up message
Victor Julien [Sat, 1 Jun 2024 14:11:36 +0000 (16:11 +0200)] 
output/streaming: suppress noisy start up message

(cherry picked from commit 3b1fecbab1dbd4fdccb0c6b27b11c2e8f329ca23)

14 months agogithub-action: remove end of life CentOS 8 stream
Victor Julien [Mon, 3 Jun 2024 16:24:57 +0000 (18:24 +0200)] 
github-action: remove end of life CentOS 8 stream

(cherry picked from commit 130d75f0254d992ceb956ab67edc76e8bec40f62)

14 months agoeve: revert ethernet addresses when needed 11217/head
Eric Leblond [Sun, 15 Oct 2023 13:39:40 +0000 (15:39 +0200)] 
eve: revert ethernet addresses when needed

EVE logging has a direction parameter that can cause the logging
of an application layer to be done in a direction that is not linked
to the packet. As a result the source IP addres could be assigned the
MAC address of the destination IP and reverse.

This patch addresses this by propagating the direction to the ethernet
logging function and using it there to define the correct mapping.

Issue #6405

(cherry picked from commit 21916b974304998d38cfcafe543ee7b94e268daf)

14 months agothreads: give threads more time to get ready 11181/head 11202/head
Victor Julien [Wed, 29 May 2024 05:03:24 +0000 (07:03 +0200)] 
threads: give threads more time to get ready

In certain conditions, it can take a long time for threads to start up.
For example in af-packet, setting up the socket, rings, etc has been
observed to take close to half a second per thread, and since the
threads go one by one in a preset order, this means the start up can
take a lot of time if there are many threads. The old logic would just
allow a hard coded 60s. This was not always enough when the number of
threads was high.

This patch makes the wait time take the number of threads into account.
It adds a second of time budget to the base 60s for each thread.

So as an example, if a system has 112 af-packet threads, it would wait
172 seconds (60 + 112) for the threads to get ready.

Ticket: #7048.
(cherry picked from commit 41b9836b11bbd653953f5c5dc5f87875e15fae8d)

14 months agothreads: optimize start up check
Victor Julien [Mon, 27 May 2024 15:12:09 +0000 (17:12 +0200)] 
threads: optimize start up check

When starting a large amount of threads, the loop was inefficient. It
would loop over the threads and if one wasn't yet ready it would sleep a
bit and then reevaluate all the threads. This reevaluation of threads
already checked was inefficient, and could lead to the time budget
running out.

This patch splits the check, and keeps track of the threads that have
already passed. This avoids the rescanning of already checked threads.

(cherry picked from commit 85fd4b2ec7d1812a3833ca715b39f18be448e64c)

14 months agodetect/port: remove SigGroupHead* ops 11142/head
Shivani Bhardwaj [Wed, 28 Feb 2024 14:29:04 +0000 (19:59 +0530)] 
detect/port: remove SigGroupHead* ops

The functions in detect-engine-port.c are only being used at the time of
parsing the ports from rules initially. Since there are no SGHs at that
point, remove the ops related to them too.

(cherry picked from commit e14fefe24a6e4e93d1c443d5691e4f7b88d8e5ee)

14 months agodetect/port: clang fmt changes
Shivani Bhardwaj [Fri, 29 Mar 2024 12:46:16 +0000 (18:16 +0530)] 
detect/port: clang fmt changes

14 months agodetect/port: handle range and upper boundary ports
Shivani Bhardwaj [Mon, 25 Mar 2024 13:38:31 +0000 (19:08 +0530)] 
detect/port: handle range and upper boundary ports

So far, if a port was found to be single which was earlier a part of the
range, port + 1 was added to the list to honor the range that it was a
part of. But, this is incorrect in case the port is 65535 or if the port
was found to be of range when it was earlier a single port.

Bug 6896

(cherry picked from commit 4227e52c4b3a5118f42675e0fae28178c026d7fd)

14 months agodetect/port: fix grouping of ports w gaps
Shivani Bhardwaj [Thu, 21 Mar 2024 08:45:39 +0000 (14:15 +0530)] 
detect/port: fix grouping of ports w gaps

If a single port happens before a range port, the port groups created
were incorrect. Fix it to use smarter range check.

For example, given,
80:80 - SGH1
100:120 - SGH2

Range created should be
80:80 - SGH1
100:120 - SGH2

Bug 6881

(cherry picked from commit 7d937db5cb87e0ab2ed3c435db109c11ed95e676)

14 months agodetect/port: handle single port that is range too
Shivani Bhardwaj [Sat, 9 Mar 2024 04:21:57 +0000 (09:51 +0530)] 
detect/port: handle single port that is range too

If a port point is single but later on also a part of a range, it ends
up only creating the port groups for single points and not the range.
Fix it by adding the port next to current single one to unique points
and marking it a range port.

Bug 6843

(cherry picked from commit 632ca75dd3f49bee865f047cc5336870f3a431d2)

14 months agoutil/interval-tree: fix coverity warning
Shivani Bhardwaj [Fri, 8 Mar 2024 08:36:31 +0000 (14:06 +0530)] 
util/interval-tree: fix coverity warning

Fix Coverity warning

** CID 1592992:  Incorrect expression  (COPY_PASTE_ERROR)
/src/util-port-interval-tree.c: 255 in SCPortIntervalFindOverlaps()

________________________________________________________________________________________________________
*** CID 1592992:  Incorrect expression  (COPY_PASTE_ERROR)
/src/util-port-interval-tree.c: 255 in SCPortIntervalFindOverlaps()
249                      * will be sorted, insert any new ports to the end of the list
250                      * and avoid walking the entire list */
251                     if (*list == NULL) {
252                         *list = new_port;
253                         (*list)->last = new_port;
254                     } else if (((*list)->last->port != new_port->port) &&
>>>     CID 1592992:  Incorrect expression  (COPY_PASTE_ERROR)
>>>     "port" in "(*list)->last->port2 != new_port->port" looks like a copy-paste error.
255                                ((*list)->last->port2 != new_port->port)) {
256                         DEBUG_VALIDATE_BUG_ON(new_port->port < (*list)->last->port);
257                         (*list)->last->next = new_port;
258                         new_port->prev = (*list)->last;
259                         (*list)->last = new_port;
260                     } else {

The code does not generate two port ranges that are same other than the
cases where port == port2 which is why it worked so far. Fix it.

Bug 6839

(cherry picked from commit 2d6708f1ff1e57f83f2dd9994173e8ee62e00616)

14 months agodetect: optimize sig_cnt setting
Victor Julien [Tue, 5 Mar 2024 07:36:08 +0000 (13:06 +0530)] 
detect: optimize sig_cnt setting

Utilize _popcnt64 where available.

(cherry picked from commit c4ac6cd)

14 months agodetect: optimize group head bitarray handling
Victor Julien [Tue, 5 Mar 2024 07:35:31 +0000 (13:05 +0530)] 
detect: optimize group head bitarray handling

During startup large rulesets use a lot of large bitarrays, that
are frequently merged (OR'd).

Optimize this using SSE2 _mm_or_si128.

(cherry picked from commit 94b4619)

14 months agodetect: prepare for SIMD optimizations
Victor Julien [Mon, 26 Feb 2024 09:52:09 +0000 (10:52 +0100)] 
detect: prepare for SIMD optimizations

Make rule group head bitarray 16 bytes aligned and padded to 16 bytes
boundaries to assist SIMD operations in follow up commits.

(cherry picked from commit 4ba1f44e0d882ffb6d7d93b2864c9dd405f78ea5)

14 months agodetect/port: use qsort instead of insert sort
Victor Julien [Mon, 26 Feb 2024 16:08:21 +0000 (21:38 +0530)] 
detect/port: use qsort instead of insert sort

Instead of using in place insertion sort on linked list based on two
keys, convert the linked list to an array, perform sorting on it using
qsort and convert it back to a linked list. This turns out to be much
faster.

Ticket #6795

(cherry picked from commit e7e4305d91a05acde921b5bc87f7adbdf566def6)

14 months agodetect/port: merge port ranges for same signatures
Shivani Bhardwaj [Wed, 21 Feb 2024 06:42:30 +0000 (12:12 +0530)] 
detect/port: merge port ranges for same signatures

To avoid getting multiple entries in the final port list and to also
make the next step more efficient by reducing the size of the items to
traverse over.

Ticket 6792
Bug 6414

(cherry picked from commit 643ae85b5faa91958fe9ee79987fa20f06849059)

14 months agodetect/port: remove the port cut/insertion stage
Shivani Bhardwaj [Tue, 20 Feb 2024 16:23:14 +0000 (21:53 +0530)] 
detect/port: remove the port cut/insertion stage

As this is already taken care of and a list of ports is available for
use by the next stage.

Ticket 6792
Bug 6414

(cherry picked from commit 83aba93f40b0c12b5336f1f5281ae33b726f57ea)

14 months agodetect/port: create list of small port ranges
Shivani Bhardwaj [Tue, 20 Feb 2024 16:22:38 +0000 (21:52 +0530)] 
detect/port: create list of small port ranges

Using the unique port points, create a list of small port ranges which
contain the DetectPort objects and the designated SGHs found by finding
the overlaps with the existing ports and copying the SGHs accordingly.

Ticket 6792
Bug 6414

(cherry picked from commit 4ac2382f26e75d73b2ee23d7555cca616a8dfe92)

14 months agodetect/port: create a tree of given ports
Shivani Bhardwaj [Fri, 16 Feb 2024 09:18:46 +0000 (14:48 +0530)] 
detect/port: create a tree of given ports

After all the SGHs have been appropriately copied to the designated
ports, create an interval tree out of it for a faster lookup when later
a search for overlaps is made.

Ticket 6792
Bug 6414

(cherry picked from commit a02c44a3a439964c0dd47d602487776bbacd8ef1)

14 months agodetect/port: find unique port points
Shivani Bhardwaj [Fri, 16 Feb 2024 08:57:52 +0000 (14:27 +0530)] 
detect/port: find unique port points

In order to create the smallest possible port ranges, it is convenient
to first have a list of unique ports. Then, the work becomes simple. See
below:

Given, a port range P1 = [1, 8]; SGH1
and another, P2 = [3, 94]; SGH2

right now, the code will follow a logic of recursively cutting port
ranges until we create the small ranges. But, with the help of unique
port points, we get, unique_port_points = [1, 3, 8, 94]

So, now, in a later stage, we can create the ranges as
[1, 2], [3, 7], [8, 8], [9, 94] and copy the designated SGHs where they
belong. Note that the intervals are closed which means that the range
is inclusive of both the points.

The final result becomes:
1. [1, 2]; SGH1
2. [3, 7]; SGH1 + SGH2
3. [8, 8]; SGH1 + SGH2
4. [9, 94]; SGH2

There would be 3 unique rule groups made for the case above.
Group 1: [1, 2]
Group 2: [3, 7], [8, 8]
Group 3: [9, 94]

Ticket 6792
Bug 6414

(cherry picked from commit c9a911b6f8a5822058590d62df8930ecef8df5c0)

14 months agoutil/interval-tree: suppress cppcheck warnings
Shivani Bhardwaj [Mon, 4 Mar 2024 08:21:59 +0000 (13:51 +0530)] 
util/interval-tree: suppress cppcheck warnings

Warning was:
src/util-port-interval-tree.c:50:1: warning: Either the condition 'tmp!=NULL' is redundant or there is possible null pointer dereference: tmp. [nullPointerRedundantCheck]
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: note: Assuming that condition 'tmp!=NULL' is not redundant
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: note: Null pointer dereference
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: warning: Either the condition 'oleft!=NULL' is redundant or there is possible null pointer dereference: oleft. [nullPointerRedundantCheck]
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: note: Assuming that condition 'oleft!=NULL' is not redundant
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: note: Null pointer dereference
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: warning: Either the condition 'oright!=NULL' is redundant or there is possible null pointer dereference: oright. [nullPointerRedundantCheck]
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: note: Assuming that condition 'oright!=NULL' is not redundant
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: note: Null pointer dereference
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: warning: Either the condition 'left!=NULL' is redundant or there is possible null pointer dereference: left. [nullPointerRedundantCheck]
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: note: Assuming that condition 'left!=NULL' is not redundant
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^
src/util-port-interval-tree.c:50:1: note: Null pointer dereference
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate);
^

(cherry picked from commit 86f89e096643bd4790e6f5831267928f240410ec)

14 months agoutil/interval-tree: add utility fns
Shivani Bhardwaj [Fri, 16 Feb 2024 08:07:23 +0000 (13:37 +0530)] 
util/interval-tree: add utility fns

Add new utility files to deal with the interval trees. These cover the
basic ops:
1. Creation/Destruction of the tree
2. Creation/Destruction of the nodes

It also adds the support for finding overlaps for a given set of ports.
This function is used by the detection engine is the Stage 2 of
signature preparation.

Ticket 6792
Bug 6414

Co-authored-by: Victor Julien <vjulien@oisf.net>
(cherry picked from commit 54558f1b4acd5983d332864acc049216b9915210)

14 months agodetect/port: make DetectPortInit non static
Shivani Bhardwaj [Wed, 14 Feb 2024 11:09:02 +0000 (16:39 +0530)] 
detect/port: make DetectPortInit non static

as this fn will be called upon and further used by other files later on.

Ticket 6792
Bug 6414

14 months agointerval-tree: add augmentation fns to the tree
Shivani Bhardwaj [Mon, 29 Jan 2024 06:08:51 +0000 (11:38 +0530)] 
interval-tree: add augmentation fns to the tree

An interval tree uses red-black tree as its base data structure and
follows all the properties of a usual red-black tree. The additional
params are:
1. An interval such as [low, high] per node.
2. A max attribute per node. This attribute stores the maximum high
   value of any subtree rooted at this node.

At any point in time, an inorder traversal of an interval tree should
give the port ranges sorted by the low key in ascending order.

This commit modifies the IRB_AUGMENT macro and it's call sites to make
sure that on every insertion, the max attribute of the tree is properly
updated.

Ticket 6792
Bug 6414

(cherry picked from commit d36d03a4289e03b61cdd3617607bf0df1ce4d706)

14 months agointerval-tree: remove splay tree implementation
Shivani Bhardwaj [Fri, 16 Feb 2024 07:17:49 +0000 (12:47 +0530)] 
interval-tree: remove splay tree implementation

Ticket 6792
Bug 6414

(cherry picked from commit 30b6e4d368b4b4ad58322ee7781d10c009133374)

14 months agointerval-tree: add base data structure
Shivani Bhardwaj [Fri, 16 Feb 2024 07:14:10 +0000 (12:44 +0530)] 
interval-tree: add base data structure

Ticket 6792
Bug 6414

(cherry picked from commit fde4ca5608137bc8a9091070ec3d88b435d73e3f)

14 months agodetect/engine: fix whitelisting check
Victor Julien [Fri, 12 Jan 2024 07:03:06 +0000 (12:33 +0530)] 
detect/engine: fix whitelisting check

In the commit 4a00ae607, the whitelisting check was updated in a quest
to make use of the conditional better but it made things worse as every
range would be whitelisted as long as it had any of the default
whitelisted port which is very common.

(cherry picked from commit fb9680bb7b17f6744c9f6f26abf4c902c83de8f3)

14 months agodetect: log relevant frames app-layer metadata 11135/head
Philippe Antoine [Fri, 19 Apr 2024 07:57:04 +0000 (09:57 +0200)] 
detect: log relevant frames app-layer metadata

Ticket: 6973

Completes commit 2b4e10224eaebb613352e9b82556b60035d032a1

(cherry picked from commit 9e01956e77e741ce9c1b9d6f64726de8054d37d9)

14 months agodetect: use direction-based tx for app-layer logging
Philippe Antoine [Thu, 18 Apr 2024 09:54:34 +0000 (11:54 +0200)] 
detect: use direction-based tx for app-layer logging

When we only have stream matches.

Ticket: 6846

This solves the case where another transaction was created
by parsing data in the other direction, before running the
detection.

Like
1. get data in direction 1
2. acked data: parse it, but do not run detection in dir 1
3. other data in direction 2
4. other data acked : parse it and create new tx,
then run detection for direction 1 with data from first packet

(cherry picked from commit 7274ad58aaeab5a65d49aa8d60839d7cf1f56e00)

14 months agooutput/alert: check flag before logging app-layer
Philippe Antoine [Wed, 13 Mar 2024 20:26:05 +0000 (21:26 +0100)] 
output/alert: check flag before logging app-layer

Ticket: 6846
(cherry picked from commit 2b4e10224eaebb613352e9b82556b60035d032a1)

14 months agooutput: do not use tx id 0 when there is no tx
Philippe Antoine [Mon, 11 Mar 2024 13:06:50 +0000 (14:06 +0100)] 
output: do not use tx id 0 when there is no tx

Ticket: 6846

This led to packet rules logging irrelevant app-layer data

(cherry picked from commit 910f6af54fa37cde1790bbff46162b7dee864bb6)

14 months agodecode/ppp: fix iplen check int handling
Victor Julien [Tue, 16 Apr 2024 06:26:40 +0000 (08:26 +0200)] 
decode/ppp: fix iplen check int handling

** CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
/src/decode-ppp.c: 64 in DecodePPPCompressedProto()
/src/decode-ppp.c: 55 in DecodePPPCompressedProto()

________________________________________________________________________________________________________
*** CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
/src/decode-ppp.c: 64 in DecodePPPCompressedProto()
58             case 0x57: { /* PPP_IPV6 */
59                 if (unlikely(len < (data_offset + IPV6_HEADER_LEN))) {
60                     ENGINE_SET_INVALID_EVENT(p, PPPIPV6_PKT_TOO_SMALL);
61                     return TM_ECODE_FAILED;
62                 }
63                 DEBUG_VALIDATE_BUG_ON(len < data_offset);
>>>     CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
>>>     "65535 /* 32767 * 2 + 1 */ < (uint16_t)(len - data_offset)" is always false regardless of the values of its operands. This occurs as the logical first operand of "?:".
64                 uint16_t iplen = MIN(USHRT_MAX, (uint16_t)(len - data_offset));
65                 return DecodeIPV6(tv, dtv, p, pkt + data_offset, iplen);
66             }
67             case 0x2f: /* PPP_VJ_UCOMP */
68                 if (unlikely(len < (data_offset + IPV4_HEADER_LEN))) {
69                     ENGINE_SET_INVALID_EVENT(p, PPPVJU_PKT_TOO_SMALL);
/src/decode-ppp.c: 55 in DecodePPPCompressedProto()
49             case 0x21: { /* PPP_IP */
50                 if (unlikely(len < (data_offset + IPV4_HEADER_LEN))) {
51                     ENGINE_SET_INVALID_EVENT(p, PPPVJU_PKT_TOO_SMALL);
52                     return TM_ECODE_FAILED;
53                 }
54                 DEBUG_VALIDATE_BUG_ON(len < data_offset);
>>>     CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
>>>     "65535 /* 32767 * 2 + 1 */ < (uint16_t)(len - data_offset)" is always false regardless of the values of its operands. This occurs as the logical first operand of "?:".
55                 uint16_t iplen = MIN(USHRT_MAX, (uint16_t)(len - data_offset));
56                 return DecodeIPV4(tv, dtv, p, pkt + data_offset, iplen);
57             }
58             case 0x57: { /* PPP_IPV6 */
59                 if (unlikely(len < (data_offset + IPV6_HEADER_LEN))) {
60                     ENGINE_SET_INVALID_EVENT(p, PPPIPV6_PKT_TOO_SMALL);

(cherry picked from commit dc5b78ec715b7c29ca5faf4d7fb687f2980019c4)

14 months agodecode/ppp: add missing types definitions
Victor Julien [Mon, 15 Apr 2024 10:29:12 +0000 (12:29 +0200)] 
decode/ppp: add missing types definitions

Recognize PPP_CCP, PPP_CBCP and PPP_COMP_DGRAM.

Does not implement decoders for these record types, so these
are logged as unsupported types. Was "wrong_type" before.

(cherry picked from commit 516441b6005f4200ae155f5234cfd0ad20d2dfbc)

14 months agodecode/ppp: clean up ppph pointer use
Victor Julien [Fri, 12 Apr 2024 13:26:46 +0000 (15:26 +0200)] 
decode/ppp: clean up ppph pointer use

No users of the pointer anymore, so remove it.

(cherry picked from commit 7e3f071e4967303c3424d0c0ea812afb2889bbec)

14 months agodecode/ppp: remove ppph check in favor of flag
Victor Julien [Fri, 12 Apr 2024 13:19:45 +0000 (15:19 +0200)] 
decode/ppp: remove ppph check in favor of flag

As we now support variable size headers, we can't use the old pointer.

Replace with a flag.

(cherry picked from commit 6067955afd225e43fa0b54c66c5b0f7f260109ed)

14 months agodecode/ppp: support different header formats
Victor Julien [Fri, 12 Apr 2024 10:42:37 +0000 (12:42 +0200)] 
decode/ppp: support different header formats

Support compressed proto and optional HDLC header.

Bug: #6942.
(cherry picked from commit 68092ff33ce437a6f6720dd9d7f47aa16574ccf1)

14 months agohostbits: release use_cnt for unix (add|remove)-hostbit
Victor Julien [Tue, 14 May 2024 04:46:25 +0000 (06:46 +0200)] 
hostbits: release use_cnt for unix (add|remove)-hostbit

Commands would leave use_cnt incremented, never decrementing them. This
would lead to a asserting triggering at shutdown.

Bug: #7020.
(cherry picked from commit d02c57bd1f21873d8a2a78e14a903f2e6c9771c2)

14 months agodevice: don't crash on unix command 'iface-bypassed-stat'
Victor Julien [Tue, 14 May 2024 04:45:30 +0000 (06:45 +0200)] 
device: don't crash on unix command 'iface-bypassed-stat'

In the default config iface bypass support is not enabled,
and storage API not initialized for it. Using it will lead to a crash.

This commit first checks if the device storage API is initialized.

Bug: #7022.
(cherry picked from commit bc2dfe4c179774cbd5c70f8f71b759e315a8f0a6)

14 months agoapp-layer: Set sc_errno upon error return
Richard McConnell [Thu, 16 May 2024 09:04:24 +0000 (10:04 +0100)] 
app-layer: Set sc_errno upon error return

Bug: https://redmine.openinfosecfoundation.org/issues/6782

Callers to these allocators often use ``sc_errno`` to provide context of
the error. And in the case of the above bug, they return ``sc_errno``,
but as it has not been set ``sc_errno = 0; == SC_OK``.

This patch simply sets this variable to ensure there is context provided
upon error.

(cherry picked from commit fc2e49f84adcd471ca70c8e6aa82e2cf9f7b17ad)

14 months agopcap-log: use correct pkthdr size for limit enforcement
Victor Julien [Tue, 21 May 2024 12:13:11 +0000 (14:13 +0200)] 
pcap-log: use correct pkthdr size for limit enforcement

The on-disk pcap pkthdr is 16 bytes. This was calculated using
`sizeof(struct pcap_pkthdr)`, which is 24 bytes on 64 bit Linux. On
Macos, it's even worse, as a comment field grows the struct to 280
bytes.

Address this by hardcoding the value of 16.

Bug: #7037.
(cherry picked from commit 6c937a9243af3423d6934439fee5df93792aa1bb)

14 months agotime: only consider packet threads
Victor Julien [Mon, 20 May 2024 20:09:06 +0000 (22:09 +0200)] 
time: only consider packet threads

In offline mode, a timestamp is kept per thread, and the lowest
timestamp of the active threads is used. This was also considering the
non-packet threads, which could lead to the used timestamp being further
behind that needed. This would happen at the start of the program, as
the non-packet threads were set up the same way as the packet threads.

This patch both no longer sets up the timestamp for non-packet threads
as well as not considering non-packet threads during timestamp
retrieval.

Fixes: 6f560144c1b9 ("time: improve offline time handling")
Bug: #7034.
(cherry picked from commit 54557997952028f4617ca37c583f4a5fd070236c)

14 months agoprofiling/rules: Improve dynamic rule handling
Jeff Lucovsky [Sat, 16 Mar 2024 12:58:11 +0000 (08:58 -0400)] 
profiling/rules: Improve dynamic rule handling

Issue: 6861

Without this commit, disabling rule profiling via suricatasc's command
'ruleset-profile-stop' may crash because profiling_rules_entered becomes
negative.

This can happen because
- There can be multiple rules evaluated for a single packet
- Each rule is profiled individually.
- Starting profiling is gated by a configuration setting and rule
  profiling being active
- Ending profiling is gated by the same configuration setting and
  whether the packet was marked as profiling.

The crash can occur when a rule is being profiled and rule profiling
is then disabled after one at least one rule was profiled for the packet
(which marks the packet as being profiled).

In this scenario, the value of profiling_rules_entered was
not incremented so the BUG_ON in the end profiling macro trips
because it is 0.

The changes to fix the problem are:
- In the profiling end macro, gate the actions taken there by the same
  configuration setting and use the profiling_rues_entered (instead of
  the per-packet profiling flag). Since the start and end macros are
  tightly coupled, this will permit profiling to "finish" if started.
- Modify SCProfileRuleStart to only check the sampling values if the
  packet hasn't been marked for profiling already. This change makes all
  rules for a packet (once selected) to be profiled (without this change
  sampling is applied to each *rule* that applies to the packet.

(cherry picked from commit bf5cfd6ab7c728125c09c1ee5fb36c4906dc02ea)

14 months agohttp: fix nul deref on memcap reached 11119/head
Philippe Antoine [Fri, 17 May 2024 07:39:52 +0000 (09:39 +0200)] 
http: fix nul deref on memcap reached

HttpRangeOpenFileAux may return NULL in different cases, including
when memcap is reached.
But is only caller did not check it before calling HttpRangeAppendData
which would dereference the NULL value.

Ticket: 7029
(cherry picked from commit fd262df457f67f2174752dd6505ba2ed5911fd96)

14 months agorust/probing: safety check for null input 11096/head
Philippe Antoine [Tue, 7 May 2024 14:33:00 +0000 (16:33 +0200)] 
rust/probing: safety check for null input

Ticket: 7013

Done consistently for all protocols

This may change some protocols behaviors which failed early
if they found there was not enough data...

(cherry picked from commit 37a9003736413b0bc9704099e189fd402922df43)

14 months agorust: return empty slice without using from_raw_parts
Philippe Antoine [Tue, 7 May 2024 08:18:14 +0000 (10:18 +0200)] 
rust: return empty slice without using from_raw_parts

As this triggers rustc 1.78
unsafe precondition(s) violated: slice::from_raw_parts requires
the pointer to be aligned and non-null,
and the total size of the slice not to exceed `isize::MAX`

Ticket: 7013
(cherry picked from commit 5dc8dea8695786daec491a6655f99c0791e47f5c)

14 months agotests: do not bother to free a null pointer
Philippe Antoine [Tue, 7 May 2024 08:17:33 +0000 (10:17 +0200)] 
tests: do not bother to free a null pointer

Ticket: #7013
(cherry picked from commit edd5507ea4d59ecb743a9ee2ca7ae1376983f1bf)

15 months agodetect/iprep: update doc about 0 value 11014/head 11016/head
Victor Julien [Thu, 25 Apr 2024 17:34:39 +0000 (19:34 +0200)] 
detect/iprep: update doc about 0 value

A value of 0 was already allowed by the rule parser, but didn't
actually work.

Bug: #6834.
(cherry picked from commit fcca5c7514a920583d65a70198f2e869c7ecf11a)

15 months agodetect/iprep: allow 0 as a reputation value
Victor Julien [Thu, 25 Apr 2024 15:07:52 +0000 (17:07 +0200)] 
detect/iprep: allow 0 as a reputation value

Rules would allow checking against value 0, but internally the value
was used to indicate "no value". To address this, the internals now
return negative values for not found. This way value 0 can be fully
supported.

Bug: #6834.
(cherry picked from commit 64dc217f9f64b2e731757ce7bac40cf616e5166c)

15 months agodetect/iprep: minor code cleanups
Victor Julien [Thu, 25 Apr 2024 12:09:21 +0000 (14:09 +0200)] 
detect/iprep: minor code cleanups

(cherry picked from commit 673d27c8610b3828c85439fd2932b7462cdc9d3c)

15 months agoci: fix macos build 10978/head 10989/head
Philippe Antoine [Tue, 23 Apr 2024 21:29:19 +0000 (23:29 +0200)] 
ci: fix macos build

use brew instead of pip
limit the number of jobs for make
set a prefix where we can install
use brew flags for library finding

(cherry picked from commit 47a1502dbb0d9ef43a820c956d0396c83b488e07)

15 months agodefrag: apply clang formatting
Shivani Bhardwaj [Mon, 29 Apr 2024 06:33:23 +0000 (12:03 +0530)] 
defrag: apply clang formatting

15 months agoclang-format.sh: prefer clang-format-14
Jason Ish [Wed, 6 Dec 2023 16:09:03 +0000 (10:09 -0600)] 
clang-format.sh: prefer clang-format-14

Add clang-format-14 as the preferred version, this is the default on
Ubuntu 22.04.

(cherry picked from commit 5ebae1e8ed85134d2aaf246a80fad7a4380a1229)

15 months agogithub-ci/formatting: update to Ubuntu 22.04
Jason Ish [Wed, 6 Dec 2023 16:09:47 +0000 (10:09 -0600)] 
github-ci/formatting: update to Ubuntu 22.04

Update the formatting CI job to Ubuntu 22.04 to get a newer version of
clang-format, in this case clang-format-14.

(cherry picked from commit 93071501b5a233b0499dc4c5f00ba9be34eb2c52)

15 months agotls/random: fix incorrect direction handling 10977/head
Shivani Bhardwaj [Fri, 26 Apr 2024 07:29:41 +0000 (12:59 +0530)] 
tls/random: fix incorrect direction handling

The connp objects were incorrectly set per direction leading to
incorrect matches on respective directions.

Bug 6989

(cherry picked from commit 14e2c579f6a0dd75e9b03b5a319613d3f23d3833)

15 months agoversion: start development towards 7.0.6 10931/head 10943/head
Shivani Bhardwaj [Tue, 23 Apr 2024 13:00:57 +0000 (18:30 +0530)] 
version: start development towards 7.0.6

15 months agorelease: 7.0.5; update changelog suricata-7.0.5
Shivani Bhardwaj [Tue, 23 Apr 2024 05:19:55 +0000 (10:49 +0530)] 
release: 7.0.5; update changelog

15 months agodetect/parse: set limits for pcre2
Philippe Antoine [Sun, 24 Mar 2024 20:12:15 +0000 (21:12 +0100)] 
detect/parse: set limits for pcre2

Ticket: 6889

To avoid regexp dos with too much backtracking.
This is already done on pcre keyword, and pcrexform transform.
We use the same default limits for rules parsing.

(cherry picked from commit 316cc528f784c86339d05907a4d6084cbe4d44e6)