]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
9 years agorule grouping: speed up port based grouping
Victor Julien [Mon, 26 Oct 2015 16:26:49 +0000 (17:26 +0100)] 
rule grouping: speed up port based grouping

Create a hash table of unique DetectPort objects before trying to
create a unique list of these objects. This safes a lot of cycles
in the creation of the list.

9 years agompm: consify packet/stream search
Victor Julien [Mon, 26 Oct 2015 16:04:47 +0000 (17:04 +0100)] 
mpm: consify packet/stream search

9 years agodetect/mpm: unify packet/stream mpm_ctx pointers
Victor Julien [Mon, 26 Oct 2015 13:18:37 +0000 (14:18 +0100)] 
detect/mpm: unify packet/stream mpm_ctx pointers

SGH's for tcp and udp are now always only per proto and per direction.
This means we can simply reuse the packet and stream mpm pointers.

The SGH's for the other protocols already used a directionless catch
all mpm pointer.

9 years agohttp_raw_header: improve mpm progress handling
Victor Julien [Wed, 21 Oct 2015 06:59:04 +0000 (08:59 +0200)] 
http_raw_header: improve mpm progress handling

9 years agodetect: optimize sgh layout
Victor Julien [Wed, 21 Oct 2015 06:35:24 +0000 (08:35 +0200)] 
detect: optimize sgh layout

9 years agodetect: remove unused content minlen tracking
Victor Julien [Wed, 21 Oct 2015 06:32:00 +0000 (08:32 +0200)] 
detect: remove unused content minlen tracking

9 years agompm: optimize calls
Victor Julien [Wed, 21 Oct 2015 06:19:21 +0000 (08:19 +0200)] 
mpm: optimize calls

For all mpm wrapper functions, check minlen vs the input buffer to see
if we can bypass the mpm search.

Next to this, make all the function inline. Also constify the input and
do other minor cleanups.

9 years agohttp_uri: mpm cleanup. Use mpm_ctx's minlen
Victor Julien [Wed, 21 Oct 2015 05:36:48 +0000 (07:36 +0200)] 
http_uri: mpm cleanup. Use mpm_ctx's minlen

9 years agompm: cleanup: move mpm funcs into buffer specific files
Victor Julien [Tue, 20 Oct 2015 15:49:32 +0000 (17:49 +0200)] 
mpm: cleanup: move mpm funcs into buffer specific files

9 years agompm: cleanup, remove unused structs and prototypes
Victor Julien [Tue, 20 Oct 2015 08:55:41 +0000 (10:55 +0200)] 
mpm: cleanup, remove unused structs and prototypes

9 years agompm: remove unused structure
Victor Julien [Tue, 20 Oct 2015 08:49:10 +0000 (10:49 +0200)] 
mpm: remove unused structure

9 years agoprofiling: output post-prefilter matches
Victor Julien [Mon, 19 Oct 2015 15:39:57 +0000 (17:39 +0200)] 
profiling: output post-prefilter matches

Dump a json record containing all sigs that need to be inspected after
prefilter. Part of profiling. Only dump if threshold is met, which is
currently set by:

 --set detect.profiling.inspect-logging-threshold=200

A file called packet_inspected_rules.json is created in the default
log dir.

9 years agodetect: move sm_list to string funcs to parser code
Victor Julien [Tue, 1 Mar 2016 16:42:40 +0000 (17:42 +0100)] 
detect: move sm_list to string funcs to parser code

9 years agoprofiling: initial rulegroup tracking
Victor Julien [Fri, 16 Oct 2015 22:21:00 +0000 (00:21 +0200)] 
profiling: initial rulegroup tracking

Per rule group tracking of checks, use of lists, mpm matches,
post filter counts.

Logs SGH id so it can be compared with the rule_group.json output.

Implemented both in a human readable text format and a JSON format.

9 years agodetect: assign id to sgh
Victor Julien [Tue, 27 Oct 2015 12:34:55 +0000 (13:34 +0100)] 
detect: assign id to sgh

9 years agodetect: shrink sgh
Victor Julien [Thu, 15 Oct 2015 13:22:44 +0000 (15:22 +0200)] 
detect: shrink sgh

Turn list of mpm_ctx pointers into a union so that we don't waste
space. The sgh's for tcp and udp are in one direction only, so the
ts and tc ones are now in the union.

9 years agodetect: move app_mpms array to init data
Victor Julien [Thu, 15 Oct 2015 12:52:01 +0000 (14:52 +0200)] 
detect: move app_mpms array to init data

9 years agompm: unify & localize mpm pattern (id) handling
Victor Julien [Thu, 15 Oct 2015 08:31:05 +0000 (10:31 +0200)] 
mpm: unify & localize mpm pattern (id) handling

So far, the patterns as passed to the mpm's would use global id's that
were shared among all buffers, directions. This would lead to a fairly
large pattern id space. As the mpm algo's use the pattern id's to
prevent duplicate matching through a pattern id based bitarray,
shrinking this space will optimize performance.

This patch implements this. It sets a flag before adding the pattern
to the mpm ctx, instructing the mpm to ignore the provided pid and
handle pids management itself. This leads to a shrinking of the
bitarray size.

This is made possible by the previous work that removes the pid logic
from the code.

Next to this, this patch moves the pattern setup stage to common util
functions. This avoids code duplication.

Update ac, ac-bs and ac-ks to use this.

9 years agompm: improve negated mpm
Victor Julien [Thu, 1 Oct 2015 11:11:44 +0000 (13:11 +0200)] 
mpm: improve negated mpm

The idea is: if mpm is negated, it's both on mpm and nonmpm sid lists
and we can kick it out in that case during the merge sort.

It only works for patterns that are 'independent'. This means that the
rule doesn't need to only match if the negated mpm pattern is limited
to the first 10 bytes for example.

Or more generally, an negated mpm pattern that has depth, offset,
distance or within settings can't be handled this way. These patterns
are not added to the mpm at all, but just to to non-mpm list. This
makes sense as they will *always* need manual inspection.

Similarly, a pattern that is 'chopped' always needs validation. This
is because in this case we only inspect a part of the final pattern.

9 years agodetect: remove signature pattern id reference
Victor Julien [Tue, 13 Oct 2015 12:56:01 +0000 (14:56 +0200)] 
detect: remove signature pattern id reference

9 years agompm: remove unused pmq merge function
Victor Julien [Tue, 13 Oct 2015 08:39:54 +0000 (10:39 +0200)] 
mpm: remove unused pmq merge function

9 years agodetect: remove stream pmq array
Victor Julien [Tue, 13 Oct 2015 08:27:26 +0000 (10:27 +0200)] 
detect: remove stream pmq array

9 years agodetect mpm: mpm store cleanup
Victor Julien [Tue, 13 Oct 2015 06:49:23 +0000 (08:49 +0200)] 
detect mpm: mpm store cleanup

Move all rule modification to the fast_pattern assigment.

9 years agodetect mpm: fast_pattern assignment cleanup
Victor Julien [Tue, 13 Oct 2015 06:33:27 +0000 (08:33 +0200)] 
detect mpm: fast_pattern assignment cleanup

9 years agodetect mpm: remove unused mpm flags
Victor Julien [Tue, 13 Oct 2015 06:44:45 +0000 (08:44 +0200)] 
detect mpm: remove unused mpm flags

9 years agodetect address: remove unused features
Victor Julien [Mon, 12 Oct 2015 19:54:32 +0000 (21:54 +0200)] 
detect address: remove unused features

9 years agodetect-port: cleanup
Victor Julien [Mon, 12 Oct 2015 19:48:41 +0000 (21:48 +0200)] 
detect-port: cleanup

9 years agodetect: remove unused dport sgh hash
Victor Julien [Mon, 12 Oct 2015 19:33:44 +0000 (21:33 +0200)] 
detect: remove unused dport sgh hash

9 years agodetect: clean up sgh's at detect engine free
Victor Julien [Mon, 12 Oct 2015 18:05:42 +0000 (20:05 +0200)] 
detect: clean up sgh's at detect engine free

9 years agodetect: remove unused flag
Victor Julien [Mon, 12 Oct 2015 16:39:57 +0000 (18:39 +0200)] 
detect: remove unused flag

9 years agodetect sgh: remove unused field
Victor Julien [Mon, 12 Oct 2015 16:21:42 +0000 (18:21 +0200)] 
detect sgh: remove unused field

9 years agodetect: free lookup structures
Victor Julien [Mon, 12 Oct 2015 15:49:25 +0000 (17:49 +0200)] 
detect: free lookup structures

9 years agodetect: output sgh stats
Victor Julien [Wed, 30 Sep 2015 07:59:05 +0000 (09:59 +0200)] 
detect: output sgh stats

Output stats for the rule groups into a json format.

9 years agodetect: add list id to string funcs
Victor Julien [Fri, 9 Oct 2015 08:12:11 +0000 (10:12 +0200)] 
detect: add list id to string funcs

9 years agompm: remove pattern id logic
Victor Julien [Mon, 12 Oct 2015 08:15:16 +0000 (10:15 +0200)] 
mpm: remove pattern id logic

9 years agompm: ac-bs use internal pattern id tracking
Victor Julien [Mon, 12 Oct 2015 08:41:57 +0000 (10:41 +0200)] 
mpm: ac-bs use internal pattern id tracking

9 years agompm: ac use internal pattern id tracking
Victor Julien [Mon, 12 Oct 2015 08:39:16 +0000 (10:39 +0200)] 
mpm: ac use internal pattern id tracking

9 years agosmtp: use rule_id mpm support instead of pattern id
Victor Julien [Mon, 12 Oct 2015 08:14:25 +0000 (10:14 +0200)] 
smtp: use rule_id mpm support instead of pattern id

9 years agoproto detect: in mpm switch to rule id
Victor Julien [Sat, 10 Oct 2015 15:10:13 +0000 (17:10 +0200)] 
proto detect: in mpm switch to rule id

Use the rule id API instead of pattern id API.

9 years agodetect: simplify negated mpm handling
Victor Julien [Sat, 10 Oct 2015 12:36:45 +0000 (14:36 +0200)] 
detect: simplify negated mpm handling

9 years agodetect grouping: multiple whitelist conditions
Victor Julien [Thu, 1 Oct 2015 13:33:42 +0000 (15:33 +0200)] 
detect grouping: multiple whitelist conditions

Instead of the binary yes/no whitelisting used so far, use different
values for different sorts of whitelist reasons. The port list will
be sorted by whitelist value first, then by rule count.

The goal is to whitelist groups that have weak sigs:

 - 1 byte pattern groups

 - SYN sigs

    Rules that check for SYN packets are mostly scan detection rules.
    They will be checked often as SYN packets are very common.

    e.g. alert tcp any any -> any 22 (flags:S,12; sid:123;)

    This patch adds whitelisting for SYN-sigs, so that the sigs end up
    in as unique groups as possible.

 - negated mpm sigs

    Currently negated mpm sigs are inspected often, so they are quite
    expensive. For this reason, try to whitelist them.

These values are set during 'stage 1', rule preprocessing.

9 years agodetect grouping: port based group whitelisting
Victor Julien [Wed, 30 Sep 2015 16:26:00 +0000 (18:26 +0200)] 
detect grouping: port based group whitelisting

Whitelist some ports in grouping to make sure they get their own group.

9 years agodetect grouping: warn on and fix up bad sigs
Victor Julien [Wed, 7 Oct 2015 05:08:02 +0000 (07:08 +0200)] 
detect grouping: warn on and fix up bad sigs

Only inspect directionless SYN scan sigs toserver. Issue a warning for
those rules.

9 years agodetect: split non-mpm list into syn/nosyn
Victor Julien [Thu, 1 Oct 2015 17:29:45 +0000 (19:29 +0200)] 
detect: split non-mpm list into syn/nosyn

Since SYN inspecting rules are expensive, this patch splits the
'non-mpm' list (i.e. the rules that are always considered) into
a 'syn' and 'non-syn' list. The SYN list is only inspected if the
packet has the SYN flag set, otherwise the non-syn list is used.

The syn-list contains _all_ rules. The non-syn list contains all
minus the rules requiring the SYN bit in a packet.

9 years agompm: constify search func args
Victor Julien [Wed, 7 Oct 2015 04:48:44 +0000 (06:48 +0200)] 
mpm: constify search func args

9 years agodetect: mpm store frees mpm_ctx' it owns
Victor Julien [Tue, 6 Oct 2015 13:04:33 +0000 (15:04 +0200)] 
detect: mpm store frees mpm_ctx' it owns

9 years agodetect: use mpm store for app layer mpms
Victor Julien [Mon, 5 Oct 2015 17:15:58 +0000 (19:15 +0200)] 
detect: use mpm store for app layer mpms

Rework app-layer mpm setup and registration to make this possible.

9 years agodetect: mpm deduplication
Victor Julien [Mon, 5 Oct 2015 08:25:03 +0000 (10:25 +0200)] 
detect: mpm deduplication

Create hash for mpm's that we can reuse. Have packet/stream mpms
use this.

9 years agodetect: remove old unused code
Victor Julien [Sat, 3 Oct 2015 15:02:30 +0000 (17:02 +0200)] 
detect: remove old unused code

9 years agodetect: set new defaults for grouping
Victor Julien [Fri, 2 Oct 2015 18:29:55 +0000 (20:29 +0200)] 
detect: set new defaults for grouping

9 years agodetect: rename groupings vars
Victor Julien [Fri, 2 Oct 2015 18:23:50 +0000 (20:23 +0200)] 
detect: rename groupings vars

9 years agodetect: remove unused grouping settings
Victor Julien [Fri, 2 Oct 2015 18:16:25 +0000 (20:16 +0200)] 
detect: remove unused grouping settings

9 years agodetect: make port grouping use config limits
Victor Julien [Wed, 30 Sep 2015 10:41:42 +0000 (12:41 +0200)] 
detect: make port grouping use config limits

9 years agodetect: change port grouping
Victor Julien [Wed, 30 Sep 2015 09:56:42 +0000 (11:56 +0200)] 
detect: change port grouping

Update port grouping logic. Previously it would create one consistent
list w/o overlap. It largely still does this, except for the 'catch
all' port group at the end of the list. This port group contains all
the sigs that didn't fit into the other groups.

9 years agodetect: sort/group port sigs
Victor Julien [Tue, 29 Sep 2015 16:42:16 +0000 (18:42 +0200)] 
detect: sort/group port sigs

9 years agodetect: display unique sgh count
Victor Julien [Tue, 29 Sep 2015 15:40:59 +0000 (17:40 +0200)] 
detect: display unique sgh count

9 years agodetect: group proto sghs
Victor Julien [Tue, 29 Sep 2015 14:46:21 +0000 (16:46 +0200)] 
detect: group proto sghs

9 years agodetect-mpm: make sgh setup proto aware
Victor Julien [Mon, 28 Sep 2015 14:03:48 +0000 (16:03 +0200)] 
detect-mpm: make sgh setup proto aware

Allow multi-proto, multi-direction sgh's.

9 years agodetect: remove obsolete grouping code
Victor Julien [Tue, 29 Sep 2015 11:20:20 +0000 (13:20 +0200)] 
detect: remove obsolete grouping code

9 years agodetect: debug output
Victor Julien [Mon, 28 Sep 2015 21:20:03 +0000 (23:20 +0200)] 
detect: debug output

9 years agodetect: per port and proto rule grouping
Victor Julien [Fri, 7 Nov 2014 22:14:26 +0000 (23:14 +0100)] 
detect: per port and proto rule grouping

Replace tree based approach for rule grouping with a per port (tcp/udp)
and per protocol approach.

Grouping now looks like:

               +----+
               |icmp+--->
               +----+
               |gre +--->
               +----+
               |esp +--->
               +----+
          other|... |
        +----->-----+
        |      |N   +--->
        |      +----+
        |
        | tcp  +----+   +----+
        +----->+ 80 +-->+ 139+-->
        |      +----+   +----+
        |
        | udp  +----+   +----+
    +---+----->+ 53 +-->+ 135+-->
    |          +----+   +----+
    |toserver
+--->
    |toclient
    |
    +--->

So the first 'split' in the rules is the direction: toserver or toclient.
Rules that don't have a direction, are in both branches.

Then the split is between tcp/udp and the other protocols. For tcp and
udp port lists are used. For the other protocols, grouping is simply per
protocol.

The ports used are the destination ports for toserver sigs and source
ports for toclient sigs.

9 years agodetect: track direction and ipproto of sgh
Victor Julien [Mon, 28 Sep 2015 08:10:58 +0000 (10:10 +0200)] 
detect: track direction and ipproto of sgh

Each SGH has a unique ipproto and direction.

9 years agodetect: pass ipproto to rule grouping funcs
Victor Julien [Mon, 28 Sep 2015 08:00:36 +0000 (10:00 +0200)] 
detect: pass ipproto to rule grouping funcs

9 years agodetect: delay sgh cleanup
Victor Julien [Mon, 28 Sep 2015 14:02:15 +0000 (16:02 +0200)] 
detect: delay sgh cleanup

9 years agodetect: delay sgh mpm setup
Victor Julien [Mon, 28 Sep 2015 08:17:34 +0000 (10:17 +0200)] 
detect: delay sgh mpm setup

9 years agoStart rule inspect with mask check
Victor Julien [Fri, 7 Nov 2014 22:43:45 +0000 (23:43 +0100)] 
Start rule inspect with mask check

9 years agorule analyzer: add no/both direction warning
Victor Julien [Sun, 27 Sep 2015 08:33:48 +0000 (10:33 +0200)] 
rule analyzer: add no/both direction warning

9 years agodetect: SYN flags
Victor Julien [Wed, 7 Oct 2015 13:38:58 +0000 (15:38 +0200)] 
detect: SYN flags

Add funcs to see if a rule needs a SYN flag in the packet.

9 years agodetect: validate http_method pattern
Victor Julien [Fri, 9 Oct 2015 09:18:36 +0000 (11:18 +0200)] 
detect: validate http_method pattern

Leading and trailing spaces and tabs are invalid as these are not part
of the buffer as returned by libhtp.

9 years agodetect: remove dead code
Victor Julien [Mon, 5 Oct 2015 17:00:24 +0000 (19:00 +0200)] 
detect: remove dead code

9 years agodetect mpm: remove dead code
Victor Julien [Mon, 5 Oct 2015 10:40:57 +0000 (12:40 +0200)] 
detect mpm: remove dead code

9 years agodetect/mpm: remove unused max_id param from API
Victor Julien [Sat, 3 Oct 2015 15:57:27 +0000 (17:57 +0200)] 
detect/mpm: remove unused max_id param from API

9 years agodetect: constify mpm/detect funcs
Victor Julien [Mon, 28 Sep 2015 09:15:09 +0000 (11:15 +0200)] 
detect: constify mpm/detect funcs

9 years agompm: remove obsolete mpm algos
Victor Julien [Tue, 20 Oct 2015 08:19:40 +0000 (10:19 +0200)] 
mpm: remove obsolete mpm algos

Remove: ac-gfbs, wumanber, b2g, b3g.

9 years agompm: fix ac-ks compilation on cygwin
Victor Julien [Mon, 12 Oct 2015 10:49:06 +0000 (12:49 +0200)] 
mpm: fix ac-ks compilation on cygwin

9 years agodetect mpm: ac-tile/ac-ks default to single
Victor Julien [Sun, 20 Sep 2015 08:17:17 +0000 (10:17 +0200)] 
detect mpm: ac-tile/ac-ks default to single

Use sgh-mpm-context single is it is set to 'auto' when ac-ks is used.

9 years agoac-ks: 32bit fixes
Victor Julien [Mon, 12 Oct 2015 06:47:37 +0000 (08:47 +0200)] 
ac-ks: 32bit fixes

9 years agoac-ks: fix mem leaks
Victor Julien [Fri, 9 Oct 2015 14:21:17 +0000 (16:21 +0200)] 
ac-ks: fix mem leaks

9 years agompm: introduce ac-ks
Victor Julien [Sat, 19 Sep 2015 20:59:03 +0000 (22:59 +0200)] 
mpm: introduce ac-ks

Introduce 'ac-ks' or the Kenneth Steele AC implementation. It's
actually 'ac-tile' written by Ken for the Tilera platform. This
patch adds support for it on other architectures as well.

Enable ac-tile for other archs as 'ac-ks'.

Fix a bunch of OOB reads in the loops that triggered ASAN.

9 years agoOpen Suricata 3.1 development branch
Victor Julien [Mon, 4 Apr 2016 16:04:32 +0000 (18:04 +0200)] 
Open Suricata 3.1 development branch

9 years agoUpdate Changelog for 3.0.1 2093/head suricata-3.0.1
Victor Julien [Mon, 4 Apr 2016 10:15:12 +0000 (12:15 +0200)] 
Update Changelog for 3.0.1

9 years agoutil-decode-der: fix NULL dereference bug 1975/head
Mats Klepsland [Thu, 31 Mar 2016 14:15:26 +0000 (16:15 +0200)] 
util-decode-der: fix NULL dereference bug

Make sure that the length is not longer than the size of the buffer
provided.

9 years agoutil-decode-der: fix heap-buffer-overflow
Mats Klepsland [Thu, 31 Mar 2016 12:28:24 +0000 (14:28 +0200)] 
util-decode-der: fix heap-buffer-overflow

9 years agoapp-layer-tls-handshake: fix heap-buffer overflow
Mats Klepsland [Thu, 31 Mar 2016 12:21:21 +0000 (14:21 +0200)] 
app-layer-tls-handshake: fix heap-buffer overflow

Fix heap-buffer overflow that occurs when we are given repeatedly
certificates with the length of zero.

9 years agohyperscan: fix minor coverity warning 1358023 1970/head
Victor Julien [Thu, 31 Mar 2016 08:07:01 +0000 (10:07 +0200)] 
hyperscan: fix minor coverity warning 1358023

*** CID 1358023:  Null pointer dereferences  (REVERSE_INULL)
/src/util-mpm-hs.c: 860 in SCHSDestroyThreadCtx()
854         if (thr_ctx->scratch != NULL) {
855             hs_free_scratch(thr_ctx->scratch);
856             mpm_thread_ctx->memory_cnt--;
857             mpm_thread_ctx->memory_size -= thr_ctx->scratch_size;
858         }
859
>>>     CID 1358023:  Null pointer dereferences  (REVERSE_INULL)
>>>     Null-checking "mpm_thread_ctx->ctx" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
860         if (mpm_thread_ctx->ctx != NULL) {
861             SCFree(mpm_thread_ctx->ctx);
862             mpm_thread_ctx->ctx = NULL;
863             mpm_thread_ctx->memory_cnt--;
864             mpm_thread_ctx->memory_size -= sizeof(SCHSThreadCtx);
865         }

9 years agohyperscan: fix minor coverity warning 1358024
Victor Julien [Thu, 31 Mar 2016 08:04:44 +0000 (10:04 +0200)] 
hyperscan: fix minor coverity warning 1358024

*** CID 1358024:  Null pointer dereferences  (REVERSE_INULL)
/src/util-mpm-hs.c: 1043 in SCHSPrintInfo()
1037         printf("  SCHSPattern    %" PRIuMAX "\n", (uintmax_t)sizeof(SCHSPattern));
1038         printf("Unique Patterns: %" PRIu32 "\n", mpm_ctx->pattern_cnt);
1039         printf("Smallest:        %" PRIu32 "\n", mpm_ctx->minlen);
1040         printf("Largest:         %" PRIu32 "\n", mpm_ctx->maxlen);
1041         printf("\n");
1042
>>>     CID 1358024:  Null pointer dereferences  (REVERSE_INULL)
>>>     Null-checking "ctx" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
1043         if (ctx) {
1044             char *db_info = NULL;
1045             if (hs_database_info(pd->hs_db, &db_info) == HS_SUCCESS) {
1046                 printf("HS Database Info: %s\n", db_info);
1047                 SCFree(db_info);
1048             }

9 years agosource-pcap-file: fix stats not being reset
browner87 [Thu, 24 Mar 2016 16:55:34 +0000 (12:55 -0400)] 
source-pcap-file: fix stats not being reset

Fix for redmine #1737. Clears stats between each scanned PCAP instead of just
on load in Unix socket mode.

9 years agoFix for redmine bug 1737
browner87 [Wed, 23 Mar 2016 15:05:05 +0000 (11:05 -0400)] 
Fix for redmine bug 1737

PCAP stats not reset between files in Unix socket mode. Added a memset to the Global Init function to clear these stats.

9 years agobyte-extract: for string, default to base "dec" if not provided
Jason Ish [Wed, 30 Mar 2016 14:46:30 +0000 (08:46 -0600)] 
byte-extract: for string, default to base "dec" if not provided

For Snort compatibility, as Snort defaults to "dec" if not provided.

Fixed issue 1697:
https://redmine.openinfosecfoundation.org/issues/1697

9 years agodetect: fix potential deadlock during reload
Victor Julien [Wed, 30 Mar 2016 17:53:04 +0000 (19:53 +0200)] 
detect: fix potential deadlock during reload

If interrupted during the BreakLoop stage during reload, a deadlock
could happen.

9 years agodetect: fix small mem leak on duplicate sigs 1968/head
Victor Julien [Wed, 30 Mar 2016 07:39:46 +0000 (09:39 +0200)] 
detect: fix small mem leak on duplicate sigs

Direct leak of 80 byte(s) in 5 object(s) allocated from:
    #0 0x4c673b in __interceptor_malloc (/home/victor/dev/suricata/src/suricata+0x4c673b)
    #1 0xb7a425 in DetectEngineSignatureIsDuplicate /home/victor/dev/suricata/src/detect-parse.c:1715:10
    #2 0xb79390 in DetectEngineAppendSig /home/victor/dev/suricata/src/detect-parse.c:1836:19
    #3 0x86fe56 in DetectLoadSigFile /home/victor/dev/suricata/src/detect.c:357:15
    #4 0x815fee in ProcessSigFiles /home/victor/dev/suricata/src/detect.c:419:13
    #5 0x8139a8 in SigLoadSignatures /home/victor/dev/suricata/src/detect.c:499:15
    #6 0xfe435d in LoadSignatures /home/victor/dev/suricata/src/suricata.c:1979:9
    #7 0xfcd87e in main /home/victor/dev/suricata/src/suricata.c:2345:17
    #8 0x7fb66bf7cec4 in __libc_start_main /build/eglibc-3GlaMS/eglibc-2.19/csu/libc-start.c:287

9 years agohyperscan: add DrMemory suppressions 1966/head
Victor Julien [Tue, 29 Mar 2016 09:44:00 +0000 (11:44 +0200)] 
hyperscan: add DrMemory suppressions

9 years agompm: add Hyperscan integration
Justin Viiret [Tue, 15 Mar 2016 01:40:24 +0000 (12:40 +1100)] 
mpm: add Hyperscan integration

This adds an MPM implementation that uses the Hyperscan regex engine
library from Intel, accessible as the "hs" mpm-algo.

9 years agompm: pass offset, depth args to add functions
Justin Viiret [Tue, 15 Mar 2016 01:38:23 +0000 (12:38 +1100)] 
mpm: pass offset, depth args to add functions

MpmAddPatternCI and MpmAddPatternCS had arguments for offset and depth,
but these were not being passed in by the caller.

9 years agoutil-hash-lookup3: Add hashlittle_safe() variant
Justin Viiret [Mon, 28 Mar 2016 22:32:26 +0000 (09:32 +1100)] 
util-hash-lookup3: Add hashlittle_safe() variant

By default, hashlittle() will read off the end of the key, up to the
next four-byte boundary, although the data beyond the end of the key
doesn't affect the hash. This read causes uninitialized read warnings
from Valgrind and Address Sanitizer.

Here we add hashlittle_safe(), which avoids reading off the end of the
buffer (using the code inside the VALGRIND-guarded block in the original
hashlittle() implementation).

9 years agocapture: warn -i user if faster options are available
Victor Julien [Wed, 25 Jun 2014 14:16:30 +0000 (16:16 +0200)] 
capture: warn -i user if faster options are available

If af-packet, netmap or pfring are available, users should use those
for best performance.

9 years agonetmap: implement capture inject packet flag
Victor Julien [Sat, 26 Mar 2016 18:56:00 +0000 (19:56 +0100)] 
netmap: implement capture inject packet flag

9 years agodetect reload: generic packet injection for capture
Victor Julien [Wed, 23 Mar 2016 16:05:14 +0000 (17:05 +0100)] 
detect reload: generic packet injection for capture

Capture methods that are non blocking will still not generate packets
that go through the system if there is no traffic. Some maintenance
tasks, like rule reloads rely on packets to complete.

This patch introduces a new thread flag, THV_CAPTURE_INJECT_PKT, that
instructs the capture thread to create a fake packet.

The capture implementations can call the TmThreadsCaptureInjectPacket
utility function either with the packet they already got from the pool
or without a packet. In this case the util func will get it's own
packet.

Implementations for pcap, AF_PACKET and PF_RING.

9 years agodetect reload: call 'breakloop' on capture method
Victor Julien [Wed, 23 Mar 2016 15:16:41 +0000 (16:16 +0100)] 
detect reload: call 'breakloop' on capture method

Split wait loop into three steps:
- first insert pseudo packets
- 2nd nudge all capture threads to break out of their loop
- third, wait for the detection thread contexts to be used

Interupt capture more than once if needed

Move packet injection into util func

9 years agosignals: cleanup signal handling
Victor Julien [Thu, 24 Mar 2016 10:51:49 +0000 (11:51 +0100)] 
signals: cleanup signal handling

Simplify handling of USR2 signal. The SCLogInfo usage could lead to
dead locks as the SCLog API can do many complicated things including
memory allocations, syslog calls, libjansson message construction.

If an existing malloc call was interupted, it could lead to the
following dead lock:

 0  __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97
 1  0x0000003140c7d2df in _L_lock_10176 () from /lib64/libc.so.6
 2  0x0000003140c7ab83 in __libc_malloc (bytes=211543457408) at malloc.c:3655
 3  0x0000003140c80ec2 in __strdup (s=0x259ca40 "[%i] %t - (%f:%l) <%d> (%n) -- ") at strdup.c:43
 4  0x000000000059dd4a in SCLogMessageGetBuffer (tval=0x7fff52b47360, color=1, type=SC_LOG_OP_TYPE_REGULAR, buffer=0x7fff52b47370 "", buffer_size=2048,
    log_format=0x259ca40 "[%i] %t - (%f:%l) <%d> (%n) -- ", log_level=SC_LOG_INFO, file=0x63dd00 "suricata.c", line=287, function=0x640f50 "SignalHandlerSigusr2StartingUp", error_code=SC_OK,
    message=0x7fff52b47bb0 "Live rule reload only possible after engine completely started.") at util-debug.c:307
 5  0x000000000059e940 in SCLogMessage (log_level=SC_LOG_INFO, file=0x63dd00 "suricata.c", line=287, function=0x640f50 "SignalHandlerSigusr2StartingUp", error_code=SC_OK,
    message=0x7fff52b47bb0 "Live rule reload only possible after engine completely started.") at util-debug.c:549
 6  0x000000000057e374 in SignalHandlerSigusr2StartingUp (sig=12) at suricata.c:287
 7  <signal handler called>
 8  _int_malloc (av=0x3140f8fe80, bytes=<value optimized out>) at malloc.c:4751
 9  0x0000003140c7ab1c in __libc_malloc (bytes=296) at malloc.c:3657
 10 0x0000000000504d55 in FlowAlloc () at flow-util.c:60
 11 0x00000000004fd909 in FlowInitConfig (quiet=0 '\000') at flow.c:454
 12 0x0000000000584c8e in main (argc=6, argv=0x7fff52b4a3b8) at suricata.c:2300

This patch simply sets a variable and lets the main loop act on that.