Commit Graph

18474 Commits (0fe0390a2f0cd7da5ace0f45286b1abdb4e7cb95)
 

Author SHA1 Message Date
Lukas Sismis 0fe0390a2f hs: suppress TOCTOU stat use
To explain a bit more the TOCTOU issue found, we can consider
a case where Suricata starts to prune, yet externally somebody also
starts erasing cache files.
Right after Suricata checks the file age with the stat function,
somebody may delete or update the file of our interest.

Suricata aging decision doesn't reflect the actual state of the file.
This commit additionally adds a check for noent failure of the unlink operation
(considered as a success). The code can still delete a file that is recently
updated but was considered stale.

In the documentation-following deployments this should not happen anyway as
one cache folder should only be used by a single Suricata instance (and within
Suricata instance only one thread handles cache eviction).
Additionally, the `stat` and `unlink` command are immediatelly followed, making
this scenario extra unlikely.

Additional comment in the code explains problems of using fstat and potential
issues on Windows.

Ticket: 8243
3 months ago
Ofer Dagan 7627756360 detect/detection_filter: add unique_on option
Add optional unique_on {src_port|dst_port} to detection_filter for
exact distinct port counting within the seconds window.

Features:
- Runtime uses a single 64k-bit (8192 bytes) union bitmap per
  threshold entry with O(1) updates.
- Follows detection_filter semantics: alerting starts after the
  threshold (> count), not at it.
- On window expiry, the window is reset and the current packet's
  port is recorded as the first distinct of the new window.

Validation:
- unique_on requires a ported transport protocol; reject rules
  that are not tcp/udp/sctp or that use ip (protocol any).

Memory management:
- Bitmap memory is bounded by detect.thresholds.memcap.
- New counters: bitmap_memuse and bitmap_alloc_fail.

Tests:
- C unit tests for parsing, distinct counting, window reset, and
  allocation failure fallback.
- suricata-verify tests for distinct src/dst port counting.

Task #7928
3 months ago
Ofer Dagan 2371829bf1 schema: add threshold stats counters
Add schema definitions for new threshold-related statistics:
- bitmap_alloc_fail: Count of bitmap allocation failures
- bitmap_memuse: Memory usage by detection_filter bitmaps
- memcap: Memory cap for threshold hash table
- memuse: Memory usage by threshold hash table

Task #7928
3 months ago
Philippe Antoine d046e82db6 detect/flowbits: align pointer in the struct
Makes leak sanitizer work without adding LSAN_OPTIONS=use_unaligned=1

Otherwise, leak sanitizer may report rule_id as leaked
when it is still owned by some global variable
3 months ago
Jason Ish 5d61f5253d lua: don't attempt to garbage collect a null value
When not sandboxed, a script can get access to the metatable and call
`.__gc` with an invalid value like nil, causing a NULL pointer dereference
in Suricata.

Ticket: #8248
3 months ago
Philippe Antoine b944e3b1ed ci: update rust version to 1.93 3 months ago
Philippe Antoine 02cb0f2ac2 rust: fix unnecessary_unwrap warnings
warning: called `unwrap` on `rd.pipe` after checking its variant with `is_some`
   --> src/smb/smb1.rs:858:28
    |
857 |             if rd.pipe.is_some() {
    |             -------------------- help: try: `if let Some(<item>) = rd.pipe`
858 |                 let pipe = rd.pipe.unwrap();
    |                            ^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#unnecessary_unwrap
    = note: `#[warn(clippy::unnecessary_unwrap)]` on by default
3 months ago
Shivani Bhardwaj 9df5fd180e flowbits: add a validation callback during setup
This should make it possible to catch invalid combinations in the same
signature early. This patch covers checking and erroring on the following
invalid cmd combinations:
- set + isset
- unset + isnotset
- set + toggle
- set + unset
- isset + isnotset
- unset + toggle

the same flowbit in the same signature which is basically an unnecessary
operation at runtime.

This also helps bring down the difficulty of handling of actual complex
flowbit chains.

Bug 7772
Bug 7773
Bug 7774
Bug 7817
Bug 7818
Bug 8166
3 months ago
Lukas Sismis b575ae3fd1 pcap-file: move packet counter to PCAP packet structure
Code refactor to gather all PCAP-related structure members
under one structure.

New pcap_v structure guards protect the union variables from
other capture modes trying to access the packet number incorrectly.

Ticket: 7835
3 months ago
Lukas Sismis 400328c3c3 pcap-file: prep codebase for pcap_cnt move refactor
For an easier review process, this is a two-step change process,
in which pcap_cnt is first accessed by functions-to-be, implemented
as simple macros.

In the follow-up commit, the actual refactor is implemented with the new
function. The old macros are deleted.

Ticket: 7835
3 months ago
Lukas Sismis f33f6e7ee5 stream: remove dead commented out code 3 months ago
Lukas Sismis c7058c1a35 stream: guard auxiliary packet counter to debug
Use of t_pcapcnt is only relevant when compiled in debug mode only.
This patch adds additional debug guard to also shield the declaration
and assignment.
3 months ago
Philippe Antoine cafc398355 dcerpc: consume bytes after gap resync
Ticket: 7567

Re-applies commit 8c3bd3e8a0
which was reverted in f64aec9d11
3 months ago
Jeff Lucovsky 54bd8edf68 decode/ipv4: Create event on unknown protos
Issue: 7146

Create an event when the IPv4 header contains an unknown IP protocol.
3 months ago
Juliana Fajardini 2c216e2b73 devguide/exceptions: minor fixes
- cleaner YouTube link
- fix weird sentence

Follow-up of
Task #5612
3 months ago
Philippe Antoine c333b28719 http1: marks tx as updated when setting an event
Ticket: 8224

We sometimes set events to the last tx, so we do not have access
to the HtpTxUserData in the caller HTPHandleError
3 months ago
Philippe Antoine 54cc752cf9 ssh: hassh can be truly disabled
Rules will not re-enable it

Ticket: 8223
3 months ago
Philippe Antoine 458211dcf2 detect/ssh: move ssh.proto to rust 3 months ago
Philippe Antoine 9cfc1cc557 detect/ssh: move obsolete keywords to rust 3 months ago
Philippe Antoine ea8ac2a02a detect/ssh: move ssh.software to rust
Adds helper function SCDetectHelperBufferProgressMpmRegister on the way
3 months ago
Philippe Antoine c0d6747e82 app-layer: GetTxIteratorFn uses a AppLayerGetTxIterState
Even if every current rust parser uses the u64 variant of the C union
3 months ago
Philippe Antoine 4b541b39f2 rust: move AppLayerEventType definition to C
and bindgen it to rust.

Will make easier the bindgen of RustParser structure which uses
a callback which uses AppLayerEventType
3 months ago
Philippe Antoine c960b7d7c1 app-layer: AppLayerParserFPtr uses a mut pointer to local storage
So, fix the fn prototype in rust ParseFn
3 months ago
Philippe Antoine f470ee448b quic: use standard tx iterator code
Will make bindgen life easier

As the fn prototype should not have istate: &mut u64
but a *mut AppLayerGetTxIterState which is an union with a u64
3 months ago
Philippe Antoine 076fcd61cd bittorrent: use standard tx iterator code
Will make bindgen life easier

As the fn prototype should not have istate: &mut u64
but a *mut AppLayerGetTxIterState which is an union with a u64
3 months ago
Philippe Antoine 1a546936c7 rust: AppLayerTxConfig uses Default impl 3 months ago
Philippe Antoine 4e64de3b3b rust: remove wrapper LoggerFlags struct definition
just use an u32 out of the box.
Will make bindgen like easier
3 months ago
Philippe Antoine f663be5983 rust: define every RustParser fn pointer unsafe
That is what bindgen will do
3 months ago
Philippe Antoine 327f45ceb3 app-layer: ApplyTxConfigFn does not return bool
It does not return anything.
The only known implementation is in dns where it does not return.
And the C code does not bother to check a return value anyways.
3 months ago
Victor Julien cf7a56dd78 counters: compact public stats context 3 months ago
Victor Julien 711c1193d0 counters: misc cleanups 3 months ago
Victor Julien 6524a3fb5c stats: add derive support; add DERIVE_DIV type
Add basic derive counter support, where a counters value is derived from
2 other counters.

Add DERIVE_DIV that divides the first counter value by the second
counters value.

Convert `decoder.avg_pkt_size` to be derived from `decoder.bytes` and
`decoder.pkts`.

Ticket: #5615.
3 months ago
Abhijeet Singh b145e389ab util/log: fix log file rotation
Fix double log file rotation in presence of both rotation flag and rotate interval

Ticket: https://redmine.openinfosecfoundation.org/issues/8153
3 months ago
Victor Julien 5f92a6cac3 detect/base64_data: reset buffer offset
When in a `base64_decode`-`base64_data` pair the decode was depending
on another match through the relative option, the `buffer_offset` would
be updated to the relative position of the previous match. During the
`base64_data` phase, a relative match would use that offset even though
the match happened in a new buffer.

Example::

        http.request_body; content:"|27|";                              \
                base64_decode:relative;                                 \
                base64_data; content:"|ff ff ff ff|"; within:16;

This use of the `buffer_offset` is incorrect as that value is relative
to a buffer and the `base64_data` points to a new buffer.

This patch addresses this by resetting DetectEngineThreadCtx::buffer_offset
before inspecting `base64_data`.

Bug: #7842.
3 months ago
Philippe Antoine f8ad6904bc features: add UNIX_SOCKET feature
for SV tests to tun conditionnaly on it

Ticket: 3464
3 months ago
Juliana Fajardini 48b15ac152 devguide: add chapter about exception policies
Adds a chapter indicating what are the main steps when adding exception
policies, how is it possible to extend them, as well as main aspects and
files to consider when doing so.

Task #5612
3 months ago
Lukas Sismis 56c1552c3e hs: warn about the same cache directory
This is especially relevant for multi-instance simultaneous setups
as we might risk read/write races.
3 months ago
Lukas Sismis 15c83be61a hs: prune stale MPM cache files
Hyperscan MPM can cache the compiled contexts to files.
This however grows as rulesets change and leads to bloating
the system. This addition prunes the stale cache files based
on their modified file timestamp.

Part of this work incorporates new model for MPM cache stats
to split it out from the cache save function and aggregate
cache-related stats in one place (newly added pruning).

Ticket: 7830
3 months ago
Lukas Sismis 08f5abe5e9 detect-engine: make mpm & spm part of MT stub ctx
As a intermediary step for Hyperscan (MPM) caching,
the MPM config initialization should be part of the default
detect engine context for later dynamic retrieval.

Ticket: 7830
3 months ago
Lukas Sismis 7031c26865 hs: touch cache files on use to signal activity
Ticket: 7830
3 months ago
Lukas Sismis fd3847db72 path: signal last use of the file (touch)
To have a system-level overview of when was the last time the file was
used, update the file modification timestamp to to the current time.

This is needed to remove stale cache files of the system.

Access time is not used as it may be, on the system level, disabled.

Ticket: 7830
3 months ago
Lukas Sismis 85f0382072 conf: add time parsing conf function 3 months ago
Lukas Sismis 3e4fdb2118 misc: time unit parsing function 3 months ago
Lukas Sismis c282880174 hs: change hash in the cache name to SHA256 3 months ago
Lukas Sismis 2a313ff429 hs: reduce cache filename size to max file limit 3 months ago
Lukas Sismis 47fc78eeae hs: update the file description 3 months ago
Philippe Antoine 251d10fa42 util-spm-hs: add missing deallocator
Add missing deallocator when hs_alloc_scratch fails.

Bug: #8146
3 months ago
Sergey Zhidkih 799f01f78f util-spm-hs: add missing deallocator
Add missing deallocator for expr when hs_compile fails.

Bug: #8146
3 months ago
Sergey Zhidkih 11073a0190 hyperscan: move error logging for hs_compile
Move error logging from util-mpm-hs to reuse it in util-spm-hs as it
has proper hs_compile error handling.

Bug: #8146.
3 months ago
Philippe Antoine 5bb9a0c3af dcerpc/tcp: fix fragmentation handling
Really count the fragments, and set it done when last was received
3 months ago