]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
3 years agosmtp: check if there is a transaction to close 7172/head
Philippe Antoine [Tue, 22 Feb 2022 12:10:59 +0000 (13:10 +0100)] 
smtp: check if there is a transaction to close

Ticket: 4948

When parsing the response for starttls

3 years agotmqh: fix possible null dereference
Philippe Antoine [Tue, 15 Mar 2022 19:59:28 +0000 (20:59 +0100)] 
tmqh: fix possible null dereference

Coverity ID: 1502953

As we check just on the next line my_pool against NULL, we should
not dereference it, even for debug validation

3 years agodetect: remove dead code about xbits keyword
Philippe Antoine [Tue, 15 Mar 2022 19:55:09 +0000 (20:55 +0100)] 
detect: remove dead code about xbits keyword

3 years agolog: prevents use of uninitialized variable
Philippe Antoine [Thu, 10 Mar 2022 14:26:48 +0000 (15:26 +0100)] 
log: prevents use of uninitialized variable

Even if the code seems unreachable for now

3 years agodetect-content: error on single char hex pairs
Jason Ish [Tue, 22 Mar 2022 15:46:45 +0000 (09:46 -0600)] 
detect-content: error on single char hex pairs

Fix parsing of content like "|aa b cc|" which was parsed as "|aa bc|"
without error or warning. This will now fail out, requiring all hex
values to be 2 chars.

Ticket #5201

3 years agostreaming: remove unused 'auto slide' support
Victor Julien [Sun, 20 Mar 2022 15:14:10 +0000 (16:14 +0100)] 
streaming: remove unused 'auto slide' support

Add debug validation checks for "impossible" conditions.

3 years agodetect: makes config keyword really require a flow
Philippe Antoine [Tue, 8 Mar 2022 11:50:16 +0000 (12:50 +0100)] 
detect: makes config keyword really require a flow

Ticket: 4972

Completes commit c3a220647

DETECT_CONFIG is added as DETECT_SM_LIST_POSTMATCH and not
as DETECT_SM_LIST_MATCH as other keywords handled in SignatureCreateMask

3 years agodetect-pcre: remove unittests
Modupe Falodun [Fri, 4 Mar 2022 13:10:54 +0000 (14:10 +0100)] 
detect-pcre: remove unittests

These tests are reimplemented in Suricata-Verify

Task: 4911

3 years agonfs: Implement frames 7112/head
Sam Muhammed [Wed, 23 Feb 2022 12:15:00 +0000 (14:15 +0200)] 
nfs: Implement frames

Feature #4872

Frames:
  - RPC Frames: Generic over TCP/UDP
     - rpc.pdu
     - rpc.hdr
     - rpc.data
     - rpc.creds -- for rpc calls

  - NFSv2, NFSv3
     - nfs.pdu
     - nfs.status -- for nfs responses

  - NFSv4 Only Frames
     - nfs4.pdu
     - nfs4.hdr
     - nfs4.ops -- for compound request/response operations
     - nfs4.status -- for nfs4 responses

RPC tcp/udp frames created with separate registeration functions e.g:
add_rpc_tcp_tc_frames()
add_rpc_udp_tc_frames()

3 years agorpc: Improve rpc_record struct
Sam Muhammed [Mon, 28 Feb 2022 11:44:45 +0000 (13:44 +0200)] 
rpc: Improve rpc_record struct

Add creds_len field to rpc_record
needed for rpc.creds frame length calculation

3 years agorust/nfs4: Add NFSPROC4_DESTROY_CLIENTID op parsers
Sam Muhammed [Sun, 20 Feb 2022 17:46:03 +0000 (19:46 +0200)] 
rust/nfs4: Add NFSPROC4_DESTROY_CLIENTID op parsers

3 years agorust/nfs4: Add NFSPROC4_DESTROY_SESSION op parsers
Sam Muhammed [Sun, 20 Feb 2022 17:25:02 +0000 (19:25 +0200)] 
rust/nfs4: Add NFSPROC4_DESTROY_SESSION op parsers

Also add respective request unittest
test_nfs4_request_destroy_session()

3 years agorust/nfs4: Add NFSPROC4_LAYOUTRETURN op parsers
Sam Muhammed [Sun, 20 Feb 2022 17:10:41 +0000 (19:10 +0200)] 
rust/nfs4: Add NFSPROC4_LAYOUTRETURN op parsers

Also add respective request unittest
test_nfs4_request_layoutreturn()

3 years agorust/nfs4: Add NFSPROC4_GETDEVINFO op parsers
Sam Muhammed [Sun, 20 Feb 2022 16:40:11 +0000 (18:40 +0200)] 
rust/nfs4: Add NFSPROC4_GETDEVINFO op parsers

Also add respective response/request unittests
test_nfs4_response_getdevinfo()
test_nfs4_request_getdevinfo()

3 years agorust/nfs4: Add NFSPROC4_LAYOUTGET op parsers
Sam Muhammed [Sun, 20 Feb 2022 15:45:14 +0000 (17:45 +0200)] 
rust/nfs4: Add NFSPROC4_LAYOUTGET op parsers

Also add respective response/request unittests
test_nfs4_response_layoutget()
test_nfs4_request_layoutget()

3 years agorust/nfs4: Add NFSPROC4_SECINFO_NO_NAME op parsers
Sam Muhammed [Sun, 20 Feb 2022 12:47:08 +0000 (14:47 +0200)] 
rust/nfs4: Add NFSPROC4_SECINFO_NO_NAME op parsers

3 years agorust/nfs4: Add NFSPROC4_RECLAIM_COMPLETE op parsers
Sam Muhammed [Sun, 20 Feb 2022 12:27:17 +0000 (14:27 +0200)] 
rust/nfs4: Add NFSPROC4_RECLAIM_COMPLETE op parsers

3 years agorust/nfs4: Add NFSPROC4_CREATE_SESSION op parsers
Sam Muhammed [Sun, 20 Feb 2022 12:15:29 +0000 (14:15 +0200)] 
rust/nfs4: Add NFSPROC4_CREATE_SESSION op parsers

Also add respective response/request unittests
test_nfs4_request_create_session()
test_nfs4_response_create_session()

3 years agorust/nfs4: Add NFSPROC4_EXCHANGEID response parser
Sam Muhammed [Sun, 20 Feb 2022 11:28:12 +0000 (13:28 +0200)] 
rust/nfs4: Add NFSPROC4_EXCHANGEID response parser

Also add test_nfs4_response_exchangeid() unittest

3 years agorust/nfs4: improve NFSPROC4_OPEN op parser
Sam Muhammed [Sun, 20 Feb 2022 10:33:44 +0000 (12:33 +0200)] 
rust/nfs4: improve NFSPROC4_OPEN op parser

Improve nfs4_res_open() parser to reflect other file-delegation types
Reflect the changes on test_nfs4_response_open() unittest

3 years agofuzz: fix integer warnings
Philippe Antoine [Tue, 18 Jan 2022 09:50:46 +0000 (10:50 +0100)] 
fuzz: fix integer warnings

Ticket: 4516

3 years agoutils: fix integer warnings in r files
Philippe Antoine [Tue, 18 Jan 2022 09:43:56 +0000 (10:43 +0100)] 
utils: fix integer warnings in r files

Ticket: 4516

3 years agostream-tcp: fix integer warnings
Philippe Antoine [Mon, 17 Jan 2022 21:37:21 +0000 (22:37 +0100)] 
stream-tcp: fix integer warnings

Ticket: 4516

3 years agoutil: fix int warnings in tm threads
Philippe Antoine [Mon, 17 Jan 2022 21:22:49 +0000 (22:22 +0100)] 
util: fix int warnings in tm threads

Ticket: 4516

3 years agoutil: fix int warnings in unit tests
Philippe Antoine [Fri, 14 Jan 2022 12:15:57 +0000 (13:15 +0100)] 
util: fix int warnings in unit tests

Ticket: 4516

3 years agoutil: fix int warnings
Philippe Antoine [Fri, 14 Jan 2022 09:05:54 +0000 (10:05 +0100)] 
util: fix int warnings

Ticket: 4516

3 years agosmb: rules for messages in the wrong direction
Jason Ish [Mon, 28 Feb 2022 21:12:37 +0000 (15:12 -0600)] 
smb: rules for messages in the wrong direction

3 years agosmb: handle records in the wrong direction
Jason Ish [Fri, 18 Feb 2022 04:57:30 +0000 (22:57 -0600)] 
smb: handle records in the wrong direction

If an SMB record is seen in the wrong direction, set an event on the PDU
frame and don't process the record in the state.

No error is returned, so the next record will be processed.

3 years agosmb: expose smb1 request/reply flags with a method
Jason Ish [Fri, 18 Feb 2022 17:43:17 +0000 (11:43 -0600)] 
smb: expose smb1 request/reply flags with a method

Adds `.is_request()` and `.is_reply()` to check if a SMB record flags
say the message is a request or a reply.

3 years agosmb: fix smb2 header flag parsing
Jason Ish [Thu, 17 Feb 2022 22:52:44 +0000 (16:52 -0600)] 
smb: fix smb2 header flag parsing

The bits were being parsed in the order they're displayed in Wireshark,
rather than the order they were being seen on the wire, resulting in
direction and async being 0 more often than they should be.

Instead of bits, take the 4 bytes as an le_u32 and just use bit masks to
extract what we need into a struct, I think its easier to reason about
this way when comparing to the Microsoft documentation.

3 years agodetect: only apply ConfigApplyTx with app-layers
Philippe Antoine [Mon, 17 Jan 2022 13:47:48 +0000 (14:47 +0100)] 
detect: only apply ConfigApplyTx with app-layers

Ticket: 4972

Otherwise, it makes no sense to look for a tx...

3 years agoapplayer/frame: remove output from GetFrame funcs
Juliana Fajardini [Thu, 24 Feb 2022 16:04:36 +0000 (16:04 +0000)] 
applayer/frame: remove output from GetFrame funcs

As these functions can be probed, having output there results in
misleading output.

3 years agodetect-dce-iface: remove unittests
Modupe Falodun [Mon, 21 Feb 2022 15:43:04 +0000 (16:43 +0100)] 
detect-dce-iface: remove unittests

These tests are reimplemented in Suricata Verify

Task: 4911

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

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

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

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

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

Bug: #5168.

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

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

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

Bug: #5168.

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

So we can reuse it.

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

3 years agosrc: use u8_tolower everywhere
Philippe Antoine [Mon, 28 Feb 2022 07:32:42 +0000 (08:32 +0100)] 
src: use u8_tolower everywhere

Ticket: 4516

Instead of basic to_lower to get the cast to avoid warning
about integer

Sames goes for u8_toupper

3 years agorange: better closing for out of order ranges
Philippe Antoine [Mon, 28 Feb 2022 10:21:28 +0000 (11:21 +0100)] 
range: better closing for out of order ranges

Ticket: 5132

In case of a duplicate range, we can return early, because
there is no new data to process.

More importantly, this commit adds a check about wether the file
got closed meanwhile, so that this just completed out of order
range, even if it brings new data, is now irrelevant.
This can happen for instance if there was a gap...

3 years agorange: validity check when end is bigger than size
Philippe Antoine [Mon, 28 Feb 2022 10:19:49 +0000 (11:19 +0100)] 
range: validity check when end is bigger than size

Ticket: 5132

Down the line, HttpRangeOpenFileAux assumes the range has a
valid value when doing buflen = end - start + 1;

3 years agodetect-dnp3: remove dnp3_data unittests
Modupe Falodun [Mon, 28 Feb 2022 08:55:42 +0000 (09:55 +0100)] 
detect-dnp3: remove dnp3_data unittests

These tests are reimplemented in Suricata-Verify

Task: 4911

3 years agoutil/mime: fix integer warnings 7074/head
Philippe Antoine [Mon, 28 Feb 2022 07:56:07 +0000 (08:56 +0100)] 
util/mime: fix integer warnings

Ticket: 4516

3 years agodetect: minor debug fixup 7067/head
Victor Julien [Thu, 24 Feb 2022 21:01:32 +0000 (22:01 +0100)] 
detect: minor debug fixup

3 years agodecode/vntag: don't leak memory in tests
Victor Julien [Wed, 23 Feb 2022 19:58:57 +0000 (20:58 +0100)] 
decode/vntag: don't leak memory in tests

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

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

Mostly helps unittests.

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

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

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

Bug: #2802.

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

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

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

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

3 years agobytejump: fix ubsan warning
Philippe Antoine [Thu, 7 Oct 2021 14:39:42 +0000 (16:39 +0200)] 
bytejump: fix ubsan warning

Instead of checking the offset, we checked the pointer after
adding the offset ot it...

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

Issue 5072

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

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

Issue: 5072

This commit registers the proto-name unit tests.

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

Issue: 5072

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

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

Issue: 5072

This commit adds utility functions handling protocol names.

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

Issue: 5072

3 years agoDoc: Fix typo in documentation of suricata.yaml. 7056/head
Andreas Dolp [Fri, 4 Feb 2022 18:49:23 +0000 (19:49 +0100)] 
Doc: Fix typo in documentation of suricata.yaml.

3 years agobuild-info: add info about fuzztargets
Juliana Fajardini [Fri, 18 Feb 2022 14:24:25 +0000 (14:24 +0000)] 
build-info: add info about fuzztargets

We were missing that information from the Development information

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

Ticket 5130

3 years agodevguide: clarify style guide for getframe funcs
Juliana Fajardini [Fri, 18 Feb 2022 19:21:23 +0000 (19:21 +0000)] 
devguide: clarify style guide for getframe funcs

As the GetFrameIdByName can be probed, we must warn developers not to
leave any output in them, or misleading messages could be printed.

Task #5129

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

Issue: 4550

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

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

Issue: 4550

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

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

Issue: 4550

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

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

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

Issue: 4550

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

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

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

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

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

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

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

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

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

Minimal frag_len. Correct msgtype and others.

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

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

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

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

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

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

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

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

Bug: #5094.

3 years agorust/derive: pin proc-macro-crate to v1.1.0. 7022/head
Jason Ish [Thu, 17 Feb 2022 13:23:38 +0000 (07:23 -0600)] 
rust/derive: pin proc-macro-crate to v1.1.0.

The just released proc-macro-crate v1.1.2 requires at least Rust 1.53.
Pin to the previous release for now.

3 years agorust/mime: convert parser to nom7
Pierre Chifflier [Wed, 19 Jan 2022 10:58:49 +0000 (11:58 +0100)] 
rust/mime: convert parser to nom7

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

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

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

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

Debug validation checks are added to catch this.

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

Bug: #5084.
Bug: #5085.
Bug: #5086.

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

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

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

Bug: #5081.
Bug: #5066.

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

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

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

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

Bug: #5066.

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

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

Sequence:

- 100.117.241.0/25 inserted into the tree

- 100.117.241.0/26 inserted into the tree

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

Then faulty insert happens:

- 100.117.241.64/26

For reference, these net blocks compute to:

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

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

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

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

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

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

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

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

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

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

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

This patch addresses the issue as follows:

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

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

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

Issue was present for IPv6 as well.

Bug: #5066.

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

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

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

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

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

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

Add similar function for IPv6.

3 years agodoc/userguide: minor rewording and reformatting for runmodes 7013/head
Victor Julien [Wed, 16 Feb 2022 06:47:41 +0000 (07:47 +0100)] 
doc/userguide: minor rewording and reformatting for runmodes

3 years agodevguide: add page about app-layer frame support
Juliana Fajardini [Tue, 21 Sep 2021 21:26:26 +0000 (22:26 +0100)] 
devguide: add page about app-layer frame support

This explains the frame support from the perspective of a developer,
with introductory explanation on how to add frame support to an
applayer proto.

Doc #4697

3 years agohttp: add comment tags to support documentation
Juliana Fajardini [Wed, 9 Feb 2022 18:12:11 +0000 (18:12 +0000)] 
http: add comment tags to support documentation

With these, the portion of code within the tags should be included
in the related code-snippets (for frame support documentation) w/o
errors, even if the code within changes. The tags can also work as
a reminder that the existing code is being shown elsewhere, so folks
know documentation might need updates, in case of major changes.

3 years agorust: add comment tags to support documentation
Juliana Fajardini [Wed, 9 Feb 2022 17:26:25 +0000 (17:26 +0000)] 
rust: add comment tags to support documentation

With these, the portion of code within the tags should be included
in the related code-snippets (for frame support documentation) w/o
errors, even if the code within changes. The tags can also work as
a reminder that the existing code is being shown elsewhere, so folks
know documentation might need updates, in case of major changes.

3 years agosip: apply rustfmt to a few functions
Juliana Fajardini [Tue, 15 Feb 2022 16:14:50 +0000 (16:14 +0000)] 
sip: apply rustfmt to a few functions

Our current rust code isn't always documentation friendly when it
comes to using code snippets. Used rustfmt to apply rust default
formatting on functions that we wanted to show in our documentation
for Frame support

3 years agotelnet: apply rustfmt to parse_request
Juliana Fajardini [Wed, 9 Feb 2022 13:29:45 +0000 (13:29 +0000)] 
telnet: apply rustfmt to parse_request

When we want to share our code in our documentation pages, the current
rust formatting isn't so nice to read. Formatted just the portion of
the code that will be shown, for now.

3 years agonfs: limits the number of active transactions per flow
Philippe Antoine [Thu, 3 Feb 2022 20:55:09 +0000 (21:55 +0100)] 
nfs: limits the number of active transactions per flow

Ticket: 4530

3 years agonfs: remove unused events variable
Philippe Antoine [Tue, 15 Feb 2022 17:00:01 +0000 (18:00 +0100)] 
nfs: remove unused events variable

3 years agonfs: derive AppLayerEvent for NFSEvent
Philippe Antoine [Thu, 3 Feb 2022 20:58:51 +0000 (21:58 +0100)] 
nfs: derive AppLayerEvent for NFSEvent

3 years agofuzz: test for too many open txs in a flow
Philippe Antoine [Thu, 6 Jan 2022 14:51:00 +0000 (15:51 +0100)] 
fuzz: test for too many open txs in a flow

so as to avoid performance problems coming from this.