Commit Graph

16589 Commits (e89ab4f88a0dbec01c2700f7ccbcedc33377e5f0)
 

Author SHA1 Message Date
Victor Julien e89ab4f88a detect/lua: add thread_init
Add optional `thread_init` function support. This function is called per
script, per thread to allow a user to initialize the lua state.
2 years ago
Victor Julien c3e61e07f0 detect/lua: improve stack dumping
Only useful when debugging. Add a prefix and a stack size indication.
2 years ago
Jeff Lucovsky 1d996c5aed log/file: Ensure file ctx pointer is returned .
The fix for issue 7447 introduced an error with threaded eve output.

The changes that were committed for that issue mishandled the return
value when a file is being opened for the 2nd or higher time.

Instead of returning the existing file context, null was returned.
2 years ago
Shivani Bhardwaj ad7ff1c91b flow/pkts: allow matching on either direction
For flow.bytes and flow.pkts keywords, allow matching in either
direction.

Feature 5646
2 years ago
Shivani Bhardwaj 52fd695e5a doc: update syntax for flow.pkts & flow.bytes 2 years ago
Shivani Bhardwaj aad313438c flow/pkts: make syntax cleaner and compact
Currently, the syntax includes direction as a part of the keyword which
is against how usually keywords are done. By making direction as a
mandatory argument, it is possible to make the syntax cleaner and the
implementation more compact and easily extendable.
Pros:
- Registration table sees lesser entries if newer options are added
- If the options have to be extended, it can be done trivially
- In accordance w existing keyword implementations

Note that this commit also retains the existing direction specific
keywords.
2 years ago
Victor Julien bd1b9f6229 stream: RST no longer acks all data
Since forever (1578ef1e3e) a valid RST
would update the internal `last_ack` representation to include all
unack'd data. This was originally done to make sure the unACK'd data was
inspected/processed at flow timeout.

It was observed however, that if GAPs existed in this unACK'd data, a
GAP could be reported in the stats and a GAP event would be raised. This
doesn't make sense, as missing segments in the unACK'd part of the
stream are completely normal. Segments simply do not all arrive in
order.

It turns out that the original behavior of updating `last_ack` to
include all unACK'd data is no longer needed.

For raw stream inspection, the detection engine will already include the
unACK'd data on flow end.

For app-layer updates the unACK'd data is often harmful, as the data
often has GAPs. Parser like the http parser would report these GAPs and
could also get confused about the post-GAP data being a new transaction
including a file. This lead to many reported errors and fantom txs and
files.

Since the GAP detection uses `last_ack` to determine GAPs, not moving
`last_ack` addresses the GAP false positives.

Ticket: #7422.
2 years ago
Victor Julien 829ba7d114 flow/manager: improve doc; minor cleanup
Explain meaning of `ts` in flow managers main loop.
2 years ago
Victor Julien 14864cda59 flow: skip lock for skippable flows
Some checks can be done w/o holding a lock:
- seeing if the flow matches the packet
- if the hash row needs a timeout check

This patch skips taking a lock in these conditions.
2 years ago
Victor Julien 2af67e17bc threads: align struct to CLS to avoid false sharing
Since `Thread` objects are part of a big allocation, more than one
Thread could be on a single cache line, leading to false sharing. Atomic
updates to one `Thread` could then lead to poor performance accessing
another `Thread`. Align to CLS (cache line size) to avoid this.
2 years ago
Victor Julien b75d1ab37f threads: seal after setup; unseal at shutdown
The idea of sealing the thread store is that its members can be accessed
w/o holding a lock to the whole store at runtime.
2 years ago
Victor Julien 276d625a66 threads: fine grained locking for Thread
Until now many accesses to the Thread structure required taking a global
lock, leading to performance issues. In practice this only happened in
offline mode.

This patch adds a finer grained locking scheme. It assumes that the
Thread object itself cannot disappear, and adds a spinlock to protect
updates to the structure.

Additionally, the `pktts` field is made an atomic, so that it can be
read w/o taking the spinlock. Updates to it are still done under lock.
2 years ago
Victor Julien ef396f7509 flow/manager: in offline mode, use owning threads time
As this may mean that a threads ts is a bit ahead of the minimum time
the flow manager normally uses, it can evict flows a bit faster.

Ticket: #7455.
2 years ago
Victor Julien ada2bfe009 flow/worker: improve flow timeout time accuracy
When timing out flows, use the timestamp from the "owning" thread. This
avoids problems with threads being out of sync with each other.

Ticket: #7455.
2 years ago
Victor Julien abe8dfc56b flow: fix flow bucket timestamp optimization
Flow Manager skips rows based on a minimized tracker that tracks the
next second at which the first flow may time out.

If seconds match a flow can still be timing out.
2 years ago
Victor Julien 0da83b05cf threads: use sleeping threads for minimum time a bit longer
If a thread doesn't receive packets for a while the packet timestamp
will no longer be used to determine a reasonable minimum timestamp for
flow timeout handling.

To avoid issues with the minimum timestamp to be set a bit too
aggressively, increase the time a thread can be inactive.
2 years ago
Victor Julien c587e90ebc time: thread time update after flow update
The flow worker needs to get the opportunity to run the flow update
before globally making it's current timestamp available. This is to
avoid another thread using the time to evict the flow that is about to
get a legitimate update.

Ticket: #7455.
2 years ago
Victor Julien 48301bf28c flow: exact flow timeout
Use a more precise calculation for timing out flows, using both the
seconds and the micro seconds.

Ticket: #7455.
2 years ago
Victor Julien 677c0fd41c time: getter for SCTime_t timestamp of a thread 2 years ago
Victor Julien dbebd89de2 stream: rename tcp reuse flag
Rename to be consistent with other naming:

STREAM_PKT_FLAG_TCP_PORT_REUSE -> STREAM_PKT_FLAG_TCP_SESSION_REUSE
2 years ago
Victor Julien deece44eaa eve/stream: add tcp-session-reuse trigger
Can be used to log when the tcp session reuse logic triggers.
2 years ago
Victor Julien 7b8214302c flow: improve thread safety during timeout checks
Timeout checks would access certain fields w/o locking, which could lead
to thread safety issues.
2 years ago
Victor Julien bc374b8e40 eve/flow: log tcp reuse as 'reason'
Ticket: #7482.
2 years ago
Victor Julien aab50e8ad0 unix/socket: cleanup start up logic
No longer init then deinit part of the engine at startup of the unix
socket mode.
2 years ago
Victor Julien b9423602b4 threads: include name in error message
When a thread fails to spawn, include the thread name in the error
message.
2 years ago
Philippe Antoine 6291e220e4 dns: improved handling of corrupt additionals
Ticket: 7228

That means log the rest of queries and answers, even if the
final field additionals is corrupt.
Set an event in this case.
2 years ago
Philippe Antoine 494d7bfe99 ldap: truly enforce max-tx
Ticket: 7465

If a bug chunk of data is parsed in one go, we could create many
transactions even if marking them as complete, and have
quadratic complexity calling find_request.

Proposed solution is to fail on creating a new transaction if too
many already exist.
2 years ago
Philippe Antoine 3b76c78cb9 profiling: use dynamic number of app-layer protos
Ticket: 5053
2 years ago
Philippe Antoine 41dc90776a app-layer/parser: use dynamic number of app-layer protos
Ticket: 5053
2 years ago
Philippe Antoine f8136eff9a fuzz: use dynamic number of app-layer protos
Ticket: 5053

delay after initialization so that StringToAppProto works
2 years ago
Philippe Antoine def6e1c719 app-layer/stats: use dynamic number of app-layer protos
Ticket: 5053
2 years ago
Philippe Antoine 2bd73b2761 util: parenthesis for macro
so that we can use safely EXCEPTION_POLICY_MAX*sizeof(x)
2 years ago
Philippe Antoine 911cd628fc frames: use dynamic number of app-layer protos
Ticket: 5053
2 years ago
Philippe Antoine 9e9333b7d0 protodetect: use dynamic number of app-layer protos
for alproto_names

Ticket: 5053
2 years ago
Philippe Antoine 61657c8ec6 protodetect: use dynamic number of app-layer protos
for expectation_proto

Ticket: 5053
2 years ago
Philippe Antoine 6b7349dbc1 protodetect: make expectation_proto part of AppLayerProtoDetectCtx
instead of a global variable.

For easier initialization with dynamic number of protocols
2 years ago
Philippe Antoine 7750226e43 fuzz: use lower pcre limits
to avoid timeouts

instead of forbidding pcre signatures on stream

Ticket: 4858
2 years ago
Philippe Antoine 5cec270598 detect: move fields around to fill memory holes
to make scan-build happy avoiding its warning :

Excessive padding in 'struct DetectEngineThreadCtx_'
(33 padding bytes, where 1 is optimal)
2 years ago
Philippe Antoine b967fcaf8f stats: remove unused pseudo_failed stat 2 years ago
Philippe Antoine 954553f1ae src: remove unused struct fields
Even if they get defined
2 years ago
Victor Julien c56b741088 github-ci: update Fedora 39 jobs to 41 2 years ago
Philippe Antoine bdcb593738 detect: improve tx_id guessing for unidirectional protocols
So we get:
1. request arrives - buffered due to not ackd
2. response arrives, acks request - request is now parsed, response isn't
3. ack for response, response parsed. Then detect runs for request,
generates alert. We now have 2 txs. txid will be 0 from AppLayerParserGetTransactionInspectId

But txid 1 is unidirectional in the other way, so we can use txid 0
metadata for logging

Ticket: 7449
2 years ago
Philippe Antoine a499529477 doc: improve documentation about guess-applayer-tx
Ticket: 7199
2 years ago
Jeff Lucovsky 2d9df5a1ae flow/var: Release key storage
Issue: 7466

This commit releases the memory for the flow variable "key" when
the flow variable is of type string. The key is allocated in the Lua
extension logic.
2 years ago
dependabot[bot] def22fab6c github-actions: bump actions/upload-artifact from 4.4.3 to 4.5.0
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.4.3 to 4.5.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](b4b15b8c7c...6f51ac03b9)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
dependabot[bot] e16f29e459 github-actions: bump github/codeql-action from 3.27.5 to 3.28.0
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.5 to 3.28.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Commits](https://github.com/github/codeql-action/compare/v3.27.5...v3.28.0)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
dependabot[bot] 8e4b18f4e4 github-actions: bump codecov/codecov-action from 5.0.7 to 5.1.2
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.0.7 to 5.1.2.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](015f24e681...1e68e06f1d)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
Jeff Lucovsky d853972c74 output/log: Remove extraneous error message
Issue: 7447

When the output file can't be opened, 2 error messages are displayed
for the same problem. The second message doesn't add value and lacks
context (error reason, e.g., "Permission denied").

Retaining the second message as a debug message.

Without this commit:

Error: logopenfile: Error opening file: "/home/jlucovsky/src/jal/suricata-verify/tests/bug-5198/output/noperms/eve.1.json": Permission denied [SCLogOpenFileFp:util-logopenfile.c:428]
Error: logopenfile: Unable to open slot 1 for file /home/jlucovsky/src/jal/suricata-verify/tests/bug-5198/output/noperms/eve.json [LogFileEnsureExists:util-logopenfile.c:737]
Error: runmodes: unable to initialize sub-module eve-log.stats [RunModeInitializeEveOutput:runmodes.c:692]

With commit:

Error: logopenfile: Error opening file: "/home/jlucovsky/src/jal/suricata-verify/tests/bug-5198/output/noperms/eve.1.json": Permission denied [SCLogOpenFileFp:util-logopenfile.c:428]
Error: runmodes: unable to initialize sub-module eve-log.stats [RunModeInitializeEveOutput:runmodes.c:692]
2 years ago
Jeff Lucovsky e72fc39f83 output/log: Improve error handling
This commit improves error handling for cases when file(s) cannot be
opened.
- Return NULL if file object can't be opened
- checks whether the file object has been opened before
  dereferencing the per-file context.

Issue: 7447
2 years ago
Shivani Bhardwaj 6f937c7545 doc: add guide for ticket title
Explain with examples what a good ticket title looks like and
why is it important to have ticket titles convey the correct issues.
2 years ago