Commit Graph

10407 Commits (suricata-6.0.13)

Author SHA1 Message Date
Jason Ish 735f5aa9ca datasets: flag to disable "write" actions
Add a new configuration flag, "datasets.rules.allow-write" to control
if rules can contain "save" or "state" rules which allow write access
to the file system.

Ticket: #6123
3 years ago
Jason Ish aee1523b45 datasets: don't allow absolute or paths with directory traversal
For dataset filenames coming from rules, do not allow filenames that
are absolute or contain a directory traversal with "..". This prevents
datasets from escaping the define data-directory which may allow a bad
rule to overwrite any file that Suricata has permission to write to.

Add a new configuration option,
"datasets.rules.allow-absolute-filenames" to allow absolute filenames
in dataset rules. This will be a way to revert back to the pre 6.0.13
behavior where save/state rules could use any filename.

Ticket: #6118
3 years ago
Jason Ish b95bbcc66d lua: disable lua rules by default
To protect against possible supply chain attacks, disable Lua rules by
default. They can be enabled under the "security" section of
suricata.yaml.

Ticket: #6122
3 years ago
Shivani Bhardwaj 342e21a5ef smtp: handle long lines per direction
Issue:
Currently, while handling of long lines, if the line exceeded the limit,
we'd set a variable state->discard_till_lf which will be reset in the
later stages based on the data that arrives. However, because there was
one variable per state, this meant that a later stage in the other
direction could also modify it which is incorrect.

Fix:
Use separate variables for each direction.

Bug 6053
3 years ago
Shivani Bhardwaj 79a1b2edb5 smtp: handle following cmd if LF was found in long line
If a long line had LF post the limit, it should be considered complete
and not wait for the next line to complete it. However, currently, any
following lines were skipped which could sometimes also be important
commands for the entire transaction.

Fix this by setting a flag in case we're truncating a long line but
after having found the LF character.

Bug 5989
3 years ago
Shivani Bhardwaj f5db4bb7d5 smtp: add function docs 3 years ago
Shivani Bhardwaj 432842ad69 smtp: handle DATA mode in middle of input parsing
Before:
If the input was such that we'd enter DATA mode in the middle, the
entire data would be passed through SMTPGetLine fn and be processed with
line limits etc in place.

After:
Since we don't want any limits to be enforced on DATA, we pass it to
SMTPPreProcessCommands fn to take care of it differently from the
commands.

Bug 5981
3 years ago
Cole Dishington 96bb6ed034 decode-ipv6: Set IPv6 proto incase of ext header parsing error
Set the IPv6 packet proto before parsing the ext headers, similar to
decode-ipv4, incase of an ext header parsing error. Otherwise
rule decode-events are not triggered for packets encapsulated in IPv6.

Bug: #6086.
(cherry picked from commit 531d99f4cf)
3 years ago
Jeff Lucovsky e027080a4e detect/byte-math: Support multiplication operator
Issue: 6070

This commit adds support for the multiplication operator to byte-math.
The regex for parsing the keyword options was missing the `*` character.
3 years ago
Victor Julien b46d54178a counters: make tcp stats independent of flow, ssn
Counters depended on availability of flow and tcp session, meaning
that 2 memcaps could affect the counters.

Bug: #5017.
(cherry picked from commit 36f6e05155)
3 years ago
Victor Julien e275a1e28e stream: update no-flow checks
(cherry picked from commit 0360cb6542)
3 years ago
Shivani Bhardwaj 1b9e4fba06 ftp: don't decrement truncated line len
In case LF was found for a long line way outside of the limit, we should
not need to update the delimiter len and current line len because the
line is capped at 4k and the LF was not within these 4k bytes.
3 years ago
Shivani Bhardwaj 544ac300a9 ftp: separate truncated line markers
So far, we store one variable in state to hold whether we want to
discard a long line till LF irrespective of direction. This means that a
long command to the client followed by a regular command w LF can be
considered as one long line which is incorrect.

Bug 6055
3 years ago
Victor Julien ad041da715 windivert: fix compile warnings
(cherry picked from commit fd93f002a0)
3 years ago
Victor Julien 6767b1ce22 detect: remove flow drop unittest
Test broke after recent changes. Functionality is tested in
suricata-verify, so just remove the test.

(cherry picked from commit 8a535a0b89)
3 years ago
Victor Julien 5c2e6c4b83 detect: add check to validate drops
(cherry picked from commit 95bf7248e8)
3 years ago
Victor Julien 644a231e9a detect: fix stateful drops for rate_filter
(cherry picked from commit 418cc1fe94)
3 years ago
Victor Julien 043bbb9f51 flow/timeout: no pseudo packets for dropped flows
When a flow is in the drop flow state, don't use pseudo packets
when it is timing out. There should be no work left to do at this
point.

(cherry picked from commit 2a95154712)
3 years ago
Victor Julien 4b9cac426a stream: simplify drop handling
Remove logic to apply flow drop, as this is now handled in the
flow engine.

However, keep the logic that frees/cleans the session state.

(cherry picked from commit d91a1e8bc6)
3 years ago
Victor Julien 416cc8455f app-layer: don't update UDP applayer for dropped packets
(cherry picked from commit 77f49661fd)
3 years ago
Victor Julien 66aed4471d detect: update/document drop flow logic
Now that flow drop is applied to packets before other processing,
no drop has to be issued on a packet.

(cherry picked from commit 85ddba63f6)
3 years ago
Victor Julien 49051b637e flow: apply flow to packet on flow lookup
Issue drop to packet as early as possible.

(cherry picked from commit 71a033ac62)
3 years ago
Victor Julien 18a71913e3 respond/reject: fix IPv6 TCP resets
Fix length and next header field settings.

Bug: #6038.
(cherry picked from commit 235ee36211)
3 years ago
Victor Julien 8acf711667 respond/reject: minor code cleanups
(cherry picked from commit 1f0aed0775)
3 years ago
Victor Julien 2084354426 respond/reject: minor cleanups
(cherry picked from commit adf0bef7f0)
3 years ago
Shivani Bhardwaj e95e9281ca smtp: return on line completion
Problem:
If we receive a long line w/o LF, we cap it to 4k bytes and wait until a
line with LF comes in order to consider the previous line complete. Any
data post the 4k bytes is discarded. Currently, if a line with LF comes
in after a long line, we reset all the parameters used for processing it
like the line.len and line.delim_len but we still make the call to
SMTPProcessRequest fn without even the need to process anything. Since
such a line (with len and delim_len set to 0) should not reach mime
decoder, a debug assertion triggers there in this case.

Fix:
Make sure to return early as the line has to be skipped and not
processed at all.

Bug 6019

(cherry picked from commit c0067a5fff)
3 years ago
Jeff Lucovsky cb71800f7b pfring: Packet structure for ts fix
Issue: 5818

This commit addresses the issue with using the address of a packed
member of a structure. The pfring timeval is within a packed structure.

(cherry picked from commit 2d28c09ea1)
3 years ago
Jeff Lucovsky d782647af8 gen: Typo correction
This commit fixes various typos in the pf-ring source modules.

Issue: 5975
(cherry picked from commit e26e7b4f0a)
3 years ago
Jeff Lucovsky 32da57bce3 config/pf-ring: Change default cluster type: cluster_flow
This commit changes the default pf-ring cluster type to cluster-flow.
Round-robin clustering is not recommended for Suricata.

Issue: 5975
(cherry picked from commit 4f7a36ac2e)
3 years ago
Jeff Lucovsky 28026024c3 config/pf-ring: Recognize and set add'l cluster types
This commit extends the pf-ring config parser to recognize the
additional cluster types:
- cluster_inner_flow
- cluster_inner_flow_2_tuple
- cluster_inner_flow_4_tuple
- cluster_inner_flow_5_tuple

Issue: 5975
(cherry picked from commit b21a4ded6e)
3 years ago
Jeff Lucovsky a5752d138e pf-ring: Add add'l cluster types
This commit adds preprocessor values for additional pf-ring
cluster-types:
- CLUSTER_INNER_FLOW
- CLUSTER_INNER_FLOW_2_TUPLE
- CLUSTER_INNER_FLOW_4_TUPLE
- CLUSTER_INNER_FLOW_5_TUPLE

Issue: 5975
(cherry picked from commit 0ac3bee423)
3 years ago
Victor Julien 10d6c8796e stream: check debug check for multi-SYN/ACK in TFO
(cherry picked from commit 89c947129d)
3 years ago
Lukas Sismis a025070cc4 runmodes: introduce unknown engine runmode
To prevent unset values of engine runmode,
this commit introduces unknown runmode which
can detect when engine runmode is being used
uninitialized.

Ticket: #6033
3 years ago
Lukas Sismis 3c4bdf08de runmodes: earlier evaluation of IPS mode
Move evaluation of engine runmode to an earlier
phase so that dependend modules rely on properly
configured engine runmode.

Ticket: #5958
3 years ago
Lukas Sismis f08de8ea2e bpf: refactor the BPF code and postpone querying of the engine mode
BPF codebase queried engine mode earlier than it was determined from
the configuration file/command line. As a result it used the default (IDS)
mode where it could've been configured later on to the IPS mode.
This could lead into an undefined behavior as some Suricata modules behave
according to the engine mode.

PF-Ring, Netmap and AF-Packet all shared almost identical code for
determining the engine mode. It was put into one common function.
Omitted the usage of SCStrdup function in PF-Ring module as it is
uppercased during thread initialization phase.

Ticket: #5958
3 years ago
Jason Ish fe45258fbd detect: fix setting of flag for rule reload
As part of 6d8b50b748, the settings of
THV_CAPTURE_INJECT_PKT ended up in a location unreachable by capture
methods that did not have PktAcqBreakLoop.

Instead, always call TmThreadsCaptureBreakLoop which handles the logic
for how the read loop should be broken.

This fixes the case where read threads won't "break" for rule reloads
until packets are seen.

Ticket: #6021
(cherry picked from commit 1c6644ef4e)
3 years ago
Juliana Fajardini 75e57dde7c flow: make exc policy work w/ simulated flowmemcap
Exception policy wouldn't be applied if we were in the context of a
simulated flow memcap hit.

Bug #5998

(cherry picked from commit 1665f71a68)
3 years ago
Victor Julien 94b36cc4a3 src: fix extern max_pending_packets type 3 years ago
Philippe Antoine 79b89df331 detect: fix possible leak found by coverity
Conditions to create the leak are likely not reachable,
but this is still a bad pattern.

(cherry picked from commit e8060990d1)
3 years ago
Victor Julien 5f1651282d streaming: improve error handling
util-streaming-buffer.c:205:5: warning: Potential leak of memory pointed to by 'sbb2' [unix.Malloc]
    BUG_ON(sbb2->offset < sbb->len);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./suricata-common.h:290:27: note: expanded from macro 'BUG_ON'
        #define BUG_ON(x) assert(!(x))
                          ^~~~~~~~~~~~
/usr/include/assert.h:99:28: note: expanded from macro 'assert'
     ? __ASSERT_VOID_CAST (0)                                           \
                           ^
1 warning generated.
3 years ago
Victor Julien f8cec1e4f5 detect: improve prepare mpms routine
Based on hash table work in:
e624328deb ("detect: split mpm per alproto for file.data & others")

Instead of using a large stack array use a hash table for the intermediate
steps of the mpm build.
3 years ago
Victor Julien 36e07f874f streaming/sbb: propegate allocation errors
(cherry picked from commit d6b4c90225)
3 years ago
Victor Julien 0b8a46de39 scan-build: use simpler aligned alloc wrapper 3 years ago
Victor Julien cc0886d39d stream: fix minor scan-build warning
stream-tcp.c:134:14: warning: Value stored to 'presize' during its initialization is never read [deadcode.DeadStores]
    uint64_t presize = SC_ATOMIC_GET(st_memuse);
             ^~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

(cherry picked from commit 0c15114450)
3 years ago
Victor Julien aaee63bab1 mime: address scan-build warnings
util-decode-mime.c:189:31: warning: Use of memory after it is freed [unix.Malloc]
            lastSibling->next = entity->child;
            ~~~~~~~~~~~~~~~~~ ^
util-decode-mime.c:827:24: warning: Potential leak of memory pointed to by 'val' [unix.Malloc]
        state->hname = NULL;
                       ^~~~
/usr/lib/llvm-16/lib/clang/16/include/stddef.h:89:24: note: expanded from macro 'NULL'
 #  define NULL ((void*)0)
                       ^
2 warnings generated.

Improve error handling and add assert to avoid these warnings.

Bug: #3147.
(cherry picked from commit 9224b3435b)
3 years ago
Victor Julien b802a6241f smtp/mime: no error logging in packet path
(cherry picked from commit 9d3c60bde3)
3 years ago
Victor Julien 07639c96f2 radix: add debug validation to assist scan-build
util-radix-tree.c:595:34: warning: Access to field 'stream' results in a dereference of a null pointer (loaded from field 'prefix') [core.NullDereference]
        if ((temp = (stream[i] ^ bottom_node->prefix->stream[i])) == 0) {
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
util-radix-tree.c:717:30: warning: Access to field 'stream' results in a dereference of a null pointer (loaded from field 'prefix') [core.NullDereference]
        if (SC_RADIX_BITTEST(bottom_node->prefix->stream[differ_bit >> 3],
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
./util-radix-tree.h:27:34: note: expanded from macro 'SC_RADIX_BITTEST'
 #define SC_RADIX_BITTEST(x, y) ((x) & (y))
                                 ^
2 warnings generated.

(cherry picked from commit fa5acc1743)
3 years ago
Victor Julien 88b305b539 detect/sigorder: assist scan-build
Bug: #3152.
(cherry picked from commit b625aa9748)
3 years ago
Victor Julien d2375ee7d2 detect/sigorder: remove unused struct fields
(cherry picked from commit 03e0a60f96)
3 years ago
Victor Julien 47b25329aa detect: fix scan-build warnings
detect-engine-address.c:1140:17: warning: Use of memory after it is freed [unix.Malloc]
            r = DetectAddressCmp(ag, ag2);
                ^~~~~~~~~~~~~~~~~~~~~~~~~
detect-engine-address.c:1169:17: warning: Use of memory after it is freed [unix.Malloc]
            r = DetectAddressCmp(ag, ag2);
                ^~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

detect-engine-port.c:1161:9: warning: Use of memory after it is freed [unix.Malloc]
        DetectPortPrint(ag2);
        ^~~~~~~~~~~~~~~~~~~~
1 warning generated.

Bug: #3150.
Bug: #3151.
(cherry picked from commit 000064de7d)
3 years ago