Commit Graph

13092 Commits (65b863b087d8f6d7c0800700f89ca33f06ad861f)

Author SHA1 Message Date
Jeff Lucovsky e9717f3ad2 detect/lua: Fix max value displayed in error msg
This commit corrects an error message displayed when the key length is
out of range.
2 years ago
Jeff Lucovsky 3d26f917ee var: Use 16-bit container for type
Issue: 6855: Match sigmatch type field in var and bit structs

Align the size and datatype of type, idx, and next members across:
- FlowVarThreshold
- FlowBit
- FlowVar
- GenericVar
- XBit
- DetectVarList

Note that the FlowVar structure has been intentionally constrained to
match the structure size prior to this commit. To achieve this, the
keylen member was restricted to 8 bits after it was confirmed its value
is checked against a max of 0xff.
2 years ago
Philippe Antoine d8ddef4c14 detect: delay tx cleanup in some edge case
Ticket: 7552

f->sgh_toserver may be NULL but because FLOW_SGH_TOSERVER is unset
and thus, we want to delay cleanup until detection has really been
run with the right signature group head.

This may happen for a rule using
`alert tcp any any -> any any` and
a app-layer keyword to client
with a app-layer supporting both udp and tcp
with stream.midstream=true
and with the first packet of a flow being a server response

In this case, we swap the flow and reset its signature group heads
2 years ago
Philippe Antoine d74bc774b7 detect: reset signature groups when reversing flow
Ticket: 7552

When we use midstream, and the first packet we see of a flow is
a response from server, and we want to match on some signature
to client :
- we had first set sgh_toserver/FLOW_SGH_TOSERVER as we first
  thought this was a packet to server
- we then swap/reverse the flow, so sgh_toclient becomes sgh_toserver
  but it contains signatures to server and cannot match our
  to_client signature

The detect engine with DetectRunSetup will set again the
signatures group heads properly
2 years ago
Jason Ish 33c29be139 detect-dns-response: remove unit tests
Should have coverage by S-V now.
2 years ago
Jason Ish 814e9ffb7a dns: add keywords for additionals and authorities rrnames
Add keywords dns.additionals.rrname and dns.authorities.rrname. Along
the way, consolidate dns.query.name and dns.answer.name into a single file
and register them altogether since there is a lot of common code.
2 years ago
Jason Ish c57e1425f5 detect: split new keyword id from registration
Split DetectHelperKeywordRegister into 2 functions, one for acquiring
a new keyword ID, and another to perform the registration.

This makes it easier to do the traditional C keyword initialization
with a dynamic ID.
2 years ago
Jason Ish a9bf6bbd0e detect-dns-response: disable clang-format around byte arrays
These arrays are manually formatted for readability.
2 years ago
Jason Ish a026293b42 dns: rename dns.response keyword to dns.response.rrname
This is a better name as the keyword is looking at all rrname type
fields in the response.
2 years ago
Nathan Scrivens 07632fdf4e dns: add dns.response sticky buffer
Feature: 7012
Add dns.response sticky buffer to match on dns response fields.
Add rust functions to return dns response packet data.
Unit tests verifying signature matching.
2 years ago
Philippe Antoine f68e2f5537 files: append data on closing even with FILE_NOSTORE
Ticket: 7577

When HTTP1 post multipart handles a small file, it will call
HTPFileClose with some data
This data needs to be appended to the streaming buffer for usage
by file.data keyword even if we do not end up storing the file
2 years ago
Jason Ish 2e52e9501f mqtt: naming and visibility cleanups
- remove rs_prefix, replace with SC if needed
- remove pub and no_mangle where not needed
- remove some unused functions and fields

Related to ticket: #7498
2 years ago
Jason Ish c726d67bb0 dcerpc: visibility and naming cleanups
- replace rs_ prefixed names with SC
- remove no_mangle and pub where not needed
- remove some unused functions

Related to ticket: #7498
2 years ago
Jason Ish f0116c3a6b bittorrent: no_mangle, pub and naming cleanups
- Remove rs_prefix
- Remove no_mangle and pub when not needed

Related to ticket: #7498
2 years ago
Jason Ish 9ed5b4c002 smtp: remove SCMimeSmtpConfigExtractUrlsSchemeReset
It doesn't appear to be needed. The vec being cleared is only set once
per run, so never needs to be cleared.

Removes one point where we have to supress the static_mut_refs compiler
warning.

Ticket: #7417
2 years ago
Philippe Antoine 97ee95c1a2 dns: move unit tests to suricata-verify
Ticket: 3725
Ticket: 7529
2 years ago
Jeff Lucovsky 49d4686144 main/flush: Support periodic flush logs
Issue: 3449
2 years ago
Jeff Lucovsky 36111450ac detect/flag: Pseudo pkt "flush log" flag
Issue: 3449

Add a flush directive to the packet that is distinct from the existing
"log flush" flag as the new flag is to distinguish between the 2 use
cases.
2 years ago
Jeff Lucovsky b18622554d output/log: Add flushing infrastructure
Issue: 3449

Add flushing functions and infrastructure. This includes:
- Flushing functions for packet loggers
- Log file flushing support
2 years ago
Jeff Lucovsky 04767f69fc output: Support buffer-size value
Issue: 3449
2 years ago
Jeff Lucovsky 7621029507 output/log: Add flush function, collapse params
Issue: 3449

Add a flush function to packet logger registration and collapse the
parameter count for registration functions.
2 years ago
Philippe Antoine 80dbaac206 flow: remove unused definition
Fixes: 3f3964555e ("detect/iponly: use flow first flags")
2 years ago
Victor Julien e1446c30fa detect/alert: optimize no-alert path
Skip qsort call if no alerts are queued. Move logic into inline helper func.
2 years ago
Victor Julien 98423a0009 detect: constify arguments 2 years ago
Victor Julien 39b030b791 detect/tx: improve branch prediction 2 years ago
Victor Julien 1000b0cf33 app-layer: optimize pstate check
To assist branch prediction, which showed a 100% miss rate, assume pstate
is non-NULL. Code review suggests all paths leading to the function actually
check pstate first, or alstate which can only be non-NULL if pstate was first
initialized. For now add a debug check.
2 years ago
Victor Julien 99eda1504a threads/flow: assist branch prediction 2 years ago
Victor Julien f876baab6b detect/pmq: assist branch prediction 2 years ago
Jeff Lucovsky dd344bd07c ftp: Move config file handling to Rust
Issue: 4082

Move the configuration file handling to Rust.

These changes will no longer terminate Suricata when there's an invalid
value for ftp.memcap. Like earlier Suricata releases, an error message
is logged "Invalid value <value> for ftp.memcap" but Suricata will no
longer terminate execution. It will use a default value of "0" instead.
2 years ago
Jeff Lucovsky f0410c93d0 ftp: convert enumerations to Rust
As part of the effort to convert the FTP/FTPDATA parser to rust, move
the enums from C to rust.

Issue: 4082
2 years ago
Jeff Lucovsky e45204aecf detect/transform: Refactor setup/apply pattern
git grep -A 1 -w InspectionBufferSetup shows many cases of the following
call patterns:
    - InspectionBufferSetup
    - InspectionBufferApplyTransforms

Refactor the implementations of those functions into
InspectionBufferSetupAndApplyTransforms to reduce function call count.

Issue: 2290 (related to changed for this issue)
2 years ago
Alice Akaki 7b350e9933 misc: fix name prefix in detect register functions 2 years ago
Philippe Antoine 359f736542 util: fix -Wshorten-64-to-32 warnings
Ticket: #6186
2 years ago
Philippe Antoine 649f30b46b htp: macro hygiene
make clang-tidy happy even if unneeded for the temporary workaround
2 years ago
Philippe Antoine 9e73de3d80 http: aliases for htp log code
In preparation of libhtp rust
2 years ago
Philippe Antoine 62a4254f5b http: constify some variables
In preparation of libhtp rust
2 years ago
Philippe Antoine 486bdc99c0 http: aliases for opaque htp_conn_t
In preparation of libhtp rust
2 years ago
Philippe Antoine e079604f79 http: aliases for opaque htp_tx_data_t
In preparation of libhtp rust
2 years ago
Jeff Lucovsky eeb2166a5a gen/typo: Improve grammar 2 years ago
Jeff Lucovsky 7d5c170dd2 gen/bool: Clarify bool checks
Remove comparisons with true or false with C bools.
2 years ago
Philippe Antoine b514b25165 detect/flow: move keyword parsing code to rust
for flow.pkts and flow.bytes keywords

Ticket: 7562

Avoid null deref when parsing flow.bytes:toserver;
2 years ago
Juliana Fajardini 06b506e2cd analysis: report rule state altered by other rule
Flowbits can make a rule such as a packet rule be treated as a stateful
rule, without actually changing the rule type.

Add a flag to allow reporting such cases via engine analysis.

Task #7456
2 years ago
Juliana Fajardini 576f2ed1e7 detect/flowbits: only walk over array if needed
For setting s->init_data for flowbit rules impacted by `set`, we can
first check whether this will be needed, and *then* walk over the
flowbits array.
2 years ago
Jason Ish 10ede91536 rust: add bindings to SCPlugin.* to sys crate
Also disable bindgen's generated layout tests.  They are valid for the
platform generating the tests, but may not be valid for other
platforms. For example, if the tests are generated on a 64 bit
platform the tests will not be valid when run on a 32 bit platform as
pointers are a different size.

However, the generating bindings are valid for both platform.

Ticket: #7341
2 years ago
Jason Ish 21ccc4f307 rust: integrate bindgen to generate Rust bindings to C
Bindgen works by processing a header file which includes all other
header files it should generate bindings for. For this I've created
bindgen.h which just includes app-layer-protos.h for now as an
example.

These bindings are then generated and saved in the "suricata-sys"
crate and become availale as "suricata_sys::sys".

Ticket: #7341
2 years ago
Victor Julien 4b855aa4a9 detect/profile: convert rule grouping dump to json builder
Ticket: #7558.
2 years ago
Victor Julien 471bde4426 tls: more permissive empty data eof check
If not all data is ACK'd during the FIN session shutdown, the last calls
to the parser can be with a non-NULL data pointer, but a input length of
0. This wasn't considered by the EOF check, which then lead to it being
seen as an error. No event was raised, but the tls error stats were
incremented.

Bug: #7554.
2 years ago
Shivani Bhardwaj bc79300dfa datasets: move initial file reading to rust
In a recent warning reported by scan-build, datasets were found to be
using a blocking call in a critical section.

datasets.c:187:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  187 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
datasets.c:292:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  292 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
datasets.c:368:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  368 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
datasets.c:442:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  442 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
datasets.c:512:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  512 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 warnings generated.

These calls are blocking in the multi tenant mode where several tenants
may be trying to load the same dataset in parallel.
In a single tenant mode, this operation is performed as a part of a
single thread before the engine startup.

In order to evade the warning and simplify the code, the initial file
reading is moved to Rust with this commit with a much simpler handling
of dataset and datarep.

Bug 7398
2 years ago
Shivani Bhardwaj 015da2c7ed rust: add C callback for FatalErrorOnInit 2 years ago
Shivani Bhardwaj 77bf58d687 datasets: remove unused fn definition 2 years ago