]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
3 years agosmtp: remove defunct check for line with single LF 7493/head
Victor Julien [Sun, 5 Jun 2022 16:23:55 +0000 (18:23 +0200)] 
smtp: remove defunct check for line with single LF

Don't fix it as DATA processing needs all the bytes.

(cherry picked from commit 96bb67f474242936c029e57be3d4da1365150943)

3 years agosmtp: turn assertions in to debug asserts
Victor Julien [Sat, 4 Jun 2022 06:49:41 +0000 (08:49 +0200)] 
smtp: turn assertions in to debug asserts

(cherry picked from commit 77fae275efb54221d9cf3badd25df38eb1ea0b86)

3 years agosmtp: simplify preprocess loop
Victor Julien [Sat, 4 Jun 2022 06:49:25 +0000 (08:49 +0200)] 
smtp: simplify preprocess loop

(cherry picked from commit 3a631085bb853d6d42c5218235cd9a581a3e106c)

3 years agomime/base64: decode cleanups and simplification
Victor Julien [Fri, 3 Jun 2022 15:10:59 +0000 (17:10 +0200)] 
mime/base64: decode cleanups and simplification

Addresses edge case: > 4 bytes at the end of the input with 2 or more
spaces.

Changes length type for remainder processing to allow for much longer
lines, which can happen in practice.

Adds a series of debug validation checks with real error handling
as well, to assist the fuzzer to find more edge cases.

(cherry picked from commit 30e47b21714b5d9039f22df7b406b201bdd15b7e)

3 years agobase64: no special case for nul char
Victor Julien [Sat, 4 Jun 2022 05:09:27 +0000 (07:09 +0200)] 
base64: no special case for nul char

Let it be handled like other invalid input.

(cherry picked from commit 92cd95b4165eef540bc974d50f54a47a6b74503d)

3 years agobase64: make decoder handle decoded data space constraints
Shivani Bhardwaj [Thu, 2 Jun 2022 15:20:07 +0000 (20:50 +0530)] 
base64: make decoder handle decoded data space constraints

So far, it was the job of caller to send the bae64 decoder a perfect
block of data and take care of the destination buffer (decoded data)
size. Now, make it the decoder's job to take care of any space
constraints that the destination buffer may have and return accordingly.

Also, handle space characters in base64 encoded data as per RFC 2045.

Update MIME parser accordingly to handle the base64 data.

Ticket: 5315
(cherry picked from commit 5b2761977871a94d559a9ba3b026593bb1ffd68b)

3 years agobase64: add Base64Ecode enum
Shivani Bhardwaj [Fri, 3 Jun 2022 10:26:36 +0000 (15:56 +0530)] 
base64: add Base64Ecode enum

(cherry picked from commit cb01cc6929b6bfdf02f7b3049d7bd110a1465fa4)

3 years agobase64: add Base64Mode enum
Shivani Bhardwaj [Thu, 12 May 2022 18:00:00 +0000 (23:30 +0530)] 
base64: add Base64Mode enum

(cherry picked from commit 9131d1d85715c817a22d2a987f4a01cf42e07757)

3 years agosmtp: treat CR as a line terminator
Shivani Bhardwaj [Fri, 29 Apr 2022 08:51:40 +0000 (14:21 +0530)] 
smtp: treat CR as a line terminator

The ideal line terminator for an SMTP line is <CRLF>. But, given that
bare LF is still allowed by many systems despite the prohibition by
standards, we have to consider that. In order to simplify things, we
consider bare CR as line terminators as well while updating the
delimiter parameter correctly if they were to be followed by a LF
immediately or as a part of next fragment.

This takes care of some edge cases that made base64 decoder error out
because unexpected data was sent to it at times.

Ticket: 5316
(cherry picked from commit 1e3282f36343c59a18d8e342d5e78aa3018b8edd)

3 years agorunmodes: fix more warnings 7462/head
Victor Julien [Thu, 28 Apr 2022 15:49:07 +0000 (17:49 +0200)] 
runmodes: fix more warnings

(cherry picked from commit a535cc5a2552d3c46792c5e5b4b3b3b6e74d4b41)

3 years agodetect/alert: directly increment alerts.discarded
Juliana Fajardini [Mon, 9 May 2022 14:24:18 +0000 (11:24 -0300)] 
detect/alert: directly increment alerts.discarded

In the unlikely case of AlertQueueExpand failure, we were incrementing
the discarded alerts stats in AlertQueueAppend via the Packet member in the
DetectEngineThreadCtx, which may not be initialized yet.

Bug #5353

(cherry picked from commit 28ac75b50594f464949c036bbb34ceff759bdc9c)

3 years agorust: Unused doc comment warning fixup 7437/head
Jeff Lucovsky [Sun, 29 May 2022 19:21:31 +0000 (15:21 -0400)] 
rust: Unused doc comment warning fixup

Since rustdoc does not generate documentation for extern blocks, Fedora
35 builds flagged 2 occurrences where doc comments existed on extern C
blocks.

3 years agostream/unittests: fix failures after last_ack fix
Victor Julien [Fri, 22 Apr 2022 17:33:13 +0000 (19:33 +0200)] 
stream/unittests: fix failures after last_ack fix

Work around many tests not setting up stream completely or correctly.

(cherry picked from commit 3d6e733aa7297f64fe87cc3b59fbbd9a527513fa)

3 years agostream: improve last_ack validation check
Victor Julien [Fri, 22 Apr 2022 16:27:15 +0000 (18:27 +0200)] 
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.
(cherry picked from commit 1f43e1477f3c5781381e75f4bed918cbc6c18dfd)

3 years agouserguide: dynamically determine copyright date
Juliana Fajardini [Wed, 9 Feb 2022 19:46:24 +0000 (19:46 +0000)] 
userguide: dynamically determine copyright date

This uses the date of doc generation to determine the copyright date
for the trailing date. Based on Jeff Lucovsky solution.

(cherry picked from commit e0c8dba7ac6eaa757daf80245688f9f2b2496eff)

3 years agodetect: optimize mpm-engine setup
Victor Julien [Fri, 1 Apr 2022 10:22:51 +0000 (12:22 +0200)] 
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.

(cherry picked from commit 9e6370ae2eb77ee5e43a2b152adfca0484431bd4)

3 years agossh: install app-layer events rules
Philippe Antoine [Fri, 25 Mar 2022 14:03:12 +0000 (15:03 +0100)] 
ssh: install app-layer events rules

(cherry picked from commit acbe6a33a21ee0b1d8712a3a3db86a653ecdb242)

3 years agosmb: ntlmssp domain_blob_offset underflow check
Philippe Antoine [Mon, 4 Apr 2022 20:51:01 +0000 (22:51 +0200)] 
smb: ntlmssp domain_blob_offset underflow check

Ticket: 5246
(cherry picked from commit e72036f12f577fb37b985147c2c847d147e49db2)

3 years agosmb: check on param parsing
Philippe Antoine [Mon, 4 Apr 2022 20:45:56 +0000 (22:45 +0200)] 
smb: check on param parsing

Ticket: 5246

so as not to overflow u16

(cherry picked from commit 817a5001a50a90800547e66fef067c0443eb9f72)

3 years agorust: RustParser same fields as AppLayerParser
Philippe Antoine [Mon, 2 May 2022 20:50:04 +0000 (22:50 +0200)] 
rust: RustParser same fields as AppLayerParser

So that there is no problem when crossing FFI

(cherry picked from commit c78722a671e819261dea9ce148966718cfca7c64)

3 years agoutil: add unit tests for CIDRFromMask()
Sascha Steinbiss [Wed, 27 Apr 2022 21:12:26 +0000 (23:12 +0200)] 
util: add unit tests for CIDRFromMask()

(cherry picked from commit 5ec6f3ba51c449f7588afac0820ad57b1cea5de9)

3 years agodetect: make int CIDRFromMask() work on big endian platforms
Sascha Steinbiss [Wed, 27 Apr 2022 18:09:50 +0000 (20:09 +0200)] 
detect: make int CIDRFromMask() work on big endian platforms

(cherry picked from commit 394356f73c026879672843fbb20b4de68a09d0ac)

3 years agodetect: initialization optimization
Victor Julien [Thu, 31 Mar 2022 16:00:57 +0000 (18:00 +0200)] 
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.

(cherry picked from commit 3352c0bee419818f138be5837729f63a9b31bb03)

3 years agodcerpc: use wrappingadd for padding parsing
Philippe Antoine [Sat, 2 Apr 2022 19:41:56 +0000 (21:41 +0200)] 
dcerpc: use wrappingadd for padding parsing

As we compute a modulo, we can safely wrap around even if there
is an overflow

Ticket: #5301
(cherry picked from commit d2f00ac824068475414a6ee402c9ecf4b0de1308)

3 years agosuricata.yaml: include version that generated this file
Jason Ish [Wed, 4 May 2022 21:19:48 +0000 (15:19 -0600)] 
suricata.yaml: include version that generated this file

Add a line to the configuration that says which version generated the
configuration file.  For example:

    # This configuration generated by:
    #     Suricata 7.0.0-dev

Issue: #4784
(cherry picked from commit b5d1a800027c25f8edcc82a9770038d3948d6293)

3 years agomemcmp: no-simd no case loop can scan forward
Victor Julien [Fri, 6 May 2022 21:52:00 +0000 (23:52 +0200)] 
memcmp: no-simd no case loop can scan forward

(cherry picked from commit f0479987ff6f5321613395a8bf1a5eb38530b977)

3 years agomemcmp: use SCMEMCMP_BYTES everywhere; general cleanups
Victor Julien [Fri, 6 May 2022 16:20:40 +0000 (18:20 +0200)] 
memcmp: use SCMEMCMP_BYTES everywhere; general cleanups

(cherry picked from commit 0fc7ba45aa6c494bdedd5276e7ec7e4e9012facb)

3 years agomemcmp: remove unreachable code from memcmp simd
Victor Julien [Thu, 5 May 2022 05:16:53 +0000 (07:16 +0200)] 
memcmp: remove unreachable code from memcmp simd

cppcheck:

src/util-memcmp.h:281:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:280:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:269:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:281:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:344:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:343:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:318:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:344:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:171:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:170:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:159:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:171:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^
src/util-memcmp.h:233:18: warning: Identical condition 'len-offset<16', second condition is always false [identicalConditionAfterEarlyExit]
        if (diff < 16) {
                 ^
src/util-memcmp.h:232:24: note: 'diff' is assigned value 'len-offset' here.
        int diff = len - offset;
                       ^
src/util-memcmp.h:208:33: note: If condition 'len-offset<16' is true, the function will return/exit
        if (likely(len - offset < 16)) {
                                ^
src/util-memcmp.h:233:18: note: Testing identical condition 'len-offset<16'
        if (diff < 16) {
                 ^

(cherry picked from commit ca97ed44361fe84cae72fad1807825f149f983eb)

3 years agomemcmp: work around GCC 12+ 'blend' issues
Victor Julien [Fri, 6 May 2022 15:46:40 +0000 (17:46 +0200)] 
memcmp: work around GCC 12+ 'blend' issues

Since GCC 12 the memcmp code using `_mm_blendv_epi8` failed to work.
Inspection of the disassembled objects suggests that it simply omits
the instruction on systems that are not AVX512 capable. On AVX512
it does replace it with VPCMPB logic that appears to work.

Luckily our use of blend is actually uncessary. A simple AND is sufficient.

Bug: #5312.
(cherry picked from commit 87c5d6943709de225d946f5eab8f1d24cdefa491)

3 years agostacktrace-on-signal: Use kill(getpid(), sig_num)
Arne Welzel [Wed, 4 May 2022 18:06:36 +0000 (20:06 +0200)] 
stacktrace-on-signal: Use kill(getpid(), sig_num)

kill(0, ...) re-raises the signal to every processes in the process
group which may impact unrelated processes.

Concretely, in our CI pipeline, a segfaulting Suricata process killed
the test driver.

(cherry picked from commit b6407c4253b2037cec7390364b4f0f69ccea6b0e)

3 years agogithub-ci: remove fedora 34: eol in 2 weeks 7426/head
Jason Ish [Tue, 24 May 2022 17:40:05 +0000 (11:40 -0600)] 
github-ci: remove fedora 34: eol in 2 weeks

Bump F34 to build to F35, and F35 to F36.

3 years agoutil/ebpf: fix deprecation warning 7401/head
Eric Leblond [Thu, 11 Feb 2021 22:32:38 +0000 (23:32 +0100)] 
util/ebpf: fix deprecation warning

The function bpf_program__title has been deprecated in favor of
bpf_program__section_name.

(cherry picked from commit d477d3a8789d55828861c515e609d024e95a0dc8)

3 years agoutil/ebpf: fix compilation
Eric Leblond [Wed, 11 May 2022 07:01:23 +0000 (09:01 +0200)] 
util/ebpf: fix compilation

Bug: #5360

3 years agolog-pcap: remove redundant check 7369/head
Victor Julien [Wed, 27 Apr 2022 09:36:21 +0000 (11:36 +0200)] 
log-pcap: remove redundant check

Check is always true but confuses cppcheck:

src/log-pcap.c:1224:32: warning: Either the condition 'filename' is redundant or there is possible null pointer dereference: filename. [nullPointerRedundantCheck]
    if ((pl->prefix = SCStrdup(filename)) == NULL) {
                               ^
src/log-pcap.c:1421:9: note: Assuming that condition 'filename' is not redundant
    if (filename) {
        ^
src/log-pcap.c:1224:32: note: Null pointer dereference
    if ((pl->prefix = SCStrdup(filename)) == NULL) {
                               ^

Bug: #5291.
(cherry picked from commit 3dfbf0bf1124aab7c7060f46b364877ab25455ee)

3 years agolog/pcap: exit on invalid filename
Eric Leblond [Wed, 10 Feb 2021 15:23:25 +0000 (16:23 +0100)] 
log/pcap: exit on invalid filename

If the filename has to % sign and if pcap logging is using multi
mode, then the pcap capture will fail. So let's exit if ever this
is the case.

(cherry picked from commit 921d44b262f30555ea747653b050dfde4188c042)

3 years agodetect/pcre: assist code analyzer around pointer logic
Victor Julien [Tue, 26 Apr 2022 19:47:37 +0000 (21:47 +0200)] 
detect/pcre: assist code analyzer around pointer logic

cppcheck:

src/detect-pcre.c:381:27: warning: Either the condition 'pcap' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]
            cut_capture = MIN((pcap - regexstr), (fcap - regexstr));
                          ^
src/detect-pcre.c:378:18: note: Assuming that condition 'pcap' is not redundant
        else if (pcap && !fcap)
                 ^
src/detect-pcre.c:381:27: note: Null pointer subtraction
            cut_capture = MIN((pcap - regexstr), (fcap - regexstr));
                          ^

Bug: #5291.
(cherry picked from commit 69b8b48b9422279943c083a24e5baf64e1c4aa94)

3 years agologopenfile: fix minor format string warning
Victor Julien [Wed, 27 Apr 2022 09:39:27 +0000 (11:39 +0200)] 
logopenfile: fix minor format string warning

cppcheck:

src/util-logopenfile.c:743:13: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            snprintf(threaded_name, len, "%s.%d.%s", tname, unique_id, ext);
            ^
src/util-logopenfile.c:752:9: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
        snprintf(threaded_name, len, "%s.%d", original_name, unique_id);
        ^

Bug: #5291.
(cherry picked from commit 07d0ae04d34cdf029729b474fb22598f154fcea6)

3 years agoja3: fix minor format string warning
Victor Julien [Wed, 27 Apr 2022 09:38:37 +0000 (11:38 +0200)] 
ja3: fix minor format string warning

cppcheck:

src/util-ja3.c:197:28: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
        (*buffer)->used += snprintf((*buffer)->data, (*buffer)->size, "%d",
                           ^
src/util-ja3.c:201:28: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
        (*buffer)->used += snprintf((*buffer)->data + (*buffer)->used,
                           ^

Bug: #5291.
(cherry picked from commit 1e13f7278585555623ff0be2d3a98476617b1219)

3 years agoaf-packet/v2: use proper type for ring
Victor Julien [Wed, 27 Apr 2022 09:32:22 +0000 (11:32 +0200)] 
af-packet/v2: use proper type for ring

cppcheck:

src/source-af-packet.c:1762:19: warning: Size of pointer 'v2' used instead of size of its data. This is likely to lead to a buffer overflow. You probably intend to write 'sizeof(*v2)'. [pointerSize]
        ptv->ring.v2 = SCMalloc(ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                  ^
src/source-af-packet.c:1767:26: warning: Size of pointer 'v2' used instead of size of its data. This is likely to lead to a buffer overflow. You probably intend to write 'sizeof(*v2)'. [pointerSize]
        memset(ptv->ring.v2, 0, ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                         ^

scan-build:

CC       source-af-packet.o
source-af-packet.c:1762:24: warning: Result of 'malloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'union thdr *' [unix.MallocSizeof]
        ptv->ring.v2 = SCMalloc(ptv->req.v2.tp_frame_nr * sizeof (union thdr *));
                       ^~~~~~~~                           ~~~~~~~~~~~~~~~~~~~~~
./util-mem.h:35:18: note: expanded from macro 'SCMalloc'
                 ^~~~~~
1 warning generated.

Bug: #5291.
(cherry picked from commit fedced209dc25443ec5eee22bfab6c99f9f652ab)

3 years agodevice: avoid uninit var warning
Victor Julien [Tue, 26 Apr 2022 19:35:29 +0000 (21:35 +0200)] 
device: avoid uninit var warning

cppcheck:

src/util-device.c:455:17: error: Uninitialized variables: *ndev.dev, *ndev.tenant_id_set, *ndev.id, *ndev.next, *ndev.tenant_id, *ndev.offload_orig [uninitvar]
        *ldev = *ndev;
                ^
src/util-device.c:618:36: note: Calling function 'LiveDeviceForEach', 2nd argument '&ndev' value is <Uninit>
    while(LiveDeviceForEach(&ldev, &ndev)) {
                                   ^
src/util-device.c:455:17: note: Uninitialized variables: *ndev.dev, *ndev.tenant_id_set, *ndev.id, *ndev.next, *ndev.tenant_id, *ndev.offload_orig
        *ldev = *ndev;
                ^

Bug: #5291.
(cherry picked from commit 3bc50df9c3397b9ab06376657c5e8c3467fbc7c5)

3 years agodetect: fix bad BUG_ON pattern
Victor Julien [Tue, 26 Apr 2022 19:33:52 +0000 (21:33 +0200)] 
detect: fix bad BUG_ON pattern

cppcheck:

src/detect-engine-uint.c:73:13: warning: Conversion of string literal "unknown mode" to bool always evaluates to true. [incorrectStringBooleanError]
            BUG_ON("unknown mode");
            ^
src/detect-engine-uint.c:328:13: warning: Conversion of string literal "unknown mode" to bool always evaluates to true. [incorrectStringBooleanError]
            BUG_ON("unknown mode");
            ^
src/detect-pcre.c:291:25: warning: Conversion of string literal "Impossible captype" to bool always evaluates to true. [incorrectStringBooleanError]
                        BUG_ON("Impossible captype");
                        ^

Bug: #5291.
(cherry picked from commit 7e2ed11a11cae89bc07e9a25425192581687993d)

3 years agotime: fix warning in timestring creation
Victor Julien [Tue, 26 Apr 2022 19:03:42 +0000 (21:03 +0200)] 
time: fix warning in timestring creation

cppcheck:

src/util-time.c:255:18: warning: Either the condition 'str!=NULL' is redundant or there is possible null pointer dereference: str. [nullPointerRedundantCheck]
        snprintf(str, size, "ts-error");
                 ^
src/util-time.c:252:48: note: Assuming that condition 'str!=NULL' is not redundant
    if (likely(t != NULL && fmt != NULL && str != NULL)) {
                                               ^
src/util-time.c:255:18: note: Null pointer dereference
        snprintf(str, size, "ts-error");
                 ^

Only `t` could possibly be NULL if `localtime_r` fails elsewhere.

Bug: #5291.
(cherry picked from commit 2f48e432cd4465bbb1f42fe7778fee44a5d0aa47)

3 years agodetect/multi-tentancy: minor format string fixes
Victor Julien [Tue, 26 Apr 2022 18:36:36 +0000 (20:36 +0200)] 
detect/multi-tentancy: minor format string fixes

cppcheck:

src/detect-engine.c:3643:5: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
    snprintf(prefix, sizeof(prefix), "multi-detect.%d", tenant_id);
    ^
src/detect-engine.c:3707:5: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
    snprintf(prefix, sizeof(prefix), "multi-detect.%d.reload.%d", tenant_id, reload_cnt);
    ^
src/detect-engine.c:4086:17: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
                snprintf(prefix, sizeof(prefix), "multi-detect.%d", tenant_id);
                ^

Bug: #5291.
(cherry picked from commit 4fcb8740e7b98eee1b5e65bd66045c9440cef8b6)

3 years agoreference: remove useless var reset
Victor Julien [Tue, 26 Apr 2022 18:18:28 +0000 (20:18 +0200)] 
reference: remove useless var reset

cppcheck:

src/util-reference-config.c:179:9: warning: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]
        fd = NULL;
        ^

Bug: #5291.
(cherry picked from commit 5a0bbb5289cd0fbf4ef50294127cb1018baf82a2)

3 years agorunmodes: minor format string fixes
Victor Julien [Tue, 26 Apr 2022 18:17:27 +0000 (20:17 +0200)] 
runmodes: minor format string fixes

cppcheck:

src/util-runmodes.c:210:9: warning: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
        ^
src/util-runmodes.c:211:9: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
        ^
src/util-runmodes.c:455:9: warning: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
        ^
src/util-runmodes.c:457:9: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
        ^

src/runmode-erf-file.c:188:9: warning: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
        ^
src/runmode-erf-file.c:189:9: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
        ^
src/runmode-pcap-file.c:201:9: warning: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(tname, sizeof(tname), "%s#%02u", thread_name_workers, thread+1);
        ^
src/runmode-pcap-file.c:202:9: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint]
        snprintf(qname, sizeof(qname), "pickup%u", thread+1);
        ^

Bug: #5291.
(cherry picked from commit 2965d809a44817223d3e6bc81e55c2286da5212b)

3 years agompm/ac-ks: address int handling issues
Victor Julien [Tue, 26 Apr 2022 18:14:39 +0000 (20:14 +0200)] 
mpm/ac-ks: address int handling issues

cppcheck:

src/util-mpm-ac-ks.c:1452:5: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
    printf("Total states in the state table:    %d\n", ctx->state_count);
    ^
src/util-mpm-ac-ks.c:606:34: error: Signed integer overflow for expression '1<<31'. [integerOverflow]
        encoded_next_state |= (1 << 31);
                                 ^

Bug: #5291.
(cherry picked from commit a8d3cd6eb4f181000256986ea7cf83074a0d2b59)

3 years agoclassification: remove useless clear
Victor Julien [Tue, 26 Apr 2022 18:12:20 +0000 (20:12 +0200)] 
classification: remove useless clear

cppcheck:

src/util-classification-config.c:189:9: warning: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]
        fd = NULL;
        ^

Bug: #5291.
(cherry picked from commit 9c672a805fe1fe78591ec0f06da56e23c99d0751)

3 years agodetect/content-inspect: code cleanup
Victor Julien [Tue, 26 Apr 2022 18:06:43 +0000 (20:06 +0200)] 
detect/content-inspect: code cleanup

Rearrange code slightly to make it more clear that `found` cannot
be NULL further down the loop.

cppcheck:

src/detect-engine-content-inspection.c:316:50: warning: Either the condition 'found!=NULL' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]
                match_offset = (uint32_t)((found - buffer) + cd->content_len);
                                                 ^
src/detect-engine-content-inspection.c:308:30: note: Assuming that condition 'found!=NULL' is not redundant
            } else if (found != NULL && (cd->flags & DETECT_CONTENT_NEGATED)) {
                             ^
src/detect-engine-content-inspection.c:316:50: note: Null pointer subtraction
                match_offset = (uint32_t)((found - buffer) + cd->content_len);
                                                 ^

Bug: #5291.
(cherry picked from commit 27e9a871d0f7feeafb8fff266b2bb4d97abd39f3)

3 years agodetect/analyzer: minor format string fixes
Victor Julien [Tue, 26 Apr 2022 18:05:51 +0000 (20:05 +0200)] 
detect/analyzer: minor format string fixes

cppcheck flagged this as:

src/detect-engine-analyzer.c:1359:13: warning: %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            fprintf(rule_engine_analysis_FD, "    Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
            ^
src/detect-engine-analyzer.c:1359:13: warning: %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            fprintf(rule_engine_analysis_FD, "    Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
            ^
src/detect-engine-analyzer.c:1359:13: warning: %d in format string (no. 3) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            fprintf(rule_engine_analysis_FD, "    Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
            ^
src/detect-engine-analyzer.c:1359:13: warning: %d in format string (no. 4) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
            fprintf(rule_engine_analysis_FD, "    Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
            ^

Bug: #5291.
(cherry picked from commit a0847e6c697055b127343cc338029bc69bbc0791)

3 years agodetect/address: remove useless checks
Victor Julien [Tue, 26 Apr 2022 18:04:28 +0000 (20:04 +0200)] 
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.
(cherry picked from commit f8a0f3d9b9f4e1aa758a493e00d38e98a552a0d6)

3 years agodetect/ipv6: remove useless code
Victor Julien [Tue, 26 Apr 2022 18:02:19 +0000 (20:02 +0200)] 
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.
(cherry picked from commit bad900516133a81afb0a6d3982fa3de5871e6ba7)

3 years agodatasets: fix cppcheck warning
Victor Julien [Tue, 26 Apr 2022 18:01:19 +0000 (20:01 +0200)] 
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.
(cherry picked from commit ea2d0ecf08842d52f77d1a88a184a85960999e1e)

3 years agoftp-data: fix direction for active mode commands
Victor Julien [Sat, 30 Apr 2022 14:54:07 +0000 (16:54 +0200)] 
ftp-data: fix direction for active mode commands

Set correct direction for PORT mode, where the server connects
to the client.

The direction is not also strictly enforced. No data in the wrong
direction will be accepted to setup the file or to be added to the
file after setup.

This also fixes files getting closed twice.

Adds some general cleanups.

Bug: #3542.
(cherry picked from commit 07bf9214513e54e04508c055bb8ed29aa3bce60f)

3 years agoippair/storage: use dedicated 'id' type
Juliana Fajardini [Wed, 14 Apr 2021 22:09:02 +0000 (23:09 +0100)] 
ippair/storage: use dedicated 'id' type

- Wrap the id in a new IPPairStorageId struct, to avoid id
confusion with other storage API calls.
- Formatting fixes by clang.

(cherry picked from commit cf516de587d27300cb5af42ae548f54351f7de5d)

3 years agoflow/storage: use dedicated 'id' type
Victor Julien [Fri, 9 Apr 2021 10:56:01 +0000 (12:56 +0200)] 
flow/storage: use dedicated 'id' type

Wrap the id in a new FlowStorageId struct to avoid id confusion with other
storage API calls.

(cherry picked from commit bc667a4a939c887bc298bbb865eda4338f8cea2f)

3 years agoapp-layer/expectation: clean up storage id logic
Victor Julien [Fri, 9 Apr 2021 08:15:39 +0000 (10:15 +0200)] 
app-layer/expectation: clean up storage id logic

(cherry picked from commit 4b3be245065062a3970c6aafa70d25bde969873e)

3 years agodetect/flowbits: remove dead code
Shivani Bhardwaj [Tue, 5 Apr 2022 10:36:08 +0000 (16:06 +0530)] 
detect/flowbits: remove dead code

3 years agodetect/flowbits: add test for bug 5154
Shivani Bhardwaj [Tue, 5 Apr 2022 10:32:41 +0000 (16:02 +0530)] 
detect/flowbits: add test for bug 5154

3 years agodetect/flowbits: use strtok_r for parsing
Shivani Bhardwaj [Wed, 30 Mar 2022 09:45:07 +0000 (15:15 +0530)] 
detect/flowbits: use strtok_r for parsing

Fixes underlying parsing issues by keeping stricter argument checks.

Redmine Bug: 5154

3 years agoftp: truncate first segment if over max length
Jason Ish [Fri, 22 Apr 2022 18:04:37 +0000 (12:04 -0600)] 
ftp: truncate first segment if over max length

The first segment was not limited to the configured maximum line length
allowing it to be up to 65k. This could result in the next input length
being negative, which while handled properly by the code, did trigger a
debug validation assertion.

The fix is to be consistent and apply the limit to the first segment as
well, which does ensure the input_len could never be less than 0.

Ticket #5281

(cherry picked from commit 9645285dff9eb8313db573d8603162a708736236)

3 years agoscripts/bundle: use git instead of tar.gz
Jason Ish [Thu, 29 Oct 2020 23:05:01 +0000 (17:05 -0600)] 
scripts/bundle: use git instead of tar.gz

To better fit with our current CI processes, use git to clone the
suricata-update and libhtp dependencies.  The requirements.txt file has
been modified to take a repo URL and a `-b` command line option for tag
or branch.

For the 6.0.x branch we will use the libhtp 0.5.x branch and the
suricata-update 1.2.4 tag.

Also allows for repo and branch names to be overrided with environment
variables:
- SU_REPO
- SU_BRANCH
- LIBHTP_REPO
- LIBHTP_BRANCH

3 years agodetect: update copyright years
Juliana Fajardini [Thu, 21 Apr 2022 14:51:21 +0000 (11:51 -0300)] 
detect: update copyright years

(cherry picked from commit 192360aa052841f21d22149b049ef94691f9a1f7)

3 years agoassorted: fix low hanging typos
Juliana Fajardini [Thu, 21 Apr 2022 15:47:03 +0000 (12:47 -0300)] 
assorted: fix low hanging typos

(cherry picked from commit 29b5f68bf0770750954780982c46c6fa82eec96b)

3 years agouserguide: explain alert queue behavior and stats
Juliana Fajardini [Wed, 6 Apr 2022 20:06:09 +0000 (17:06 -0300)] 
userguide: explain alert queue behavior and stats

Added sections along packet-alert-max config section explaining
packet alert queue overflow (when Suri reaches packet alert max), when
alerts are discarded etc.

Since from the user perspective it shouldn't matter how we process the
alert queue, the term "replace" is used, even though there's not exactly
a replacing action happening, with the queue bein pre-processed before
being appended to the Packet.

Also described the associated stats and added an explanation on when to
change packet-alert-max.

Task #5178

(cherry picked from commit 1956dc3d5da5dfdc55e0f8304e815b99bd7567e4)

3 years agodetect/stats: log out total of suppressed alerts
Juliana Fajardini [Wed, 20 Apr 2022 16:49:31 +0000 (13:49 -0300)] 
detect/stats: log out total of suppressed alerts

Related to
Task #4943
Task #5179

(cherry picked from commit 877b32c1e42c6edde3fa5f6ab73293e0a4ad27c3)

3 years agodetect/stats: log out total of discarded alerts
Juliana Fajardini [Tue, 5 Apr 2022 19:54:29 +0000 (16:54 -0300)] 
detect/stats: log out total of discarded alerts

Add a counter to our stats log with the total of alerts that have been
discarded due to packet alert queue overflow.

Task #5179

(cherry picked from commit 8616c90fe7573815137a1dbc7fdfeded95f2b38f)

3 years agodetect/alert: move apply-action-flow code to func
Juliana Fajardini [Wed, 27 Apr 2022 22:18:27 +0000 (19:18 -0300)] 
detect/alert: move apply-action-flow code to func

Trying to clean PacketAlertFinalize a bit more.

(cherry picked from commit 9b275d3878643fa27ac4f54d74ba66b51e115459)

3 years agodetect/alert: remove unused functions
Juliana Fajardini [Wed, 20 Apr 2022 20:50:43 +0000 (17:50 -0300)] 
detect/alert: remove unused functions

Since we now only copy the PacketAlerts to the Packet's queue after
processing them, we no longer do packet alert appending from
detect-engine-alert, nor do we remove PacketAlerts from the queue (if
they're discarded by overflow or thresholding, they're not copied to the
final alert queue).

Task #4943

(cherry picked from commit e4e688a9b0add66aa0b97df0f7b1b9e60f68fb90)

3 years agodetect/alert: preprocess then append alert queue
Juliana Fajardini [Tue, 19 Apr 2022 20:43:10 +0000 (17:43 -0300)] 
detect/alert: preprocess then append alert queue

Do all alert queue processing before actually appending
the PacketAlerts to the Packet's alert queue.

Adjusted changes to use macro instead of functions, in cases where the
latter didn't exist in this branch.

Task #4943

(cherry picked from commit 185b43edff7f3f9db0c919663eb02ceb49787a8f)

3 years agodetect/engine: use alert queue from det_ctx
Juliana Fajardini [Tue, 19 Apr 2022 13:58:22 +0000 (10:58 -0300)] 
detect/engine: use alert queue from det_ctx

Task #4943

(cherry picked from commit aa547a8de38d7066d47d83449fba67a0a640260d)

3 years agodetect/alert: add infra for new alert queue
Juliana Fajardini [Mon, 18 Apr 2022 21:14:52 +0000 (18:14 -0300)] 
detect/alert: add infra for new alert queue

Initial work to bring part of the alert queue processing to
DetectEngineThreadCtx.

Task #4943

(cherry picked from commit 88805f03eec038fd67a18599d7d9f037db083941)

3 years agodoc/userguide: explain packet-alert-max config
Juliana Fajardini [Wed, 6 Apr 2022 14:54:52 +0000 (11:54 -0300)] 
doc/userguide: explain packet-alert-max config

Task #4207

(cherry picked from commit 49542d0f1bb35d889f798a50c04f4a257b816695)

3 years agodecode: make packet_alert_max configurable
Juliana Fajardini [Wed, 19 Jan 2022 18:29:39 +0000 (18:29 +0000)] 
decode: make packet_alert_max configurable

The maximum of possible alerts triggered by a unique packet was
hardcoded to 15. With usage of 'noalert' rules, that limit could be
reached somewhat easily. Make that configurable via suricata.yaml.

Conf Bug#4941

Task #4207

(cherry picked from commit 3ace577d5426e2e1afd1cdf0736151022771226c)

3 years agounittests: alloc Packet with PacketGetFromAlloc
Juliana Fajardini [Mon, 2 May 2022 22:22:33 +0000 (19:22 -0300)] 
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.

Backport: edit a few more files/unittests that were not present in 7.0.x

Related to
Task #4207

(cherry picked from commit a6bda3596bdd1a0ac04afe5553609c6f7cba0023)

3 years agosignal/stack: Default stack-on-signal setting: off 7324/head
Jeff Lucovsky [Tue, 26 Apr 2022 18:47:06 +0000 (14:47 -0400)] 
signal/stack: Default stack-on-signal setting: off

Ticket: 5228

This commit changes the default value of the stack-on-signal feature to
be disabled.

3 years agosignal/stack: Remove redundant initialization
Jeff Lucovsky [Tue, 26 Apr 2022 18:46:06 +0000 (14:46 -0400)] 
signal/stack: Remove redundant initialization

Ticket: 5228

This commit removes the redundant initialization of the stack-on-signal
functionality.

3 years agodetect: fix rule inspection order
Victor Julien [Mon, 25 Apr 2022 16:00:24 +0000 (18:00 +0200)] 
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.
(cherry picked from commit 4bb00964ac22f0f96704cf5befca76d056763142)

3 years agodetect: use bool for uint16_t used as bool
Victor Julien [Tue, 30 Nov 2021 12:35:48 +0000 (13:35 +0100)] 
detect: use bool for uint16_t used as bool

(cherry picked from commit bb3d49d5bf6376756e124a79b4f25799d934617c)

3 years agostream: improve flow end payload logging
Victor Julien [Sat, 23 Apr 2022 11:59:34 +0000 (13:59 +0200)] 
stream: improve flow end payload logging

Use all available data, including un-ACK'd, when in flow timeout
mode.

Bug: #5276.
(cherry picked from commit c40df43609becc467e86d756098829b3174c80c7)

3 years agostream/unittests: fix failures after last_ack fix
Victor Julien [Fri, 22 Apr 2022 17:33:13 +0000 (19:33 +0200)] 
stream/unittests: fix failures after last_ack fix

Work around many tests not setting up stream completely or correctly.

(cherry picked from commit 3d6e733aa7297f64fe87cc3b59fbbd9a527513fa)

3 years agostream: improve last_ack validation check
Victor Julien [Fri, 22 Apr 2022 16:27:15 +0000 (18:27 +0200)] 
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.
(cherry picked from commit 1f43e1477f3c5781381e75f4bed918cbc6c18dfd)

3 years agoversion: start development towards 6.0.6
Victor Julien [Wed, 27 Apr 2022 09:06:22 +0000 (11:06 +0200)] 
version: start development towards 6.0.6

3 years agorelease: 6.0.5; update changelog; require htp 0.5.40 7288/head suricata-6.0.5
Victor Julien [Thu, 21 Apr 2022 06:34:30 +0000 (08:34 +0200)] 
release: 6.0.5; update changelog; require htp 0.5.40

3 years agosmtp: support per-tx file accounting
Victor Julien [Thu, 18 Mar 2021 07:38:03 +0000 (08:38 +0100)] 
smtp: support per-tx file accounting

(cherry picked from commit 0867b0dbcdd9a6973d505714928ea7323a4f5384)

3 years agodetect-file-data: remove SMTP unittests
Modupe Falodun [Fri, 14 Jan 2022 15:53:28 +0000 (16:53 +0100)] 
detect-file-data: remove SMTP unittests

These tests are reimplemented as Suricata-verify tests

Task: 4938
(cherry picked from commit 3dbf74ff1025b843eb09b0e4d5e2c90614d7cc9e)

3 years agosmtp: don't pass partial boundary on to mime parser
Victor Julien [Fri, 15 Apr 2022 13:51:10 +0000 (15:51 +0200)] 
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.

(cherry picked from commit e7417a8e96fcd23fa9e3b529d7c2bbd7b3efb928)

3 years agomime: allow partial lines as input
Victor Julien [Fri, 15 Apr 2022 13:49:09 +0000 (15:49 +0200)] 
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.

(cherry picked from commit 6e800a8548d9d2699589cac6afca3c0fa7613202)

3 years agosmtp: pre process DATA and BDAT commands
Shivani Bhardwaj [Thu, 14 Apr 2022 15:59:32 +0000 (21:29 +0530)] 
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.

(cherry picked from commit cf749fd450ca41dc001c2a1c10d8d17500dcedce)

3 years agosmtp: fix indefinite buffering if no LF in line
Shivani Bhardwaj [Mon, 14 Feb 2022 11:23:52 +0000 (16:53 +0530)] 
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

(cherry picked from commit 078c251deacc78b8abb40c5ab89d19c29e31bdf8)

3 years agosmtp: add truncated line event
Shivani Bhardwaj [Wed, 20 Apr 2022 07:25:54 +0000 (12:55 +0530)] 
smtp: add truncated line event

(cherry picked from commit 57a7cf7a0bcc9140a326c91a21e5d21fd2236f49)

3 years agosmtp: use AppLayerResult instead of buffering
Shivani Bhardwaj [Mon, 3 Jan 2022 14:14:53 +0000 (19:44 +0530)] 
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

(cherry picked from commit 8918f53f6bc9b9a858f44964c74ec2dcaa4312fa)

3 years agodoc/userguide: document ftp max-line-length
Jason Ish [Thu, 7 Apr 2022 21:58:58 +0000 (15:58 -0600)] 
doc/userguide: document ftp max-line-length

(cherry picked from commit 7d6bc60abb6eefce3f0d20222b2a843de9ea5a6e)

3 years agoftp: truncate command data that is too long
Jason Ish [Wed, 6 Apr 2022 21:38:35 +0000 (15:38 -0600)] 
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

(cherry-picked from commit cf8ed576e09a68886760259055e309e51bf5bec3)

3 years agodetect: config checks alstate before getting tx
Philippe Antoine [Fri, 8 Apr 2022 13:15:23 +0000 (15:15 +0200)] 
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

(cherry picked from commit dccf2e4c30b968477d9cc7e7a86b64b97893831c)

3 years agodetect: not an iponly signature if it needs app-layer
Philippe Antoine [Wed, 30 Mar 2022 13:24:32 +0000 (15:24 +0200)] 
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

(cherry picked from commit 0cba561fecffe93596d38691561d4316c3b8efb2)

3 years agodetect: makes config keyword really require a flow
Philippe Antoine [Tue, 8 Mar 2022 11:50:16 +0000 (12:50 +0100)] 
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

(cherry picked from commit 00da0d3420fd6ebbdbe7990b26eebf7650856eca)

3 years agodetect: only apply ConfigApplyTx with app-layers
Philippe Antoine [Mon, 17 Jan 2022 13:47:48 +0000 (14:47 +0100)] 
detect: only apply ConfigApplyTx with app-layers

Ticket: 4972

Otherwise, it makes no sense to look for a tx...

(cherry picked from commit c3a220647b31b453b0fc14ecfb028defad2778dc)

3 years agodns: don't parse a full request during probe if not enough data
Jason Ish [Mon, 28 Feb 2022 22:48:34 +0000 (16:48 -0600)] 
dns: don't parse a full request during probe if not enough data

If there is more data than a header, but not enough for a complete DNS
message, the hostname parser could return an error causing the probe to
fail on valid DNS messages.

So only parse the complete message if we have enough input data. This is
reliable for TCP as DNS messages are prefixed, but for UDP its just
going to be the size of the input buffer presented to the parser, so
incomplete could still happen.

Ticket #5034

(cherry picked from commit 27679a12aa4e03e960112f387640419d29780e5a)

3 years agodns: better error handling when parsing names
Jason Ish [Tue, 1 Feb 2022 21:44:43 +0000 (15:44 -0600)] 
dns: better error handling when parsing names

The DNS name parser will error out with an error even if the
error is incomplete. Instead of manually generating errors,
use '?' to let the nom error ripple up the error handling chain.

The reason this wasn't done in the first place is this code
predates the ? operator, or we were not aware of it at the time.

This prevents the case where probing fails when there is enough data to
parse the header, but not enough to complete name parser. In such a case
a parse error is returned (instead of incomplete) resulting in the
payload not being detected as DNS.

Ticket #5034

(cherry picked from commit 0623ada24df1da99c72bb8cd4959b2cb0e64ccc2)

3 years agosmb: protocol detection on pattern without midstream
Jason Ish [Thu, 31 Mar 2022 18:45:07 +0000 (12:45 -0600)] 
smb: protocol detection on pattern without midstream

To recognize a protocol, Suricata first looks for
patterns, which can be confirmed by a probing parser.
If this does not work, Suricata can try to run
some probing parsers on some ports.

This is the case for SMB.

This commit makes handling the confirming and the probing
paser differently even if they share much code.

The confirmation parser knows that a pattern has been found.
So, it must not do the midstream case of looking for this
pattern in the whole buffer, but only check it at the beginning.
But it must reverse direction if needed.

Ticket #4849

Backported manually by jason.ish@oisf.net.

(cherry picked from commit 464ff80c6a8efd1212b617a80c726173573caf42)