]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
4 years agodetect/rules: Fix copy/paste error 5470/head
Jeff Lucovsky [Wed, 23 Sep 2020 12:15:41 +0000 (08:15 -0400)] 
detect/rules: Fix copy/paste error

This commit corrects a copy/paste error handling the `include-mpm-stats`
configuration setting.

(cherry picked from commit db9776af64dfd0872cb4374b01e9871dea2a03b5)

4 years agodetect/rules: Increase array size to remove SEGV
Jeff Lucovsky [Sat, 19 Sep 2020 12:47:56 +0000 (08:47 -0400)] 
detect/rules: Increase array size to remove SEGV

This commit changes the size of reporting variables to be dynamic based
on the buffer ids in use instead of a fixed value to address a SEGV when
the fixed value was less than the max buffer/type id in use.

(cherry picked from commit d911fb87b8c9bb496adebed03a7113ec0b6526d8)

4 years agohttp: error check htp_list_size
Victor Julien [Mon, 5 Oct 2020 06:17:19 +0000 (08:17 +0200)] 
http: error check htp_list_size

This avoids a potential casting to uint64_t of -1, leading to a very
high upper bound of the tx loop.

(cherry picked from commit e07a4393a9dc07d199a04540d0b54119ee95a2a5)

4 years agoapplayer: keep running detection on protocol change 5448/head
Philippe Antoine [Wed, 9 Sep 2020 08:09:33 +0000 (10:09 +0200)] 
applayer: keep running detection on protocol change

ie do not stop on first try if we do not have enough data

(cherry picked from commit 07cbdb32b3f6e63e2d08b29e6db0c0ac3d819a70)

4 years agosignature: checks for integer overflow in limits propagation
Philippe Antoine [Thu, 23 Jul 2020 09:26:16 +0000 (11:26 +0200)] 
signature: checks for integer overflow in limits propagation

(cherry picked from commit a99ad4c1e4251c8a4a667d613ccb1fb334a9b268)

4 years agodetect: checks for overflow when comparing signatures priorities
Philippe Antoine [Thu, 27 Aug 2020 15:11:10 +0000 (17:11 +0200)] 
detect: checks for overflow when comparing signatures priorities

(cherry picked from commit 16742394424e8c9654708fbc93b990b9ddc70dff)

4 years agosignature: checks for integer overflow in limits propagation
Philippe Antoine [Thu, 23 Jul 2020 09:26:16 +0000 (11:26 +0200)] 
signature: checks for integer overflow in limits propagation

(cherry picked from commit 61c327dd80f02484481cbea6d48168063ae90a69)

4 years agodetect: fix read overflow in DetectGetLastSMByListId
Philippe Antoine [Thu, 23 Jul 2020 11:28:57 +0000 (13:28 +0200)] 
detect: fix read overflow in DetectGetLastSMByListId

(cherry picked from commit 5c31383d1c9ecbd93f0eae4ef02ae17ff98bcbed)

4 years agodetect/asn1: Fixes definite long form parsing of length field
Emmanuel Thomspon [Thu, 9 Apr 2020 16:22:11 +0000 (12:22 -0400)] 
detect/asn1: Fixes definite long form parsing of length field

(cherry picked from commit a9f590b350196d06375a926a35c05b6927aead97)

4 years agosignature: adds file flag for file_data keyword 5358/head
Philippe Antoine [Fri, 1 May 2020 08:54:51 +0000 (10:54 +0200)] 
signature: adds file flag for file_data keyword

So that SigValidate can check if a protocol not supporting
files was set after this keyword

(cherry picked from commit e5d4332ede1201c44b40d655b51dcc0062d5cfc1)

4 years agonfs: check post-gap timeouts once a second at most
Victor Julien [Mon, 20 Jul 2020 12:30:39 +0000 (14:30 +0200)] 
nfs: check post-gap timeouts once a second at most

Based on 25f2efe97749611760e6e26d388b420091423732

(cherry picked from commit fc7cecb4ae820c098322bb1098cd20902fd84604)

4 years agonfs: update ts only if it changed
Victor Julien [Mon, 20 Jul 2020 12:18:52 +0000 (14:18 +0200)] 
nfs: update ts only if it changed

Based on 8aa380600da15b95e74a6649e6003a1c484c4ce0

(cherry picked from commit 5d65e5a7481628d533dd7d8fdedd675b46867d80)

4 years agonfs: fix 'dangling' files in lossy sessions
Victor Julien [Mon, 20 Jul 2020 12:49:59 +0000 (14:49 +0200)] 
nfs: fix 'dangling' files in lossy sessions

In case of lossy connections the NFS state would properly clean up
transactions, including file transactions. However for files the
state was never set to 'truncated', leading to files to stay 'active'.

This would lead these files staying in the NFS's state. In long running
sessions with lots of files this would lead to performance and memory
use issues.

This patch cleans truncates the file that was being transmitted when
a file transaction is being closed.

Based on 65e9a7c31cc68bdb1fb3e1412b0a56260265c608

(cherry picked from commit bcd416e6baf8475fc4a41830c16488a4225b8eba)

4 years agohtp: enforce body limits more exact 5333/head
Victor Julien [Thu, 4 Jun 2020 20:50:38 +0000 (22:50 +0200)] 
htp: enforce body limits more exact

(cherry picked from commit a4568a634d5df223a4caaed4552b54f9e4598c12)

4 years agodetect/content: Validate content byte array
Jeff Lucovsky [Thu, 11 Jun 2020 13:08:42 +0000 (09:08 -0400)] 
detect/content: Validate content byte array

This commit checks whether the content byte array is compatible with the
transforms, if any, for the rule.

(cherry picked from commit 051465ee74422eb7578bdb8ef92f76037d7c47ec)
(cherry picked from commit 6d169fa90982239c5717ae85ae986f22a324496f)

4 years agodetect: Add transform validation api
Jeff Lucovsky [Thu, 11 Jun 2020 13:07:43 +0000 (09:07 -0400)] 
detect: Add transform validation api

This commit extends the API with a function that validates arguments
against the transforms for the SM list (if any).

(cherry picked from commit 8f1a7111ed10f2b017d5190682a6961a1729942d)
(cherry picked from commit 0e1b58847b1980f80ed5a5b488a292704ad66f14)

4 years agodetect/transform: Add validation function
Jeff Lucovsky [Thu, 11 Jun 2020 13:05:08 +0000 (09:05 -0400)] 
detect/transform: Add validation function

This commit adds a function to pre-validate buffers. If a content
buffer contains whitespace, the validation fails.

(cherry picked from commit bc81474e3fb715b1ef110338676fc15de34744c0)
(cherry picked from commit 96bac523d3c6e55d5cf33ace1a0cbd7a469cf7e3)

4 years agodetect/transform: Add transform "validate" function
Jeff Lucovsky [Thu, 11 Jun 2020 12:31:55 +0000 (08:31 -0400)] 
detect/transform: Add transform "validate" function

This commit adds an (optional) entry for a validation function. The
validation function, if present, will be used during rule processing.

Its role is to determine if the arguments are compatible with the
transform. E.g., a content string of "this string has whitespace" is not
compatible with the `strip_whitespace` transform.

(cherry picked from commit 596875fa68af18746abbbd9e307d14a93f23c3f7)
(cherry picked from commit 00ffcf1012178a9dfeb1559ec826cde60273830b)

4 years agowindows: fix timestring timezone display
Victor Julien [Sat, 23 May 2020 18:57:21 +0000 (20:57 +0200)] 
windows: fix timestring timezone display

Bug: #3690
(cherry picked from commit bbdc11842d324005567bac5eafdea5fd0fc62688)

4 years agodetect/asn1: Fix relative_offset keyword option
Emmanuel Thompson [Tue, 28 Apr 2020 18:03:26 +0000 (14:03 -0400)] 
detect/asn1: Fix relative_offset keyword option

- Fix relative_offset keyword option to be relative in regards to the
last content match
- Change relative_offset to int32_t with bounds check to allow the full
range of the packet buffer size (uint16_t)
- Added checks for over/underflows
- Changed the offset type to uint16_t because the offset is applied to
the payload length, which is a uint16_t
- Adjusted test cases to work relative to the content match
- Added test case to verify bounds

(cherry picked from commit be3379f00e30fd4776c6a3a622c2b27ca60a92e1)

4 years agoredis: ensure a dump per second
Eric Leblond [Thu, 23 Jan 2020 12:30:29 +0000 (13:30 +0100)] 
redis: ensure a dump per second

In sync mode, Suricata was waiting to have batch size alerts before
logging them. This was introducing delay in some configuration with
low traffic.

(cherry picked from commit f5e2968f129737ccbd5f0ee8ae3776203714b229)

4 years agoredis: fix reconnect in batch mode
Eric Leblond [Thu, 23 Jan 2020 12:10:44 +0000 (13:10 +0100)] 
redis: fix reconnect in batch mode

In case of redis outage, the redis session was reset but the replies
were still fetch even if there is none replies in the new session.

(cherry picked from commit ec8eba28a8ec0b7cb6eba5291da0174e8ab018db)

4 years agofile-hash-common: fix rule_file truncation
Jason Ish [Fri, 26 Jun 2020 17:45:38 +0000 (11:45 -0600)] 
file-hash-common: fix rule_file truncation

Loading file hash lists uses dirname(3) on the
de_ctx->rule_file which modifies the contents,
removing the last part of the path. So on subsequent
calls the rule_file no longer contains the rule_file,
but instead just the directory name.

Mostly noticed when using "-S" with rule files outside
of the default-rule-path which requires more hunting for
the rule file.

(cherry picked from commit b8d1677b9ce25a2fe2e1d275518613f9c7a45548)

4 years agodoc: Fix spelling error
Jeff Lucovsky [Fri, 12 Jun 2020 12:37:51 +0000 (08:37 -0400)] 
doc: Fix spelling error

(cherry picked from commit 297f91479e356bcba9301448b0e274f7762d4ea1)

4 years agogeneral: Fix spelling error
Jeff Lucovsky [Fri, 12 Jun 2020 12:37:23 +0000 (08:37 -0400)] 
general: Fix spelling error

(cherry picked from commit 9c47b8c1bfb5aa06e077ef976a348bf5e2d09bba)

5 years agodnp3: fix buffer over read in responses parsing 5181/head
Philippe Antoine [Sun, 21 Jun 2020 20:22:47 +0000 (22:22 +0200)] 
dnp3: fix buffer over read in responses parsing

(cherry picked from commit d465bb86863acd4c0cd534f0748c5a2ef1283241)

5 years agooutput/tftp: Include common options 5140/head
Jeff Lucovsky [Mon, 29 Jun 2020 13:48:20 +0000 (09:48 -0400)] 
output/tftp: Include common options

This commit will cause common metadata values and the community id to be
included in log output when configured.

(cherry picked from commit 0bb62e0abb0b4956e71b232c4e4094fa2545e1f9)

5 years agooutput/smb: Include common output options
Jeff Lucovsky [Mon, 29 Jun 2020 13:50:21 +0000 (09:50 -0400)] 
output/smb: Include common output options

This commit will cause common metadata values and the community id to be
included in log output when configured.

(cherry picked from commit c590d6f4591fc8127afc3e1468b879b5f4999875)

5 years agooutput/dhcp: Include common output options
Jeff Lucovsky [Mon, 29 Jun 2020 13:50:53 +0000 (09:50 -0400)] 
output/dhcp: Include common output options

This commit will cause common metadata values and the community id to be
included in log output when configured.

(cherry picked from commit 7a939ae9c237b17b31afd3bf91dfa1701be882ea)

5 years agochangelog: update for 4.1.8 suricata-4.1.8
Victor Julien [Mon, 27 Apr 2020 18:39:15 +0000 (20:39 +0200)] 
changelog: update for 4.1.8

5 years agohtp: fix test after libhtp changes
Victor Julien [Mon, 27 Apr 2020 07:34:16 +0000 (09:34 +0200)] 
htp: fix test after libhtp changes

5 years agodetect/smtp: Refactor command check
Jeff Lucovsky [Fri, 17 Apr 2020 18:01:36 +0000 (14:01 -0400)] 
detect/smtp: Refactor command check

This commit refactors the code that matches reply with command.

Bug: #3676

5 years agoapp-layer/smtp: Improve RSET handling
Jeff Lucovsky [Thu, 16 Apr 2020 14:44:53 +0000 (10:44 -0400)] 
app-layer/smtp: Improve RSET handling

This commit improves how the parser handles the `RSET` command.
Termination of the transaction occurs when the `RSET` ack is seen (reply
code 250).

Bug: #3676

5 years agoenip: more precise probing parser
Philippe Antoine [Mon, 6 Apr 2020 15:22:33 +0000 (17:22 +0200)] 
enip: more precise probing parser

Bug: #3674

5 years agodetect/port: limit recursion in port parsing
Victor Julien [Tue, 14 Apr 2020 09:00:39 +0000 (11:00 +0200)] 
detect/port: limit recursion in port parsing

Bug: #3601

5 years agodetect/address: limit recursion during parsing
Victor Julien [Tue, 14 Apr 2020 06:01:49 +0000 (08:01 +0200)] 
detect/address: limit recursion during parsing

Allow a max depth of 64.

Bug: #3601

5 years agoleak: fixes leak in DetectAddressParse2
Philippe Antoine [Wed, 3 Jul 2019 13:26:08 +0000 (15:26 +0200)] 
leak: fixes leak in DetectAddressParse2

(cherry picked from commit 19ab85f17e878dc237695be5f61b3fb269749eab)

5 years agodetect/address: minor cleanups
Victor Julien [Tue, 14 Apr 2020 06:01:37 +0000 (08:01 +0200)] 
detect/address: minor cleanups

5 years agodecode: cleanup packet properly on bad packets
Victor Julien [Sun, 5 Apr 2020 12:35:29 +0000 (14:35 +0200)] 
decode: cleanup packet properly on bad packets

In case of bad IPv4, TCP or UDP, the per packet ip4vars/tcpvars/udpvar
structures would not be cleaned up because the cleanup depends on the
'header' pointer being set, but the error handling would unset that.

This could mean these structures were already filled with values before
the error was detected. As packets were recycled, the next packet decoding
would use this unclean structure.

To make things worse these structures are part of unions. IPv4/IPv6 and
TCP/ICMPv4/ICMPv6 share the same memory location.

LibFuzzer+UBSAN found this both locally and in Oss-Fuzz:

decode-ipv6.c:654:9: runtime error: load of value 6, which is not a valid value for type 'bool'
    #0 0x6146f0 in DecodeIPV6 /src/suricata/src/decode-ipv6.c:654:9
    #1 0x617e96 in DecodeNull /src/suricata/src/decode-null.c:70:13
    #2 0x9dd8a4 in DecodePcapFile /src/suricata/src/source-pcap-file.c:412:9
    #3 0x4c8ed2 in LLVMFuzzerTestOneInput /src/suricata/src/tests/fuzz/fuzz_sigpcap.c:158:25
    #4 0x457e51 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:556:15
    #5 0x457575 in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:470:3
    #6 0x459917 in fuzzer::Fuzzer::MutateAndTestOne() /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:698:19
    #7 0x45a6a5 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:830:5
    #8 0x448728 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:824:6
    #9 0x472552 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:19:10
    #10 0x7ff0d097b82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #11 0x41bde8 in _start (/out/fuzz_sigpcap+0x41bde8)

Bug: #3610

5 years agossl: don't say we consumed bytes if we didn't consume them
Victor Julien [Fri, 21 Feb 2020 19:07:19 +0000 (20:07 +0100)] 
ssl: don't say we consumed bytes if we didn't consume them

5 years agossl: fix handshake cert buffer sizing
Victor Julien [Fri, 3 Apr 2020 15:03:47 +0000 (17:03 +0200)] 
ssl: fix handshake cert buffer sizing

'trec' buffer was not grown properly when it was checked as too small.
After this it wasn't checked again so that copying into the buffer could
overflow it.

Bug: #3608

5 years agoftp: FTPParseResponse bufferizes lines 4891/head
Philippe Antoine [Mon, 16 Mar 2020 13:46:51 +0000 (14:46 +0100)] 
ftp: FTPParseResponse bufferizes lines

Protects against evasion by TCP packet splitting

The problem arised if the FTP response is split on multiple packets

The fix is to bufferize the content, until we get a complete line

5 years agodetect: refactoring parsing of ip range 4889/head
Philippe Antoine [Sat, 25 Apr 2020 09:38:53 +0000 (11:38 +0200)] 
detect: refactoring parsing of ip range

To optimize first netmask

(cherry picked from commit ae102ca0961fddd54c1f7d07b8772d43d06f3f41)

5 years agosignature: minimizes ip CIDR for ip range
Philippe Antoine [Wed, 22 Apr 2020 07:54:49 +0000 (09:54 +0200)] 
signature: minimizes ip CIDR for ip range

Example leading to over allocation is 41.232.107.2-43.252.37.6

(cherry picked from commit 8ca9c0e8f04598ebcbe72bafce1512b8fe2f554a)

5 years agofastlog: fix unlikely memleak 4885/head
Victor Julien [Fri, 24 Apr 2020 08:27:18 +0000 (10:27 +0200)] 
fastlog: fix unlikely memleak

Fix memleak is case of alloc error during startup.

(cherry picked from commit 28837b203e45a8cc24b4b7b97f7bf9c5e118eb7b)

5 years agogithub-ci: check all commits on pr
Jason Ish [Tue, 21 Apr 2020 15:29:57 +0000 (09:29 -0600)] 
github-ci: check all commits on pr

On a pull request, attempt to compile all commits from
the base branch to the head of the PR branch.

The job is in a separate workflow file to limit it to
pull-requests only, as the base branch is not available
on push (something to look into).

(cherry picked from commit d955acc01cc0ce7bd5bf04b0e36a96fb55ee56f5)

5 years agodetect/lua: Unregister Lua object on free
Jeff Lucovsky [Fri, 24 Apr 2020 12:56:33 +0000 (08:56 -0400)] 
detect/lua: Unregister Lua object on free

This commit ensures that the LUA object is unregistered when the Lua
object is freed.

(cherry picked from commit e718ec674f3e113e627d44bfa547474d90d01d8e)

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)