Commit Graph

10855 Commits (c862e84c01d59b71cd44b57998936c48b4d142b2)

Author SHA1 Message Date
Victor Julien f8a0f3d9b9 detect/address: remove useless checks
Cppcheck flagged this:

src/detect-engine-address.c:1035:48: warning: Either the condition 'ghn!=NULL' is redundant or there is possible null pointer dereference: gh. [nullPointerRedundantCheck]
    int r = DetectAddressIsCompleteIPSpaceIPv4(gh->ipv4_head);
                                               ^
src/detect-engine-address.c:1297:17: note: Assuming that condition 'ghn!=NULL' is not redundant
        if (ghn != NULL) {
                ^
src/detect-engine-address.c:1283:44: note: Calling function 'DetectAddressIsCompleteIPSpace', 1st argument 'ghn' value is 0
        if (DetectAddressIsCompleteIPSpace(ghn)) {
                                           ^
src/detect-engine-address.c:1035:48: note: Null pointer dereference
    int r = DetectAddressIsCompleteIPSpaceIPv4(gh->ipv4_head);
                                               ^

Cleanup code could only be reached with non-NULL pointers, so simplify checks.

Bug: #5291.
4 years ago
Victor Julien bad9005161 detect/ipv6: remove useless code
Remove useless allocation and free.

Found by cppcheck as a potential issue:

src/detect-engine-address-ipv6.c:385:12: warning: Either the condition 'tmp!=NULL' is redundant or there is possible null pointer dereference: tmp. [nullPointerRedundantCheck]
    memset(tmp,0,sizeof(DetectAddress));
           ^
src/detect-engine-address-ipv6.c:525:13: note: Assuming that condition 'tmp!=NULL' is not redundant
    if (tmp != NULL)
            ^
src/detect-engine-address-ipv6.c:385:12: note: Null pointer dereference
    memset(tmp,0,sizeof(DetectAddress));
           ^

But code turned out not to do anything, so removed.

Bug: #5291.
4 years ago
Victor Julien ea2d0ecf08 datasets: fix cppcheck warning
src/datasets.c:107:17: error: Uninitialized variable: hash [uninitvar]
    memcpy(out, hash, outs);
                ^
src/datasets.c:93:26: note: Assuming condition is false
    for (x = 0, i = 0; i < ins; i+=2, x++) {
                         ^
src/datasets.c:107:17: note: Uninitialized variable: hash
    memcpy(out, hash, outs);
                ^

Bug: #5291.
4 years ago
Victor Julien 4bb00964ac detect: fix rule inspection order
Fix rules from the 'match' list getting added to the tx candidates list
unsorted. In some cases this could lead to the same sid getting inspected
twice leading to a DEBUG_VALIDATION_BUG_ON trigger.

Bug: #5144.
4 years ago
Victor Julien c40df43609 stream: improve flow end payload logging
Use all available data, including un-ACK'd, when in flow timeout
mode.

Bug: #5276.
4 years ago
Victor Julien b50d5eb8c8 eve/alert: add pkt_src/pcap_cnt to tunnel
Makes it easier to correlate an alert to the original packet.
4 years ago
Victor Julien 9336ab5dcd eve: add pkt_src
This will tell the user if a record was generated based on a real packet,
a flow timeout packet or others.
4 years ago
Victor Julien 3d6e733aa7 stream/unittests: fix failures after last_ack fix
Work around many tests not setting up stream completely or correctly.
4 years ago
Victor Julien 1f43e1477f stream: improve last_ack validation check
If a packet after the initialization would come with ACK flag set
but a ACK value of 0, the last_ack tracking could get confused. Fix
this by not checking for 0 but instead checking if the ACK flag
has been seen.

Bug: #4549.
4 years ago
Victor Julien e7417a8e96 smtp: don't pass partial boundary on to mime parser
If the start of a line looks like it might be a mime boundary we
yield to the get line logic if we don't have enough data to be
conclusive.
4 years ago
Victor Julien 6e800a8548 mime: allow partial lines as input
If we get a zero length delim we assume its a partial line and we
won't append CRLF just yet.
4 years ago
Shivani Bhardwaj cf749fd450 smtp: pre process DATA and BDAT commands
The input data received in DATA and BDAT command modes can be huge and
could have important data, like a legit huge email. Therefore, exempt
these from the line buffering limits which were introduced to regulate
the size of lines that we buffer at any point in time.

As a part of this patch, anything that comes under DATA or BDAT is
processed early without buffering as and when it arrives. The ways of
processing remain the same as before.
4 years ago
Shivani Bhardwaj 078c251dea smtp: fix indefinite buffering if no LF in line
Issue
-----
So far, with the SMTP parser, we would buffer data up until an LF char
was found indicating the end of one line. This would happen in case of
fragmented data where a line might come broken into multiple chunks.
This was problematic if there was a really long line without any LF
character. It would mean that we'd keep buffering data up until we
encounter one such LF char which may be many many bytes of data later.

Fix
---
Fix this issue by setting an upper limit of 4KB on the buffering of
lines. If the limit is reached then we save the data into current line
and process it as if it were a regular request/response up until 4KB
only. Any data after 4KB is discarded up until there is a new LF char in
the received input.

Cases
-----
1. Fragmentation
The limit is enforced for any cases where a line of >= 4KB comes as diff
fragments that are each/some < 4KB.
2. Single too long line
The limit is also enforced for any cases where a single line exceeds the
limit of buffer.

Reported by Victor Julien.
Ticket 5023
4 years ago
Shivani Bhardwaj 57a7cf7a0b smtp: add truncated line event 4 years ago
Jason Ish cf8ed576e0 ftp: truncate command data that is too long
FTP control commands will be buffered forever until a new line is seen,
this can lead to memory exhaustion in Suricata.

To fix, set an upper bound, 4096 bytes on the size of the command that
is saved in the transaction. The input continues to be parsed to find
the end of the command so the parser can continue to move onto the next
command.

The result is that the command data in the transaction is truncated,
which also shows up in the ftp transaction logs.

This value is configurable with the max-line-length field in the ftp
app-layer.protocols section.

As FTP doesn't have events at this time, add a new fields to eve-log
that specificy if the request, or the response has been truncated.

Ticket #5024
4 years ago
Philippe Antoine cedffdf14c protocol: forbids concurrent protocol upgrades
Ticket: 5243

When switching from SMTP to TLS, and getting HTTP1 instead of
expected TLS, and HTTP1 requesting upgrade to HTTP2, we do not
overwrite the alproto_orig value so as not to have type confusion
in AppLayerParserStateProtoCleanup
4 years ago
Victor Julien f5408ec2d7 detect/frame: fix frame detect registration
Rewrite keyword parser.

Duplicate short names could lead to buffer confusion and memory leaks.

Bug: #5238.
4 years ago
Victor Julien af90478167 detect/frames: reduce severity of validation check 4 years ago
Victor Julien 3a7d09edfc detect/frame: get data using stream callback
Inspect only data that has already been consumed by the
app-layer parser. This allows for simpler progress tracking.
4 years ago
Victor Julien ffe036e881 frame: introduce entry for getting stream data for frame 4 years ago
Victor Julien 96bc11d0d0 stream: make raw data handling more generally usable
Move raw detection logic out of main StreamReassembleRawDo() so that
it can be reused for other parts of the engine.

The caller now has to specify a right edge of the data.
4 years ago
Victor Julien afb97d1dee stream: add offset to raw stream callback
This gives the called function to understand where it is in the
stream.
4 years ago
Victor Julien 205bc1e288 app-layer: disable stream app tracking on no parser
If protocol has no parser enabled or implemented, disable the app
progress tracking in the stream engine to reduce the workload in
the stream engine.
4 years ago
Philippe Antoine 8ecf7e403e source: pcap timestamp microsecond consistency
That is it should be less than 1 000 000.
Have the same for fuzz targets where the bug came from.

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44177
4 years ago
Philippe Antoine dccf2e4c30 detect: config checks alstate before getting tx
Ticket: 4972

As is done in detect-lua-extensions.
We can have a flow with alproto unknown, no state, and therefore
cannot run AppLayerParserGetTx which could try to run a NULL
function
4 years ago
Philippe Antoine 45d1a9ae77 detect: faster linked list copy
In DetectAppLayerInspectEngineCopyListToDetectCtx
Avoid quadratic complexity by remembering last element
of the linked list we are inserting into
4 years ago
Philippe Antoine 2a22b4ca1f flow: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine 1cc9762b6a host/ippair: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine b1eaa1e8cd util: using size_t len for byte utils
Ticket: 4516

Like ByteExtractStringUint64, because most of their inputs come
from strlen which returns a size_t
4 years ago
Philippe Antoine f30975fb16 app-layer: fix integer warnings
Ticket: 4516
4 years ago
Victor Julien 1c8559b3ab debug: support %m output format again
Use thread local storage to avoid the previous dead lock issues.
4 years ago
Victor Julien ce4e543719 threading: simplify thread name logic 4 years ago
Victor Julien 013fb2dde3 frames: remove dead condition in eof check 4 years ago
Victor Julien 86e8611f5e app-layer: don't switch dir if proto already known 4 years ago
Victor Julien 7b55f8b2e3 fuzz/sigpcap_aware: set pkt_src to wire
Avoids an assert if DEBUG is compiled in:

fuzz_sigpcap_aware: source-pcap-file.c:420: TmEcode DecodePcapFile(ThreadVars *, Packet *, void *): Assertion `!(p->pkt_src != PKT_SRC_WIRE && p->pkt_src != PKT_SRC_FFR)' failed.
4 years ago
Victor Julien 61df4120da detect/frame: improve assert accuracy
Handle frames of unknown size correctly.

Bug: #5226.
4 years ago
Victor Julien c824804e2b eve: allow /dev/null in threaded mode
Avoids creation of actual files called /dev/null.N which take
up space in /dev/ which lives in memory.
4 years ago
Victor Julien 5deb479f4c flow: cleanup locking debug leftovers 4 years ago
Victor Julien 57533d3e47 flow: fix and simplify locking
Since:

9551cd0535 ("threading: don't pass locked flow between threads")

`MoveToWorkQueue()` unconditionally unlocks the flow. This allows simpler
locking handling, including of tcp reuse flows.

The simpler logic also fixes a scenario where TCP reuse flows got "unlocked"
twice, once in `FlowGetFlowFromHash()` and once in `MoveToWorkQueue()`.

Bug: #5248.
Coverity: 1494354.
4 years ago
Philippe Antoine e3180e3248 output: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine 0cba561fec detect: not an iponly signature if it needs app-layer
Ticket: 4972

This may happen with `config` keyword which is postmatch,
but may require a transaction
4 years ago
Juliana Fajardini a6bda3596b unittests: alloc Packet with PacketGetFromAlloc
Some unittests used SCMalloc for allocating new Packet the unittests.
While this is valid, it leads to segmentation faults when we move to
dynamic allocation of the maximum alerts allowed to be triggered by a
single packet.

This massive patch uses PacketGetFromAlloc, which initializes a Packet
in such a way that any dynamic allocated structures within will also be
initialized.

Related to
Task #4207
4 years ago
Shivani Bhardwaj 6d2a2a0731 detect/dataset: fix space condition in rule lang
If there is a space following a keyword that does not expect a value,
the rule fails to load due to improper value evaluation.
e.g. Space after "set" command
alert http any any -> any any (http.user_agent; dataset:set  ,ua-seen,type string,save datasets.csv; sid:1;)

gives error
[ERRCODE: SC_ERR_UNKNOWN_VALUE(129)] - dataset action "" is not supported.

Fix this by handling values correctly for such cases.
4 years ago
Shivani Bhardwaj 7366396011 detect/dataset: cleanup dead code 4 years ago
Victor Julien 2b5eeab7d4 detect/urilen: don't pass null pointer to pcre2 free
Bug #5228.
4 years ago
Victor Julien 087151ddc3 detect/mpm: initialization micro optimization 4 years ago
Victor Julien 54a6dd09dd detect: pattern id assignment through hash table
Only consider active part of the pattern for mpm (so consider chop).

Move data structure to hash list table over the custom array logic.
4 years ago
Victor Julien a14854bce9 detect: keyword list to hash to improve perf
Since the switch to pcre2 this was much more heavily used, which
would lead to measurable time spent in list handling.
4 years ago
Victor Julien 9e6370ae2e detect: optimize mpm-engine setup
Instead of a loop over the rules in a group *per engine* do a single
loop in which all the engines are prepared in parallel.
4 years ago
Victor Julien 3352c0bee4 detect: initialization optimization
A lot of time was spent in `SigMatchListSMBelongsTo` for the `mpm_sm`.

Optimize this by keeping the value at hand during Signature parsing and
detection engine setup.
4 years ago
Victor Julien b804a84c93 hash: constify data input 4 years ago
Victor Julien 4b0e3d79bb detect/analyzer: support frames in pattern dump 4 years ago
Victor Julien 47629b7aeb detect/filemagic: don't pass unused pointer 4 years ago
Arne Welzel 8ef066318d flow-manager: fix off-by-one in flow_hash row allocation
The current code doesn't cover all rows when more than one flow manager is
used. It leaves a single row between ftd->max and ftd->min of the next
manager orphaned. As an example:

    hash_size=1000
    flowmgr_number=3
    range=333

    instance  ftd->min  ftd->max
    0         0         333
    1         334       666
    2         667       1000

    Rows not covered: 333, 666
4 years ago
Victor Julien 9537d119b9 http: fix reassembled range file accounting 4 years ago
Victor Julien 6d30f4442c http2: fix file accounting for ranged files
Increment files_opened for tx that 'gets' reassembled ranged file
4 years ago
Victor Julien 54d34c96f5 files: open/log debug validation bugon
Meant to find more cases where there is a mismatch.
4 years ago
Philippe Antoine cfcade58ad http: move xff logging to alert object
Ticket: 4860

instead of root field
4 years ago
Philippe Antoine 862e84877f ssl: first pass limit when allocating buffer for certificates
With this check, on the first packet of a certificate presenting
a length of 16Mbytes, we only allocate up to 65Kb

When we get to the point where need more than 65Kb, we realloc
to the true size.

With this check, it makes it more expensive for an attacket to use
this allocation as a way to trigger ressource exhaustion...
4 years ago
Philippe Antoine 99b3443369 smtp: check if there is a transaction to close
Ticket: 4948

When parsing the response for starttls
4 years ago
Philippe Antoine 68fa080069 tmqh: fix possible null dereference
Coverity ID: 1502953

As we check just on the next line my_pool against NULL, we should
not dereference it, even for debug validation
4 years ago
Philippe Antoine 568ab841d8 detect: remove dead code about xbits keyword 4 years ago
Philippe Antoine 4640b15d8c log: prevents use of uninitialized variable
Even if the code seems unreachable for now
4 years ago
Jason Ish 8d1e4a1d0b detect-content: error on single char hex pairs
Fix parsing of content like "|aa b cc|" which was parsed as "|aa bc|"
without error or warning. This will now fail out, requiring all hex
values to be 2 chars.

Ticket #5201
4 years ago
Victor Julien 6e90bf4739 streaming: remove unused 'auto slide' support
Add debug validation checks for "impossible" conditions.
4 years ago
Philippe Antoine 00da0d3420 detect: makes config keyword really require a flow
Ticket: 4972

Completes commit c3a220647

DETECT_CONFIG is added as DETECT_SM_LIST_POSTMATCH and not
as DETECT_SM_LIST_MATCH as other keywords handled in SignatureCreateMask
4 years ago
Modupe Falodun 54bc43d3ed detect-pcre: remove unittests
These tests are reimplemented in Suricata-Verify

Task: 4911
4 years ago
Philippe Antoine df83f7899d fuzz: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine 5790280c95 utils: fix integer warnings in r files
Ticket: 4516
4 years ago
Philippe Antoine dca76a45a8 stream-tcp: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine 068fb700df util: fix int warnings in tm threads
Ticket: 4516
4 years ago
Philippe Antoine 1bb51d114c util: fix int warnings in unit tests
Ticket: 4516
4 years ago
Philippe Antoine b3ab126394 util: fix int warnings
Ticket: 4516
4 years ago
Philippe Antoine c3a220647b detect: only apply ConfigApplyTx with app-layers
Ticket: 4972

Otherwise, it makes no sense to look for a tx...
4 years ago
Juliana Fajardini e5838b8193 applayer/frame: remove output from GetFrame funcs
As these functions can be probed, having output there results in
misleading output.
4 years ago
Modupe Falodun 44208010db detect-dce-iface: remove unittests
These tests are reimplemented in Suricata Verify

Task: 4911
4 years ago
Victor Julien 935ea745f5 detect/iponly: add tests for 5168 4 years ago
Victor Julien 053b2b3b5b detect/address: minor unittest cleanup 4 years ago
Victor Julien 79b7b7a0dd detect/iponly: validate netmask
Only accept netmask in dotted quad notation if they can be turned
into a CIDR.

According to rfc 4632, CIDR (compat) netmasks are all that should be
used.

Bug: #5168.
4 years ago
Victor Julien 259bd8aa92 detect/address: validate netmasks
Only accept netmask in dotted quad notation if they can be turned
into a CIDR.

According to rfc 4632, CIDR (compat) netmasks are all that should be
used.

Bug: #5168.
4 years ago
Victor Julien 4020e2faa7 detect/iponly: break out range insert code
So we can reuse it.
4 years ago
Victor Julien a67b97e14c util/cidr: add util to convert netmask to cidr 4 years ago
Philippe Antoine eb189e805a src: use u8_tolower everywhere
Ticket: 4516

Instead of basic to_lower to get the cast to avoid warning
about integer

Sames goes for u8_toupper
4 years ago
Philippe Antoine 3fd8e908f8 range: better closing for out of order ranges
Ticket: 5132

In case of a duplicate range, we can return early, because
there is no new data to process.

More importantly, this commit adds a check about wether the file
got closed meanwhile, so that this just completed out of order
range, even if it brings new data, is now irrelevant.
This can happen for instance if there was a gap...
4 years ago
Philippe Antoine bfcd6cb46a range: validity check when end is bigger than size
Ticket: 5132

Down the line, HttpRangeOpenFileAux assumes the range has a
valid value when doing buflen = end - start + 1;
4 years ago
Modupe Falodun 14b21de306 detect-dnp3: remove dnp3_data unittests
These tests are reimplemented in Suricata-Verify

Task: 4911
4 years ago
Philippe Antoine ae6c416972 util/mime: fix integer warnings
Ticket: 4516
4 years ago
Victor Julien ec01a94a5f detect: minor debug fixup 4 years ago
Victor Julien b7526bf4e6 decode/vntag: don't leak memory in tests 4 years ago
Victor Julien 0437ca61ff unittests: clean up packet clear logic 4 years ago
Victor Julien f07d5b2d89 decode: release refs from PacketFree
Mostly helps unittests.
4 years ago
Victor Julien 49a36bb323 detect/iprep: fix host locking issues
Separate the code paths between reusing a Packet stored host reference
and fetching a new reference from the host hash.

This addresses the issue where in some conditions use_cnt could get
desync'd.

Bug: #2802.
4 years ago
Victor Julien 172d2b28a5 iprep: unify free handling
Introduce a new util function to free a Hosts iprep code. It also
handles the Host use_cnt decrement.

This change makes sure we also decrement the use_cnt when cleaning
up when shutting down the host table.

Move the BUG_ON check for use_cnt into the HostClearMemory() func
to check it in more cases.
4 years ago
Philippe Antoine a6a6f6d538 bytejump: fix ubsan warning
Instead of checking the offset, we checked the pointer after
adding the offset ot it...
4 years ago
Jeff Lucovsky 4f2f745bed detect/ipproto: Use builtin protocol table
Issue 5072

This commit causes the built-in protocol table to be used for protocol
name and number validation.
4 years ago
Jeff Lucovsky 3bd1d258a9 detect/tests: Register protoname tests
Issue: 5072

This commit registers the proto-name unit tests.
4 years ago
Jeff Lucovsky b524967257 detect/ipproto: Add init/release functions
Issue: 5072

This commit insures that the protocol name hashtables are initialized
and released.
4 years ago
Jeff Lucovsky ff0cf89738 util/proto: Protocol-name functions
Issue: 5072

This commit adds utility functions handling protocol names.
4 years ago
Jeff Lucovsky 1e2883602b error/hash: Add error code for hash add failures
Issue: 5072
4 years ago
Jeff Lucovsky 6232c94235 threads: Honor per-thread stack size setting
Issue: 4550

This commit adjusts the per-thread stack size if a size has been
configured. If the setting has not been configured, the default
per-thread stack size provided by the runtime mechanisms are used.
4 years ago
Jeff Lucovsky e4d60f451b config/thread: Use config'd per-thread stack size
Issue: 4550

This commit checks if there's a config setting for threading.stack-size
and assigns the value to a global variable for use during thread
creation.
4 years ago
Victor Julien a0c0471f1f output: fix timestamp missing usecs
On ARM 32bit with Musl `tv_usecs` is defined as `int64_t` which lead to
CreateIsoTimeString() printing all zeros on the usecs. Work around this
by first assigning to a `int64_t` and then updating the expected format
string to accept `int64_t`.

Bug: #5094.
5 years ago
Victor Julien 8a73b242e3 detect/address: use common cidr code 5 years ago
Victor Julien 38aec1439c radix: fix unittests after stict checks 5 years ago
Victor Julien 7fd6fe732b radix: improve address range handling
Handle non-exact address ranges from string. This can come directly
from user input, so here it is accepted but the address is converted
to the address range start. A warning will be issued.

Debug validation checks are added to catch this.

This issue could lead to bad input from iprep (with cidr), defrag config
and htp server personalities to produce a bad radix tree.

Bug: #5084.
Bug: #5085.
Bug: #5086.
5 years ago
Victor Julien 51d4e0dced detect/iponly: fix netmask handling
If the ipaddress was not the address range start, it was not masked to turn
it into that. So 1.2.3.4/24 was not stored as address 1.2.3.0 with netmask 24,
but as 1.2.3.4 with netmask 24. This was then propagated into the radix tree,
where it was used as an exact key in exact lookups, giving unexpected results.

This patch implements the netmask handling for IPv4 and IPv6, and adds a set
of tests for it.

Bug: #5081.
Bug: #5066.
5 years ago
Victor Julien 311085dd34 radix: fix unittest not cleaning up 5 years ago
Victor Julien 860daceb04 detect/iponly: update SigNumArray comment 5 years ago
Victor Julien d04dface20 radix: cleanup test 5 years ago
Victor Julien 89b7ac0a60 radix: add tests for Bug #5066
Bug: #5066.
5 years ago
Victor Julien 6aa6e3f953 radix: fix FP/FN issue in IP-only
A bug was reported about the IP-only rules not correctly matching. This was
traced to the rules in question not getting recorded into the IP-only radix
tree correctly.

Sequence:

- 100.117.241.0/25 inserted into the tree

- 100.117.241.0/26 inserted into the tree

Both are part of the same radix node, but recorded by their different netmasks
in the user data portion.

Then faulty insert happens:

- 100.117.241.64/26

For reference, these net blocks compute to:

- 100.117.241.0/25:  100.117.241.0  - 100.117.241.127
- 100.117.241.0/26:  100.117.241.0  - 100.117.241.63
- 100.117.241.64/26: 100.117.241.64 - 100.117.241.127

The IP-only engine first does a search to get to the user data it may need to
include. It does so for with `SCRadixFindKeyIPV4ExactMatch` for single IPs, or
using `SCRadixFindKeyIPV4Netblock` in case of a netblock. Any "match" from
either of these is considered an "exact match" by the IP-only setup code.

This exact match expectation turned out to be wrong and
`SCRadixFindKeyIPV4Netblock` behaved more like "best match" instead, which is
a non-exact match, but its the next best match if no exact match is found.

The way the look up for 100.117.241.64/26 went wrong, is that it returned
the user data for 100.117.241.0/26. This happens as follows:

- first it would do an exact find, which didn't give a result

- then it removed bits from the keystream until it found a matching node
  and explore if any of the netmasks it contained matched. Here the first
  step of the bug started:

  it considered the netmask (with user data) a match that matched the
  number of bits of the matching key, but not of the actual range netmask cidr
  value.

  So in this case the number of shared bits between `100.117.241.0/25` and
  `100.117.241.64/26` was 25, so it assumed that the user data for the
  netmask 25 was the match.

  To summarize this step, there are 2 problems with this:
  1. it returns a match on something that isn't an exact match
  2. it considered the wrong netmask value

- the radix code then took the returned node, and did the netmask check
  again. This time it did use its own netmask value, so this time
  it did find the netmask 26 (+ user data). However because of the node that
  was returned, this netmask (+user data) belongs to `100.117.241.0`, not to
  `100.117.241.64`.

- the IP-only detection code was satisfied with what it assumed to be
  "exact match" and just updated the user data to include the user data that
  should have been associated with `100.117.241.64/26` to `100.117.241.0/26`.

This patch addresses the issue as follows:

It makes `SCRadixFindKeyIPV4Netblock` also return an exact match by propagating
the netmask in the search and in the evaluation of the stored netmasks.

It does away with the secondary netmask (+user data) evaluation.
`SCRadixFindKeyIPV4Netblock` is expected to handle this correctly.

The IP-only engine will fall back to the "not found" path, which does an explicit
"best match" lookup and then insert a new entry into the radix tree based on
the user data of the "best match".

Issue was present for IPv6 as well.

Bug: #5066.
5 years ago
Victor Julien 6381b1a643 detect/iponly: cleanups 5 years ago
Victor Julien de4354abcb detect/iponly: minor debug 'Print' improvements 5 years ago
Victor Julien 3ca3c9dfbe radix: minor debug 'Print' improvements 5 years ago
Victor Julien e04d378e58 util/cidr: simplify IPv4 CIDR handling; add IPv6
Instead of building a table at init just calculate it on demand.

Callsites are all during init, so its not performance critical.

Add similar function for IPv6.
5 years ago
Juliana Fajardini e0b9f0e175 http: add comment tags to support documentation
With these, the portion of code within the tags should be included
in the related code-snippets (for frame support documentation) w/o
errors, even if the code within changes. The tags can also work as
a reminder that the existing code is being shown elsewhere, so folks
know documentation might need updates, in case of major changes.
5 years ago
Philippe Antoine 5fe9188a95 fuzz: test for too many open txs in a flow
so as to avoid performance problems coming from this.
5 years ago
Victor Julien e1f7c63fa8 swf: fix coverity warnings
*** CID 1499365:    (UNINIT)
/src/util-file-swf-decompression.c: 98 in FileSwfZlibDecompression()
92         infstream.avail_in = (uInt)compressed_data_len;
93         infstream.next_in = (Bytef *)compressed_data;
94         infstream.avail_out = (uInt)decompressed_data_len;
95         infstream.next_out = (Bytef *)decompressed_data;
96
97         inflateInit(&infstream);

>>>     CID 1499365:    (UNINIT)
>>>     Using uninitialized value "infstream.total_out" when calling "inflate".
98         int result = inflate(&infstream, Z_NO_FLUSH);
99         switch(result) {
100             case Z_STREAM_END:
101                 break;
102             case Z_OK:
103                 break;

/src/util-file-swf-decompression.c: 98 in FileSwfZlibDecompression()
92         infstream.avail_in = (uInt)compressed_data_len;
93         infstream.next_in = (Bytef *)compressed_data;
94         infstream.avail_out = (uInt)decompressed_data_len;
95         infstream.next_out = (Bytef *)decompressed_data;
96
97         inflateInit(&infstream);

>>>     CID 1499365:    (UNINIT)
>>>     Using uninitialized value "infstream.total_out" when calling "inflate".
98         int result = inflate(&infstream, Z_NO_FLUSH);
99         switch(result) {
100             case Z_STREAM_END:
101                 break;
102             case Z_OK:
103                 break;

*** CID 1499363:  Error handling issues  (CHECKED_RETURN)
/src/util-file-swf-decompression.c: 97 in FileSwfZlibDecompression()
91
92         infstream.avail_in = (uInt)compressed_data_len;
93         infstream.next_in = (Bytef *)compressed_data;
94         infstream.avail_out = (uInt)decompressed_data_len;
95         infstream.next_out = (Bytef *)decompressed_data;
96
>>>     CID 1499363:  Error handling issues  (CHECKED_RETURN)
>>>     Calling "inflateInit_(&infstream, "1.2.11", 112)" without checking return value. This library function may fail and return an error code.
97         inflateInit(&infstream);
98         int result = inflate(&infstream, Z_NO_FLUSH);
99         switch(result) {
100             case Z_STREAM_END:
101                 break;
102             case Z_OK:

Bug: #5079.
5 years ago
Victor Julien 4312676aed dnp3/eve: regenerate object logging code
To propagate jb_set_string_from_bytes() generator update.

Bug: #5080.
5 years ago
Jeff Lucovsky a3443845fb log/stack: Propagate original signal
Issue: 4550

This commit modifies the "stack trace on signal" to propagate the
original signal received instead of always raising SIGABRT.
5 years ago
Victor Julien 84d91e2e0d app-layer: fix counter setup logic
Completes 0ccf5b9147
5 years ago
Victor Julien 27cd54dc0d frames: address coverity issue
Minor cleanups to assist coverity.

Bug: #5065.
5 years ago
Modupe Falodun 786cf41599 detect-bytetest: remove unittests
These tests are reimplemented as Suricata-Verify

Task: 4911
5 years ago
Victor Julien c96d22e8a1 frames: support UDP frames
UDP frames point to the UDP packet payloads.

The frames are removed after each packet.

Ticket: #4983.
5 years ago
Victor Julien 97ef60cd9b output/file: remove 'waldo' code
It was no longer used after "file-store v1" was removed.
5 years ago
Victor Julien f9c04992c3 file/store: warning grammer fixup 5 years ago
Victor Julien b06bd1a1fe htp: rearrange tx user data for more efficiency 5 years ago
Victor Julien 39b1f1aca6 output/lua: minor cleanups 5 years ago
Victor Julien e5fd0d4f76 output/streaming: use unique thread data name 5 years ago
Victor Julien b36683e04f output/stats: use unique thread data name 5 years ago
Victor Julien 008f4aee69 output/packet: use unique thread data name 5 years ago
Victor Julien dd1dc88c65 output/filedata: use unique thread data name 5 years ago
Victor Julien c7db9aa50d output/file: use unique thread data name 5 years ago
Victor Julien 45f13b3d01 output/tx: use unique thread data name 5 years ago
Victor Julien 0be99f3e35 output: minor header cleanups 5 years ago
Victor Julien 645a04c233 output: declare OutputLoggerThreadStore once 5 years ago
Victor Julien 0ccf5b9147 app-layer: fix error counter logic 5 years ago
Modupe Falodun cf5c58c075 detect-uricontent: convert unittests to FAIL/PASS APIs 5 years ago
Modupe Falodun dc8908b282 detect-uricontent: remove unittests
These tests are reimplemented as Suricata-verify

Task: 4911
5 years ago
Modupe Falodun 26c9e66586 detect-engine-enip: remove unittests
These test is reimplemented in Suricata-Verify

Task: 4911
5 years ago
Victor Julien 609a7eaab2 app-layer: error counters
Per app-layer error counters for:
gap, parser, internal (AppLayerResult issues), alloc
5 years ago
Victor Julien ae0b8d92da flow/manager: remove dead code 5 years ago
Victor Julien 5618886aa9 stream: remove unused defines 5 years ago
Modupe Falodun d2dad66a2b detect-dce-opnum: remove unittests
These tests are reimplemented in Suricata-Verify

Task: 4911
5 years ago
Philippe Antoine 4247605d87 smtp: check if we have a current transaction
Ticket: 4948

This is not the perfect solution, but it prevents to trigger
the assert, and keep the assert.
A better solution would need to create transaction from
the reponse parsing, in case a later command was buffered and
not answered. But this would not be enough as NoNewTx prevents
the creation of a new transaction for RSET...
5 years ago
Philippe Antoine 2ef4172437 ftp: limits the number of active transactions per flow
Ticket: 4530

As for HTTP2 and MQTT.
In FTP case, transactions are pipelined, not identified by an id.
So, there are less chances of DOS by quadratic complexity.
5 years ago
Philippe Antoine b39554b11f fuzz: target for applayer cleans transactions
Ticket: 4530

Otherwise, we timeout because we kept too many of them
as Suricata would not
5 years ago
Aaron Bungay a5d3a1f92c src: use bool instead of int 5 years ago
Aaron Bungay 272786908c smtp/mime: configurable url scheme extraction
Parse extract-url-schemes from the mime config.
e.g. 'extract-urls-schemes: [http, https, ftp, mailto]'
Update MimeDecConfig struct to new url extraction fields.
Change app-layer-smtp.c & util-decode-mime.c to initialize new struct
fields for MimeDecConfig.
Sets the default value for extract-url-schemes if not found in the
config to 'extract-urls-schemes: [http]' for backwards compatibility.

Uses the schemes defined in the mime config value for
extract-urls-schemes to search for URLS starting with those scheme
names followed by "://".
Logs the URLS with the scheme + '://' at the start if the
log-url-scheme is set in the mime config, otherwise the old behaviour
is reverted to and the urls are logged with the schemes stripped.

Removed unused constant URL_STR now that URLS are being searched for
using extract-urls-schemes mime config values instead of just URL's
starting with 'http://'.

Added commented out new options for extract-urls-schemes and
log-url-scheme to suricata.yaml.in.

Update FindUrlStrings comments.
Remove old outdated comments/commented code from FindUrlStrings.
Update test case for mime which now needs schemes list to be set.
Add Test Cases for FindUrlStrings() method.

Feature: #2054
5 years ago
Modupe Falodun b77d1d7d2e detect-flowbits: remove unittests
These tests are reimplemented in Suricata-Verify

Task: 4911
5 years ago
Philippe Antoine 1e1a4ab1c4 detect: logs an error if a protocol is disabled
So that the user knows that the rule cannot match
5 years ago
Philippe Antoine bf30eb344a detect: checking validity of rules with http protocol
We want to check that a rule beginning with alert http
can be valid, that is if either HTTP1 or HTTP2 is enabled.
So, AppLayerProtoDetectGetProtoName will do a more complex
check for this ALPROTO_HTTP (any).
5 years ago
Jeff Lucovsky b53fced452 general: Fix typo 5 years ago
Jeff Lucovsky be2155b4ed config/ref: Raise errors for ref.config parsing
This commit raises an error in configuration test mode if there was an
error parsing reference.config.

Issue: 4659
5 years ago
Modupe Falodun 8d615842f9 detect/bypass: remove unittest
This test is reimplemented in Suricata-Verify

Task: 4911
5 years ago
Victor Julien 738e756eaf eve/pgsql: log txs in flow direction 5 years ago
Angelo Mirabella 41a139b590 stream-tcp-reassemble: fix reassembly direction for FIN packets
Suricata invokes the stream reassembly logic only for the current packet
direction if the packet contains a FIN flag. However, this does not
handle the case in which the packet ACKs data from the opposing direction.
This patch forces the invocation of the stream reassembly logic
on both direction when Suricata sees a FIN packet.
5 years ago
Jason Ish 9e096dda4e windows: exit early if live capture requested without npcap 5 years ago
Modupe Falodun 154e4eb395 http-response-line: remove unittest
This test is reimplemented in Suricata-Verify

Task: 4911
5 years ago
Modupe Falodun 926c02a141 detect/modbus: remove unittests
These tests are reimplemented in Suricata-Verify

Task: 4911
5 years ago
Modupe Falodun 0984528ddb detect-http-request-line: remove unittests
These tests are reimplemented as Suricata-Verify

Task: 4911
5 years ago
Modupe Falodun dff7e7d34e detect/hostbits: remove unittests
These tests are reimplemented as Suricata-Verify tests

Task: 4911
5 years ago
Modupe Falodun 47f70bf1f4 detect/proto: remove unittests
This test is reimplemented in Suricata-Verify

Task: 4911
5 years ago
Philippe Antoine 749b9c7635 fuzz: cleans all flow after one run
Completes commit e2370d6861
for all the fuzz targets processing pcaps
using a generic function.

FlowShutdown is not used because it uses the loop to destroy
mutexes, which we want to reuse for fuzzing
5 years ago
Victor Julien 40c315aa35 detect/frames: fix coverity warning
Harmless warning, but it was correct in that the code made no sense:
1497420 Dereference before null check
5 years ago
Victor Julien e902aaf838 detect/frames: fix crash when parsing bad rule
Indexing of Signature::init_data::smlists would fail for a rule that
used a frame w/o content, as the array would only be expanded when
adding a content. Adding a check to see if there list id is in bounds
is an implicit check for the "no content" case.

Bug #5011.
5 years ago
Victor Julien c6be6d2c6f detect/frames: fix error messages 5 years ago
Juliana Fajardini 0bf1227f0f pgsql: fix defect found by coverity
Pgsql was using bitwise operations to assign password output config to
its context flags, but mixing that with logic negation of the default
value, resulting in the expressions having a constant value as result.

Bug: #5007
5 years ago
Jason Ish 59ac1fe277 logging: change ownership of application log if needed
When running with privilege dropping, the application log file
is opened before privileges are dropped resulting in Suricata
failing to re-open the file for file rotation.

If needed, chown the application to the run-as user/group after
opening.

Ticker #4523
5 years ago
Jason Ish 08518df373 startup: initialize run as user info sooner
Initialize the run-as user info after loading the config, but
before setting up logging (previously it was done while initializing
signal handlers). This will allow the log file to be given the
correct permissions if Suricata is configured to run as a non-root
user.
5 years ago
Lukas Sismis f668524731 dpdk: adjust setting of MTU to the new DPDK API (21.11) 5 years ago
Philippe Antoine e8060990d1 detect: fix possible leak found by coverity
Conditions to create the leak are likely not reachable,
but this is still a bad pattern.
5 years ago
Juliana Fajardini 579d7dcc01 pgsql: add initial support
- add nom parsers for decoding most messages from StartupPhase and
SimpleQuery subprotocols
- add unittests
- tests/fuzz: add pgsql to confyaml

Feature: #4241
5 years ago
Shivani Bhardwaj 8918f53f6b smtp: use AppLayerResult instead of buffering
Also, remove tests that check for the removed buffers and any middle
states while parsing and buffering.

Ticket 4907
5 years ago
Victor Julien e02b52c895 quic: add quic.ua for matching user agent 5 years ago
Victor Julien da8b024b99 detect/quic: add quic.sni sticky buffer 5 years ago
Victor Julien 24a21af4ab quic: redo quic.version; parser cleanups
Reimplement quic.version as sticky buffer.

Removed unused parts of the parser.

Set unidirectional tx flag to fix double matching.
5 years ago
Emmanuel Thompson 7e51987263 quic: Add QUIC App Layer
Parses quic and logs a CYU hash for gquic frames
5 years ago
Philippe Antoine 23fb139e00 detect: do not upgrade base64 decode when fuzzing
As fuzzing will put a very big value, and then
ThreadCtxDoInit will try to allocate it,
ending in out of memory
5 years ago
Victor Julien ca29d33c69 proto-detect: set flags in packet direction for UDP 5 years ago
Victor Julien 449cc82943 proto-detect: fix UDP not setting alproto_ts/tc
This would lead to the `app-layer-protocol` keyword not matching correctly.
5 years ago
Philippe Antoine 0cfdec1266 detect: xor transform
Ticket: 3285

The xor transform applies xor decoding to a buffer, with a key
specified as an option in hexadecimal. Arbitrary key sizes are
accepted.
5 years ago
Philippe Antoine 1d4fe38ccb detect: adds test with invalid uint mode << 5 years ago
Philippe Antoine 2012b14470 detect: use generic functions for icode parsing 5 years ago
Philippe Antoine e2370d6861 fuzz: cleans all flow after one run
Makes the fuzz target more stateless

And manages to find bugs on the FlowFree path
5 years ago
Philippe Antoine add1a0f561 fuzz: use parsed rules in sigpcap target
Ticket: 4125

As commit d21a252238
But for sigpcap target as well
5 years ago
Philippe Antoine 529678d501 dns: wrap with HAVE_LUA
This is just code style, to minimize the compiled code.
5 years ago
Philippe Antoine 6885b66883 fuzz: enable template protocols
Ticket: 4125
5 years ago
Philippe Antoine ed11e32076 enip: fix too restrictive check in probing parser
As is shown later in the code, enip_len can be
ENIP_LEN_REGISTER_SESSION which is 4, which is
smaller than sizeof(ENIPEncapHdr) which is 24
5 years ago
Philippe Antoine 09c84d0c26 fuzz: use fuzzing confyaml for protodetect target
As is done for other targets,
so that all app-layer protocols are enabled,
even the ones disabled by default such as enip

And resets protocol detection every time we try
so that probing_parser_toserver_alproto_masks are fresh.
5 years ago
Victor Julien 44c9241b6a telnet: initial support with frames
Bootstrapped using setup script. Basic option parsing for purpose
of tagging frames.
5 years ago
Victor Julien fc4279de85 htp: improve request/response size accuracy 5 years ago
Victor Julien 52ad906d31 htp: implement basic request/response frames 5 years ago
Victor Julien af797b5926 ssl: implement frames for SSLv3 and TLS 5 years ago
Victor Julien a492d94826 detect/frames: implement 'frame' keyword
Implement a special sticky buffer to select frames for inspection.

This keyword takes an argument to specify the per protocol frame type:

    alert <app proto name> ... frame:<specific frame name>

Or it can specify both in the keyword:

    alert tcp ... frame:<app proto name>.<specific frame name>

The latter is useful in some cases like http, where "http" applies to
both HTTP and HTTP/2.

    alert http ... frame:http1.request;
    alert http1 ... frame:request;

Examples:

    tls.pdu
    smb.smb2.hdr
    smb.smb3.data

Consider a rule like:

    alert tcp ... flow:to_server; content:"|ff|SMB"; content:"some smb 1 issue";

this will scan all toserver TCP traffic, where it will only be limited by a port,
depending on how rules are grouped.

With this work we'll be able to do:

    alert smb ... flow:to_server; frame:smb1.data; content:"some smb 1 issue";

This rule will only inspect the data portion of SMB1 frames. It will not affect
any other protocol, and it won't need special patterns to "search" for the
SMB1 frame in the raw stream.
5 years ago
Victor Julien 02f98796a7 detect/frames: limit mixing frames and other detection
Don't allow mixing of payload/stream/tx and frame keywords. Initial
support is only for 'pure' frame inspection.
5 years ago
Victor Julien 3cbe33de57 detect/analyzer: add frame support 5 years ago
Victor Julien f6f124f283 detect/engine: support frames
Implement the low level detect engine support for inspecting frames,
including MPM, transforms and inspect API's.
5 years ago
Victor Julien c0ec3984fa eve/alert: add support for logging frame
If detection was done in a frame, the frame will be added to the
eve.alert output.
5 years ago
Victor Julien 60bfade351 eve: implement frame logging
This is mostly to assist development and QA. It produces too much data
for practical use.
5 years ago
Victor Julien a27ee49c73 app-layer: move app_progress forward on errors as well
In case of APP_LAYER_ERROR still move the app_progress forward.
This helps validation of frame offsets and should be harmless
otherwise.
5 years ago
Victor Julien 1556e86c7d app/frames: initial support
The idea of stream frames is that the applayer parsers can tag PDUs and
other arbitrary frames in the stream while parsing. These frames can then
be inspected from the rule language. This will allow rules that are more
precise and less costly.

The frames are stored per direction in the `AppLayerParserState` and will only
be initialized when actual frames are in use. The per direction storage has a
fixed size static portion and dynamic support for a larger number. This is done
for effeciency.

When the Stream Buffer slides, frames are updated as they use offsets relative
to the stream. A negative offset is used for frames that started before the
current window.

Frames have events to inspect/log parser errors that don't fit the TX model.

Frame id starts at 1. So implementations can keep track of frame ids where 0
is not set.

Frames affect TCP window sliding. The frames keep a "left edge" which
signifies how much data to keep for frames that are still in progress.
5 years ago
Victor Julien e6f49e5a05 app/frames: implement name to id API for frames 5 years ago
Victor Julien eeee740e84 stream: add util function to get 'usable' data 5 years ago
Lukas Sismis 52d8d35453 dpdk: fix received/error counters 5 years ago
Victor Julien 3cbbe66ea2 tests/pppoe: clean up more tests to use PASS/FAIL macros 5 years ago
Steven Ottenhoff 6bf2117056 pppoe: fix protocol field length variation
Detect when protocol field is not a 16 bit field.
Added tests to prove logic

Ticket: 4810
5 years ago
Steven Ottenhoff 260bc03603 test/pppoe: refactor to use FAIL/PASS macros 5 years ago
Modupe Falodun 3dbf74ff10 detect-file-data: remove SMTP unittests
These tests are reimplemented as Suricata-verify tests

Task: 4938
5 years ago
Eric Leblond 264eddb81f output/alert: don't call basic logging twice
Issue: 4106
5 years ago
Victor Julien a7e77dd22d stream: suppress noisy debug message 5 years ago
Victor Julien 78f5e082f5 stream: fix stream pruning being too aggressive
Pruning of StreamBufferBlocks could remove blocks that fell entirely
after the target offset due to a logic error. This could lead to data
being evicted that was still meant to be processed in theapp-layer
parsers.

Bug: #4953.
5 years ago
Victor Julien 544ff0fb52 stream: debug code for showing segment list state 5 years ago
Jeff Lucovsky f30d8ece80 detect: Avoid recomputing ntohl() in addr match
This commit makes a small optimization when comparing IPv4 and IPv6
addresses by making the host order value invariant and calculating the
value once, before entering the loop.
5 years ago
Philippe Antoine 86ea7f2474 file: define own variable instead of PATH_MAX
to be used for maximum size of file names,
and not depend on the OS
5 years ago
Philippe Antoine c56b1c99d5 ssl: fix int warnings
especially increasing padding_len size
5 years ago
Philippe Antoine 078e1cdacc smtp: fix int warnings
and explicitly truncating filename's length
5 years ago
Philippe Antoine 23f242dfc2 app: fix int warnings in generic app files 5 years ago
Philippe Antoine 334b1382e0 http: : fix int warnings
Explicitly truncate file names to UINT16_MAX

Before, they got implicitly truncated, meaning a UINT16_MAX + 1
file name, went to 0 file name (because of modulo 65536)
5 years ago
Philippe Antoine defce022b4 ftp: fix int warnings
Explicitly truncate a file name if it is longer
than UINT16_MAX
5 years ago
Jeff Lucovsky 22e89ec4a3 log: Coverity REVERSE_INULL warnings
This commit addresses Coverity reported "REVERSE_INULL" warnings.

Issue: 4699
5 years ago
Philippe Antoine e1c0725e05 doc: fix typo lenght/length 5 years ago
Jason Ish 6392216f6b base64: use the Rust base64 encode implementation
Replace our internal base64 implementation with a ffi wrapper
around the Rust implementation provided by an external crate.
5 years ago
Jason Ish 6d3dcf27a6 eve: use JsonBuilder for encoding base64
Replaces all usages of Base64Encode just before writing to a
JsonBuilder with jb_set_base64 and jb_append_base64.
5 years ago
Victor Julien c073d5cfbf app-layer: use StreamSlice as input to parsers
Remove input, input_len and flags in favor of stream slice.
5 years ago
Victor Julien 6466296b32 app-layer: add StreamSlice to pass data to parsers
Since object to contain relevant pointer, length, offset, flags to make
it easy to pass these to the parsers.
5 years ago
Jeff Lucovsky 7f0f463b64 logging/diag: Enable stacktrace diagnostic if config'd
This commit adds a signal handler for SIGSEGV when configured. The
signal handler emits a one line stack trace using SCLogError. The intent
is to provide diagnostic information in deployments where core files are
not possible.

The diagnostic message is from the offending thread and includes the
stack trace; each frame includes the symbol + offset.
5 years ago
Jeff Lucovsky 501c870a2c error: Add error code for sig-related diagnostics
This commit adds an error code for the diagnostic code used for
diagnostic messages following unexpected termination due to signals..
5 years ago
Philippe Antoine bf9bbdd612 detect: fix app-layer-protocol keyword for HTTP
Ticket: 4920

Completes commit c8dbe24fb6
which introduced AppProtoEquals to have a generic
check for http in signature can mean http1 or http2 in
traffic.

This commit missed this case, as I only looked for
git grep "alproto ==" and here we deal with
alproto_tc and alproto_ts, but not alproto by itself.
5 years ago
Jason Ish fcbdc30426 dns: create transaction even if z-bit was set
It appears that DNS servers will still process a DNS request even if the
z-bit is set, our parser will fail the transaction. So create the
transaction, but still set the event.

Ticket #4924
5 years ago
Lukas Sismis de53e07559 dpdk/ice: setup RSS for Intel ICE PMD
Set RSS hash function according to Intel ICE PMD available hash functions

Set hash functions according to the support by the ICE PMD, so that no warning
regarding RSS setting is issued.
5 years ago
Lukas Sismis 3f7a50eeb7 dpdk/ixgbe: setup RSS for Intel IXGBE PMD
Set RSS hash function according to Intel IXGBE PMD available hash functions.

During configuration, a warning appeared stating that RSS hash function
has been changed from one value to the other. This has meant that
the supported hash functions did not cover all required hash functions
by the configuration. This commit solves the warning.
5 years ago
Lukas Sismis 639aa04c5f dpdk/i40e: support RSS on Intel i40e PMD driver
Due to peculiar behavior of i40e PMD driver, the RSS is required to be set
via rte_flow rules or a hash filter as compared to other NICs where RSS is
configured through port configuration structure.
RTE_FLOW rules are created on 5-tuples (as opposed to 3-tuple configured
on the other NICs). Fragmented traffic have been tested with this setup
and it has been proven that fragmented packets of the same flow are
received on the same queue. At the same time, setting 3-tuple on rte_flow
rules have not yield in the expected results.

Notes from the experiments:

- Configuration of 5-tuple (as is in the commit):
    fragmented and nonfragmented packets are received by the same workers
    even when I applied seed to alter them via tcpreplay-edit (option --seed)

- Setting only ETH_RSS_FRAG_IPV4 and ETH_RSS_IPV4 (i.e. setting 3-tuple):
    when setting ETH_RSS_IPV4, the PMD driver says that pctype is not
    supported (generally this means that the "type" of traffic is not
    a valid configuration for the i40e)

- Setting only ETH_RSS_FRAG_IPV4 and ETH_RSS_NONFRAG_IPV4_OTHER:
    this doesn't work well, packets of the same flow are received on
    the different workers (my explanation is that the fragmented packets are
    matched with ETH_RSS_FRAG_IPV4 but the other UDP packets are not matched
    with ETH_RSS_NONFRAG_IPV4_OTHER rte_flow rule (they would be matched with
    ETH_RSS_NONFRAG_IPV4_UDP).
5 years ago
Victor Julien f98df5c3fd dpdk: add RSS flags that are set in the NIC 5 years ago
Victor Julien 56dfec48b9 dpdk: add specific error counters 5 years ago
Lukas Sismis a7faed1245 dpdk: initial support with workers runmode
Register a new runmode - DPDK. This enables a new flag on Suricata start
(--dpdk).

With the flag given, DPDK runmode is enabled.

Runmode loads the configuration and then initializes EAL.

If successful, it configures the physical NICs according to the configuration
file. After that, worker threads are initialized and then are in continuous
receive loop.
5 years ago
Jason Ish 92eb14c5ad datasets: initialize after dropping privileges
Move initialization of datasets to a point after privileges
have been dropped.

Ticket 4239
5 years ago
Philippe Antoine dd32238667 ftp: do not set alproto if one was already found
Ticket: 4857

If a pattern such as GET is seen ine the beginning of the
file transferred over ftp-data, this flow will get recognized
as HTTP, and a HTTP state will be created during parsing.

Thus, we cannot override directly alproto's values

This solves the segfault, but not the logical bug that the flow
should be classified as FTP-DATA instead of HTTP
5 years ago
Victor Julien a02f263e56 app-layer/htp: cleanup test 5 years ago
Victor Julien 0a1c3267e6 htp: rename callbacks to make purpose clearer 5 years ago
Victor Julien 258415b23f stream: unify ack'd right edge handling
Use util function in all code needing the ack'd data.
5 years ago
Victor Julien ac11502629 detect/engine: store buffer name in local array
Instead of storing a name and description as a pointer in DetectBufferType
store them in fixed size arrays. This is in preparation of runtime registration
of buffer types, where a constant name/desc is not available.
5 years ago
Victor Julien 6ee818cb3e stream/reassembly: ignore min_inspect_depth on TCP state CLOSED 5 years ago
Victor Julien 55202f826a detect/http: don't set min-inspect-depth higher than setting 5 years ago
Philippe Antoine 27dd0c6b3d eve/ftp-data: log alert metadata in ftp-data object
Ticket: 4860

instead of directly in root
5 years ago
Philippe Antoine 87d9c44ec5 rust: export constants via cbindgen
so that constants are not defined twice in Rust anc C
So that we are sure they have the same value
5 years ago
Philippe Antoine 8feb9c35ae mime: move FindMimeHeaderTokenRestrict to rust
Also fixes the case where the token name is present
in a value
5 years ago
Modupe Falodun 76131c8cff detect-ipopts: convert unittests to FAIL/PASS APIs
Bug: 4047
5 years ago
Victor Julien ecce116117 detect/fast_pattern: allow for rule time registration
In preparation of more dynamic logic in rule loading also doing
some registration, allow for buffers to be registered as fast_patterns
during rule parsing.

Leaves the register time registrations mostly as-is, but copies the
resulting list into the DetectEngineCtx and works with that onwards.
This list can then be extended.
5 years ago
Victor Julien db27244379 detect: add buffer helper functions 5 years ago
Victor Julien 707b75ccda detect: split register time and detect load time buffer funcs 5 years ago
Victor Julien 5bcaae0a01 detect: use hashes for all buffer to id
Instead of a map that is constantly realloc'd, use 2 hash tables for
DetectBufferType entries: one by name (+transforms), the other by
id. Use these everywhere.
5 years ago
Victor Julien 51dcf3d76a detect: increase SigMatch type from u8 to u16 5 years ago
Victor Julien bb3d49d5bf detect: use bool for uint16_t used as bool 5 years ago
Victor Julien 6d7c1519ed common: fix missing ; in header 5 years ago
Philippe Antoine c9d222a483 detect: allows <> syntax for uint ranges 5 years ago
Philippe Antoine 5af4ef4532 detect: use prefilter values for modes 5 years ago
Philippe Antoine 3f15b2492c detect: errors for rule with impossible conditions
Such as >255 for an uint8 field
5 years ago
Philippe Antoine f4449d3fb3 fuzz: restrict flags passed to AppLayerProtoDetectGetProto
Completes commit 05f9b3ffc6
5 years ago
Jason Ish 7732efbec2 app-layer: include decoder events in app-layer tx data
As most parsers use an events structure we can include it in the
tx_data structure to reduce some boilerplate/housekeeping code
in app-layer parsers.
5 years ago
Philippe Antoine 86f5d33f75 enip: fix int warnings
There seems to fix a real bug when an ENIP connection
has more than 65k transactions
5 years ago
Philippe Antoine 86b5c81ea2 dnp3: fix int warnings
There is a hack to know the type of an integer
and do an explicit cast in the python script
generating the C file

Also extends some bounds check against negative values
5 years ago
Philippe Antoine 53fc70a9a7 protodetect: fix int warnings
There is actually a real evasion with AppLayerProtoDetectPMGetProto
using u16 instead of u32 for buflen
5 years ago
Philippe Antoine 46981ccd98 warning: explicit casts to double 5 years ago
Philippe Antoine b88f015bfb source/pcap: remove unused code 5 years ago
Philippe Antoine 05f9b3ffc6 fuzz: restrict flags passed to AppLayerProtoDetectGetProto
So that rust does not panic with an unhandled value
5 years ago
Victor Julien 39bf623fdd af-packet: add send error counter 5 years ago
Victor Julien 373278438d packetpool: ReleasePacket callback check on getter
Any packet coming from the pool should have `PacketPoolReturnPacket`
as its callback. Check that this is the case.
5 years ago
Victor Julien 8a5b945c7b af-packet: only ref mpeer if needed in tpacket v2
We only use it in autofp mode, for reference counting purposes.

Removes 2 atomic operations per packet in the more common workers
runmode.
5 years ago
Victor Julien d272075da0 af-packet: minor output updates 5 years ago
Victor Julien e9c6ad19b3 af-packet: optimize packet setup
Don't set fields we don't use in V3.
5 years ago
Victor Julien cad0ff9ebb af-packet: add counters on how poll() works
Use `capture.afpacket.*` counter name space.
5 years ago
Victor Julien c7ad3f8d30 af-packet: don't check ifstate per send call in IPS
Instead just accept that the socket state leads to `sendto` errors.
So print at most one error per socket.
5 years ago
Victor Julien dab036727f af-packet: simplify AFPWritePacket
Since return code was ignored by all callers, we can just turn it into a
void function and slightly simplify the logic.
5 years ago
Victor Julien 3f79f452ad af-packet: use BUG_ON for 'impossible' condition 5 years ago
Victor Julien 2fab3ff0e8 af-packet: refactor VLAN hdr handling
Update the packet payload after decode, instead of during IPS send.

This means the updates happen in the capture thread, and the VLAN header
is available to logging as well.

Ticket: #4805.
5 years ago
Victor Julien b9189946f9 af-packet: remove tpacket-v1 support
Ticket: #4796.

V2 (for IDS and IPS) and V3 (for IDS) are widely supported. V2 was introduced
in 2008, so we can safely assume that all systems can run V2+.
5 years ago
Jason Ish 1f6a15cdf3 app-layer/template: don't always enable if unittests built
314ec77f88 had the unintended side affect
of enabling the template parser and detection buffer if unittests were
enabled.

Fix this by using the new `Default` method for registering parsers.
However, the buffer still needs an explicit configuration check.

Also convert Notice debug messages to Debug to reduce output when in
unittest mode.  If we feel stronly this should still be Notice in the
template, that is a conversion we can make in the generation script when
generating a new parser.
5 years ago
Jeff Lucovsky 6a470a84e7 tftp: Change references to echo
This commit changes the references to the "echo" protocol to tftp. The
references to echo are part of the template parser code.
5 years ago
Jeff Lucovsky ca7d097225 netmap: V14 API changes
This commit modifies the Netmap packet handling to use API version 14.

@bmeeks8 contributed many changes instrumental to this effort.
5 years ago
Jeff Lucovsky 3496e543af util: Add sys/ioctl.h to common include
This commit adds another system include file based on autoconf to the
common Suricata include file for convenience.
5 years ago
Jeff Lucovsky 84ee01dbe9 util/log: Include device name with thread count 5 years ago
Philippe Antoine c023116857 range: prevents memory leak of file from HTTP2
If a HTTP2 transaction gets freed before the end of the range
request, we need to have the files container which is in
the state, to transfer owernship of this file to the files
container.

Ticket: 4811
5 years ago
Philippe Antoine 15649424a7 conf: avoid quadratic complexity
Ticket: 4812

When adding many sequence nodes
5 years ago
Modupe Falodun c33cfed704 detect-fragoffset: convert unittests to FAIL/PASS APIs
Bug: #4040
5 years ago
Jason Ish 52b9c12f41 smtp: log transaction even if no email present
The SMTP transaction logger was not writing the log if the email
portion of the logger failed, such as in the case of STARTTLS
where this is no email decoded.

Ticket #4817
5 years ago
Sam Muhammed fcf399b02c detect/proto: convert unittests to FAIL/PASS APIs
Task #4027
5 years ago
Modupe Falodun 2a800d572c detect-icode: convert unittests to FAIL/PASS APIs
Bug: #4045
5 years ago
Modupe Falodun 97801c795b detect-id: convert unittests to FAIL/PASS APIs
Bug: #4046
5 years ago
Sam Muhammed 4076c8b762 detect/siggroup: convert unittests to FAIL/PASS APIs
Task #4028
5 years ago
Benjamin Wilkins e21a50fee6 lua: Fix SCRule functions for match scripts
Save Signature structure to lua register so SCRule functions can work
in match scripts, where no PacketAlert is present

Resolves Feature #2450
5 years ago
Jason Ish 9b71f56728 modbus: free eve thread context on deinit
Was triggering ASAN leak detection.
5 years ago
Jason Ish 55ff912ee7 app-layer: remove IsTxEventAware: never used
The function AppLayerParserProtocolIsTxEventAware is not used so
remove.
5 years ago
Jason Ish 1ad71b96da app-layer: remove tx detect state setter and getter
Instead access detect state through AppLayerParserGetTxData.
5 years ago
Jason Ish 9c67c634c1 app-layer: include DetectEngineState in AppLayerTxData
Every transaction has an existing mandatory field, tx_data. As
DetectEngineState is also mandatory, include it in tx_data.

This allows us to remove the boilerplate every app-layer has
for managing detect engine state.
5 years ago
Eric Leblond 6d5f59696d profiling: fix profiling with sample rate
Rules profiling was returning invalid results when used with sample
rate. The problem was that the sample condition was run twice in the
packet flow. As a result, the second pass was not initializing the
variable storing the initial CPU ticks and the resulting performance
counters were reporting invalid values.

Bug: #4836.
5 years ago
Philippe Antoine 16f4e5f31c detect: file_data keyword works on nfs protocol
Ticket: #4839
5 years ago
Philippe Antoine 6cb6225b28 tcp: rejects FIN+SYN packets as invalid
Ticket: #4569

If a FIN+SYN packet is sent, the destination may keep the
connection alive instead of starting to close it.
In this case, a later SYN packet will be ignored by the
destination.

Previously, Suricata considered this a session reuse, and thus
used the sequence number of the last SYN packet, instead of
using the one of the live connection, leading to evasion.

This commit errors on FIN+SYN so that they do not get
processed as regular FIN packets.
5 years ago
Victor Julien 50e2b973ee stream/tcp: handle RST with MD5 or AO header
Special handling for RST packets if they have an TCP MD5 or AO header option.
The options hash can't be validated. The end host might be able to validate
it, as it can have a key/password that was communicated out of band.

The sender could use this to move the TCP state to 'CLOSED', leading to
a desync of the TCP session.

This patch builds on top of
843d0b7a10 ("stream: support RST getting lost/ignored")

It flags the receiver as having received an RST and moves the TCP state
into the CLOSED state. It then reverts this if the sender continues to
send traffic. In this case it sets the following event:

    stream-event:suspected_rst_inject;

Bug: #4710.
5 years ago
Philippe Antoine be617a3c1b protodetect: opposing side cannot change protocol
Ticket: #4562

As the data which triggered the opposing side
was the same protocol and not another one,
that means the protocol change failed.

Prevents a memory leak in later call of AppLayerParserParse
which would allocate a new state and leak the old one
5 years ago