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

15 months agohttp2: do not log duplicate headers
Philippe Antoine [Thu, 28 Mar 2024 10:15:51 +0000 (11:15 +0100)] 
http2: do not log duplicate headers

Ticket: 6900

And thus avoid DOS by logging a request using a compressed
header block repeated many times and having a long value...

(cherry picked from commit 03442c9071b8d863d26b609d54c6eacf4de9e340)

15 months agohttp2: use a reference counter for headers
Philippe Antoine [Wed, 27 Mar 2024 13:33:54 +0000 (14:33 +0100)] 
http2: use a reference counter for headers

Ticket: 6892

As HTTP hpack header compression allows one single byte to
express a previously seen arbitrary-size header block (name+value)
we should avoid to copy the vectors data, but just point
to the same data, while reamining memory safe, even in the case
of later headers eviction from the dybnamic table.

Rust std solution is Rc, and the use of clone, so long as the
data is accessed by only one thread.

(cherry picked from commit 390f09692eb99809c679d3f350c7cc185d163e1a)

15 months agoutil/base64: fix buffer overflow
Philippe Antoine [Thu, 28 Mar 2024 13:00:02 +0000 (14:00 +0100)] 
util/base64: fix buffer overflow

Ticket: 6902

In case the caller of DecodeBase64 does not supply a big enough
output buffer.

(cherry picked from commit fd47e67dc65f9111895c88fb406c938b1f857325)

15 months agodefrag: fix check for complete packet
Jason Ish [Fri, 12 Jan 2024 17:09:59 +0000 (11:09 -0600)] 
defrag: fix check for complete packet

The list of fragments may still contain overlaps, so adding up the
fragment lengths is flawed. Instead track the largest size of
contiguous data that can be re-assembled.

Bug: #6675
(cherry picked from commit d226d0a3fce8837936e1bdfaee496c80d417e0a5)

15 months agodefrag: fix subsequent overlap of start of original (bsd)
Jason Ish [Thu, 7 Dec 2023 22:44:56 +0000 (16:44 -0600)] 
defrag: fix subsequent overlap of start of original (bsd)

Fix the BSD policy case where a subsequent fragment starts before an
original fragment and overlaps the beginning of the original
fragment. In this case the overlapping data from the new fragment is
preferred.

Suricata was preferring the data from the original fragment, but it
should only do that when the original fragment has an offset <= to the
new fragment.

- Adds test for this case

Bug: #6669
(cherry picked from commit f1709ea551124e1a64fdc509993ad022ab27aa77)

15 months agodefrag: check next fragment for overlap before stopping re-assembly
Jason Ish [Tue, 28 Nov 2023 18:35:26 +0000 (12:35 -0600)] 
defrag: check next fragment for overlap before stopping re-assembly

Instead of breaking the loop when the current fragment does not have
any more fragments, set a flag and continue to the next fragment as
the next fragment may have data that occurs before this fragment, but
overlaps it.

Then break if the next fragment does not overlap the previous.

Bug: #6668
(cherry picked from commit d0fd0782505d837e691ceef1b801776f0db82726)

15 months agodefrag: use uint8_t in unit tests
Jason Ish [Fri, 12 Jan 2024 15:26:22 +0000 (09:26 -0600)] 
defrag: use uint8_t in unit tests

(cherry picked from commit bdd17de73d6507a02729e069d31c590a760fb9b7)

15 months agodefrag: consistent unit test naming
Jason Ish [Mon, 27 Nov 2023 22:27:27 +0000 (16:27 -0600)] 
defrag: consistent unit test naming

Use a more consistent naming scheme between ipv4 and ipv6.

(cherry picked from commit 2f00b5870abc6053fca8271a0a827babc03d56f0)

15 months agodefrag: make tests more readable
Jason Ish [Mon, 27 Nov 2023 21:59:23 +0000 (15:59 -0600)] 
defrag: make tests more readable

Make tests more readable for comparing to the paper "Target-Based
Fragmentation Reassembly".

(cherry picked from commit 6339deadceaf84654b62d23f3292cb514d6587a5)

15 months agodefrag: minor cleanups
Jason Ish [Fri, 8 Dec 2023 22:27:12 +0000 (16:27 -0600)] 
defrag: minor cleanups

- typo in comment
- remove debug function that is not used and no longer valid

(cherry picked from commit 276d3d6541327891b027bd5e3ee7994c58ea3fb3)

15 months agoips: check for livedev.use-for-tracking 10922/head 10927/head
Victor Julien [Tue, 16 Apr 2024 13:07:46 +0000 (15:07 +0200)] 
ips: check for livedev.use-for-tracking

For the capture methods that support livedev and IPS,
livedev.use-for-tracking is not supported.

This setting causes major flow tracking issues, as both sides of
a flow would be tracked in different flows.

This patch disables the livedev.use-for-tracking setting if it
is set to true. A warning will be issued.

Ticket: #6726.
(cherry picked from commit 08841f27ffc1b0e06d2d08d9336a73032261c78c)

15 months agocapture: improve IDS + IPS check
Victor Julien [Tue, 16 Apr 2024 13:38:13 +0000 (15:38 +0200)] 
capture: improve IDS + IPS check

Improve it for af-packet, dpdk, netmap. Check would not consider
an interface IDS if the `default` section contained a copy-mode
field.

(cherry picked from commit 58bff9b85508671f45f044d3fe212d29ffe1f95a)

15 months agostreaming/buffer: improve integer handling safety
Victor Julien [Thu, 28 Mar 2024 12:46:23 +0000 (13:46 +0100)] 
streaming/buffer: improve integer handling safety

Unsafe handling of buffer offset and to be inserted data's length
could lead to a integer overflow. This in turn would skip growing
the target buffer, which then would be memcpy'd into, leading to
an out of bounds write.

This issue shouldn't be reachable through any of the consumers of
the API, but to be sure some debug validation checks have been
added.

Bug: #6903.
(cherry picked from commit cf6278f95adaba86e0db578dad95cba386a7d509)

15 months agodetect/http-server-body: avoid FP on toserver direction
Philippe Antoine [Wed, 17 Apr 2024 11:39:39 +0000 (13:39 +0200)] 
detect/http-server-body: avoid FP on toserver direction

Ticket: 6948

http.response_body keyword did not enforce a direction, and thus
could match on files sent with POST requests

(cherry picked from commit e6895b835a76a96a18c5e9c33f46c89687eceab9)

15 months agodpdk: support 52 byte long key on ice (E810) cards 10917/head
Lukas Sismis [Tue, 26 Mar 2024 21:17:17 +0000 (22:17 +0100)] 
dpdk: support 52 byte long key on ice (E810) cards

Ticket: 6872

(cherry picked from commit 10590e6d946ff8711acef09cfe3f79be88910c17)

15 months agodpdk: enlarge key length to 52 bytes
Lukas Sismis [Tue, 26 Mar 2024 21:16:29 +0000 (22:16 +0100)] 
dpdk: enlarge key length to 52 bytes

(cherry picked from commit d4085fceb6998a8257df99c7b546c6d6ecc75e1b)

15 months agodetect/ipopts: Handle multiple ip options
Jeff Lucovsky [Tue, 16 Apr 2024 12:34:42 +0000 (08:34 -0400)] 
detect/ipopts: Handle multiple ip options

Issue: 6864

Multiple IP options were not handled properly as the value being OR'd
into the packet's ip option variable were enum values instead of bit
values.

(cherry picked from commit d7026b7b11e117cbaa99d2a56be3738a84c08d5c)

15 months agodetect/ipopts: Remove unneeded PCRE logic
Jeff Lucovsky [Thu, 21 Mar 2024 13:37:26 +0000 (09:37 -0400)] 
detect/ipopts: Remove unneeded PCRE logic

Issue: 6864

Reduce complexity by eliminating the PCRE logic and adding a unittest to
validate null/empty string handling

(cherry picked from commit ee942391f78d9d1c88f28eefc22072b1c14179bd)

15 months agodetect/ipopt: Misc. cleanup
Jeff Lucovsky [Thu, 21 Mar 2024 13:38:57 +0000 (09:38 -0400)] 
detect/ipopt: Misc. cleanup

Minor changes to improve readability, remove extraneous include files.

(cherry picked from commit c27dee7a9baf5b5c6697e80aef7f83a43dd3b709)

15 months agodataset: cleanup datasets that hit the memcap while loading 10905/head 10913/head
Andreas Herz [Tue, 16 Apr 2024 15:22:20 +0000 (17:22 +0200)] 
dataset: cleanup datasets that hit the memcap while loading

Datasets that hit the memcap limit need to be discarded if the memcap is
hit or otherwise the datasets are still loaded with partial data while
the signature is not loaded due to the memcap error.

Ticket: #6678
(cherry picked from commit 1f9600e487173b785de186184d93633b246425fd)

15 months agoci: clean some disk space to run CIFuzz again 10886/head
Philippe Antoine [Fri, 12 Apr 2024 08:32:46 +0000 (10:32 +0200)] 
ci: clean some disk space to run CIFuzz again

(cherry picked from commit 365a66ac1cd6eebfdbcf1f58e91d1ce3d7242286)

15 months agoconf: avoid quadratic complexity 10874/head
Philippe Antoine [Thu, 21 Mar 2024 08:38:25 +0000 (09:38 +0100)] 
conf: avoid quadratic complexity

Ticket: 6878

Follow up on 15649424a76d01eb332d85620ffc4956d4f3d9be

When adding many sequence nodes, either from start or scalar event

We add "sequence nodes" whose name is an integer cf sequence_node_name
and then run ConfNodeLookupChild to see if it had been already set
(from the command line cf comment in the code)
And ConfNodeLookupChild iterates the whole linked list...

1. We add node 1
2. To add node 2, we check if node 1 equals this new node
3. To add node 3, we check if nodes 1, or 2 equals this new node's name
And so on...

This commits avoids these checks ig the list is empty at the beginning

(cherry picked from commit 240e068b81275e287ffe6555d4c457a0b3916066)

15 months agoflow/inject: Select thread_id by flow flag 10861/head
Jeff Lucovsky [Mon, 15 Apr 2024 14:17:17 +0000 (10:17 -0400)] 
flow/inject: Select thread_id by flow flag

Issue: 6957

Rather than selecting the thread_id index by packets traveling to the
server, use the flow flags. If the flow has been reversed, the second
slot is represents the thread id to be used.

(cherry picked from commit c305ed149c58818779c504b6666fe9c2cb0be4ff)

15 months agoschema: Add stats.capture and in_iface properties
Arne Welzel [Tue, 20 Feb 2024 11:50:40 +0000 (12:50 +0100)] 
schema: Add stats.capture and in_iface properties

New suricata-verify test listens on loopback interface, resulting
in the capture and in_iface fields in the stats and event objects.

(cherry picked from commit f9cf87a003d273ec175590e2ffec053d2672af95)

15 months agostats: Fix non-worker stats missing
Arne Welzel [Sat, 17 Feb 2024 17:19:27 +0000 (18:19 +0100)] 
stats: Fix non-worker stats missing

Commit b8b8aa69b49ac0dd222446c28d00a50f9fd7d716 used tm_name of the
first StatsRecord of a thread block as key for the "threads" object.
However, depending on the type of thread, tm_name can be NULL and would
result in no entry being included for that thread at all. This caused
non-worker metrics to vanish from the "threads" object in the
dump-counters output.

This patch fixes this by remembering the first occurrence of a valid
tm_name within the per-thread block and adds another unittest to
cover this scenario.

(cherry picked from commit f17204191d3bb2201e6b6b1c4cf2e7a96148e8cd)

15 months agopcap: support LINKTYPE_IPV6 (229)
Victor Julien [Fri, 12 Apr 2024 09:02:13 +0000 (11:02 +0200)] 
pcap: support LINKTYPE_IPV6 (229)

This is just another variant of DLT_RAW.

Ticket: #6943.
(cherry picked from commit 76322368ed3ef89c04082939c58535c7234d7173)

15 months agodefrag: fix wrong datalink being logged
Victor Julien [Sat, 23 Mar 2024 19:17:54 +0000 (20:17 +0100)] 
defrag: fix wrong datalink being logged

Eve's packet_info.linktype should correctly indicated what the `packet`
field contains. Until now it was using DLT_RAW even if Ethernet or other
L2+ headers were present.

This commit records the datalink of the packet creating the first
fragment, which can include the L2+ header data.

Bug: #6887.
(cherry picked from commit 49c67b2bb1baa84b7105bca82afe6909be890855)

15 months agodefrag: match up v4 and v6 packet setup
Victor Julien [Sun, 3 Dec 2023 20:15:36 +0000 (21:15 +0100)] 
defrag: match up v4 and v6 packet setup

v4 was doing redundant recursion level setup.

v6 was missing PKT_REBUILT_FRAGMENT flag.

(cherry picked from commit af97316f42c6616536dc8012577827fee9a56f11)

15 months agodoc: add note about fast_pattern w base64_data 10846/head
Shivani Bhardwaj [Wed, 3 Apr 2024 07:12:11 +0000 (12:42 +0530)] 
doc: add note about fast_pattern w base64_data

Bug 6859

15 months agobase64_data: inform of use w fast_pattern
Shivani Bhardwaj [Wed, 3 Apr 2024 07:02:12 +0000 (12:32 +0530)] 
base64_data: inform of use w fast_pattern

Bug 6859

15 months agojsonbuilder: fix serialization of nan and inf 10799/head
Jason Ish [Fri, 5 Apr 2024 14:35:36 +0000 (08:35 -0600)] 
jsonbuilder: fix serialization of nan and inf

When outputting a float, check if its infinity, or not a number and
output a null instead.

Using a null was chosen as this is what serde_yaml, Firefox, Chrome,
Node, etc. do.

Ticket: #6921
(cherry picked from commit 71f59e529c3ceaba977ec5d3492bb8b3d3184cd1)

15 months agodetect/http: fix compile warning in body tests 10793/head
Victor Julien [Thu, 28 Mar 2024 09:43:46 +0000 (10:43 +0100)] 
detect/http: fix compile warning in body tests

When --enable-unittests w/o --enable-debug is used.

(cherry picked from commit e651cf922a02f5882593a23bd2ed9327a5e8d2cc)

15 months agohost-info: remove pcre2_substring_list_free use
Victor Julien [Thu, 4 Apr 2024 15:51:48 +0000 (17:51 +0200)] 
host-info: remove pcre2_substring_list_free use

Function prototype has changed in a recent release. Rather than dealing
with detecting that, fall back to our regular pattern of using
pcre2_substring_copy_bynumber().

Bug: #6918.
(cherry picked from commit b224209f45317abfbea1a1f43f17fa63ae904745)

15 months agoconfigure: .git can be a file as well
Jason Ish [Fri, 5 Apr 2024 16:33:14 +0000 (10:33 -0600)] 
configure: .git can be a file as well

In worktree scenarios, .git is a file. Assuming its a directory causes
the release date to check the ChangeLog instead of the last commit,
while not a big issue, can be confusing.

15 months agoconfigure: export release date for documentation
Jason Ish [Mon, 1 Apr 2024 16:37:49 +0000 (10:37 -0600)] 
configure: export release date for documentation

Sphinx embeds a date in the generated man pages, and to provide
reproducible builds this date needs to be provided to Sphinx,
otherwise it will use the current date.

If building from Git, extract the date from the most recent commit. In
a release, this commit would be the commit that sets the version so is
accurate.

If .git does not exist, use the most recent data found in the
ChangeLog.

The ChangeLog is not used when building from git, as the main/master
branch may not have recent enough timestamps.

This should provide a consistent date when re-building the
distribution from the same non-git archive, or from the same git
commit.

Ticket: #6911
(cherry picked from commit b58dd5e5855864217fe898b43a3e8f9aaff47ae9)

15 months agodocs/userguide: use a consistent date for reproducible builds
Jason Ish [Mon, 1 Apr 2024 16:35:39 +0000 (10:35 -0600)] 
docs/userguide: use a consistent date for reproducible builds

By default, when Sphinx generates the man pages, the current date will
be embedded in them. This can be set to a specific date with the
"today" variable. Typically the date embedded in manpages in the
release date.

To achieve this, attempt to use the environment variable, RELEASE_DATE
to set the "today" variable, reverting back to the empty string if not
set. It is up to our build system to properly set this date.

Ticket: #6911
(cherry picked from commit 51bf1c35103261d075a283d103371a2d9a8a76f7)

15 months agoconfigure: don't check ./revision, it never exists
Jason Ish [Tue, 2 Apr 2024 15:41:08 +0000 (09:41 -0600)] 
configure: don't check ./revision, it never exists

Stop checking the ./revision file for the git revision info, its never
created.

(cherry picked from commit c00c2b116fb0ca2ecdec7a95d94454bce9c18595)

15 months agodocs/conf.py: fix python escape warning
Jason Ish [Mon, 1 Apr 2024 16:34:45 +0000 (10:34 -0600)] 
docs/conf.py: fix python escape warning

/home/jason/oisf/dev/suricata/master/doc/userguide/conf.py:74: SyntaxWarning: invalid escape sequence '\('
  "AC_INIT\(\[suricata\],\s*\[(.*)?\]\)",

(cherry picked from commit 4c16032f63c85eb6bb29b37505440cfe9072c372)

15 months agodpdk: add interrupt (power-saving) mode
Lukas Sismis [Wed, 27 Sep 2023 12:38:36 +0000 (14:38 +0200)] 
dpdk: add interrupt (power-saving) mode

When the packet load is low, Suricata can run in interrupt
mode. This more resembles the classic approach of processing
packets - CPU cores run low and only fetch packets
on interrupt.

Ticket: #6696
(cherry picked from commit 2a2898053c120fa59cb792623b10c2660d8e8cde)

16 months agoflow: Swap thread_ids 10738/head 10770/head 10771/head
Jeff Lucovsky [Mon, 11 Mar 2024 18:58:07 +0000 (14:58 -0400)] 
flow: Swap thread_ids

Issue: 6835

When swapping the flow's direction, also swap the thread_ids.

This should help with the issues identified in
https://redmine.openinfosecfoundation.org/issues/2725

(cherry picked from commit 3c5745978f85f4bf049e2892c8bda167f9e53033)

16 months agoflow/inject: Ensure initialized thread value used
Jeff Lucovsky [Mon, 11 Mar 2024 18:57:16 +0000 (14:57 -0400)] 
flow/inject: Ensure initialized thread value used

Issue: 6835

When injecting a flow, ensure that the selected thread_id has been
initialized. When a flow is picked up midstream, the initialized thread
can be the second thread element.

(cherry picked from commit 9ad73faa0a52428e47412474514b125fda6aa03d)

16 months agorust/mqtt: fix clippy 1.77 warning 10721/head 10724/head
Philippe Antoine [Thu, 21 Mar 2024 21:45:41 +0000 (22:45 +0100)] 
rust/mqtt: fix clippy 1.77 warning

error: creating a mutable reference to mutable static is discouraged
   --> src/mqtt/mqtt.rs:752:23
    |
752 |     let max_msg_len = &mut MAX_MSG_LEN;
    |                       ^^^^^^^^^^^^^^^^ mutable reference to mutable static
    |
    = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
    = note: this will be a hard error in the 2024 edition
    = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior

16 months agorust/smb: fix clippy nightly warning
Philippe Antoine [Thu, 21 Mar 2024 15:15:53 +0000 (16:15 +0100)] 
rust/smb: fix clippy nightly warning

error: unnecessary use of `to_vec`
    --> src/smb/smb.rs:1048:62
     |
1048 |         let (name, is_dcerpc) = match self.guid2name_map.get(&guid.to_vec()) {
     |                                                              ^^^^^^^^^^^^^^ help: replace it with: `guid`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned
     = note: `#[deny(clippy::unnecessary_to_owned)]` implied by `#[deny(warnings)]`

And also other uses of to_vec() on already Vec

(cherry picked from commit f7cde8f00ef6d1f92bd86a47d5888bda06941f46)

16 months agorust: fix clippy 1.77 warning
Philippe Antoine [Thu, 21 Mar 2024 15:02:23 +0000 (16:02 +0100)] 
rust: fix clippy 1.77 warning

Ticket: 6883

error: field `0` is never read
  --> src/asn1/mod.rs:36:14
   |
36 |     BerError(Err<der_parser::error::BerError>),
   |     -------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |     |
   |     field in this variant
   |

(cherry picked from commit 02f2fb88333af767ab3b171643357d607f4e86f6)

16 months agorust: add MSRV as rust-version 10677/head
Victor Julien [Wed, 20 Mar 2024 10:02:44 +0000 (11:02 +0100)] 
rust: add MSRV as rust-version

Update github-actions to use it for the MSRV check.

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)