]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
5 years agoflow: cleanup expectations first 4881/head
Victor Julien [Fri, 3 Apr 2020 08:09:07 +0000 (10:09 +0200)] 
flow: cleanup expectations first

Make sure to cleanup expectations for a flow as the first step, before
parts of the flow itself are getting cleaned/freed.

Also indicate use unlikely as flows with expectations should be relatively
rare.

(cherry picked from commit 09a21545ce00de8ef161f097603f98770351e9be)

5 years ago app-layer-expectation: clean expectation and add limits
Eric Leblond [Fri, 7 Feb 2020 23:05:01 +0000 (00:05 +0100)] 
 app-layer-expectation: clean expectation and add limits

When a flow timeout, we can have still existing expectations that
are linked to this flow. Given that there is a delay between the
real ending of the flow and its destruction by Suricata, the
expectation should be already honored so we can assume the risk
to clean the expectations that have been triggered by the
to-be-deleted flow.

This patch introduces a limitation in term of number of
expectations attached to one IPPair. This is done using
a circle list so we have a FIFO approach on expectation
handling.

Circleq list code is copied from BSD code like was pre existing code
in queue.h.

(cherry picked from commit 1ddd77fae06d7b41b7d7752c70ebfce3d335983e)
(cherry picked from commit 6c9d1c08614fdbd42c22b5aca0d4c438bd404c5e)

Commits squashed to avoid circular dependeny by Shivani Bhardwaj.

5 years agoapp-layer-expectation: update copyright date
Eric Leblond [Sun, 9 Feb 2020 19:33:21 +0000 (20:33 +0100)] 
app-layer-expectation: update copyright date

(cherry picked from commit fcfeeeb694f01508bf98ecc8e22dc3d30ef34f95)

5 years agoapp-layer-expectation: remove unused parameter
Eric Leblond [Tue, 10 Dec 2019 21:15:14 +0000 (22:15 +0100)] 
app-layer-expectation: remove unused parameter

(cherry picked from commit 03e4bfeb026a568857617a2e1e135c4b3bbd1505)

5 years agodetect/ftp: FTP memory accounting fixes
Jeff Lucovsky [Tue, 21 Apr 2020 14:36:27 +0000 (10:36 -0400)] 
detect/ftp: FTP memory accounting fixes

This commit continues the work started by @vanlink and corrects the
accounting of FTP memory usage against the memcap limit.

(cherry picked from commit aa3f784d32308b642052c076787ace547b260781)

5 years agodetect: fix insertion in linked list for fast pattern
Philippe Antoine [Mon, 20 Apr 2020 11:57:44 +0000 (13:57 +0200)] 
detect: fix insertion in linked list for fast pattern

Make sure we do not add the same list_id twice
by checking at least all the lists with the current priority

(cherry picked from commit cd26fc139ec8766a73892174fd929e9478a050bc)

5 years agodetect: Provide function to clear per-thread ctx
Jeff Lucovsky [Sat, 21 Mar 2020 14:10:09 +0000 (10:10 -0400)] 
detect: Provide function to clear per-thread ctx

This commit provides an interface to free previously allocated
per-thread contextual information on the keyword lists.

(cherry picked from commit d1151f3f8e5d21f08c47dd9d3e3650768f7d3004)

5 years agoutil: removes warning about double conversion
Philippe Antoine [Fri, 1 Nov 2019 07:48:56 +0000 (08:48 +0100)] 
util: removes warning about double conversion

From clang 10 :
implicit conversion from 'unsigned long' to 'double' changes value
from 18446744073709551615 to 18446744073709551616

(cherry picked from commit 20e06f45c037d0943d58e6eb1d8b4f4f602032f0)

5 years agokerberos: fix against packet split in record size 4833/head
Philippe Antoine [Fri, 6 Mar 2020 09:45:23 +0000 (10:45 +0100)] 
kerberos: fix against packet split in record size

(cherry picked from commit 23f796a021cd4a0f2614418a5d2d40acefd56df3)

5 years agodetect/iponly: fix parsing of '0' valued netmask
Victor Julien [Sat, 11 Apr 2020 11:54:00 +0000 (13:54 +0200)] 
detect/iponly: fix parsing of '0' valued netmask

(cherry picked from commit 4d50eb1647709c9f2b8809f91b2af67be99ce4ab)

5 years agodetect/parse: fix minor memory leak in error path
Victor Julien [Fri, 10 Apr 2020 07:55:36 +0000 (09:55 +0200)] 
detect/parse: fix minor memory leak in error path

Only reachable on SCMalloc so should be unlikely to be reached.

(cherry picked from commit 5abead93259e8d0bfb3f7556b9653debe320621a)

5 years agodetect/parse: properly free bidir sigs in error path
Victor Julien [Fri, 10 Apr 2020 08:02:43 +0000 (10:02 +0200)] 
detect/parse: properly free bidir sigs in error path

(cherry picked from commit fc6ada85411caa9c08df3eae1cc908436a4ea257)

5 years agoconf: returns instead of exiting in ConfYamlParse
Philippe Antoine [Wed, 15 Apr 2020 09:48:13 +0000 (11:48 +0200)] 
conf: returns instead of exiting in ConfYamlParse

So that we can keep on fuzzing even on too much recursion

(cherry picked from commit fe1d36ec7eff8fecbe39f4d7447c0ab24a9d37ee)

5 years agoconf/yaml: limit recursion depth while paring YAML
Jason Ish [Thu, 9 Apr 2020 21:59:23 +0000 (15:59 -0600)] 
conf/yaml: limit recursion depth while paring YAML

A deeply nested YAML file can cause a stack-overflow while
reading in the configuration to do the recursive parser. Limit
the recursion level to something sane (128) to prevent this
from happening.

The default Suricata configuration has a recursion level of 128
so there is still lots of room to grow (not that we should).

Redmine ticket:
https://redmine.openinfosecfoundation.org/issues/3630

(cherry picked from commit 4dc80a6e6f9b396de5dc25d3468522316c4661d0)

5 years agonfs: fix buffering code using wrong dir 4810/head
Victor Julien [Fri, 20 Mar 2020 08:40:23 +0000 (09:40 +0100)] 
nfs: fix buffering code using wrong dir

(cherry picked from commit a2ebab10e2f0e54122b3f8afa852971454c00bfb)

5 years agodns: log addresses in flow direction, not packet (C)
Jason Ish [Wed, 1 Apr 2020 22:41:06 +0000 (16:41 -0600)] 
dns: log addresses in flow direction, not packet (C)

Address issue with source and destination addresses be logged
in the wrong order. This was already addressed in the Rust code
with c2d833fcaf1b01fea8e7dfda71b2e965521c963d.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/3340

5 years agogithub-ci: add build with Rust disabled
Jason Ish [Fri, 27 Mar 2020 22:12:55 +0000 (16:12 -0600)] 
github-ci: add build with Rust disabled

5 years agohtp: simplify depth check
Victor Julien [Mon, 16 Sep 2019 10:44:42 +0000 (12:44 +0200)] 
htp: simplify depth check

(cherry picked from commit c68fbfcfe690934e370f90a4f3e04872a1878c37)

5 years agodoc: update file-extraction section
Giuseppe Longo [Mon, 28 Jan 2019 20:39:07 +0000 (21:39 +0100)] 
doc: update file-extraction section

(cherry picked from commit 972be0a560a610f20e967b74cd488900ef86de73)

5 years agoapp-layer-htp: use stream depth with filestore
Giuseppe Longo [Mon, 28 Jan 2019 15:15:22 +0000 (16:15 +0100)] 
app-layer-htp: use stream depth with filestore

This permits to use stream-depth value set for file-store.

Currently if a file is being stored and hits a limit,
such as request or response body, it will be truncated
although file-store.stream-depth is enabled but the file should be
closed and not truncated.

Two unit tests have been added to verify that:
- a file is stored correctly
- chunk's length computation doesn’t cause an underflow

(cherry picked from commit de904db8305688dfe7454bb6a2126cae40b5ba3d)

5 years agoapp-layer-parser: flag a tx to use stream depth
Giuseppe Longo [Thu, 24 Jan 2019 22:22:11 +0000 (23:22 +0100)] 
app-layer-parser: flag a tx to use stream depth

This adds a new API that permit to set the stream-depth
file for file-storing when a rule with filestore keyword is matched.

(cherry picked from commit ed5a439b8e8680c74b8bec8873e1a126081b7fce)

5 years agodecode/erspan: ERSPAN TypeI configurable 4797/head
Jeff Lucovsky [Tue, 3 Mar 2020 13:50:37 +0000 (08:50 -0500)] 
decode/erspan: ERSPAN TypeI configurable

For the backport, ERSPAN TypeI decode is

1. Disabled by default
2. Configurable: `decoder.erspan_typeI.enabled`

(cherry picked from commit ae6beedd13df60b129de702eabc0a7364fd973d5)
(cherry picked from commit 33b56b31b50a96e5022ca86ba1b7185efb832355)

5 years agodecode: Handle ERSPAN Type I
Jeff Lucovsky [Sat, 28 Dec 2019 14:44:56 +0000 (09:44 -0500)] 
decode: Handle ERSPAN Type I

(cherry picked from commit aec4e9a032855a710d71a4c397affcdce5351b39)
(cherry picked from commit 237964a6ee7862f783b15c1e7ce469ca1edd3b01)

5 years agopcap/file: improve time handling
Victor Julien [Fri, 28 Feb 2020 12:17:03 +0000 (13:17 +0100)] 
pcap/file: improve time handling

This patch addresses two problems.

First, various parts of the engine, but most notably the flow manager (FM),
use a minimum of the time notion of the packet threads. This did not
however, take into account the scenario where one or more of these
threads would be inactive for prolonged times. This could lead to the
time used by the FM could get stale.

This is addressed by keeping track of the last time the per thread packet
timestamp was updated, and only considering it for the 'minimum' when it
is reasonably current.

Second, there was a minor race condition at start up, where the FM would
already inspect the hash table(s) while the packet threads weren't active
yet. Since FM gets the time from the packet threads, it would use a bogus
time of 0.

This is addressed by adding a wait loop to the start of the FM that waits
for 'time' to get ready.

(cherry picked from commit 072c421e46abb8d3ddeaea818736a68299a20da5)

5 years agothreads/time: rename ts to pktts to make purpose clear
Victor Julien [Fri, 28 Feb 2020 12:06:09 +0000 (13:06 +0100)] 
threads/time: rename ts to pktts to make purpose clear

(cherry picked from commit 4977daec3297dcd06548c67d4d2779530f78c13d)

5 years agopcap/file: fix race during pcap processing start
Victor Julien [Thu, 27 Feb 2020 16:20:18 +0000 (17:20 +0100)] 
pcap/file: fix race during pcap processing start

A race condition during the start of pcap file processing could cause
missed alerts and logged events. This race happens between the packet
threads and the flow manager. It was observed on slower hardware, but in
theory could happen on any machine. It required the 'autofp' runmode.

In commit 6f560144c1b9 ("time: improve offline time handling") the logic
was added to make the flow manager use a minimum of all the packet threads
perception of time.

The race condition was that the flow manager may become active _before_
all of the packet threads have started processing packets and thus setting
their timestamp. The threads that had not yet initialized their timestamp
would not be considered when calculating the minimum.

As a result of this, older packets timestamps would not yet be registered.
This would give the Flow Manager a timestamp too far in the future. While
the FM was running, the packet processing would start and a flow would
be created. This flow would then immediately be considered 'timed out' by
the FM, due to the timestamp too far in the future.

In the observed case, the thread processing packet 1 from the pcap had not
yet started processing while other threads had already started. The FM was
also already active. Due to the timestamps in the pcap this meant that the
time the FM used was about 500 seconds in the future compared to packet 1.

This patch fixes the issue by initializing all of the threads timestamps
with the timestamp value of the first packet. This way the minimum will
always consider this timestamp.

(cherry picked from commit ae4137937e0c5a0f80547be7f9dae08e8768babb)

5 years agodecode: Fix typos/spelling
Jeff Lucovsky [Sat, 28 Dec 2019 14:45:31 +0000 (09:45 -0500)] 
decode: Fix typos/spelling

(cherry picked from commit 427ec4e739611975b983fcf06bec8fc9b8f8917e)
(cherry picked from commit 8d946d7e89e42daa0fa81a70d3d10b6ebeb28b34)

5 years agodetect/threshold: Correct typos
Jeff Lucovsky [Wed, 4 Mar 2020 14:37:04 +0000 (09:37 -0500)] 
detect/threshold: Correct typos

(cherry picked from commit c20ab53eaeb57d873a5ea065f31adcec28786078)

5 years agodetect/threshold: Don't allow duplicates
Jeff Lucovsky [Wed, 4 Mar 2020 14:35:54 +0000 (09:35 -0500)] 
detect/threshold: Don't allow duplicates

This commit detects duplicate threshold rule options. When duplicates
are found in a rule, an error message is displayed and the rule is
rejected.

(cherry picked from commit ff9a01ee1b63452d1b047f9bcc7522e3ab1eda10)

5 years agosmb: fix rustc 1.42 warnings
Victor Julien [Tue, 17 Mar 2020 19:44:33 +0000 (20:44 +0100)] 
smb: fix rustc 1.42 warnings

(cherry picked from commit a729d266c398d0d3a9f43d7df3f351245d1773e3)

5 years agotime: fix function name typo
Victor Julien [Fri, 28 Feb 2020 09:22:23 +0000 (10:22 +0100)] 
time: fix function name typo

(cherry picked from commit 6176338d0b0bbce1771d73ee3683923dec97c330)

5 years agotime: remove unused time structure
Victor Julien [Thu, 27 Feb 2020 19:27:20 +0000 (20:27 +0100)] 
time: remove unused time structure

(cherry picked from commit 1b1855c3bd3a243dad590a5fa3e1139d0a90e5b5)

5 years agotime: minor code cleanup
Victor Julien [Thu, 27 Feb 2020 19:20:33 +0000 (20:20 +0100)] 
time: minor code cleanup

(cherry picked from commit 13b4ece11d77f383b9674f01609d41ec29458097)

5 years agospelling: Fix spelling error 4794/head
Jeff Lucovsky [Sat, 22 Feb 2020 18:24:45 +0000 (13:24 -0500)] 
spelling: Fix spelling error

(cherry picked from commit 6d94b096a9bdf069465aae447aea036609bfb9bb)

5 years agodetect/ssl_state: Fix memory leaks from pcre_get_substring
Jeff Lucovsky [Sat, 22 Feb 2020 18:24:13 +0000 (13:24 -0500)] 
detect/ssl_state: Fix memory leaks from pcre_get_substring

This commit replaces usages of pcre_get_substring with
pcre_copy_substring to avoid leaking memory on error conditions.

(cherry picked from commit 6c3503932ff604443820b85421ef0271deaf7032)

5 years agodetect/flowvar: Fix memory leaks from pcre_get_substring
Jeff Lucovsky [Sat, 22 Feb 2020 18:23:04 +0000 (13:23 -0500)] 
detect/flowvar: Fix memory leaks from pcre_get_substring

This commit replaces usages of pcre_get_substring with
pcre_copy_substring to avoid leaking memory on error conditions.

(cherry picked from commit 9fe51a8bd280c3662d5b48bbd9c8745a7bdd0822)

5 years agodetect/filestore: Fix memory leaks from pcre_get_substring
Jeff Lucovsky [Sat, 22 Feb 2020 18:21:36 +0000 (13:21 -0500)] 
detect/filestore: Fix memory leaks from pcre_get_substring

This commit replaces usages of pcre_get_substring with
pcre_copy_substring to avoid leaking memory on error conditions.

(cherry picked from commit c2071e1c4e2d2ff89f7f7e07cefb307c095338e3)

5 years agoutil-error: define SC_ERR_PCRE_COPY_SUBSTRING
Jeff Lucovsky [Sat, 22 Feb 2020 18:25:02 +0000 (13:25 -0500)] 
util-error: define SC_ERR_PCRE_COPY_SUBSTRING

(cherry picked from commit bcea73026635c3bf080d9dab1717077acc23c5f2)

5 years agodetect/pktvar: fix memory leaks
Victor Julien [Sun, 5 Apr 2020 14:56:35 +0000 (16:56 +0200)] 
detect/pktvar: fix memory leaks

(cherry picked from commit aba4e195484a4ee2068ca13ed7852aab81f00d5a)

5 years agodetect/parse: fix crash on 'internal' keyword use
Victor Julien [Tue, 31 Mar 2020 12:04:07 +0000 (14:04 +0200)] 
detect/parse: fix crash on 'internal' keyword use

When keyword __flowvar__postmatch__, an internal keyword, is used
in a rule the 'Setup' func ptr will be NULL. This caused a crash.

(cherry picked from commit 095981cb2a7b204e66770ab5ab4efcf5034caa27)

5 years agodetect/pkt_data: error on unconsumed transforms
Victor Julien [Tue, 31 Mar 2020 08:38:06 +0000 (10:38 +0200)] 
detect/pkt_data: error on unconsumed transforms

If a rule has transforms w/o consuming them (e.g. a content keyword),
don't consider 'pkt_data' valid.

(cherry picked from commit 13c9d0ca7e3a41a8023dc80def36e24686288742)

5 years agodetect/pkt_data: code and test cleanup
Victor Julien [Tue, 31 Mar 2020 09:37:51 +0000 (11:37 +0200)] 
detect/pkt_data: code and test cleanup

(cherry picked from commit e1c474a1b08eb31e53c455cd7a14c64d8af96acc)

5 years agodetect/ssl: Fix memory leak in version parsing
Jeff Lucovsky [Mon, 6 Apr 2020 13:55:41 +0000 (09:55 -0400)] 
detect/ssl: Fix memory leak in version parsing

This commit fixes a memory leak in the SSL version handling that
manifests when the version identifier is incomplete or incorrect.

(cherry picked from commit 6bffe0bd353654b0f2e5e123cd3f68d2570c5553)

5 years agostream/tcp: fix STREAM_HAS_SEEN_DATA macro
Victor Julien [Tue, 24 Mar 2020 12:11:03 +0000 (13:11 +0100)] 
stream/tcp: fix STREAM_HAS_SEEN_DATA macro

The macro would not return true for smaller TCP streams, leading to
cases where the app-layer was not notified of EOF.

(cherry picked from commit e500c59b994ef2c4ba1c2bd17b4d4ff674a144ef)

5 years agomime: Test cases for filename length limit 4734/head
Jeff Lucovsky [Fri, 14 Feb 2020 13:38:53 +0000 (08:38 -0500)] 
mime: Test cases for filename length limit

(cherry picked from commit c92975e22b809e9f4121b653670ae1233fe3e567)

5 years agosmtp/mime: Fix typos
Jeff Lucovsky [Wed, 5 Feb 2020 14:21:05 +0000 (09:21 -0500)] 
smtp/mime: Fix typos

(cherry picked from commit 9a33b5d5ded247e94a6572092ab2aca3f51752b3)

5 years agosmtp/mime: Set event when name exceeds limit
Jeff Lucovsky [Wed, 5 Feb 2020 14:20:29 +0000 (09:20 -0500)] 
smtp/mime: Set event when name exceeds limit

(cherry picked from commit 130b8d26e7e8e64ca42dc7e4db9890619d9730aa)

5 years agosmtp/mime: Restrict file name lengths
Jeff Lucovsky [Tue, 4 Feb 2020 15:13:49 +0000 (10:13 -0500)] 
smtp/mime: Restrict file name lengths

This commit places restrictions on the length of the file name specified
in attachments (`name=` or `filename=`) to `NAME_MAX`. Names exceeding
these limits will be truncated and processing will continue with the
truncated name.

(cherry picked from commit d0d20bd8746ad8933a515fa4facf9e3e10f22ecc)

5 years agodag: Skip over ERF_TYPE_META records
Stephen Donnelly [Thu, 5 Mar 2020 21:49:17 +0000 (10:49 +1300)] 
dag: Skip over ERF_TYPE_META records

Suricata generates an error on unrecognised ERF types.
Suricata should ignore ERF 'Provenance' records with ERF_TYPE_META.

(cherry picked from commit 47082dd5df1b71485333039cd6af75b39cdfffeb)

5 years agodetect/parse: move spaces skip up the stack
Philippe Antoine [Wed, 9 Oct 2019 14:59:13 +0000 (16:59 +0200)] 
detect/parse: move spaces skip up the stack

Switch to isspace() as well.

(cherry picked from commit 52970d850858bb9784fe562422e9cf2c3aec4230)

5 years agochangelog: update for 4.1.7 suricata-4.1.7
Victor Julien [Thu, 13 Feb 2020 11:32:45 +0000 (12:32 +0100)] 
changelog: update for 4.1.7

5 years agorust: build and dist fixes 4549/head
Victor Julien [Thu, 13 Feb 2020 12:14:03 +0000 (13:14 +0100)] 
rust: build and dist fixes

Bring up to date with 5.0.x.

5 years agorust/Makefile: Don't include Cargo.toml
Jason Ish [Thu, 16 Jan 2020 15:09:13 +0000 (09:09 -0600)] 
rust/Makefile: Don't include Cargo.toml

There is no need to include Cargo.toml in the distribution,
it is always generated from Cargo.toml.in during
./configure.

(cherry picked from commit c6f168eb98c665f82e43500ed17f9807ae3c3639)

5 years agostream/reassembly: fix data overlap check
vanlink [Thu, 16 Jan 2020 08:27:57 +0000 (16:27 +0800)] 
stream/reassembly: fix data overlap check

Fix function CheckOverlap bug.

(cherry picked from commit 2456f27d08142b571a06ffd211c90a5fa557366a)

5 years agostreaming/api: fix overlap check
Victor Julien [Sat, 14 Dec 2019 19:20:45 +0000 (20:20 +0100)] 
streaming/api: fix overlap check

In some cases a SBB could be seen as overlapping with the requested
offset, when it was in fact precisely before it. In some special cases
this could lead to the stream engine not progressing the 'raw' progress.

(cherry picked from commit 2c050187a3ad78388e57781c4feb74426bc75e21)

5 years agonfs: implement post-GAP transaction cleanup 4544/head
Victor Julien [Tue, 11 Feb 2020 10:55:18 +0000 (11:55 +0100)] 
nfs: implement post-GAP transaction cleanup

Close all prior transactions in the direction of the GAP, except the
file xfers. Those use their own logic described below.

After a GAP all normal transactions are closed. File transactions
are left open as they can handle GAPs in principle. However, the
GAP might have contained the closing of a file and therefore it
may remain active until the end of the flow.

This patch introduces a time based heuristic for these transactions.
After the GAP all file transactions are stamped with the current
timestamp. If 60 seconds later a file has seen no update, its marked
as closed.

This is meant to fix resource starvation issues observed in long
running SMB sessions where packet loss was causing GAPs. Due to the
similarity of the NFS and SMB parsers, this issue is fixed for NFS
as well in this patch.

Bug #3424.
Bug #3425.

(cherry picked from commit f68c255f090a94162df1fcd7e7262548a2119c50)

5 years agothreading: fix global declaration of trans_q 4542/head
Victor Julien [Wed, 29 Jan 2020 07:27:43 +0000 (08:27 +0100)] 
threading: fix global declaration of trans_q

(cherry picked from commit bd3fac73b1c20eba1577023adb7cafc80b083bd3)

5 years agotls: fix missing extern logic for cert_id tracking
Victor Julien [Wed, 29 Jan 2020 12:50:05 +0000 (13:50 +0100)] 
tls: fix missing extern logic for cert_id tracking

(cherry picked from commit aeefc82eb92e8b7b72cb31810c5f1040f8df2ace)

5 years agostats: fix missing extern keyword
Victor Julien [Wed, 29 Jan 2020 12:46:56 +0000 (13:46 +0100)] 
stats: fix missing extern keyword

(cherry picked from commit 62c0f3d2b46f41d1b0462eb6eecbf7b95650c452)

5 years agodefrag: fix use of globals
Victor Julien [Wed, 29 Jan 2020 12:43:49 +0000 (13:43 +0100)] 
defrag: fix use of globals

(cherry picked from commit 903291f88ac8d4d3042337d27f89bb4317e6b8ce)

5 years agothreading: fix queue handlers globals use
Victor Julien [Wed, 29 Jan 2020 12:30:35 +0000 (13:30 +0100)] 
threading: fix queue handlers globals use

(cherry picked from commit 5c3c6c609ca4e466613d83f37c7fd65a56213fca)

5 years agohtp: fix globals use for flags
Victor Julien [Wed, 29 Jan 2020 12:28:17 +0000 (13:28 +0100)] 
htp: fix globals use for flags

(cherry picked from commit 3ae1854d2fc28c185c2d66a8c98d1049c92e1289)

5 years agoproto: fix globals use
Victor Julien [Wed, 29 Jan 2020 12:27:58 +0000 (13:27 +0100)] 
proto: fix globals use

(cherry picked from commit 85289f32835276f4c3acbcc54b64e36c125f3e4c)

5 years agoflow: fix global variable use
Victor Julien [Wed, 29 Jan 2020 12:23:36 +0000 (13:23 +0100)] 
flow: fix global variable use

(cherry picked from commit 5e583f3a12e94ccd91d20477066294730527180e)

5 years agostream: fix global declaration of the config
Victor Julien [Wed, 29 Jan 2020 10:55:27 +0000 (11:55 +0100)] 
stream: fix global declaration of the config

(cherry picked from commit 29f54a34ae608ed0fda2d8f10e753ccabf7cee02)

5 years agothreading/modules: fix global declarations
Victor Julien [Wed, 29 Jan 2020 10:51:11 +0000 (11:51 +0100)] 
threading/modules: fix global declarations

(cherry picked from commit 2436daccd9574064d9f880813e0e8ba3de944d64)

5 years agoippair: fix global declarations
Victor Julien [Wed, 29 Jan 2020 09:56:54 +0000 (10:56 +0100)] 
ippair: fix global declarations

(cherry picked from commit c5f4b41881369e099159c148de652f729124b4ed)

5 years agohost: fix global declarations
Victor Julien [Wed, 29 Jan 2020 09:37:44 +0000 (10:37 +0100)] 
host: fix global declarations

(cherry picked from commit 0a006d2258625b46043b38f62fedfcd0a8ee470c)

5 years agompm: fix global declarations
Victor Julien [Wed, 29 Jan 2020 09:28:16 +0000 (10:28 +0100)] 
mpm: fix global declarations

(cherry picked from commit 29780d6164d20531365d9bd82d8890a3dc662d8f)

5 years agodetect: fix global declaration of sigmatch_table
Victor Julien [Wed, 29 Jan 2020 09:22:57 +0000 (10:22 +0100)] 
detect: fix global declaration of sigmatch_table

(cherry picked from commit b89059bda7814eccf1373c5dc8d8aaa13c46e590)

5 years agospm: fix global declaration of spm_table
Victor Julien [Wed, 29 Jan 2020 09:11:54 +0000 (10:11 +0100)] 
spm: fix global declaration of spm_table

(cherry picked from commit 0118e07d57a34c5fa72a57fdbae8bf2d3c182478)

5 years agothreading: fix global declaration of threading_set_cpu_affinity
Victor Julien [Wed, 29 Jan 2020 07:33:18 +0000 (08:33 +0100)] 
threading: fix global declaration of threading_set_cpu_affinity

(cherry picked from commit a12c0b499df7a1f9761ae190796f551a6b63ccbe)

5 years agounix-socket: avoid using global variable w/o extern
Victor Julien [Wed, 29 Jan 2020 07:15:21 +0000 (08:15 +0100)] 
unix-socket: avoid using global variable w/o extern

(cherry picked from commit 45955d2e589f040cee74dce35a53d26de9cfe29c)

5 years agodecode: fix default-packet-size global variable
Victor Julien [Wed, 29 Jan 2020 07:10:59 +0000 (08:10 +0100)] 
decode: fix default-packet-size global variable

(cherry picked from commit a9a522fac3d2424d72e133d799be2644e3ac6df0)

5 years agoinit: Fix dropping privileges in nflog runmode 4539/head
Timo Sigurdsson [Mon, 3 Feb 2020 22:17:17 +0000 (23:17 +0100)] 
init: Fix dropping privileges in nflog runmode

Using the run-as configuration option with the nflog capture method
results in the following error during the startup of suricata:
[ERRCODE: SC_ERR_NFLOG_BIND(248)] - nflog_bind_pf() for AF_INET failed

This is because SCDropMainThreadCaps does not have any capabilities
defined for the nflog runmode (unlike other runmodes). Therefore, apply
the same capabilities to the nflog runmode that are already defined for
the nfqueue runmode. This has been confirmed to allow suricata start
and drop its privileges in the nflog runmode.

Fixes redmine issue #3265.

Signed-off-by: Timo Sigurdsson <public_timo.s@silentcreek.de>
(cherry picked from commit 1262ecbde0c2130f3fd4ca336cd2646828de9391)

5 years agoafl: fix compilation
Victor Julien [Fri, 7 Feb 2020 13:50:39 +0000 (14:50 +0100)] 
afl: fix compilation

(cherry picked from commit f05c12b70f78d5369ec19c5759db033fb103f052)

5 years agosource-pcap-file: Pcap File Init Failure Handling (#1694) 4530/head
Danny Browning [Mon, 18 Feb 2019 16:57:21 +0000 (09:57 -0700)] 
source-pcap-file: Pcap File Init Failure Handling (#1694)

Better handle case where pcap file receive thread fails to initialize. Allow
initialize to complete, but terminate the thread quickly. Delay exiting
unix socket runmode as late as possible.

(cherry picked from commit c0ab45aa6fbe1a299facf45e34ba2bcb3d76ce75)

5 years agotravis: remove cocci and macos builds 4515/head
Jason Ish [Thu, 30 Jan 2020 16:20:38 +0000 (10:20 -0600)] 
travis: remove cocci and macos builds

These tests are covered by Github actions and removing
them may speed up the Travis builds to get results sooner.

Its still worth keeping some of these builds as they test
more compile time options than the Github Actions currently
do.

Backport of 222a81f85dfea32f518f68eda51d9f45e1bcc46a.

5 years agorust: remove unnecessary parentheses (Rust 1.40 fixup) 4512/head
Jason Ish [Thu, 19 Dec 2019 17:02:56 +0000 (11:02 -0600)] 
rust: remove unnecessary parentheses (Rust 1.40 fixup)

Rust 1.40 in strict mode will now fail the build on the
presence of unnecessary parentheses.

warning: unnecessary parentheses around type
  --> src/smb/smb2_ioctl.rs:41:12
   |
41 |         -> (&mut SMBTransaction)
   |            ^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
   |
   = note: `#[warn(unused_parens)]` on by default

(cherry picked from commit 5ee8323028aeb0d2c4926bae3bf8dafd05215d56)

5 years agomodbus: Update correct TX flags
Jeff Lucovsky [Sat, 11 Jan 2020 14:49:55 +0000 (09:49 -0500)] 
modbus: Update correct TX flags

(cherry picked from commit d4428d94deba7ba5fafeb76505012492136b0519)

5 years agosmb: handle file transactions post-GAP
Victor Julien [Tue, 21 Jan 2020 11:20:40 +0000 (12:20 +0100)] 
smb: handle file transactions post-GAP

After a GAP all normal transactions are closed. File transactions
are left open as they can handle GAPs in principle. However, the
GAP might have contained the closing of a file and therefore it
may remain active until the end of the flow.

This patch introduces a time based heuristic for these transactions.
After the GAP all file transactions are stamped with the current
timestamp. If 60 seconds later a file has seen no update, its marked
as closed.

This is meant to fix resource starvation issues observed in long
running SMB sessions where packet loss was causing GAPs.

5 years agoflow: expose last time as a function
Jason Ish [Tue, 3 Dec 2019 20:10:45 +0000 (14:10 -0600)] 
flow: expose last time as a function

This function returns the individual components
of the timeval in output pointers making it suitable
for use over Rust FFI.

5 years agoconfigure.ac: fix --disable-geoip 4447/head
Fabrice Fontaine [Sun, 6 Oct 2019 07:53:23 +0000 (09:53 +0200)] 
configure.ac: fix --disable-geoip

$enableval should be used to know if the user has passed --enable-geoip
or --disable-geoip

Fixes:
 - http://autobuild.buildroot.org/results/a7a34f760ae5fe0922fdb720b8234dbcd85ed222

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
(cherry picked from commit 61becb29bf2bcce5febd7f98e09b0006d217c8cb)

5 years agogithub-ci: use container for 18.04 build
Jason Ish [Fri, 13 Dec 2019 15:14:35 +0000 (09:14 -0600)] 
github-ci: use container for 18.04 build

As the action runs natively on 18.04 we were not explicitly
setting a container, but this means we're using what GitHub
provides us as a default state which might be broken. Instead
use the standard Ubuntu 18.04 container.

(cherry picked from commit b9515671be598c89badf1fb5d2652497d493bcd3)

5 years agochangelog: update for 4.1.6 suricata-4.1.6
Victor Julien [Fri, 13 Dec 2019 12:47:04 +0000 (13:47 +0100)] 
changelog: update for 4.1.6

5 years agodetect/asn1: fix offset bounds checking
Victor Julien [Sun, 3 Nov 2019 08:50:14 +0000 (09:50 +0100)] 
detect/asn1: fix offset bounds checking

(cherry picked from commit 627cc23769dc574ca13e6fd6e1af1ab34b5bb575)

5 years agoipv4: continue parsing options after invalid option
Jason Ish [Thu, 14 Nov 2019 20:56:43 +0000 (14:56 -0600)] 
ipv4: continue parsing options after invalid option

As long as an option has a valid length, we can continue
parsing the options after an invalid one.

(cherry picked from commit 8609939e60cdd52dc1745e2eeb5dc3db275acd13)

5 years agoipv4: fail packet decoding on bad ipv4 option length
Jason Ish [Thu, 14 Nov 2019 17:34:56 +0000 (11:34 -0600)] 
ipv4: fail packet decoding on bad ipv4 option length

Currently all failures in IPv4 option decode are ignore with
respect to continuing to handle the packet.

Change this to fail, and abort handling the packet if the
option length is invalid.

Ticket 3328:
https://redmine.openinfosecfoundation.org/issues/3328

(cherry picked from commit df8db1ddb0736300bad4a7fee811d333ab77cb54)

5 years agodecode: Change return type of IPv4 and TCP options decode
Jeff Lucovsky [Tue, 26 Mar 2019 21:30:09 +0000 (14:30 -0700)] 
decode: Change return type of IPv4 and TCP options decode

The return value from the options decoder in TCP and IPv4 is ignored.
This commit changes the return type of the function to `void` and
modifies existing return points to return without a value.

When an error occurs, the packet state is being set to indicate whether
it's valid or not and the existing return value is never used.

(cherry picked from commit 8e464530ef9c788bb5482ff8806aadb4001c4d43)

5 years agostream: reject broken ACK packets
Victor Julien [Thu, 21 Nov 2019 15:10:21 +0000 (16:10 +0100)] 
stream: reject broken ACK packets

Fix evasion posibility by rejecting packets with a broken ACK field.
These packets have a non-0 ACK field, but do not have a ACK flag set.

Bug #3324.

Reported-by: Nicolas Adba
(cherry picked from commit fa692df37a796c3330c81988d15ef1a219afc006)

5 years agostream: fix SYN_SENT RST/FIN injection
Victor Julien [Thu, 21 Nov 2019 13:47:04 +0000 (14:47 +0100)] 
stream: fix SYN_SENT RST/FIN injection

RST injection during the SYN_SENT state could trick Suricata into marking
a session as CLOSED. The way this was done is: using invalid TSECR value
in RST+ACK packet. The ACK was needed to force Linux into considering the
TSECR value and compare it to the TSVAL from the SYN packet.

The second works only against Windows. The client would not use a TSVAL
but the RST packet would. Windows will reject this, but Suricata considered
the RST valid and triggered the CLOSED logic.

This patch addresses both. When the SYN packet used timestamp support
the timestamp of incoming packet is validated. Otherwise, packet responding
should not have a timestamp.

Bug #3286

Reported-by: Nicolas Adba
(cherry picked from commit 9f0294fadca3dcc18c919424242a41e01f3e8318)

5 years agoconfigure: require libhtp 0.5.32 4442/head
Victor Julien [Fri, 13 Dec 2019 10:12:15 +0000 (11:12 +0100)] 
configure: require libhtp 0.5.32

(cherry picked from commit 9bcc1118e18076ac401d9fd47ee20e8fdc9837f3)

5 years agohtp: close request only from request side
Victor Julien [Wed, 11 Dec 2019 19:57:57 +0000 (20:57 +0100)] 
htp: close request only from request side

This allows the response side to keep going for just
a bit longer.

(cherry picked from commit 040aff5197ba19caef1113c1c5c323eef72a9f69)

5 years agostream: in IDS mode, call app-layer at EOF
Victor Julien [Wed, 11 Dec 2019 19:57:07 +0000 (20:57 +0100)] 
stream: in IDS mode, call app-layer at EOF

On stream end call app-layer with empty message in IDS mode.

(cherry picked from commit 77539e08fc8a4e548035663c46fc5f9bea8188d3)

5 years agostats: fix stats not always syncing in flow timeout 4439/head
Victor Julien [Thu, 5 Dec 2019 08:20:31 +0000 (09:20 +0100)] 
stats: fix stats not always syncing in flow timeout

(cherry picked from commit 83bbe287e7d2713669990dee41181d33f7cd571b)

5 years agothreading: add debug validation for stale packets
Victor Julien [Mon, 25 Nov 2019 18:45:42 +0000 (19:45 +0100)] 
threading: add debug validation for stale packets

(cherry picked from commit 58b9a2dc2135e491307f6aeb32d007ee325ca458)

5 years agothreading: fix shutdown race condition
Victor Julien [Fri, 8 Nov 2019 11:09:24 +0000 (12:09 +0100)] 
threading: fix shutdown race condition

A BUG_ON statement would seemingly randomly trigger during the threading
shutdown logic. After a packet thread reached the THV_RUNNING_DONE state,
it would sometimes still receive flow timeout packets which would then
remain unprocessed.

1 main:   TmThreadDisableReceiveThreads(); <- stop capturing packets
2 worker: -> TmThreadTimeoutLoop (THV_FLOW_LOOP) phase starts
3 main:   FlowForceReassembly();           <- inject packets from flow engine
4 main:   TmThreadDisablePacketThreads();  <- then disable packet threads
5 main:   -> checks if 'worker' is ready processing packets
6 main:   -> sends THV_KILL to worker
7 worker: breaks out of TmThreadTimeoutLoop and changes to THV_RUNNING_DONE.

Part of the problem was with (5) above. When checking if the worker was
already done with its work, TmThreadDisablePacketThreads would not consider
the injected flow timeout packets. The second part of the problem was with (7),
where the worker checked if it was ready with the TmThreadTimeoutLoop in a
thread unsafe way.

As a result TmThreadDisablePacketThreads would not wait long enough for the
worker(s) to finish its work and move the threads to the THV_RUNNING_DONE
phase by issuing the THV_KILL command.

When waiting for packet processing threads to process all in-flight packets,
also consider the 'stream_pq'. This will have received the flow timeout
packets.

Bug #1871.

(cherry picked from commit fe9aeed0f0e65da7e7f61b5722580efc86f6355a)

5 years agothreading: fix flow timeout loop race
Victor Julien [Fri, 8 Nov 2019 10:35:02 +0000 (11:35 +0100)] 
threading: fix flow timeout loop race

(cherry picked from commit 825173a2baa988ab51ded416811070363f945f7d)

5 years agothreads: improve flow timeout loop
Victor Julien [Wed, 12 Jun 2019 07:56:26 +0000 (09:56 +0200)] 
threads: improve flow timeout loop

Improve thread safety and remove BUG_ON

(cherry picked from commit 92d38683ce8271e5550c1fcc5be6a2e9258a5207)

5 years agothreading: improve thread queues checking by dumping more info
Victor Julien [Sun, 3 Nov 2019 09:37:42 +0000 (10:37 +0100)] 
threading: improve thread queues checking by dumping more info

(cherry picked from commit 56354afd4113c38a72042dd5a5fa3f2b91c2b5b2)