Commit Graph

16806 Commits (c33bebd630b304ab2a6ea9cf13fb150d7abf0fbc)
 

Author SHA1 Message Date
Juliana Fajardini 38f8508bf5 pgsql: apply rustfmt changes 1 week ago
Juliana Fajardini ff8d4e972c pgsql: don't always return error for parsing errors
This allows the app-proto to continue onto parsing next PDUs, if
possible.

Bug #5524
1 week ago
Juliana Fajardini 4fed424d74 pgsql: don't fail if proto parses unknown message
Even if unknown, if the message is properly parsed, allow the parser to
proceed.

Related to
Bug #5524
1 week ago
Juliana Fajardini cc841e66db pgsql/parser: always use fn for parsing PDU length
Some inner parsers were using it, some weren't. Better to standardize
this. Also take the time to avoid magic numbers for representing the
expected lengths for pgsql PDUs.
Also throwing PgsqlParseError and allowing for incomplete results.

Related to
Task #5566
Bug #5524
1 week ago
Juliana Fajardini 29d3aa7a6a pgsql: add PgsqlParserError
Building on top of work done by Jason Ish.

Related to
Bug #5524
1 week ago
Juliana Fajardini 737fea751f pgsql/parser: simplify response parsing
The initial parsing for message type checking was more complex than
needed be.

Related to
Bug #5524
1 week ago
Juliana Fajardini 24375a1fef pgsql/parser: fix response message length
Some backend messages can be the shortest pgsql length possible,
4 bytes, but the parser expectd all messages to be longer than that.

Related to
Bug #5524
1 week ago
Jeff Lucovsky eeb2166a5a gen/typo: Improve grammar 1 week ago
Jeff Lucovsky 7d5c170dd2 gen/bool: Clarify bool checks
Remove comparisons with true or false with C bools.
1 week 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;
1 week ago
Philippe Antoine 8ae5665767 detect/krb5: avoid integer underflow with krb5.ticket_encryption
Ticket: 7560

When passing INT32_MIN aka 0x80000000, we cannot compute -vali
as it does not fit into a i32
1 week 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
1 week 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.
1 week 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 weeks ago
Jason Ish 9b73de6f6d rust: add auto-generated header to sys.rs
We don't keep bindgen's autogenerated do not edit line as it contains
the bindgen version which could break the CI check for out of date
bindings. So add our own do not edit line.

Ticket: #7341
2 weeks ago
Jason Ish 45641eab1e github-ci: test that bindgen bindings are up to date
Regenerates the `sys.rs` and looks for any difference. Check will fail
if there is a difference.

Ticket: #7341
2 weeks ago
Jason Ish 4554c4778d rust: use AppProto from generated bindings instead of duplicating
Have bindgen generate bindings for app-layer-protos.h, then use the
generated definitions of AppProto/AppProtoEnum instead if defining
them ourselves.

This header was chosen as its used by Rust, and its a simple header
with no circular dependencies.

Ticket: #7341
2 weeks 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 weeks ago
Jason Ish 8f22e55678 rust/sys: stub in suricata-sys crate for Rust bindings to C
Follow Rust convention of using a "sys" crate for bindings to C
functions. The bindings don't exist yet, but will be generated by
bindgen and put into this crate.

Ticket: #7341
2 weeks ago
Jason Ish 19debb7382 configure: check for existence of bindgen
Require a minimum version of 0.66.0.

Ticket: #7341
2 weeks ago
Victor Julien 4b855aa4a9 detect/profile: convert rule grouping dump to json builder
Ticket: #7558.
2 weeks 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 weeks ago
Jason Ish c861685e28 configure: require minimum version of cbindgen to be 0.20.0
0.10.0 doesn't work anymore. In some combinations 0.20.0 doesn't work
either, however it does work in our CI jobs.
2 weeks 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 weeks ago
Shivani Bhardwaj 015da2c7ed rust: add C callback for FatalErrorOnInit 2 weeks ago
Shivani Bhardwaj 0ce8b15ca8 rust: add macro to return val if unwrap fails 2 weeks ago
Shivani Bhardwaj 77bf58d687 datasets: remove unused fn definition 2 weeks ago
Jason Ish 97e01a8cc8 doc/userguide: upgrade notes for Lua
- Sandboxed Lua for rules
- Search path changes for Lua output scripts
2 weeks ago
Jason Ish c3716ac56b output-lua: lua module search path configuration
By default, use an empty search path. This gives us a predictable
default. If a user needs access to external modules, the search path
must be set in the configuration file.

Ticket: #7169
2 weeks ago
Jason Ish 8402d79962 output-lua: remove unused includes 2 weeks ago
Jason Ish 32287c7694 output-lua: rename script directory variable
It had a rather generic name of "path", which in Lua usually means a
search path, which we'll be adding.
2 weeks ago
Jason Ish c6d038b8a4 doc/userguide: document Lua base64 library
Ticket: #7074
2 weeks ago
Jason Ish 018f274e2a lua: add base64 lib
Export our base64 decoding and encoding functions to Lua.

Ticket: #7074
2 weeks ago
Jason Ish 7a936cb486 base64: expose no padding and padding optional variants
A no padding option is provided as a mode, as its a variant suitable
for encoding and decoding.

A padding optional function is added that is indifferent to padding
when decoding. This can be useful when you're not sure if padding
exists, and don't really care.
2 weeks ago
Jason Ish ad6d9e0d93 base64: prefix base64 C API with "SC" 2 weeks ago
Jason Ish fd488170c4 lua: update lua to 5.4.7
This version of out Lua crate also supports cross compiling.
2 weeks ago
Victor Julien 38318438d1 doc/userguide: add lua packetlib docs 2 weeks ago
Victor Julien 7226a0b2e7 detect/lua: register built-in libs also for open setup
Register internal libs for the case where loading external modules is allowed.
2 weeks ago
Victor Julien cdd2f56cfe doc: remove old lua packet methods 2 weeks ago
Victor Julien 48ef7aab64 lua: remove old lua payload/packet calls
Moving forward the packetlib is to be used.

Ticket: #7488.
2 weeks ago
Victor Julien fbb6b0de61 lua: add initial suricata.packet lib
Example:

```
local packet = require "suricata.packet"

function init (args)
    local needs = {}
    return needs
end

function match (args)
    p = packet.get()
    payload = p:payload()
    ts = p:timestring()

    for line in payload:gmatch("([^\r\n]*)[\r\n]+") do
        if line == "GET /index.html HTTP/1.0" then
            ipver, srcip, dstip, proto, sp, dp = p:tuple()
            SCLogNotice(string.format("%s %s->%s %d->%d (pcap_cnt:%d) match! %s", ts, srcip, dstip, sp, dp, p:pcap_cnt(), line));
            return 1
        end
    end

    return 0
end
```

Methods:
`get` creates the packet object.
`payload` returns the packet payload as a buffer
`packet` returns the whole packet (includes headers)
`pcap_cnt` returns the `pcap_cnt` (pcap file mode only)
`tuple` returns various fields: srcip, dstip, proto, sp, dp
`sp` returns source port
`dp` returns destination port
`timestamp` returns time as 2 numbers: seconds and microseconds
`timestring_legacy` returns a timestamp as a string (like fastlog)
`timestring_iso8601` returns a iso8601 compat timestring (like eve)

Ticket: #7488.
2 weeks ago
Victor Julien 4dbd6ccd2c detect/lua: minor code cleanup 2 weeks ago
Victor Julien 3f53d657a9 detect/lua: remove unused tls flag 2 weeks ago
Victor Julien d545b4d860 threads: fix int as pointer warning for pthread_exit
clang-tidy:
        warning: integer to pointer cast pessimizes optimization opportunities

Since the returned code of -1 was never read, just return NULL.
2 weeks ago
Victor Julien 3d46c18474 commandline: fix undefined behavior in parsing list-keywords
Flagged by clang-tidy.
2 weeks ago
Victor Julien b285e433ef flow/queue: remove circular dependency
flow-queue.h included flow.h, but was also included by it.
2 weeks ago
Victor Julien f81e8f02c1 includes: explicitly check for and include mm_malloc.h
Helps code analyzers.
2 weeks ago
Victor Julien b6a610df26 build: pass LOCAL_STATE_DIR through autoconf.h
Helps tooling like cppcheck, clang-tidy.
2 weeks ago
Victor Julien 5928adc852 detect: remove unused arg from get detect tx 2 weeks ago
Victor Julien ce948040a1 detect: don't cast void on void func 2 weeks ago