Commit Graph

13661 Commits (6c88cc1e0c7f8ef0c2518cb00e58b834b862f1e6)

Author SHA1 Message Date
Jason Ish 708874053f detect/mpm: prevent format string truncation warnings
- Declare the profiling name variable once we know the actual size allowed
for the name instead of before. Prevents an snprintf truncation warning.

- Account for the null byte when calculating how much space is left to
avoid an snprintf format string truncation warning.
1 year ago
Victor Julien 2b6df6381a detect/mpm: improve profiling name for frame/pkt buffers 1 year ago
Victor Julien 6655283d2d detect/mpm: improve profiling name creation
The (p)name is used in profiling and will now always have the full id.

Ticket: #7861.
1 year ago
Victor Julien 38a2cba5c3 misc: harden string shortener
Ticket: #7861.
1 year ago
Philippe Antoine d590fdfe42 detect/tls: fix null deref with subjectaltname
Ticket: 7881
1 year ago
Jeff Lucovsky 9f32550e18 detect/entropy: Ensure entropy matcher has flow
Make sure that the flow is available to the entropy matcher so it can
handle content that's not anchored to a sticky buffer.

Issue: 7838
1 year ago
Victor Julien 39dfcaf1b3 unix-socket: address scan-build warning
CC       unix-manager.o
unix-manager.c:258:13: warning: Use of memory after it is freed [unix.Malloc]
  258 |         if (item->fd == fd) {
      |             ^~~~~~~~
1 warning generated.
1 year ago
Victor Julien f963c408bd unix-socket: fix memory leak on client disconnect
If a client loses the connection during a reload it initiated there is
a small memory leak.

Bug: #7891.
1 year ago
Shivani Bhardwaj 5820b52b0a detect: remove redundant fw rule path log 1 year ago
Victor Julien f333a528f3 stream: workaround scan-build warnings
stream-tcp.c:1938:16: warning: Access to field 'next' results in a dereference of a null pointer (loaded from variable 'tail') [core.NullDereference]
 1938 |     tail->next = old_head;
      |     ~~~~       ^
1 warning generated.

stream-tcp.c:1982:5: warning: Potential leak of memory pointed to by 'q' [unix.Malloc]
 1982 |     ssn->queue_len++;
      |     ^~~
1 warning generated.
1 year ago
Victor Julien d352b75ac6 stream: add more liberal timestamp behavior in 3WHS
RFC 7323 forbids a server to respond with a timestamp option in the
SYN/ACK when the SYN didn't have a timestamp option:

   A TCP MAY send the TSopt in an initial <SYN> segment (i.e., segment
   containing a SYN bit and no ACK bit), and MAY send a TSopt in
   <SYN,ACK> only if it received a TSopt in the initial <SYN> segment
   for the connection.

   Once TSopt has been successfully negotiated, that is both <SYN> and
   <SYN,ACK> contain TSopt, the TSopt MUST be sent in every non-<RST>
   segment for the duration of the connection, and SHOULD be sent in an
   <RST> segment (see Section 5.2 for details).

However, in the real world this pattern happens on benign traffic. This
would lead to missing logs and detection, and in IPS mode such sessions
would be blocked.

This patch allows this pattern when the `stream.liberal-timestamps` is
enabled (enabled by default).

Bug #4702.
1 year ago
Victor Julien be6315dba0 stream: improve SYN and SYN/ACK retransmission handling
Take SEQ and ACK into account for more scenarios.

SYN on SYN_SENT

In this case the SYN packets with different SEQ and other properties are
queued up. Each packet updates the ssn to reflect the last packet to
come in. The old ssn data is added to a TcpStateQueue entry in
TcpSession::queue. If the max queue length is exceeded, the oldest entry
is evicted. The queue is actually a single linked list, where the list
head reflects the oldest entry.

SYN/ACK on SYN_SENT

In this case the first check is if the SYN/ACK matches the session. If
it doesn't, the queue is checked to see if there SYN's stored. If one is
found that matches, it is used and the session is updated to reflect
that.

SYN/ACK on SYN_RECV

SYN/ACK resent on the SYN_RECV state. In this case the ssn is updated
from the current packet. The old settings are stored in a TcpStateQueue
entry in the TcpSession::queue.

ACK on SYN_RECV

Checks any stored SYN/ACKs before checking the session. If a queued
SYN/ACK was sound, the session is updated to match it.

Ticket: #3844.
Ticket: #7657.
1 year ago
Victor Julien d815d0748c stream: avoid ineffective state bump in TFO
Do not set session state to established, as it is unconditionally
overwritten to syn_recv afterwards.
1 year ago
Victor Julien 49b98ab3bf stream: minor improvement to timestamp debug messages
Add pcap_cnt for easier debugging.
1 year ago
Thomas Winter 804ce2ed3c decode/pppoe: CDPCP as a known protocol
Cisco Discovery Protocol Control Protocol may be sent over pppoe.
We should allow it to help network functions.
1 year ago
Thomas Winter 1f5fc68dc4 decode/pppoe: Don't mark expected PPP protos as unsupported
After upgrading from 7.0.6 to 7.0.8, regular ppp packets are getting
dropped when ppp rules in decoder-events.rules were set as drop.
This was caused by commit a8f35806 ("detect: fix decoder only events").
Previously these rules would not be alerted or dropped.

It turns out several PPP protocols in a switch statement were falling
into the PPP_UNSUP_PROTO case. This has always been the case, I assume
the intention was that they don't get further inspected for size and
other decode errors hence unsupported.
But really some of the protocols are fundamentally required for a PPP
connection to take place.

Change some types that we know should be allowed to pass this.

Ticket: 7651
1 year ago
Thomas Winter 498ae6d1fa decode/pppoe: Run clang-format
These files have existing problems which prevent patches from
passing the format check on them.
1 year ago
Philippe Antoine 5379b52af2 detect/tls: tls.cert_subject is not a multi-buffer
Ticket: 7867
1 year ago
Philippe Antoine 08ee3c3447 detect/dsize: define offset in edge case
Ticket: 7802
1 year ago
Philippe Antoine 06c82a79ab output/alert-debug: do not return on app-layer
just continue, so that we call aft->file_ctx->Write

Ticket: 4178
1 year ago
Juliana Fajardini 1d27e268d1 schema: add descriptions for flow stats counters
Task #7794
1 year ago
Shivani Bhardwaj b7866b8043 stream: remove incorrect defensive check
As a part of the commit d096b98 a defensive check was added stating that
the stream must have EOF flag set if it is in TCP_CLOSING state or
above. However, this led to a false positive reported by oss-fuzz whose
analysis showed that this does not hold true for TCP_CLOSING state. It
does hold true only for TCP_CLOSED or if packet has PKT_PSEUDO_STREAM_END
set.
TCP_CLOSING state correspond to an established flow hence the correct
course of action is to remove the assertion.

Bug 7636

Co-authored-by: Philippe Antoine <pantoine@oisf.net>
1 year ago
Philippe Antoine 287b1323ba detect/integer: support missing modes for u8 prefilter
Ticket: 7865

<=, >=, and != were missing

Also warns if an unimplemented mode is tried
1 year ago
Charlie Vigue 84145e212d util: Fix a hash table collision bug
In util-hash.c there was some behavior that is unexpected and likely
incorrect. To see this behavior, create a hash table 32 entries wide
and use the default hash function. Then add a short string “abc”,
observe the string is stored properly. Now remove a string “iln”, and
observe string “abc” is no longer in the table.

This is because the hash function is not properly handling collisions in
some edge cases.

Includes new unit test:

- UT verifies that the hash function generates a collision for
  the selected test data. This must be true for the bug to be present.
  Then UT demonstrates the bug by adding two items to the hash table
  that collide, and then removing one of them 2x. The bug is that the
  other value is removed as well.

Bug #7828 --> https://redmine.openinfosecfoundation.org/issues/7828

Signed-off-by: Charlie Vigue <charlie.vigue@openvpn.com>
1 year ago
Boris Tonofa 080995f551 detect-file-hash: drop redundant rule_file NULL check
de_ctx->rule_file is never NULL inside DetectFileHashParse(); add a comment
stating this fact and remove the superfluous NULL guard.

No functional change – the patch only clarifies the code and trims a few
lines of dead code.

Bug 7769
1 year ago
Juliana Fajardini 49629f7cb6 schema/decoder: add descriptions for stats counters
Task #7793
1 year ago
Adam Kiripolsky 775fc7795e dpdk: fix parsing of DPDK EAL argument options
Fix parsing of DPDK EAL argument options taken from suricata.yaml.

Ticket: 7856
1 year ago
Jeff Lucovsky e57eeb24b5 misc: fix typos
Fix typos in src/detect-engine.c

Issue: 7819
1 year ago
Jeff Lucovsky 06e89736b3 detect/mt: Prevent deadlock when adding tenants
This commit modifies the call path for registering MT tenants to avoid
deadlocks on the master->lock

When performing tenant operations, e.g., using suricatasc to send a
register-tenant command, a deadlock occurs when

- DetectEngineMTApply: acquires master->lock
- Calls DetectEngineReloadThreads
- Within DetectEngineReloadThreads, calls DetectEngineMultiTenantEnabled
- Which first acquires master->lock

Commit 2bea5af introduced changes to the master->lock usage leading to
the deadlock situation.

Issue: 7819
1 year ago
Shivani Bhardwaj 982c9222dd detect/port: add BUG_ON on impossible condition
to assist Coverity in assessing the state of x correctly.
1 year ago
Shivani Bhardwaj e54dd8d814 detect/port: clean up already initialized vars 1 year ago
Shivani Bhardwaj 917c6f3da7 engine/analyzer: write rule failure report to correct file
The failure report was always just written to rules_fast_pattern.txt. In
case that setting is disabled or there's nothing fast-pattern related,
the report should be written to the usual rules_analysis.txt.

Bug 7821
1 year ago
Shivani Bhardwaj eb39dba5dd engine/analyzer: check if file pointer exists before writing
de_ctx->ea->fp_engine_analysis_fp is only initialized if
engine-analysis.rules-fast-pattern is enabled in the configuration. If
this config param is missing, this leads to segfault.

Bug 7822
1 year ago
Juliana Fajardini 03bc95c108 detect/engine: simplify stats counters registration 1 year ago
Juliana Fajardini a8453d73cd detect: remove unused non-pf stats counters
Remove unused rule prefilter-related stats counters that aren't in use.

94644ac960 (detect: move non-pf rules into special prefilter engines)
removed the logic that made use of and incremented the stats counters:
- det_ctx->counter_fnonmpm_list
- det_ctx->counter_nonmpm_list

Some code was left, registering them, and mentioning them in the
json schema.

Ticket #7834
1 year ago
Philippe Antoine 2e3dfd318b file: remove unused flag
FLOWFILE_NO_SIZE_* are unused, whose removal shows that
SIG_GROUP_HEAD_HAVEFILESIZE gets unused, whose removal shows that
SignatureIsFilesizeInspecting gets unused
1 year ago
Adam Kiripolsky fe2d64e758 app-layer: fix ippair memcap counters
Fixed counter for ippair.memcap by using the correct function,
IPPairGetMemcap.
Until now IPPairGetMemuse was used both for memuse and memcap.

Ticket: 7827
1 year ago
Lukas Sismis e4a406d375 hyperscan: prevent LTO opmitizing out hash calculation
Since cached_hash was updated through reference (hash), it seems
LTO did not notice this and optimized the whole code block, returning
zero.
This in turn caused all caches to have the same name and to overwrite.
On subsequent runs, only the last cache was loaded for all SGHs
causing wrong MPM assignment.

Ticket: 7824
1 year ago
Jason Ish 81e7316616 lua/bytevarlib: return luaL_error to suppress warning
Even though luaL_error never returns, use a return to make it
clear. Also prevents a compiler warning about idx being used
uninitialized.
1 year ago
Jason Ish 0e80aca3c3 detect-engine-address: initialize pointer in unit tests
To prevent the compiler warning about "c" being used uninitialized
with LTO.
1 year ago
Jason Ish a1c5e93d45 util-byte: fix usage of util-byte integer parsers
Functions like ByteExtractStringUint8 return 0 or less on
failure. Many usages of this function treat 0 as successful as its our
common pattern.

Ticket: #7836
1 year ago
Philippe Antoine c20dddb046 output: fix NULL deref if no app-layer is logged
Ticket: 7815
1 year ago
Philippe Antoine 9a01c1be8e output: fix condition for community id with same ip
Ticket: 5689
1 year ago
Philippe Antoine 271854a3ea counters: hard fail on allocation failure during init
Ticket: 7813
1 year ago
Philippe Antoine 9545eab4c8 conf/output: friendly error message on bad configuration
Ticket: 7611

Instead of segfault

output.types expects a sequence of one-key mappings, instead
of directly a mapping
1 year ago
Philippe Antoine 7be505e887 doh: do not log dns events when there is no DNS
Ticket: 7740

When we have a pure HTTP2 transaction (such as settings), we want
to log a http event
1 year ago
Eric Leblond a28d544550 doc: add some missing url and desc
Keywords registration should provide a desc and a link to the
documentation. This patch adds desc and/or url for on most keywords
missing that.

This allows better output for list-keywords command line which
is then use in Suricata Language Server.
1 year ago
Jason Ish 116d1763d9 lib: opt-in signal handlers
Instead of enabling signal handlers by default, require the user of
the library to opt-in. This is done with the call to
SCEnableDefaultSignalHandlers, which sets a flag to add the default
signal handlers.

This seems like the least invasive way to do this at this time, but it
will require some re-thinking for 9.0, especially if migrate globals
to engine instances, signal handling will need to be re-thought.

Ticket: #6814
1 year ago
Lukas Sismis 239de05b9d dpdk: auto threads assign one too many threads
Configuration option `threads: auto` in DPDK's interface node
overassigns available threads to the interface.
Commit 4dfd44d3 changed the signedness of the remaining threads counter,
which caused surpass of the counter initialization.
The if-clause is switched to first initialize and then use the counter.

Ticket: 7798
1 year ago
Boris Tonofa 66e7437bef detect-bytetest: remove meaningless NULL check on data_offset
The condition data_offset == NULL can never be true: data_offset has
already been validated as non-NULL a few lines earlier. The guard seems
to have been intended for the offset argument, yet throughout the
codebase offset is never passed as NULL. (In the unit tests, offset is
NULL, but those tests pass the value parameter as NULL, which causes the
function to return before offset is dereferenced.)

Remove the pointless check to simplify control flow and silence
static-analysis warnings.

No functional change.

Bug 7767
1 year ago