Commit Graph

19680 Commits (a329e0a3b9abb5ee7a844f3acd921fefa93b56b8)
 

Author SHA1 Message Date
Jeff Lucovsky 4a647784c7 doc/bytemath: document the result of wide shifts
Record that << and >> yield 0 when rvalue is 64 or more, beside the
existing note about division by zero. A shift count can come from a
byte_extract variable, so the rule text alone does not say which
counts land in that case.

Issue: 8845
2 months ago
Jeff Lucovsky 89d09c457c detect/bytemath: reject literal shift counts of 64
Fail rule load when byte_math pairs << or >> with a literal rvalue of
64 or more. rvalue was bounded only to u32::MAX, so a rule shifting by
100 loaded and then produced 0 for every packet it inspected, spending
detection work on a comparison whose outcome was settled before the
first packet arrived.

A variable rvalue still loads. Its value comes from a byte_extract on
the packet and is not known until the rule runs, so the guard in
DetectByteMathDoMatch() stays the only check covering that path.

DetectByteMathParse() reports every SCByteMathParse() failure as
"invalid bytemath values", so the rejected rule is named by the
"error parsing signature" line that follows rather than by the reason
the parser gave.

Issue: 8845
2 months ago
Jeff Lucovsky e5d035fd16 detect/bytemath: guard right shift against wide counts
Zero the result when a byte_math right shift count reaches 64, the
width of the uint64_t being shifted, so the operation no longer
depends on behavior C11 6.5.7p3 leaves undefined. The left shift case
has done this since 473ca6dcf4; the right shift case was left
unguarded.

DetectByteMathDoMatch() shifted by whatever count it was handed. On
x86_64 the hardware masks the count to its low six bits, so a count of
64 became a shift of 0 and returned the extracted value unchanged
instead of 0. That value is stored in det_ctx->byte_values[] and feeds
any byte_test, isdataat, or content offset later in the signature, so
the signature's verdict follows from an arithmetic result the standard
does not define.

The count reaches the shift from the wire. When byte_math names a
variable for rvalue, DetectEngineContentInspectionInternal() reads it
out of det_ctx->byte_values[] at
detect-engine-content-inspection.c:614, where a preceding byte_extract
stored bytes taken from the payload, so one payload byte of 0x40 sets
the count to 64.

Issue: 8845
2 months ago
Shivani Bhardwaj 389700eca2 flow/rate: fix ring flushing
The fn to flush the ring is supposed to flush the entire ring buffer but
it only resets the buffer up to the "length" bytes. Fix this calculation
to correctly reflect the number of bytes that need to be reset.

Ticket: 8826
2 months ago
Victor Julien 54504ed13c affinity: handle NULL set name from --set affinity path
Setting a cpu-affinity path with --set, like

  --set threading.cpu-affinity.worker-cpu-set.threads=28

creates an intermediate node under cpu-affinity whose val is NULL.

With a legacy list format cpu-affinity, AffinitySetupLoadFromConfig()
red the set name from the node val and passed it to
GetAffinitySetName(), which then dereferenced the NULL pointer.

Address it by simply checking for the NULL.

Ticket: #6735.
2 months ago
Philippe Antoine 7c669548cb nfs: optionally parse nfs3 read attr-follows
Ticket: 8750
2 months ago
Philippe Antoine c9434b3703 detect/frame: fix assert
A rule like `frame:http1.response; to_md5;` could have a buffer
bigger than the frame

Ticket: 8763
2 months ago
Philippe Antoine 7c394b9774 datasets: add size checks for hashes read
Ticket: 8768
2 months ago
Lukas Sismis 092ae272e2 firewall: validate action scope against the hook class
Validate the resolved scope against the class of hook it is being applied
to and fail at startup if it does not fit.

Ticket: 8712
2 months ago
Lukas Sismis 0aaa80d4f3 firewall: add default-policy to policy config
Every hook has a built-in default policy, but expressing anything other
than the built-in meant naming each hook explicitly.
This commit adds a `default-policy` setting that covers all hooks below it.
For any hook the most specific setting present wins.

DoParseAppSubStatePolicy() collapses into DoParseAppPolicy() as a sub state
hook only differs by an extra path segment.

Ticket: 8712
2 months ago
Lukas Sismis 1aa0259876 firewall: share the generic app hook name helper
Mapping an app-layer progress state to its generic request-/response-
hook alias was hardcoded in multiple places.

This commit adds a wrapper to unify it to a single function.
It returns the config-form (hyphenated) name, or NULL for an
intermediate state.

Ticket: 8712
2 months ago
Jason Ish acd9d3a09e github-ci: update rust known version to 1.98.0 2 months ago
Jason Ish 99f7b1f437 dhcp: remove unused import in test
To address clippy warning.
2 months ago
Juliana Fajardini 34b7a9ef82 scripts: check doc rules as TD and FW rules
Previously, a rule that had firewall-only syntax or keywords would fail
the script check.

Since we can't guarantee that a firewall rule will look different than a
detection one, run rule examples against both scenarios before failing
them.
2 months ago
Juliana Fajardini f3e27b0e41 scripts: check-doc-rules tries local bin first
If the point is to check the docs for added changes, it makes sense to
that used binary is the one that comes with the doc changes. Thus, try
using the local binary first, before falling back to usr/bin installed
Suricata.
2 months ago
Yash Datre 398687d5d4 detect: add tcp.session keyword for unified TCP lifecycle matching
Introduce the tcp.session: keyword that accepts a comma-separated subset
of {setup, established, closing} and matches packets whose TCP session
state falls within the named phases.

This lets a rule writer cover the full TCP lifecycle in one rule instead
of separate flow:not_established + flow:established rules.

Changes:
- New detect-tcp-session.{c,h} with parser, match function, unit tests
- Register DETECT_TCP_SESSION in detect-engine-register.{c,h}
- Add to Makefile.am source list
- Extend engine-analyzer text output for tcp.session:
- Extend firewall.json keyword_info with tcp_session phase values
- Update flow-keywords.rst documentation
- Require TCP protocol and SIG_FLAG_REQUIRE_PACKET at setup

Ticket: 7704
2 months ago
Shivani Bhardwaj 63daa73032 detect/ipv6: classify ipv6 ranges as like_ip_only
IPOnly Engine does not support parsing and recording IPv6 ranges. So,
passing a range of ipv6 there just results in non-fatal errors in
parsing the IP addresses which means they fail to be added to the radix
tree struct.
Re-classify the ipv6 ranges as like_ip_only so they fall out of the
IPOnly engine and are processed per packet.

Ticket: 8847
2 months ago
Jason Ish 17bd53c29c rust/ffi: add flow accessors to flow wrapper
Ticket: #8599
2 months ago
Jason Ish d3d206faa5 rust/ffi: add safe flow storage wrapper
Add a typed FlowStorage<T> wrapper around the flow storage bindings.

Update example and docs.

Ticket: #8447
2 months ago
Jason Ish 8a5c729ac9 rust/ffi: add number setters to jsonbuilder wrapper 2 months ago
Jason Ish f3332694e3 rust/ffi: bindgen flow storage
Ticket: #8447
2 months ago
Jason Ish 8cf5d4d770 rust/ffi: use Flow wrapper in flow and eve callbacks
Pass the safe Flow wrapper to the flow init/update/finish callbacks and
the EVE callback instead of a raw sys::Flow pointer.

Ticket: #8599
2 months ago
Jason Ish b4043dc207 rust/ffi: add wrapper around Flow
Ticket: #8599
2 months ago
Jason Ish 440e15878b flow: update example plugin to use address accessors 2 months ago
Jason Ish bedd65f766 flow: add accessors for flow addresses
Expose source and destination addresses as raw byte pointers, so FFI
callers do not need the internal FlowAddress layout.
2 months ago
Jason Ish f205d181f9 examples: use flow access functions
To prevent direct access to the flow structure and be subject to changes
in its size.

Ticket: #8632
2 months ago
Jason Ish 06235a3232 ndpi: use flow access functions
To prevent direct access to the flow structure and be subject to changes
in its size.

Ticket: #8632
2 months ago
Jason Ish 358b0b621b flow: include cleanup
Include flow-bindgen.h into flow.h and use flow.h in our source.
flow-bindgen.h exists for the purposes of bindgen only.
2 months ago
Jason Ish c0de5bca46 flow: add accessor functions
Add accessor functions to allow NDPI and our plugin examples to access
flow fields in an opaque manner.

Provides accessors for:

- is ipv4
- is ipv6
- ip protocol
- to server packet count
- to destination packet count

Ticket: #8632
2 months ago
Jason Ish 038d4a21e3 ndpi: flow storage can fail, cleanup if it does 2 months ago
Jason Ish f739a8a73c ndpi: don't access flow storage directly
Remove the check for Flow.storage being NULL. With flex arrays, as long as the
flow is allocated, .storage will never be NULL. We do make sure the flow
is not NULL, and the storage functions are safe to the storage being
NULL.

Prevents NDPI from accessing this flow field to be less sensitive to ABI
changes with respect to data structure sizes.

Ticket: #8632
2 months ago
Jason Ish e51cc381b7 flow-storage: include cleanup 2 months ago
Jason Ish 4481f27657 smtp: avoid scan-build false-positive null dereference
Scan-build reports a possible NULL dereference that is not reachable.
2 months ago
Jason Ish 0be6e345fd smtp: handle mid-session helo/ehlo like rset
RFC 5321 says a mid-session EHLO should work just like RSET. We more or
less ignored it, which meant transaction state could carry over.

Treat a HELO/EHLO received during a transaction as RSET once the server
accepts it.

Ticket: #8715
2 months ago
Lukas Sismis b82b4496af detect/firewall: group policies under packet and app nodes
The policy config was a flat map mixing packet hooks and app-layer
protocols: `packet-filter` next to `dns`. There was no node that meant
"the packet hooks" or "the app-layer hooks", so a setting could not be
scoped to one group.

Move each group under its own node:

    packet-filter     -> packet.filter
    packet-pre-flow   -> packet.pre-flow
    packet-pre-stream -> packet.pre-stream
    <proto>.<hook>    -> app.<proto>.<hook>

Ticket: 8712
2 months ago
Lukas Sismis 04c9fd9e22 detect/firewall: address HTTP/1 policies as http1
AppProtoToString(ALPROTO_HTTP1) returns "http", so an HTTP/1 policy had to
be written as `http:` while its rule hooks were already spelled `http1:`.
Use the same name in both places.

Ticket: 8712
2 months ago
Lukas Sismis 3adbd677e8 app-layer: query raw protocol names
To avoid back-and-forth of http1 conversion
a second query function was added to support
existing use cases.

This change will be handy for the upcoming
default-policy for firewall settings
2 months ago
Jason Ish 9a2b700471 github-ci: run dist in rust-vars job 2 months ago
Jason Ish df58deac96 github-ci: update rust-vars job to rust 1.85 2 months ago
Jason Ish 7c283ba954 rust: set CARGO_ENV when generating ffi bindings
This is required when rustc is not in a standard path. The other
cbindgen calls already had this, so it was just missed while adding the
ffi bindings, but shows up when rustc is at a path like
/usr/lib/rust-1.89/bin/rustc, but that directory is not in your path.
2 months ago
Jason Ish 6af3bf93f3 github-ci/builds: update ubuntu builds to rust 1.89 2 months ago
Jason Ish 0b86dce1f1 github-ci/docs: use rust 1.89 2 months ago
Jason Ish b639fb0d67 github-ci/commits: update to ubuntu 24.04; rust 1.89 2 months ago
Jason Ish bd522291cf github-ci/formatting: update to rust 1.89 2 months ago
Jason Ish bc868647fe github-ci/nix: update to nixos-25.11
To pick up a newer version of Rust.
2 months ago
Jason Ish eb887f00dc github-ci: update rust vars job to rust 1.85 2 months ago
Jason Ish 98f42f8462 rust: disable clippy warning for manual c str literals
Disable the clippy warning for not using modern C string
literals. Ubuntu 24.04 still ships cbindgen 0.26.0 that doesn't
support these, so migrating to modern C string literals would require
Ubuntu 24.04 users wishing to build from git to install cbindgen with
cargo.
2 months ago
Jason Ish 2bea5b6aad rust: set minimum rust version to 1.85
1.85 was chosen for now as it supports edition 2024. However, we have
not set our edition to 2024 yet.
2 months ago
Jason Ish 6b8c482012 github-ci: break ubuntu/debian script into 2 scripts
Debian 13 ships Rust 1.85 by default, Ubuntu requires installing a
specific patch to get newer then 1.75. So to support a newer MSRV,
these operating systems need different examples.
2 months ago
Jason Ish 05882e7be0 github-ci: cleanups to almalinux minimal build
Don't install extra repo's in the script, do it in CI. These are covered
by the documentation as they vary depending on the version and variant.
2 months ago