]> git.ipfire.org Git - people/ms/suricata.git/log
people/ms/suricata.git
11 years agodecode: introduce DecodeThreadVarsFree
Victor Julien [Wed, 5 Mar 2014 11:18:57 +0000 (12:18 +0100)] 
decode: introduce DecodeThreadVarsFree

As a mirror of DecodeThreadVarsAlloc, DecodeThreadVarsFree is used
to free the memory that DecodeThreadVarsAlloc alloc'd, including
AppLayer storage.

11 years agoapp-layer: cleanups
Victor Julien [Wed, 5 Mar 2014 11:17:20 +0000 (12:17 +0100)] 
app-layer: cleanups

Clean up AppLayerParserThreadCtxAlloc and AppLayerParserThreadCtxFree.
Both used confusing variables in loops, with the wrong types.

11 years agoForce pidfile creation of --pidfile.
Jason Ish [Wed, 26 Mar 2014 15:51:27 +0000 (09:51 -0600)] 
Force pidfile creation of --pidfile.

A pidfile can be useful when not in daemon mode, for example
when running under a process supervisor.

11 years agojson: somewhere along the way IP/port pairs had gotten swapped in
Tom DeCanio [Wed, 2 Apr 2014 01:03:28 +0000 (18:03 -0700)] 
json: somewhere along the way  IP/port pairs had gotten swapped in
http and ssh eve logs

11 years agoChange configure to allow statically linking libpcre.
Ken Steele [Tue, 11 Mar 2014 15:34:45 +0000 (11:34 -0400)] 
Change configure to allow statically linking libpcre.

Statically linking libpcre requires using -lpthread, which is added
when building Suricata, but not while checking for libpcre in configure.

11 years agotls: no event on 'new session ticket' in handshake
Victor Julien [Sat, 8 Mar 2014 15:10:09 +0000 (16:10 +0100)] 
tls: no event on 'new session ticket' in handshake

Don't set an event on encountering a 'new session ticket' (4) record
in the TLS handshake.

11 years agoipv6: add support for PAD1
Victor Julien [Sat, 8 Mar 2014 13:35:56 +0000 (14:35 +0100)] 
ipv6: add support for PAD1

Support PAD1 in IPv6 HOP options header and DST options header.

11 years agoicmpv6: add multicast types
Victor Julien [Sat, 8 Mar 2014 13:12:47 +0000 (14:12 +0100)] 
icmpv6: add multicast types

Only add them to check if the code is 0 and to make sure the default
case doesn't set an 'unknown type' event.

11 years agoTLS: register patterns for tls-alerts
Victor Julien [Wed, 12 Mar 2014 21:52:00 +0000 (22:52 +0100)] 
TLS: register patterns for tls-alerts

Register patterns for when server has an alert as the first message.

11 years agodetect state: fix indent
Victor Julien [Wed, 12 Mar 2014 14:08:27 +0000 (15:08 +0100)] 
detect state: fix indent

AMATCH block was indented too far.

11 years agodetect state: remove alproto check for AMATCH
Victor Julien [Wed, 12 Mar 2014 14:07:16 +0000 (15:07 +0100)] 
detect state: remove alproto check for AMATCH

Not all AMATCHes set a alproto.

11 years agoFix app-layer-protocol FP on multi TX flow
Victor Julien [Wed, 12 Mar 2014 12:57:30 +0000 (13:57 +0100)] 
Fix app-layer-protocol FP on multi TX flow

In case of multiple transactions, the stored AMATCH list would not have
been reset, but it would still be reconsidered. Even though none would
match, the engine would still conclude that the rule matched.

11 years agoUpdate Changelog for 2.0 release
Victor Julien [Tue, 25 Mar 2014 08:46:44 +0000 (09:46 +0100)] 
Update Changelog for 2.0 release

11 years agotls: fix problem with tls.store keyword
Eric Leblond [Fri, 21 Mar 2014 10:15:47 +0000 (11:15 +0100)] 
tls: fix problem with tls.store keyword

Pierre Chifflier pointed out that a rule like:
 alert tls any any -> any any (msg:"TLS store"; tls.issuerdn:!"C=FR"; tls.store;)
was alerting but not storing the certificate. If the filter was
removed:
 alert tls any any -> any any (msg:"TLS store"; tls.store;)
then tls.store is working as expected.

This was linked with fact that logging is only done once for a SSL
state. So without filter, once we have the info we can log and we
run the storage. But when there is a filter, we log and then there
is a filter analysis and alerting. And as logging as already be done
we don't enter in the logging function and there is no storage.

This patch forces the entrance in the log function when there is a
request for TLS storage. And it adds an exit in the logging function
to only do the storage part if the TLS state has already being logged.

11 years agoUpdate Changelog for 2.0rc3 release
Victor Julien [Tue, 18 Mar 2014 12:10:27 +0000 (13:10 +0100)] 
Update Changelog for 2.0rc3 release

11 years agoyaml: remove rbn, add tls
Victor Julien [Tue, 18 Mar 2014 12:36:56 +0000 (13:36 +0100)] 
yaml: remove rbn, add tls

Remove rbn rule files from default rule list. The files are empty
causing a warning.

Add tls-event.rules to the default list.

11 years agoaf-packet: fix init sync with no traffic
Victor Julien [Tue, 18 Mar 2014 09:46:30 +0000 (10:46 +0100)] 
af-packet: fix init sync with no traffic

Previously the sync code would depend on traffic to complete. This
patch adds poll support and can complete the setup if the poll timeout
is reached as well.

Part of bug #1130.

11 years agoaf-packet: move packet fanout code
Eric Leblond [Mon, 17 Mar 2014 12:58:06 +0000 (13:58 +0100)] 
af-packet: move packet fanout code

The sooner is the better for that caode as these means we will get
all sockets binded to fanout group as fast as possible.

11 years agoaf-packet: synchronize reading start
Eric Leblond [Tue, 11 Mar 2014 08:48:34 +0000 (09:48 +0100)] 
af-packet: synchronize reading start

This patch is updating af-packet to discard packets that have been
sent to a socket before all socket in a fanout group have been setup.
Without this, there is no way to assure that all packets for a single
flow will be treated by the same thread.

Tests have been done on a system with an ixgbe network card. When using
'cluster_flow' load balancing and disactivating receive hash on the iface:
 ethtool -K IFACE rxhash off
then suricata is behaving as expected and all packets for a single flow
are treated by the same thread.

For some unknown reason, this is not the case when using cluster_cpu. It
seems that in that case the load balancing is not perfect on the card side.

The rxhash offloading has a direct impact on the cluster_flow load balancing
because load balancing is done by using a generic hash key attached to
each skb. This hash can be computed by the network card or can be
computed by the kernel. In the xase of a ixgbe network card, it seems there
is some issue with the hash key for TCP. This explains why it is necessary to
remove the rxhash offloading to have a correct behavior. This could also
explain why cluster_cpu is currently failing because the card is using the
same hash key computation to do the RSS queues load balancing.

11 years agofast-log: restore logging of Drop/wDrop
Victor Julien [Fri, 14 Mar 2014 08:50:16 +0000 (09:50 +0100)] 
fast-log: restore logging of Drop/wDrop

Restore drop print logic. Probably got lost in large refactoring round
introducing log APIs.

Bug #1138.

11 years agodetect: allow alias registration for rule keywords
Victor Julien [Thu, 13 Mar 2014 16:09:28 +0000 (17:09 +0100)] 
detect: allow alias registration for rule keywords

This allows for registering a keyword under another name while keeping
the old name active and supported.

Do this for 'luajit', which can now also be used as just 'lua'.

11 years agojson alert: fix action
Victor Julien [Tue, 4 Mar 2014 13:41:45 +0000 (14:41 +0100)] 
json alert: fix action

It would give 'Pass' as an action when the rule is set to 'alert'.

11 years agoeve-http: register with app-layer api
Victor Julien [Wed, 12 Mar 2014 08:31:34 +0000 (09:31 +0100)] 
eve-http: register with app-layer api

The HTTP module of Eve didn't register itself with the app-layer
for HTTP. This meant that if no other HTTP logger was active, the
HTTP logging in Eve wouldn't work.

This patch makes the HTTP Eve module register itself correctly.

Bug #1133.

11 years agoeve-file: set event_type to fileinfo
Victor Julien [Tue, 11 Mar 2014 16:15:05 +0000 (17:15 +0100)] 
eve-file: set event_type to fileinfo

To remain constistent with the other logs, set the event type to
the same name as the structure containing the defails. In this
case fileinfo.

Part of bug #1127.

11 years agoeve-files: file -> fileinfo
Victor Julien [Tue, 11 Mar 2014 14:48:10 +0000 (15:48 +0100)] 
eve-files: file -> fileinfo

Due to what appears to be an issue in logstash, the 'file' part of
the file event types was masked by a field that logstash-forwarder
added itself.

Since logstash-forwarder is an important part of the logstash stack,
this patch works around the issue by renaming our 'file' structure
to 'fileinfo', thus resolving the naming conflict.

Bug #1127

11 years agoeve-http: print <unknown> like in eve-files
Victor Julien [Tue, 11 Mar 2014 11:11:33 +0000 (12:11 +0100)] 
eve-http: print <unknown> like in eve-files

When UA or Host are unknown, print <unknown> instead of <useragent
unknown> or <hostname unknown>.

Bug #1131.

11 years agoFix live reload
Victor Julien [Mon, 10 Mar 2014 11:39:19 +0000 (12:39 +0100)] 
Fix live reload

Fix memsets clearing out of bounds memory on live reload, causing
crashes and corrupted backtraces.

Bug #1128.

11 years agopfring: call enable_ring after set_cluster
Victor Julien [Mon, 10 Mar 2014 07:54:40 +0000 (08:54 +0100)] 
pfring: call enable_ring after set_cluster

Move pfring_enable_ring to the start of ReceivePfringLoop() so that
it's guaranteed to be called after all threads have called
pfring_set_cluster first.

This is necessary because pfring will already make packets available
to thread N, while thread N+1 is still registering itself. This leads
to cases where the first packet(s) of a flow are processed by a
different thread in Suricata than the later ones.

This is a race condition only at start up. New flows after the pfring
initialization is complete will not be influenced by this.

Bug #1129.

11 years agoUpdate ChangeLog for 2.0rc2 release
Victor Julien [Thu, 6 Mar 2014 12:24:23 +0000 (13:24 +0100)] 
Update ChangeLog for 2.0rc2 release

11 years agoyaml: comment out example config
Victor Julien [Thu, 6 Mar 2014 11:35:53 +0000 (12:35 +0100)] 
yaml: comment out example config

Comment out htp settings that should only serve as an example.

11 years agoyaml: increase default memcaps
Victor Julien [Thu, 6 Mar 2014 11:35:20 +0000 (12:35 +0100)] 
yaml: increase default memcaps

Increase default flow and stream reassembly memcaps.

11 years agoeve-log: enable in default config
Victor Julien [Thu, 6 Mar 2014 11:34:22 +0000 (12:34 +0100)] 
eve-log: enable in default config

In the default config, eve-log is now enabled by default. All loggers
except 'drop' are enabled.

11 years agoeve-log: output cleanup
Victor Julien [Thu, 6 Mar 2014 11:33:14 +0000 (12:33 +0100)] 
eve-log: output cleanup

Suppress debug messages and print in a nicer way which modules are
being enabled.

11 years agoBug 611: fix for iponly
Victor Julien [Wed, 5 Mar 2014 09:43:30 +0000 (10:43 +0100)] 
Bug 611: fix for iponly

Fix Bug 611 for ip-only rules as well. If 'alert ip' rule has ports,
don't match on protocols that don't have ports. Like ICMP.

Bug #611.

11 years agooutput-json: update timestamp format
Eric Leblond [Wed, 5 Mar 2014 21:39:10 +0000 (22:39 +0100)] 
output-json: update timestamp format

This patch updates the timestamp format used in eve loggin.
It uses a ISO 8601 comptatible string. This allow tools parsing
the output to easily detect adn/or use the timestamp.

In the EVE JSON output, the value of the timestamp key has been
changed to 'timestamp' (instead of 'time'). This allows tools
like Splunk to detect the timestamp and use it without configuration.

Logstash configuration is simple:

input {
   file {
      path => [ "/usr/local/var/log/suricata/eve.json" ]
      codec =>   json
      type => "suricata-log"
   }
}

filter {
   if [type] == "suricata-log" {
      date {
        match => [ "timestamp", "ISO8601" ]
      }
   }
}

In splunk, auto detection of the fle format is failling and it seems
you need to define a type to parse JSON in
$SPLUNK_DIR/etc/system/local/props.conf:

[suricata]
KV_MODE = json
NO_BINARY_CHECK = 1
TRUNCATE = 0

Then you can simply declare the log file in
$SPLUNK_DIR/etc/system/local/inputs.conf:

[monitor:///usr/local/var/log/suricata/eve.json]
sourcetype = suricata

In both cases the timestamp are correctly imported by
the tools.

11 years agopfring: get vlan id from header
Eric Leblond [Tue, 4 Feb 2014 15:33:30 +0000 (16:33 +0100)] 
pfring: get vlan id from header

PF_RING is delivering the packet with VLAN header stripped. This
patch updates the code to get the information from PF_RING extended
header information.

This patch uses the new function SCKernelVersionIsAtLeast to know
that we've got a old kernel that do not strip the VLAN header from
the message before sending it to userspace.

11 years agoOpenBSD: set correct magic path
Victor Julien [Thu, 6 Mar 2014 07:57:35 +0000 (08:57 +0100)] 
OpenBSD: set correct magic path

For all 5.x OpenBSDs it seems the magic path is:
    /usr/local/share/misc/magic.mgc

11 years agoipfw: fix build
Eric Leblond [Wed, 5 Mar 2014 21:18:02 +0000 (22:18 +0100)] 
ipfw: fix build

Buildbot reported:
 runmode-ipfw.c: In function 'RunModeIpsIPFWAuto':
 runmode-ipfw.c:85: error: implicit declaration of function 'LiveDeviceHasNoStats'

11 years agohttp: add info message about memcap
Eric Leblond [Mon, 3 Mar 2014 16:57:10 +0000 (17:57 +0100)] 
http: add info message about memcap

Display a message about http memcap when it is set in config file.

11 years agoFix False Positive of rules with ports on portless protocols
Victor Julien [Tue, 4 Mar 2014 16:49:36 +0000 (17:49 +0100)] 
Fix False Positive of rules with ports on portless protocols

In case of 'alert ip' rules that have ports, the port checks would
be bypassed for non-port protocols, such as ICMP. This would lead to
a rule matching: a false positive.

This patch adds a check. If the rule has a port setting other than
'any' and the protocol is not TCP, UDP or SCTP, then we rule won't
match.

Rules with 'alert ip' and ports are rare, so the impact should be
minimal.

Bug #611.

11 years agoFix BytesToString indexing array using wrong index
Victor Julien [Tue, 4 Mar 2014 11:42:16 +0000 (12:42 +0100)] 
Fix BytesToString indexing array using wrong index

This would lead to reading past the end of the buffer and also writing
past the end of the newly allocated buffer.

Bug #1121

11 years agojson output: fix vlan byte order in output
Victor Julien [Tue, 4 Mar 2014 10:30:08 +0000 (11:30 +0100)] 
json output: fix vlan byte order in output

VLAN functions/macros return vlan id in host byte order, so no need
to convert them in output functions.

11 years agoFix null dereference in eve-log
Victor Julien [Tue, 4 Mar 2014 10:13:37 +0000 (11:13 +0100)] 
Fix null dereference in eve-log

Eve-log would call GET_VLAN_ID on the packets vlan header if p->vlan_idx
was bigger than 0. GET_VLAN_ID would then unconditionally dereference
p->vlanh[0] or [1]. However, there are a number of cases in which these
pointers are not set. Defrag pseudo packets, AF_PACKET and in the future
PF_RING, do set the id's, but not the header pointers.

This patch adds 2 new macro's which are wrappers around a function:

VLAN_GET_ID1 and VLAN_GET_ID2 get the id's by calling DecodeVLANGetId.

This function will return the correct id.

Bug #1120.

11 years agoCoverity fix
Victor Julien [Tue, 4 Mar 2014 08:55:59 +0000 (09:55 +0100)] 
Coverity fix

Coverity 992695, fix potential array index with negative int. Very unlikely
case at rule keyword parsing stage.

11 years agoconfigure: simplify OpenBSD handling
Victor Julien [Wed, 26 Feb 2014 21:01:52 +0000 (22:01 +0100)] 
configure: simplify OpenBSD handling

Treat all OpenBSD versions in the same way. No more -fgnu89-inline.

11 years agoDisable emerging-icmp in default config
Victor Julien [Wed, 26 Feb 2014 16:59:21 +0000 (17:59 +0100)] 
Disable emerging-icmp in default config

The file has no active rules by default.

11 years agomake install-full: get correct version of ET
Victor Julien [Wed, 26 Feb 2014 16:58:01 +0000 (17:58 +0100)] 
make install-full: get correct version of ET

Version 2.0.

11 years agossh: fix scan-build warnings
Victor Julien [Sun, 2 Mar 2014 10:57:13 +0000 (11:57 +0100)] 
ssh: fix scan-build warnings

app-layer-ssh.c:165:5: warning: Value stored to 'input_len' is never read
    input_len -= 1;
    ^            ~
1 warning generated.

app-layer-ssh.c:160:5: warning: Value stored to 'input_len' is never read
    input_len -= 4;
    ^            ~
1 warning generated.

11 years agossh: improve banner checking
Victor Julien [Sun, 2 Mar 2014 10:08:49 +0000 (11:08 +0100)] 
ssh: improve banner checking

Don't use input_len as banner length. Instead, look for banner end
to calculate banner length.

Add test for banner buffering corner case.

11 years agossh: fixes for minor scan-build warnings
Victor Julien [Sun, 2 Mar 2014 09:27:43 +0000 (10:27 +0100)] 
ssh: fixes for minor scan-build warnings

/usr/share/clang/scan-build/ccc-analyzer -DHAVE_CONFIG_H -I. -I..   -I./../libhtp/  -I/usr/include/nspr   -I/usr/include/nss -I/usr/include/nspr   -DLOCAL_STATE_DIR=\"/usr/local/var\" -g -O2 -Wall -Wno-unused-parameter -std=gnu99 -DHAVE_LIBNET11 -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H -DHAVE_LIBNET_ICMPV6_UNREACH  -I/usr/include -DLIBPCAP_VERSION_MAJOR=1 -DHAVE_PCAP_SET_BUFF -DHAVE_LIBCAP_NG -DREVISION="51e0dee" -MT app-layer-ssh.o -MD -MP -MF .deps/app-layer-ssh.Tpo -c -o app-layer-ssh.o app-layer-ssh.c
app-layer-ssh.c:164:5: warning: Value stored to 'input' is never read
    input += 1;
    ^        ~
app-layer-ssh.c:165:5: warning: Value stored to 'input_len' is never read
    input_len -= 1;
    ^            ~
app-layer-ssh.c:212:13: warning: Value stored to 'ret' is never read
            ret = 0;
            ^     ~
3 warnings generated.

11 years agossh: add json logger
Victor Julien [Sat, 1 Mar 2014 22:12:29 +0000 (23:12 +0100)] 
ssh: add json logger

Sub module of eve-log, but can also run separately as ssh-json-log. Only
one at a time though.

11 years agossh: improve large and fragmented banner handling
Victor Julien [Sat, 1 Mar 2014 21:23:18 +0000 (22:23 +0100)] 
ssh: improve large and fragmented banner handling

Including tests.

11 years agossh: disable inspection in encrypted phase
Victor Julien [Sat, 1 Mar 2014 17:11:19 +0000 (18:11 +0100)] 
ssh: disable inspection in encrypted phase

When both sides of the session have completed the encryption setup,
flag the stream to disable detection.

11 years agossh: allow for space characters in the software version
Victor Julien [Sat, 1 Mar 2014 17:09:20 +0000 (18:09 +0100)] 
ssh: allow for space characters in the software version

Previously the software version would only contain up to the first
space.

E.g. in SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu3

It would contain "OpenSSH_4.7p1".

This patch changes the behavior to:

"OpenSSH_4.7p1 Debian-8ubuntu3"

11 years agossh: clean up flags
Victor Julien [Sat, 1 Mar 2014 16:32:27 +0000 (17:32 +0100)] 
ssh: clean up flags

11 years agossh: reenable ssh.protoversion keyword
Victor Julien [Sat, 1 Mar 2014 16:07:15 +0000 (17:07 +0100)] 
ssh: reenable ssh.protoversion keyword

11 years agossh: reenable ssh.softwareversion keyword
Victor Julien [Sat, 1 Mar 2014 15:59:26 +0000 (16:59 +0100)] 
ssh: reenable ssh.softwareversion keyword

11 years agossh: handle fragmented banner
Victor Julien [Sat, 1 Mar 2014 15:50:07 +0000 (16:50 +0100)] 
ssh: handle fragmented banner

Cleanups.

11 years agossh: server support, cleanups
Victor Julien [Sat, 1 Mar 2014 14:49:54 +0000 (15:49 +0100)] 
ssh: server support, cleanups

11 years agossh: record parser
Victor Julien [Sat, 1 Mar 2014 14:37:50 +0000 (15:37 +0100)] 
ssh: record parser

11 years agossh: reenable parser as stub
Victor Julien [Sat, 1 Mar 2014 09:12:00 +0000 (10:12 +0100)] 
ssh: reenable parser as stub

Reenable the SSH parser. It now compiles, however the actual parsing
code is still disabled (commented out).

11 years agoclassification: add category to some stream rules
Eric Leblond [Wed, 8 Jan 2014 19:28:21 +0000 (20:28 +0100)] 
classification: add category to some stream rules

All stream events signatures deserve a category.

11 years agorunmode: remove unused variable.
Eric Leblond [Wed, 8 Jan 2014 14:55:58 +0000 (15:55 +0100)] 
runmode: remove unused variable.

default_mode_auto is not used anymore and can be removed.

11 years agoExit if BPF filter file is specified in IPS mode
Eric Leblond [Wed, 26 Feb 2014 10:13:33 +0000 (11:13 +0100)] 
Exit if BPF filter file is specified in IPS mode

This patch adds a check that was missing when specifying BPF filter
from a file. Suricata behavior should have been the same as when
BPF filter is specified on command line.

11 years agoipfw: fix operator error in test
Eric Leblond [Thu, 27 Feb 2014 17:39:07 +0000 (18:39 +0100)] 
ipfw: fix operator error in test

Fix warning spotted by clang on FreeBSD:

source-ipfw.c:241:49: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
        if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
                                                ^  ~~~~~~~~~~~~~
source-ipfw.c:241:49: note: use '|' for a bitwise operation
        if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
                                                ^~
                                                |

Use same logic as the one used in other capture mode.

11 years agoipfw: improve exit message
Eric Leblond [Thu, 27 Feb 2014 17:16:13 +0000 (18:16 +0100)] 
ipfw: improve exit message

This patch synchronizes the exit message with what is done in
NFQ capture mode.

11 years agoipfw: update running modes to hide device stats
Eric Leblond [Thu, 27 Feb 2014 17:12:37 +0000 (18:12 +0100)] 
ipfw: update running modes to hide device stats

This patch adds call to the function used to disable the display
of live device stats at exit.

11 years agonfq: update message displayed at exit
Eric Leblond [Thu, 27 Feb 2014 17:08:46 +0000 (18:08 +0100)] 
nfq: update message displayed at exit

This patch updates the message displayed at exit to have something
more readable.

11 years agonfq: update running modes to hide device stats
Eric Leblond [Thu, 27 Feb 2014 17:07:34 +0000 (18:07 +0100)] 
nfq: update running modes to hide device stats

This patch adds call to the function used to disable the display
of live device stats at exit.

11 years agoutil-device: add function to avoid stat display
Eric Leblond [Thu, 27 Feb 2014 17:03:13 +0000 (18:03 +0100)] 
util-device: add function to avoid stat display

In the case of running mode like NFQ there is no need possibility
to compute the statistics as it is done in LiveDevice (drop and
checksum count are meaningless).

This patch adds a function that allow running mode to disable the
display of the counters at exit.

11 years agoutil-device: fix debug message
Eric Leblond [Thu, 27 Feb 2014 16:33:42 +0000 (17:33 +0100)] 
util-device: fix debug message

Reference to Pcap was not correct.

11 years agoMove memcpy_lower() into new util-memcpy.h
Ken Steele [Wed, 26 Feb 2014 21:42:22 +0000 (16:42 -0500)] 
Move memcpy_lower() into new util-memcpy.h

Remove local copies from each MPM file and use include file instead.
Might be better to also add util-memcpy.c rather than inlining it each time,
to get smaller code, since only seems to be used at initialization.

11 years agoStore case-insensitive patterns as lowercase.
Ken Steele [Wed, 26 Feb 2014 21:15:42 +0000 (16:15 -0500)] 
Store case-insensitive patterns as lowercase.

This is required because SCMemcmpLowercase() expects it first argument
to be already lowercase for the comparison. This is done by using
memcpy_tolower() for NO_CASE patterns.

This addresses code review comments from Victor.

11 years agoRemove case_state usage
Ken Steele [Fri, 14 Feb 2014 04:21:53 +0000 (23:21 -0500)] 
Remove case_state usage

The case_state in MPMs was just to track when a pid could have no-case and
case-sensitive matches for the same PID. Now that can't happen after fixing
bug 1110, so remove the code and storage for case_state.

11 years agoWhen assigning Pattern IDs pids, check Case flags
Ken Steele [Fri, 14 Feb 2014 03:38:33 +0000 (22:38 -0500)] 
When assigning Pattern IDs pids, check Case flags

This fixes bug 1110. When assigning PIDs, use the NO_CASE flag when comparing
for duplicates. The state of the flag must be the same, but also use the same
type of comparisons when checking for duplicates.

Previously, "foo":CS would match with "foo":CI when it should not.
and "foo":CI would not match "FoO":CI when it should. Both of those
cases are fixed with this change.

This then allows simplifying the use of pid in MPMs because now if they
pids match, then so do the flags, so checking the flags is not required.

11 years agoCleanup in ac-tile MPM
Ken Steele [Wed, 12 Feb 2014 20:23:44 +0000 (15:23 -0500)] 
Cleanup in ac-tile MPM

Remove return from void functions.
Add some commments
Remove inline on functions where it doesn't make sense.
Rewrote if statement to be more clear.

11 years agounittest: fix mutex unlock w/o a lock
Victor Julien [Thu, 27 Feb 2014 13:31:46 +0000 (14:31 +0100)] 
unittest: fix mutex unlock w/o a lock

Fixes an error in a test. SCMutexUnlock was called w/o a prior
SCMutexLock.

11 years agopool: on Init() error, properly clean up
Victor Julien [Thu, 27 Feb 2014 12:23:45 +0000 (13:23 +0100)] 
pool: on Init() error, properly clean up

In the stream engine, Init() can fail if the memcap is reached. In this
case the segment was not freed by PoolGet:

==8600== Thread 1:
==8600== 70,480 bytes in 1,762 blocks are definitely lost in loss record 611 of 612
==8600==    at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8600==    by 0x914CC8: TcpSegmentPoolAlloc (stream-tcp-reassemble.c:166)
==8600==    by 0xA0D315: PoolGet (util-pool.c:297)
==8600==    by 0x9302CD: StreamTcpGetSegment (stream-tcp-reassemble.c:3768)
==8600==    by 0x921FE8: StreamTcpReassembleHandleSegmentHandleData (stream-tcp-reassemble.c:1873)
==8600==    by 0x92EEDA: StreamTcpReassembleHandleSegment (stream-tcp-reassemble.c:3584)
==8600==    by 0x8D3BB1: HandleEstablishedPacketToServer (stream-tcp.c:1969)
==8600==    by 0x8D7F98: StreamTcpPacketStateEstablished (stream-tcp.c:2323)
==8600==    by 0x8F13B8: StreamTcpPacket (stream-tcp.c:4243)
==8600==    by 0x8F2537: StreamTcp (stream-tcp.c:4485)
==8600==    by 0x95DFBB: TmThreadsSlotVarRun (tm-threads.c:559)
==8600==    by 0x8BE60D: TmThreadsSlotProcessPkt (tm-threads.h:142)

tcp.segment_memcap_drop   | PcapFile                  | 1762

This patch fixes PoolGet to both Cleanup and Free the Alloc'd data in
case Init fails.

11 years agoFix memory leak in proto - name mapping
Victor Julien [Thu, 27 Feb 2014 10:35:47 +0000 (11:35 +0100)] 
Fix memory leak in proto - name mapping

==15745== 3 bytes in 1 blocks are definitely lost in loss record 5 of 615
==15745==    at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==15745==    by 0x71858C1: strdup (strdup.c:42)
==15745==    by 0xA20814: SCProtoNameInit (util-proto-name.c:75)
==15745==    by 0x952D1B: PostConfLoadedSetup (suricata.c:1983)
==15745==    by 0x9537CD: main (suricata.c:2112)

Also, clean up and add a check to make sure it's initialized only once.

11 years agolua: fix minor memory leak
Victor Julien [Thu, 27 Feb 2014 09:59:50 +0000 (10:59 +0100)] 
lua: fix minor memory leak

The full path of the script names is stored in a buffer that wasn't
freed at exit.

==24195== 41 bytes in 1 blocks are definitely lost in loss record 300 of 613
==24195==    at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24195==    by 0x565D06: DetectLoadCompleteSigPath (detect.c:251)
==24195==    by 0x7CABE8: DetectLuajitParse (detect-luajit.c:595)
==24195==    by 0x7CD2AE: DetectLuajitSetup (detect-luajit.c:827)
==24195==    by 0x7DC273: SigParseOptions (detect-parse.c:547)
==24195==    by 0x7DDC75: SigParse (detect-parse.c:856)
==24195==    by 0x7E1C2B: SigInitHelper (detect-parse.c:1336)
==24195==    by 0x7E2968: SigInit (detect-parse.c:1559)
==24195==    by 0x7E37B1: DetectEngineAppendSig (detect-parse.c:1831)
==24195==    by 0x566D17: DetectLoadSigFile (detect.c:335)
==24195==    by 0x567636: SigLoadSignatures (detect.c:423)
==24195==    by 0x951A97: LoadSignatures (suricata.c:1816)

This patch frees the buffer.

11 years agoprofiling: fix memory leak
Victor Julien [Thu, 27 Feb 2014 09:55:01 +0000 (10:55 +0100)] 
profiling: fix memory leak

For packets that were freed, not recycled, profiling memory wasn't
freed:

==15745== 13,312 bytes in 8 blocks are definitely lost in loss record 611 of 615
==15745==    at 0x4C2C494: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==15745==    by 0xA190D5: SCProfilePacketStart (util-profiling.c:963)
==15745==    by 0x4E4345: PacketGetFromAlloc (decode.c:134)
==15745==    by 0x83FE75: FlowForceReassemblyPseudoPacketGet (flow-timeout.c:276)
==15745==    by 0x8413BF: FlowForceReassemblyForHash (flow-timeout.c:588)
==15745==    by 0x841897: FlowForceReassembly (flow-timeout.c:716)
==15745==    by 0x9540F6: main (suricata.c:2296)
==15745==
==15745== 14,976 bytes in 9 blocks are definitely lost in loss record 612 of 615
==15745==    at 0x4C2C494: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==15745==    by 0xA190D5: SCProfilePacketStart (util-profiling.c:963)
==15745==    by 0x4E4345: PacketGetFromAlloc (decode.c:134)
==15745==    by 0x83FE75: FlowForceReassemblyPseudoPacketGet (flow-timeout.c:276)
==15745==    by 0x841508: FlowForceReassemblyForHash (flow-timeout.c:620)
==15745==    by 0x841897: FlowForceReassembly (flow-timeout.c:716)
==15745==    by 0x9540F6: main (suricata.c:2296)

This patch addresses that.

11 years agolock profiling: fix memory leak
Victor Julien [Tue, 7 Jan 2014 10:56:23 +0000 (11:56 +0100)] 
lock profiling: fix memory leak

If lock profiling was compiled in, but disabled in the config a
serious memory leak condition was triggered.

Valgrind output:

==11169== 9,091,248 bytes in 189,401 blocks are definitely lost in loss record 564 of 564
==11169==    at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11169==    by 0xABC44C: LockRecordAdd (util-profiling-locks.c:112)
==11169==    by 0xABC950: SCProfilingAddPacketLocks (util-profiling-locks.c:141)
==11169==    by 0xA04CD5: TmThreadsSlotVarRun (tm-threads.c:562)
==11169==    by 0x958793: TmThreadsSlotProcessPkt (tm-threads.h:142)
==11169==    by 0x9599C3: PcapFileCallbackLoop (source-pcap-file.c:172)
==11169==    by 0x56FC130: ??? (in /usr/lib/x86_64-linux-gnu/libpcap.so.1.4.0)
==11169==    by 0x959D24: ReceivePcapFileLoop (source-pcap-file.c:210)
==11169==    by 0xA05B9E: TmThreadsSlotPktAcqLoop (tm-threads.c:703)
==11169==    by 0x6155F6D: start_thread (pthread_create.c:311)
==11169==    by 0x6E399CC: clone (clone.S:113)

11 years agocapture: use 64 bits counters
Eric Leblond [Thu, 27 Feb 2014 10:47:38 +0000 (11:47 +0100)] 
capture: use 64 bits counters

Some of the packets counters were using a 32bit integer. Given the
bandwidth that is often seen, this is not a good idea. This patch
switches to 64bit counter.

11 years agoaf-packet: fix livedev packets counter
Eric Leblond [Thu, 27 Feb 2014 10:41:07 +0000 (11:41 +0100)] 
af-packet: fix livedev packets counter

Packets counter is incremented in AFPDumpCounters and it was
also incremented during packet reading. The result was a value
that is twice the expected result.

Spotted-by: Victor Julien <victor@inliniac.net>
11 years agostream-tcp: proper error if segment pool init fails
Victor Julien [Wed, 26 Feb 2014 14:18:26 +0000 (15:18 +0100)] 
stream-tcp: proper error if segment pool init fails

Until now a PoolInit failure for the segment pools would result in
an abort() through BUG_ON(). This patch adds a proper error message,
then exits.

Bug #1108.

11 years agostream-tcp: fix error handling in segment pool
Victor Julien [Wed, 26 Feb 2014 14:14:14 +0000 (15:14 +0100)] 
stream-tcp: fix error handling in segment pool

When TcpSegmentPoolInit fails (e.g. because of a too low memcap),
it would free the segment. However, the segment memory is managed
by the Pool API, which would also free the same memory location.
This patch fixes that.

Also, memset the structure before any checks are done, as the segment
memory is passed to TcpSegmentPoolCleanup in case of error as well.

Bug #1108

11 years agocommandline parsing: check optarg ptr before using it
Victor Julien [Wed, 26 Feb 2014 11:41:15 +0000 (12:41 +0100)] 
commandline parsing: check optarg ptr before using it

Fixes:
** CID 1075221:  Dereference after null check  (FORWARD_NULL)
/src/suricata.c: 1344 in ParseCommandLine()

The reason it gave this warning is that in other paths using optarg
there was a check, so the checker assumed optarg can be NULL.

11 years agoicmpv6: Fix Coverity warnings on ND_* types
Victor Julien [Wed, 26 Feb 2014 11:21:24 +0000 (12:21 +0100)] 
icmpv6: Fix Coverity warnings on ND_* types

This patch fixes:
** CID 1187544:  Missing break in switch  (MISSING_BREAK)
/src/decode-icmpv6.c: 268 in DecodeICMPV6()

** CID 1187545:  Missing break in switch  (MISSING_BREAK)
/src/decode-icmpv6.c: 270 in DecodeICMPV6()

** CID 1187546:  Missing break in switch  (MISSING_BREAK)
/src/decode-icmpv6.c: 272 in DecodeICMPV6()

** CID 1187547:  Missing break in switch  (MISSING_BREAK)
/src/decode-icmpv6.c: 274 in DecodeICMPV6()

It duplicates the logic instead of adding 'fall through' statements
as the debug statements were wrong and confusing. For ND_REDIRECT
all 5 ND_* types would have been printed.

11 years agoOnly update mPipe stats occasionally around the packet loop.
Ken Steele [Fri, 21 Feb 2014 21:03:57 +0000 (16:03 -0500)] 
Only update mPipe stats occasionally around the packet loop.

Check for termination or stats update only once every 10,000 times
around the mPipe packet processing loop, to reduce locking.

11 years agoisdataat: fix coverity issue
Victor Julien [Wed, 26 Feb 2014 06:19:19 +0000 (07:19 +0100)] 
isdataat: fix coverity issue

During keyword setup there was a path that in theory could lead to
indexing an array with a negative int.

Coverity 400608

11 years agofast-pattern: fix error check in keyword setup
Victor Julien [Wed, 26 Feb 2014 06:14:46 +0000 (07:14 +0100)] 
fast-pattern: fix error check in keyword setup

Check the right variable. Coverity 1038096

11 years agobyte_extract/test/jump: fix coverity issues
Victor Julien [Wed, 26 Feb 2014 05:28:30 +0000 (06:28 +0100)] 
byte_extract/test/jump: fix coverity issues

During keyword setup there was a path that in theory could lead to
indexing an array with a negative int.

Coverity 992695, 400605, 400604

11 years agoMinor cleanups
Victor Julien [Wed, 26 Feb 2014 05:49:45 +0000 (06:49 +0100)] 
Minor cleanups

Remove useless checks: coverity 103813010381311038132
Small other fixes: coverity 1164817

11 years agohtp: fix pointer check logic
Victor Julien [Wed, 26 Feb 2014 06:01:09 +0000 (07:01 +0100)] 
htp: fix pointer check logic

Don't check pointer after it has already been used.

Coverity 1047545

11 years agorule reload: fix unitialized memory access on error
Victor Julien [Wed, 26 Feb 2014 05:41:10 +0000 (06:41 +0100)] 
rule reload: fix unitialized memory access on error

Coverity 709220

11 years agooutput-json: fix minor memory leak on error
Victor Julien [Wed, 26 Feb 2014 05:20:19 +0000 (06:20 +0100)] 
output-json: fix minor memory leak on error

If the json file couldn't be opened, a minor memory leak would occur.

Coverity 1166039

11 years agoftp: fix memory leak
Victor Julien [Tue, 25 Feb 2014 21:52:18 +0000 (22:52 +0100)] 
ftp: fix memory leak

db pointers in both directions were not freed. This patch frees them
in the state free function.

Bug #1090

11 years agotls: fix uninitialized var use
Victor Julien [Tue, 25 Feb 2014 21:45:46 +0000 (22:45 +0100)] 
tls: fix uninitialized var use

errcode wasn't initialized and in some code paths it remained
uninitialized, leading to us evaluating this uninitialized value.

Bug #1091

11 years agosmtp: don't read uninitialized value
Victor Julien [Tue, 25 Feb 2014 21:40:46 +0000 (22:40 +0100)] 
smtp: don't read uninitialized value

If a reply would be seen before a command, a read of a uninitialized
value could happen.

This patch adds a check for this.

Bug #1089.

11 years agohtp: don't assume HTPCallbackRequestLine is the first callback
Victor Julien [Tue, 25 Feb 2014 19:22:55 +0000 (20:22 +0100)] 
htp: don't assume HTPCallbackRequestLine is the first callback

By assuming that HTPCallbackRequestLine would always be run first,
an memory leak was introduced. It would not check if user data already
existed in the tx, causing it to overwrite the user data pointer is
it already existed.

Bug #1092.