]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
16 months agoversion: start development towards 7.0.5 10671/head
Shivani Bhardwaj [Wed, 20 Mar 2024 07:49:51 +0000 (13:19 +0530)] 
version: start development towards 7.0.5

16 months agorelease: 7.0.4; update changelog suricata-7.0.4
Shivani Bhardwaj [Tue, 19 Mar 2024 10:42:41 +0000 (16:12 +0530)] 
release: 7.0.4; update changelog

16 months agossh: limit length for banner logs
Philippe Antoine [Mon, 19 Feb 2024 15:57:55 +0000 (16:57 +0100)] 
ssh: limit length for banner logs

Ticket: 6770
(cherry picked from commit c4b8fb7aca482d1a1555e27072ca26896b52a480)

16 months agossh: avoid quadratic complexity from long banner
Philippe Antoine [Thu, 22 Feb 2024 09:14:36 +0000 (10:14 +0100)] 
ssh: avoid quadratic complexity from long banner

Ticket: 6799

When we find an overlong banner, we get into the state just
waiting for end of line, and we just want to skip the bytes
until then.
Returning AppLayerResult::incomplete made TCP engine retain
the bytes and grow the buffer that we parsed again and again...

(cherry picked from commit 271ed2008bb7392ca2803ab6dac8952491616151)

16 months agoci: update ubuntu22.04 builds with clang14+asan 10660/head 10663/head
Philippe Antoine [Thu, 14 Mar 2024 08:00:15 +0000 (09:00 +0100)] 
ci: update ubuntu22.04 builds with clang14+asan

using a workround about ASLR

(cherry picked from commit 632e52ca2b72f8a3462b22896cb5d25d9d724f9c)

16 months agodetect: flush when setting no_inspection
Philippe Antoine [Mon, 27 Nov 2023 16:07:21 +0000 (17:07 +0100)] 
detect: flush when setting no_inspection

Ticket: 6578

When a protocol such as SSH sets no_inspection, we still have to
flush the current streams and packets that contain clear-text
for detection.

(cherry picked from commit cc3b4b01ec285d481e7ddcc7e062d1c8ec3b542c)

16 months agodetect: update packet action on protocol change
Philippe Antoine [Tue, 3 Oct 2023 10:39:13 +0000 (12:39 +0200)] 
detect: update packet action on protocol change

Ticket: #6305

When running FlowWorkerStreamTCPUpdate, one of the dequeued packet
may set the flow action to drop, without updating the not-pseudo
packet action, as is done usually with a previous call to
FlowHandlePacketUpdate

(cherry picked from commit 4c4f7ff1a2324bff9e4e09dd8354878b2455ac34)

16 months agoyaml: remove newline from error message
Victor Julien [Mon, 20 Nov 2023 08:31:40 +0000 (09:31 +0100)] 
yaml: remove newline from error message

(cherry picked from commit f53c4ab1494acad333e73965f13cde67cf663b1c)

16 months agonapatech: emit HBA deprecation only once 10644/head 10648/head 9478/head
Jonathan Perkins [Fri, 21 Jul 2023 18:27:37 +0000 (14:27 -0400)] 
napatech: emit HBA deprecation only once

Issue: 6313
This commit removes duplicate HBA deprecation messages from being
emitted.

16 months agodecode/pppoe: skip useless loop unless debug 10627/head
Philippe Antoine [Mon, 11 Mar 2024 14:58:24 +0000 (15:58 +0100)] 
decode/pppoe: skip useless loop unless debug

Looping over tags has no effects, except debug logging

(cherry picked from commit 59d18b9a68e35b6e1129368f5cdccea6764dfc9c)

16 months agodecode/pppoe: pointer cast consistency
Philippe Antoine [Mon, 19 Feb 2024 09:53:02 +0000 (10:53 +0100)] 
decode/pppoe: pointer cast consistency

Ticket: 6787

To do pointer arithmetic, we need to use uint8_t* pointer :
Pointer arithmetic in C is automatically scaled according
to the size of the data type.

Also simplifies the loop condition

(cherry picked from commit d2db8bfdca7c2483f51c35a726d73f1912638199)

16 months agodpdk: output unknown NIC's NUMA node message only on multi-node systems
Lukas Sismis [Sat, 2 Mar 2024 14:57:43 +0000 (15:57 +0100)] 
dpdk: output unknown NIC's NUMA node message only on multi-node systems

Ticket: #6715
(cherry picked from commit 566e89a0d6aa56073705f97d972fc59911d9122e)

16 months agonetmap: Avoid HW errors when using pipes 10620/head
Jeff Lucovsky [Thu, 7 Mar 2024 20:24:36 +0000 (15:24 -0500)] 
netmap: Avoid HW errors when using pipes

Issue: 6837

When using netmap pipes (with lb, for example), avoid direct hardware
related IOCTLs that will fail (not supported with pipes).

(cherry picked from commit af529a56a9bcb37bae5243236a4505fff0df268b)

16 months agoplugins: initialize plugins earlier
Jason Ish [Tue, 27 Feb 2024 22:16:08 +0000 (16:16 -0600)] 
plugins: initialize plugins earlier

Capture plugins need to be registered before LiveDeviceFinalize,
otherwise Suricata errors before the plugin gets a chance to load.

Bug: #6811
(cherry picked from commit 25d0e0b68c333029fb8263cb9a2a287f9064b5c8)

16 months agothread modules: separate initialization from registration
Jason Ish [Tue, 27 Feb 2024 22:07:33 +0000 (16:07 -0600)] 
thread modules: separate initialization from registration

Move the zero'ing to the thread module array InitGlobal in an effort
to fix capture modules.

At some point device validation moved to a point in startup before
plugins are loaded meaning that capture plugins could not be
used. Moving plugin registration early enough caused some of their
registration to be wiped out as clearing the array was done after.

Bug: #6811
(cherry picked from commit 96e61b043c9b6757ca84ddb74543073b2ef3d7e6)

16 months agodpdk: add a user warning on the change of RX/TX descriptors 10607/head
Lukas Sismis [Sat, 9 Mar 2024 12:42:33 +0000 (13:42 +0100)] 
dpdk: add a user warning on the change of RX/TX descriptors

Ticket: #6739
(cherry picked from commit 9185ca8f3801537b359a14d5ad90ca4728dca1ad)

16 months agooutput/filestore: delay snprintf until needed
Philippe Antoine [Tue, 27 Feb 2024 20:45:03 +0000 (21:45 +0100)] 
output/filestore: delay snprintf until needed

Perf optimization so that we do not call snprintf in the
common code path.

Ticket: 6796
(cherry picked from commit d255a5c7a309c067e15dde01560631f4ed427db1)

16 months agooutput/filestore: remove duplicate snprintf
Philippe Antoine [Mon, 26 Feb 2024 16:28:25 +0000 (17:28 +0100)] 
output/filestore: remove duplicate snprintf

Ticket: 6796
(cherry picked from commit 7641c07af95f4373c50812890737358fda885a4c)

16 months agooutput: log tx only when there is a fresh app update
Philippe Antoine [Thu, 22 Feb 2024 08:42:41 +0000 (09:42 +0100)] 
output: log tx only when there is a fresh app update

Ticket: 6796

Similar to commit for detection
9240ae250cc369306803740279df2ab3eca6b54a

We only have more logging to do if the app update was fresh,
ie if p->app_update_direction != 0

If we have data acknowledged in one direction,
and then many packets in the other direction,
the APP_UPDATED flow flags did not get reset because we did not
run detection yet in this direction,
but there is nothing more to do after the first packet in the
other direction.

(cherry picked from commit c41540f8391b44bf4d91d32641cc608ebfecb19c)

16 months agouserguide: fix explanation about bsize ranges 10587/head
Juliana Fajardini [Wed, 24 Jan 2024 15:00:41 +0000 (12:00 -0300)] 
userguide: fix explanation about bsize ranges

Our code handles Uint ranges as exclusive, but for bsize, our
documentation stated that they're inclusive.

Cf. from uint.rs:

    DetectUintMode::DetectUintModeRange => {
        if val > x.arg1 && val < x.arg2 {
            return true;
        }
    }

Task #6708

(cherry picked from commit 244a35d539989c00eb5cbac86e7355227cd9da03)

16 months agodoc: mention the limited number of RX/TX descriptors on Intel NICs
Lukas Sismis [Sun, 11 Feb 2024 20:14:08 +0000 (21:14 +0100)] 
doc: mention the limited number of RX/TX descriptors on Intel NICs

Ticket: 6748
(cherry picked from commit 356f9ffa130fbaaf82e7e28de98bdc24fe32f945)

17 months agodpdk: max cache size should be lower than one of the constraints 10577/head
Lukas Sismis [Sun, 11 Feb 2024 19:43:37 +0000 (20:43 +0100)] 
dpdk: max cache size should be lower than one of the constraints

Ticket: 6741
(cherry picked from commit c65ff35819845a3f42c75f79d54f9ab91c5c2ec9)

17 months agodpdk: sanitize integer overflow in the configuration
Lukas Sismis [Sun, 11 Feb 2024 12:42:20 +0000 (13:42 +0100)] 
dpdk: sanitize integer overflow in the configuration

Ticket: #6737
(cherry picked from commit cc2eb2d8b77e96586a607f661c7eed9ab41076fc)

17 months agohugepages: run hugepage check only on DPDK runmode and on Linux 10553/head
Lukas Sismis [Sat, 10 Feb 2024 19:04:55 +0000 (20:04 +0100)] 
hugepages: run hugepage check only on DPDK runmode and on Linux

Previous implementation allowed FreeBSD to enter into the hugepage
analysis. It then failed with an error message because hugepage/
NUMA node paths that are used in the codebase to retrieve info about
the system are not the same with the structure in Linux.

Additionally, the messages were logged on error level. It has been
demoted to info level because the whole hugepage analysis checkup is
only for informational purposes and does not affect Suricata operation.

The hugepage analysis and the hugepage snapshots are now limited to
only run in the DPDK runmode.

Ticket: #6760
Ticket: #6762
(cherry picked from commit 4b0704db5501c76592b2e12912b82a17f95fd842)

17 months agoerrors: add SC_ENOENT error
Lukas Sismis [Sat, 10 Feb 2024 19:04:24 +0000 (20:04 +0100)] 
errors: add SC_ENOENT error

(cherry picked from commit f88bd2dd3f37adeb44351921ae6313278964ef3d)

17 months agopfring: fix leak of configuration data and in single mode 10533/head
Jason Ish [Tue, 27 Feb 2024 22:55:59 +0000 (16:55 -0600)] 
pfring: fix leak of configuration data and in single mode

Fix leak of configuration data on exit. Also, in single mode set
thread count to one instead of the CPU count.

Bug: #4734
(cherry picked from commit 5f0853599b15adafdf47399375728d70a94c9867)

17 months agopfring: fix leak of packet on exit
Jason Ish [Tue, 27 Feb 2024 23:19:54 +0000 (17:19 -0600)] 
pfring: fix leak of packet on exit

Bug: #4734
(cherry picked from commit 358f1e35eed415d57cf24500deb58d1224c67b71)

17 months agocppcheck: Address cpcheck report of an FP
Jeff Lucovsky [Sat, 25 Nov 2023 14:22:19 +0000 (09:22 -0500)] 
cppcheck: Address cpcheck report of an FP

Issue: 6527

Address the FP raised by cppcheck -- note that although the code
corectly checks to ensure that `to_shift != &sb->reqion`, the logic was
detected as a FP. Rework the code to eliminate the FP.

(cherry picked from commit 40e3514e7a6c89a786ebf17469404524fb0d2d52)

17 months agodetect/address: avoid cppcheck false positive
Victor Julien [Tue, 20 Feb 2024 15:06:08 +0000 (16:06 +0100)] 
detect/address: avoid cppcheck false positive

src/detect-engine-address.c:1386:5: error: Memory leak: map.string [memleak]
    return true;
    ^

Seems cppcheck looses track of the pointer after the unnecessary cast to
void.

Bug: #6527.
(cherry picked from commit 78703bbc865a1dd15a1ae1c4c996b0150096ed0e)

17 months agocppcheck/detect: Address cppcheck memory leak
Jeff Lucovsky [Sat, 25 Nov 2023 14:20:43 +0000 (09:20 -0500)] 
cppcheck/detect: Address cppcheck memory leak

Issue: 6527

Ensure that the `map->string` memory isn't leaked following an error
return from `HashListTableAdd`

(cherry picked from commit 8b2fd434fc04ae84317d44d0a450af3ead9a157f)

17 months agodetect: fix memory leak in error handling
Victor Julien [Tue, 20 Feb 2024 15:06:57 +0000 (16:06 +0100)] 
detect: fix memory leak in error handling

Pointed out by cppcheck:

src/detect-parse.c:1544:9: error: Memory leak: sig.init_data [memleak]
        SCFree(sig);
        ^

Bug: #6527.
(cherry picked from commit eb1d0c2cc2b673a8f751cd88546e7c37e33ab8e0)

17 months agorunmode/unix-socket: fix cppcheck warnings
Victor Julien [Sat, 17 Feb 2024 09:52:59 +0000 (10:52 +0100)] 
runmode/unix-socket: fix cppcheck warnings

src/runmode-unix-socket.c:547:9: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
        snprintf(tstr, sizeof(tstr), "%d", cfile->tenant_id);
        ^
src/runmode-unix-socket.c:1040:5: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
    snprintf(prefix, sizeof(prefix), "multi-detect.%d", tenant_id);
    ^
src/runmode-unix-socket.c:1189:5: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
    snprintf(prefix, sizeof(prefix), "multi-detect.%d", tenant_id);
    ^

(cherry picked from commit 872f007a14cdea70345d381620c40ac4c8e95bca)

17 months agodetect/mpm: don't test for impossible condition
Victor Julien [Fri, 5 Jan 2024 07:29:16 +0000 (08:29 +0100)] 
detect/mpm: don't test for impossible condition

Functions can't get called with NULL signature or NULL
Signature::init_data.

(cherry picked from commit 124a8dea204b400f27ac2b8c15c994ffa996b1ea)

17 months agomqtt: Improve frame parsing w/mult. PDUs 10489/head 10508/head
Jeff Lucovsky [Wed, 3 Jan 2024 14:28:41 +0000 (09:28 -0500)] 
mqtt: Improve frame parsing w/mult. PDUs

This commit improves the mqtt parsing of frames to handle multiple PDUs.

Issue: 6592
(cherry picked from commit f9a20dafc6abe2c03dea98286c86430b447d8196)

17 months agotcp: do not assign TCP flags to pseudopackets 10484/head 10485/head
Lukas Sismis [Tue, 6 Feb 2024 10:38:19 +0000 (11:38 +0100)] 
tcp: do not assign TCP flags to pseudopackets

Previously pseudopackets were assigned with ACK flag which falsely turned
"SYN" flows to "SYN/ACK" flows when Suricata ran with raw content-matching
rules. The problem occured during the flow timeout or Suricata shutdown,
essentially, when the flow was being kicked out (with a pseudopacket).

When Suricata ran without raw content-matching rules (the ruleset did not
contain content matching keywords or it only contained keywords that are
app-layer content-matching) then raw stream reassembly tracking is turned off
(SignatureHasStreamContent()).
This in turn disabled a check in StreamNeedsReassembly() and the right edge
was not checked with the raw stream progress. In turn, it did not generate
a pseudopacket that would go through the detection engine. Suricata with
raw content-matching keywords would therefore on a flow with SYN packet only
return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION which would generate
the pseudopacket.

In Suricata versions <= 6.0.x, the flow output was correct because
only the commit 1bb6f44ff01363fa29488f1ae83b9368e33c2770 started to
differentiate the right edge calculation between the raw and application
layer streams. The older Suricata versions used only the application layer
right edge equation and therefore did not generate a pseudopacket.

Ticket: #6734
(cherry picked from commit ebf465a11bffcd2049e17648e6c46c067692b02a)

17 months agomulti-tenant: fix loader dead lock 10442/head
Victor Julien [Sun, 11 Feb 2024 08:29:38 +0000 (09:29 +0100)] 
multi-tenant: fix loader dead lock

A dead lock could occur at start up, where a loader thread would
get stuck on it's condition variable, while the main thread was
polling the loaders task results.

The vector to the dead lock is as follows:

main                         loader
DetectEngineMultiTenantSetup
-DetectLoaderSetupLoadTenant
--DetectLoaderQueueTask
---lock loader
---add task
---unlock loader
                        lock loader
                        check/exec tasks
                        unlock loader
---wake up threads
                        lock ctrl mutx
                        cond wait ctrl
                        unlock ctrl
-DetectLoadersSync
--lock loader
--check tasks
--unlock loader

Between the main thread unlocking the loader and waking up the
threads, it is possible that the loader has already moved ahead
but not yet entered its conditional wait. The main thread sends
its condition signal, but since the loader isn't yet waiting on
it the signal is ignored. Then when the loader does enter its
conditional wait, the signal is not sent again.

This patch updates the logic to send signals much more often.
It also makes sure that the signal is sent under lock, as the
API requires.

Bug: #6768.

Co-authored-by: Shivani Bhardwaj <shivani@oisf.net>
17 months agostats: Add unittest for basic stats serialization
Arne Welzel [Thu, 8 Feb 2024 17:23:38 +0000 (18:23 +0100)] 
stats: Add unittest for basic stats serialization

Main purpose is to validate that the 30 of bond0.30 isn't expanded into
a nested object during serialization.

(cherry picked from commit 08db0f302b3b2817d0fdfb1fe836fd16cc5e8775)

17 months agostats: Do not expand dots of tm_name
Arne Welzel [Mon, 5 Feb 2024 16:45:30 +0000 (17:45 +0100)] 
stats: Do not expand dots of tm_name

When an interface with dots is used, per worker stats are nested by the
dot-separated-components of the interface due to the usage of
OutputStats2Json().

Prevent this by using OutputStats2Json() on a per-thread specific object
and setting this object into the threads object using the
json_object_set_new() which won't do the dot expansion.

This was tested by creating an interface with dots in the name
and checking the stats.

    ip link add name a.b.c type dummy

With Suricata 7.0.2, sniffing on the a.b.c interface results in the
following worker stats format:

    "threads": {
      "W#01-a": {
        "b": {
          "c": {
            "capture": {
              "kernel_packets": 0,

After this fix, the output looks as follows:

    "threads": {
      "W#01-a.b.c": {
        "capture": {
          "kernel_packets": 0,

Ticket: #6732
(cherry picked from commit b8b8aa69b49ac0dd222446c28d00a50f9fd7d716)

17 months agodetect-engine-iponly: improve ip list performance
Simon Dugas [Fri, 29 Dec 2023 16:58:50 +0000 (11:58 -0500)] 
detect-engine-iponly: improve ip list performance

The runtime complexity of insertion sort is approx. O(h*n)^2 where
h is the size of the HOME_NET and n is the number of ip only rules
that use the HOME_NET.

Replacing this with qsort significantly improves rule load time when
a large HOME_NET is used in combination with a moderate amount of ip
only rules.

(cherry picked from commit 17f9d7aeccd5a69ef2e3344386d1585d231e2933)

17 months agodetect/tls.certs: fix direction handling
Victor Julien [Sat, 27 Jan 2024 08:59:55 +0000 (09:59 +0100)] 
detect/tls.certs: fix direction handling

Direction flag was checked against wrong field, leading to undefined behavior.

Bug: #6778.
(cherry picked from commit 3c06457b74db5a2fd070fe1675c72f53423786de)

17 months agothreads/mutex: Ensure mutex held before signaling
Jeff Lucovsky [Sun, 4 Feb 2024 14:44:44 +0000 (09:44 -0500)] 
threads/mutex: Ensure mutex held before signaling

Ensure that the mutex protecting the condition variable is held before
signaling it. This ensures that the thread(s) awaiting the signal are
notified.

Issue: 6569
(cherry picked from commit 2a1a70b3089751b30f623871063ce155451d4cbc)

17 months agonetmap: Release lock to avoid deadlock
Jeff Lucovsky [Thu, 8 Feb 2024 14:12:47 +0000 (09:12 -0500)] 
netmap: Release lock to avoid deadlock

Issue: 6755

When NetmapOpen encounters an error opening the netmap device, it'll
retry a bit. When the retry limit is reached, it'll shutdown Suricata.

This commit ensures that the device list lock is not held when before
closing all open devices before terminating Suricata.

(cherry picked from commit 364adeeb0442592ceea4d329622ca5fe34bf31fd)

17 months agoutil/mime: fix memory leak
Alexey Simakov [Wed, 7 Feb 2024 14:51:00 +0000 (17:51 +0300)] 
util/mime: fix memory leak

Fix memory leak at util-decode-mime:MimeDecInitParser, which
root cause is not-freeing allocated memory for mimeMsg

Bug: #6745
(cherry picked from commit 231c892befe25c23d5d3b54e48077c8446940eb5)

17 months agodetect: respect directionality for filestore
Philippe Antoine [Thu, 25 Jan 2024 13:26:09 +0000 (14:26 +0100)] 
detect: respect directionality for filestore

Ticket: 6617

So that rules with keyword like `filestore:to_server,flow`
only store the files to server and not the ones to client...

Directionality only worked with the default scope, ie the
current file, and not the scope tx or scope flow.
For non-default scope, tx or flow, both directions were stored
whatever the directionality specified.

For these non-default scopes, this commit keeps a default
of both directions, but use only one direction if specified.

Need to split flag FLOWFILE_STORE per direction, so that Suricata
can retain this (optional) directional info from the filestore
keyword.

Fixes: 79499e476979 ("app-layer: move files into transactions")
(cherry picked from commit 63caa0b40a66ecf1a34bbb6d942d4a044b7728a5)

17 months agoapp-layer/template: use a max number of txs 10416/head
Philippe Antoine [Mon, 12 Feb 2024 12:42:14 +0000 (13:42 +0100)] 
app-layer/template: use a max number of txs

Ticket: 6773
(cherry picked from commit c99d93c2574cfa0fe2b94c1ab3a2cacd5a15035c)

17 months agodetect: errors on 65k filestore signatures 10357/head
Philippe Antoine [Mon, 9 Oct 2023 12:49:54 +0000 (14:49 +0200)] 
detect: errors on 65k filestore signatures

Errors when a detection engine gets 65k filestore signatures to
avoid the hard limit to have 65k filestore per signature group
head

Ticket: #6393
(cherry picked from commit db99c45d239d5ca6e805094195f7ae39d3051e44)

17 months agodetect/http: report error on alloc failure 10350/head 10355/head
Victor Julien [Fri, 9 Feb 2024 07:09:38 +0000 (08:09 +0100)] 
detect/http: report error on alloc failure

(cherry picked from commit 7e4dba7dfbd063be554b6145b747d7879eaa1f84)

17 months agodetect/http_header: fix leak on realloc failure
Philippe Antoine [Thu, 8 Feb 2024 19:23:59 +0000 (20:23 +0100)] 
detect/http_header: fix leak on realloc failure

(cherry picked from commit b48ec8a03922f36e76f2d6d942f2963afc2a3345)

17 months agodetect-http: add superfluous alloc check for cocci
Jason Ish [Thu, 8 Feb 2024 19:21:11 +0000 (13:21 -0600)] 
detect-http: add superfluous alloc check for cocci

Add not-needed SCCalloc return check to satisfy our Cocci malloc
checks as it can't see that the caller immediately checks the return
value of this simple wrapper around SCCalloc.

(cherry picked from commit f800ed0f901488d19fccf858ba0711792bf407ff)

17 months agorust: fix clippy ptr_arg warnings
Philippe Antoine [Thu, 8 Feb 2024 14:47:23 +0000 (15:47 +0100)] 
rust: fix clippy ptr_arg warnings

error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
   --> src/dns/log.rs:371:29
    |
371 | pub fn dns_print_addr(addr: &Vec<u8>) -> std::string::String {
    |                             ^^^^^^^^ help: change this to: `&[u8]`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

(cherry picked from commit 68b0052018079adc11ea1e35ab686c30716a8aad)

17 months agoci: authors check using OISF repo
Philippe Antoine [Wed, 7 Feb 2024 20:54:28 +0000 (21:54 +0100)] 
ci: authors check using OISF repo

As flagged critical by codescan

(cherry picked from commit 7f5e98e6df279be39a47c18ac0553a1cfebb906c)

17 months agoversion: start development towards 7.0.4 10342/head
Shivani Bhardwaj [Fri, 9 Feb 2024 04:21:21 +0000 (09:51 +0530)] 
version: start development towards 7.0.4

17 months agorelease: 7.0.3; update changelog suricata-7.0.3
Shivani Bhardwaj [Thu, 8 Feb 2024 09:12:53 +0000 (14:42 +0530)] 
release: 7.0.3; update changelog

17 months agohttp2: limit number of concurrent transactions
Philippe Antoine [Thu, 9 Nov 2023 15:15:36 +0000 (16:15 +0100)] 
http2: limit number of concurrent transactions

Ticket: 6481

Instead of just setting the old transactions to a drop state so
that they get later cleaned up by Suricata, fail creating new ones.

This is because one call to app-layer parsing can create many
transactions, and quadratic complexity could happen in one
single app-layer parsing because of find_or_create_tx

(cherry picked from commit 80abc22f6475b6a87a33166729a871203f34d578)

17 months agopgsql: parse only PDU when type is unknown
Philippe Antoine [Tue, 17 Oct 2023 20:04:57 +0000 (22:04 +0200)] 
pgsql: parse only PDU when type is unknown

A next PDU may already be in the slice to parse.
Do not skip its parsing, ie do not use rest, but take just
the length of the pdu

(cherry picked from commit 86de7cffa7e8f06fe9d600127e7dabe89c7e81dd)

17 months agopgsql: parse auth message within its bound
Philippe Antoine [Tue, 17 Oct 2023 20:01:27 +0000 (22:01 +0200)] 
pgsql: parse auth message within its bound

If the next PDU is already in the slice next, do not use it and
restrict ourselves to the length of this PDU.
Avoids overconsumption of memory by quadratic complexity, when
having many small PDUS in one big chunk being parsed

Ticket: #6411
(cherry picked from commit f52c033e566beafb4480c139eb18662a2870464f)

17 months agodetect: fixes use-after-free with http.request_header
Philippe Antoine [Tue, 7 Nov 2023 09:33:21 +0000 (10:33 +0100)] 
detect: fixes use-after-free with http.request_header

Ticket: #6441

This keyword and the response one use a multiple inspection buffer.
But the different instances point to the same memory address
that comes from HttpHeaderGetBufferSpace and is not owned
by the transaction, and is rebuilt, which is a functional
bug in itself.

As it gets crafted, it can get reallocated if one header
is over 1024 bytes, while the previous freed pointer will still get
used for the previous headers.

(cherry picked from commit bc422c17d6961f03f673f2999a949913e89fc2d0)

17 months agosmtp: avoid creating empty transaction
Philippe Antoine [Tue, 14 Nov 2023 20:51:37 +0000 (21:51 +0100)] 
smtp: avoid creating empty transaction

Ticket: 6477

So as to avoid ending up with too many empty transactions.

This happens when Suricata sees a DATA command in the current
transaction but did not have a confirmation response for it.
Then, if Suricata receives another DATA command, it will
create another new transaction, even if the previous one
is empty. And so, a malicious client can create many empty
transactions by just sending a repeated amount of DATA commands
without having a confirmation code for them.

Suricata cannot use state->current_command == SMTP_COMMAND_DATA
to prevent this attack and needs to resort to a new boolean
is_data because the malicious client may send another dummy command
after each DATA command.

This patch leaves only one call to SMTPTransactionCreate

(cherry picked from commit 61f2e4e1e5b34dfd8ae44d1c15253e2da65f6e6a)

17 months agosmtp: config limit maximum number of live transactions
Philippe Antoine [Thu, 9 Nov 2023 11:27:59 +0000 (12:27 +0100)] 
smtp: config limit maximum number of live transactions

Ticket: #6477
(cherry picked from commit 8f73a0ac5588cb5e5c501b3c7a07cb5d35b99d92)

17 months agohttp1: configurable max number of live tx per flow
Philippe Antoine [Tue, 17 Oct 2023 13:28:53 +0000 (15:28 +0200)] 
http1: configurable max number of live tx per flow

Ticket: #5921

Co-authored-by: Jason Ish <jason.ish@oisf.net>
(cherry picked from commit 4175680a8a1c0dfaa491ee63d6e36c011d498473)

17 months agohttp1: remove transactions from their list
Philippe Antoine [Fri, 7 Apr 2023 14:02:41 +0000 (16:02 +0200)] 
http1: remove transactions from their list

instead of keeping a NULL pointer in an array

Ticket: #5921
(cherry picked from commit 8f63a8f3bffbbaf8fae4985ee5f974ab326b08c0)

17 months agohttp2: handle reassembly for continuation frames
Philippe Antoine [Thu, 25 Jan 2024 15:01:14 +0000 (16:01 +0100)] 
http2: handle reassembly for continuation frames

Ticket: 5926

HTTP2 continuation frames are defined in RFC 9113.
They allow header blocks to be split over multiple HTTP2 frames.
For Suricata to process correctly these header blocks, it
must do the reassembly of the payload of these HTTP2 frames.
Otherwise, we get incomplete decoding for headers names and/or
values while decoding a single frame.

Design is to add a field to the HTTP2 state, as the RFC states that
these continuation frames form a discrete unit :
> Field blocks MUST be transmitted as a contiguous sequence of frames,
> with no interleaved frames of any other type or from any other stream.
So, we do not have to duplicate this reassembly field per stream id.

Another design choice is to wait for the reassembly to be complete
before doing any decoding, to avoid quadratic complexity on partially
decoding of the data.

(cherry picked from commit aff54f29f8c3f583ae0524a661aa90dc7a2d3f92)

18 months agomqtt: fix logic when setting event 10278/head 10308/head
Philippe Antoine [Tue, 17 Oct 2023 08:26:57 +0000 (10:26 +0200)] 
mqtt: fix logic when setting event

Especially sets transactions to complete when we get a response
without having seen the request, so that the transactions
end up getting cleaned (instead of living/leaking in the state).

Also try to set the event on the relevant transaction, instead
of creating a new transaction just for the purpose of having
the event.

Ticket: #6299
(cherry picked from commit 89936b6530690c6d03869b2ad8b82f9f84776f94)

18 months agodetect: merge sorted lists instead of qsort
Philippe Antoine [Mon, 18 Sep 2023 11:27:47 +0000 (13:27 +0200)] 
detect: merge sorted lists instead of qsort

Ticket: #6299

Simply because it is faster (just linear).

This is for merging match_array into tx_candidates

(cherry picked from commit 5bb8800588e7b4a09e1770f049cd88be71e2d30b)

18 months agodetect: avoids case of useless detection on txs
Philippe Antoine [Thu, 7 Sep 2023 12:33:04 +0000 (14:33 +0200)] 
detect: avoids case of useless detection on txs

When a TCP flow packet has not led to app-layer updates,
it is useless to run DetectRunTx, as there cannot be new
matches.

This happens for instance, when one side sends in a row multiple
packets which are not acked (and thus not parsed in IDS mode).

Doing so requires to move up the call to
AppLayerParserSetTransactionInspectId
so that it is run the same times DetectRunTx is run, and not in the
case where the transaction was not updated.

Ticket: 6299
(cherry picked from commit 9240ae250cc369306803740279df2ab3eca6b54a)

18 months agodoc: note what version "requires" was added in 10253/head
Jason Ish [Wed, 24 Jan 2024 15:55:37 +0000 (09:55 -0600)] 
doc: note what version "requires" was added in

(cherry picked from commit 8bf8131c31088f501f4d151f8748a817f89f7c1f)

18 months agodetect/requires: reset sigerror flags for each rule
Jason Ish [Wed, 24 Jan 2024 15:02:19 +0000 (09:02 -0600)] 
detect/requires: reset sigerror flags for each rule

"sigerror_ok" and "sigerror_requires" were not being reset after each
rule which could lead to a rule load error being incorrectly tracked
as skipped rather than failed.

Also initialize "skippedsigs" to 0 along with "goodsigs" and
"badsigs", while not directly related to this issue, could also throw
off some stats.

Ticket: #6710
(cherry picked from commit de3cbe4c90fb7fb6d54b6876ab515f791145271a)

18 months agorequirements: use libhtp 0.5.x
Jason Ish [Wed, 24 Jan 2024 20:41:47 +0000 (14:41 -0600)] 
requirements: use libhtp 0.5.x

Move to libhtp to the 0.5.x branch instead of 0.5.45.

(cherry picked from commit c3b3c11e30e1afdbde5c196a0692ee5e2c379cb1)

18 months agodoc: remove references to prehistoric versions
Lukas Sismis [Mon, 11 Dec 2023 00:47:55 +0000 (01:47 +0100)] 
doc: remove references to prehistoric versions

Remove references that are mentioning Suricata 3 or less
As a note - only one Suricata 4 reference found:
(suricata-yaml.rst:"In 4.1.x")
Fast pattern selection criteria can be internally found by inspecting
SupportFastPatternForSigMatchList and SigTableSetup functions.

Ticket: #6699
(cherry picked from commit 6e4cc79b398d91e243bd1574cbbcbbf7cd021c5d)

18 months agodpdk: rework hugepage hints to use per-numa information
Lukas Sismis [Mon, 30 Oct 2023 11:33:57 +0000 (12:33 +0100)] 
dpdk: rework hugepage hints to use per-numa information

Previous integration of hugepage analysis only fetched data
from /proc/meminfo. However this proved to be often
deceiving mainly for providing only global information and
not taking into account different hugepage sizes (e.g. 1GB
hugepages) and different NUMA nodes.

Ticket: #6697
(cherry picked from commit ca6f7c2d002cdad8eb3630860b5023560626aee0)

18 months agoflow-bypass: Set bypass thread to running state
Vincent Li [Fri, 4 Aug 2023 17:49:35 +0000 (17:49 +0000)] 
flow-bypass: Set bypass thread to running state

When running Suricata in XDP bypass mode (bypass: yes),

Suricata started up with error:
Error: threads: thread "FB" failed to start in time: flags 0003

"FB" thread does not transition from THV_INIT_DONE to THV_RUNNING.

Set "FB" thread THV_RUNNING state in BypassedFlowManager().

Bug: #6254

Signed-off-by: Vincent Li <vincent.mc.li@gmail.com>
(cherry picked from commit f80d26db0b62d4a547290a1cf536754f79927a3b)

18 months agoipfw: close(2) instead shutdown(2) of the divert(4) socket
Gleb Smirnoff [Thu, 11 Jan 2024 21:35:21 +0000 (13:35 -0800)] 
ipfw: close(2) instead shutdown(2) of the divert(4) socket

The shutdown(2) syscall would always return ENOTCONN for FreeBSD 11,
FreeBSD 12, FreeBSD 13 and FreeBSD 14.  It could do some action on the
socket in the kernel in FreeBSD 10 and before, did not test.

(cherry picked from commit b239e88c9303d83a3074ed69c4989bd136bbf8b4)

18 months agodetect: case-insensitive comparison for requires
Philippe Antoine [Thu, 4 Jan 2024 10:42:55 +0000 (11:42 +0100)] 
detect: case-insensitive comparison for requires

Ticket: 6656
(cherry picked from commit d3218385e942a4a01f3938f0cd7050f5dc7c9a6f)

18 months agosource/erf-dag: compiler warnings
Stephen Donnelly [Wed, 10 Jan 2024 03:39:34 +0000 (16:39 +1300)] 
source/erf-dag: compiler warnings

Bug: #6667.

Fix compiler warnings for function pointer parameters missing const with --enable-dag

(cherry picked from commit c28cc93e23e829dac34ca0170df754ab1063c482)

18 months agoendace: Fix source-dag timestamps
Stephen Donnelly [Mon, 11 Dec 2023 02:32:06 +0000 (15:32 +1300)] 
endace: Fix source-dag timestamps

Bug: #6618.

Fix Endace ERF to SCTime_t timestamp conversion

Fix typo preventing compilation with --enable-dag

(cherry picked from commit 879db3dbc3e93912c784375c85d88404a9371f31)

18 months agostats: add rules skipped 10211/head
Jason Ish [Tue, 19 Dec 2023 18:13:23 +0000 (12:13 -0600)] 
stats: add rules skipped

Rule skipped is a count of the number of rules that are skipped due to
missing requirements.

Feature: #6637
(cherry picked from commit b453eea1502cc5455f383c4fe82c6011fee93495)

18 months agodetect-parse: parse sid in pre-scan
Jason Ish [Wed, 29 Nov 2023 18:57:23 +0000 (12:57 -0600)] 
detect-parse: parse sid in pre-scan

During the pre-scan for "requires", also parse the SID if possible. If
the rule fails high level parsing (syntax), the SID will not be
parsed.

But every keyword other than "sid" and "requires" should expect to be
provided with a parsed sid.

(cherry picked from commit 71bbba9248e696f0fd2e912ad9631052b3788775)

18 months agorequires: pre-scan rule for requires expressions
Jason Ish [Wed, 29 Nov 2023 16:54:54 +0000 (10:54 -0600)] 
requires: pre-scan rule for requires expressions

Add a "pre-scan" rule parse that will check for requires statement. It
will return a special error code (-4) if the requires fails due to
missing requirements.

Syntactic errors will also abort parsing here.

Feature: #5972
(cherry picked from commit 435c03172ed7ebaa117765760e75bdfd38c7fca0)

18 months agorequires: add requires keyword
Jason Ish [Tue, 28 Nov 2023 21:35:09 +0000 (15:35 -0600)] 
requires: add requires keyword

Add a new rule keyword "requires" that allows a rule to require specific
Suricata versions and/or Suricata features to be enabled.

Example:

  requires: feature geoip, version >= 7.0.0, version < 8;
  requires: version >= 7.0.3 < 8
  requires: version >= 7.0.3 < 8 | >= 8.0.3

Feature: #5972

Co-authored-by: Philippe Antoine <pantoine@oisf.net>
(cherry picked from commit 5d5b0509a543f2b6f09cc81acf0248a361b03aa1)

18 months agofeature: provide a Rust binding to the feature API
Jason Ish [Fri, 15 Dec 2023 00:19:41 +0000 (18:19 -0600)] 
feature: provide a Rust binding to the feature API

As the feature module is not available for Rust unit tests, a mock
version is also provided.

(cherry picked from commit 15ed51f9b87011025615245d89152da9c567f49b)

18 months agohtp/swf: Remove flash deprecation notice
Jeff Lucovsky [Tue, 16 Jan 2024 15:36:07 +0000 (10:36 -0500)] 
htp/swf: Remove flash deprecation notice

Issue: 6605

Flash decompression will remain so the deprecation notice is not needed.

(cherry picked from commit 995f5fc8c5fa925e8ac1540f8f4bc2e68df3908a)

18 months agolog/sguil: Issue deprecation notice if sguil mode
Jeff Lucovsky [Tue, 16 Jan 2024 15:10:35 +0000 (10:10 -0500)] 
log/sguil: Issue deprecation notice if sguil mode

Issue: 6688

18 months agouserguide: remove old css files 10196/head
Jason Ish [Thu, 30 Nov 2023 17:46:14 +0000 (11:46 -0600)] 
userguide: remove old css files

In our conf.py we reference some ReadTheDocs stylesheets that appear to
be old and break formatting of some items like bulletted lists.

Bug: #6589
(cherry picked from commit cc0adaaf4a747fbefa5e8d5afec73760cbb8b2f9)

18 months agodetect/stream_size: fix prefiltering registration
Eric Leblond [Sat, 18 Nov 2023 21:07:47 +0000 (22:07 +0100)] 
detect/stream_size: fix prefiltering registration

Ticket: #6551
(cherry picked from commit 180459eeb6c248b70a8b20b1e14f829318bb242d)

18 months agodetect: strip_pseudo_headers transform 10170/head
Philippe Antoine [Tue, 12 Dec 2023 08:34:04 +0000 (09:34 +0100)] 
detect: strip_pseudo_headers transform

Ticket: 6546
(cherry picked from commit adf5e6da7bdf81d65ccfeb115e6bc50e7031a0ca)

18 months agodoc: fix byte_test examples 10143/head
Philippe Antoine [Wed, 6 Dec 2023 19:32:50 +0000 (20:32 +0100)] 
doc: fix byte_test examples

As this keyword has 4 mandatory arguments, and some examples
had only three...

Ticket: 6629
(cherry picked from commit 4933b817aacc649edc52409426500a9ec271ccc6)

18 months agopgsql: fix u16 overflow in query data_row 10137/head
Juliana Fajardini [Wed, 11 Oct 2023 20:24:45 +0000 (17:24 -0300)] 
pgsql: fix u16 overflow in query data_row

Found by oss-fuzz with quadfuzz.

Cf https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63113

According to PostgreSQL documentation the maximum number of rows can be
the maximum of tuples that can fit onto max u32 pages - 4,294,967,295 (cf
https://www.postgresql.org/docs/current/limits.html). Some rough
calculations for that indicate that this could go over max u32, so
updating the data_row data type to u64.

Bug #6389

(cherry picked from commit 8d3de85edda97b0c585253803da3faeccc257942)

18 months agogithub/action: fix Debian 12 intermittent failures
Victor Julien [Thu, 7 Dec 2023 09:07:24 +0000 (10:07 +0100)] 
github/action: fix Debian 12 intermittent failures

Parallel builds caused issues during `cargo vendor`. So do just a single
thread build.

 make[4]: Entering directory '/__w/suricata/suricata/rust'
cbindgen --config /__w/suricata/suricata/rust/cbindgen.toml \
--quiet --output /__w/suricata/suricata/rust/dist/rust-bindings.h
CARGO_HOME="/github/home/.cargo"  /usr/bin/cargo vendor
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
ERROR: Couldn't execute `cargo metadata` with manifest "/__w/suricata/suricata/rust/Cargo.toml": Metadata(Output { status: ExitStatus(unix_wait_status(25856)), stdout: "", stderr: "    Blocking waiting for file lock on package cache\n    Blocking waiting for file lock on package cache\nerror: failed to download `adler v1.0.2`\n\nCaused by:\n  unable to get packages from source\n\nCaused by:\n  failed to parse manifest at `/github/home/.cargo/registry/src/github.com-1ecc6299db9ec823/adler-1.0.2/Cargo.toml`\n\nCaused by:\n  no targets specified in the manifest\n  either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present\n" })
ERROR: Couldn't generate bindings for /__w/suricata/suricata/rust.
make[4]: *** [Makefile:597: dist/rust-bindings.h] Error 1
make[4]: *** Waiting for unfinished jobs....

(cherry picked from commit c82d93490c4b41f3047f78aa34c4e135ddbf2c79)

18 months agodetect/bytejump: don't reuse content flag
Victor Julien [Fri, 8 Dec 2023 08:38:38 +0000 (09:38 +0100)] 
detect/bytejump: don't reuse content flag

To avoid future problems with overlapping flag values, give bytejump
its own DETECT_BYTEJUMP_OFFSET_VAR flag.

The values are currently not overlapping, so this patch should have
no side effects.

(cherry picked from commit 101452056d559b4e5eab27c2d9fb651d2e32c412)

18 months agodetect/analyzer: print int keyword values correctly
Victor Julien [Fri, 8 Dec 2023 09:31:21 +0000 (10:31 +0100)] 
detect/analyzer: print int keyword values correctly

To avoid negative values to be misrepresented.

Bug: #6615.
(cherry picked from commit de5b8ae0b45636352e641cff7eeb4f1fc89c8129)

18 months agojsonbuilder: add set_int for signed ints
Victor Julien [Fri, 8 Dec 2023 09:30:25 +0000 (10:30 +0100)] 
jsonbuilder: add set_int for signed ints

Bug: #6615
(cherry picked from commit b8440a0917548061049df19e4d42200df67cb478)

18 months agorust: allow clippy::items_after_test_module
Philippe Antoine [Thu, 4 Jan 2024 08:51:33 +0000 (09:51 +0100)] 
rust: allow clippy::items_after_test_module

As clippy began to complain about jsonbuilder.rs

(cherry picked from commit 673d13d44555843883915eb691b58a195ad021e8)

18 months agodetect/profiling: improve pcap reading performance
Victor Julien [Sat, 16 Dec 2023 15:45:00 +0000 (16:45 +0100)] 
detect/profiling: improve pcap reading performance

When reading a pcap, packet time can move much faster than wall
clock time. This would trigger many more profile syncs than before.

As the sync is using a lock to synchronize with other threads, this
is an expensive operation.

Bug: #6619.

Fixes: b591813b8690 ("profiling/rules: reduce sync logic scope")
(cherry picked from commit bcb2b50cfc34430e0e91dea781c90d2259ef8f0d)

18 months agodetect/content: fix offset for negative distance
Victor Julien [Wed, 20 Dec 2023 20:40:47 +0000 (21:40 +0100)] 
detect/content: fix offset for negative distance

Fix offset calculation on sigs with negative distance. Can lead to FN
in certain cases.

Bug: #6661.
(cherry picked from commit 2911656d6c11e8ef64a55ce64216382cd22151fe)

18 months agoeve/email: improve logging binary data
Victor Julien [Mon, 8 Jan 2024 06:43:04 +0000 (07:43 +0100)] 
eve/email: improve logging binary data

Use jb_append_string_from_bytes() as it works better than
BytesToString+jb_append_string when logging binary data.

Bug: #6664.
(cherry picked from commit f5565f42e7ae993963d7135271813ff30780bc96)

19 months agostats: incr app-proto flow counter for detection-only 10099/head
Philippe Antoine [Thu, 14 Dec 2023 10:31:37 +0000 (11:31 +0100)] 
stats: incr app-proto flow counter for detection-only

Ticket: 6633
(cherry picked from commit 3103505cb0fa87f18b63434a94c1b3814f5b8003)

19 months agopgsql: remove unused msg field 10081/head
Juliana Fajardini [Fri, 15 Dec 2023 16:57:01 +0000 (13:57 -0300)] 
pgsql: remove unused msg field

The `ConsolidatedDataRow` struct had a `length` field that wasn't truly
used.

Related to
Bug #6389

(cherry picked from commit 1afb485dfa253f4b409fa1acf0b7790cf1d2f09b)

19 months agodetect/transform: Clarify transformation validation 10067/head 10068/head
Jeff Lucovsky [Tue, 14 Nov 2023 13:23:43 +0000 (08:23 -0500)] 
detect/transform: Clarify transformation validation

Issue: 6439

Clarify the transform validation step. When a transform indicates that
the content/byte-array is not compatible, validation will stop.

Content is incompatible is some cases -- e.g., following the
to_lowercase transform with content containing uppercase characters.
An alert is not possible since the content contains uppercase and the
transform has converted the buffer into all lowercase.

(cherry picked from commit a46779d866b1b121adc73164215ba6437f53c208)

19 months agodetect/transform: Register case-change transforms
Jeff Lucovsky [Thu, 9 Nov 2023 13:35:46 +0000 (08:35 -0500)] 
detect/transform: Register case-change transforms

Issue: 6439
(cherry picked from commit 1110a86cb9bc3815aec2db1b5cc3253d63db53f5)

19 months agodoc/transform: Document case-changing transforms.
Jeff Lucovsky [Thu, 9 Nov 2023 11:22:55 +0000 (06:22 -0500)] 
doc/transform: Document case-changing transforms.

Issue: 6439
(cherry picked from commit 9ee55d23949a1bb42e6b48429d720fcc6c15147b)