Commit Graph

6570 Commits (e117461d4bc02bc7e0e84850e9309629c1f3c07c)
 

Author SHA1 Message Date
Eric Leblond 50ea76a88b detect-tls: fix memleaks 9 years ago
Eric Leblond a53aef9c57 tm-threads: unify thread names handling
TmThreadCreate copy string provided as name for threads to
avoid any issue is a non allocated string is used.

This patch also introduce TmThreadSetGroupName function. This
function is used to be sure we have an allocation when
assigning the thread group name. This way we can free allocated
memory at exit.

Both code changes have required some fixes in different parts of
the code to be in sync with the new API.

Good point about these changes is that it fixes an inconsistency
were some names were not allocated and some were.
9 years ago
Eric Leblond d367750633 defrag: free defrag tree at exit
This fixes:

72 bytes in 3 blocks are definitely lost in loss record 153 of 316
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x9AF041: SCRadixCreateRadixTree (util-radix-tree.c:430)
   by 0x50FF5D: DefragPolicyLoadFromConfig (defrag-config.c:138)
   by 0x5129F5: DefragInit (defrag.c:962)
   by 0x87ECFD: UnixSocketPcapFilesCheck (runmode-unix-socket.c:386)
   by 0x90FEC0: UnixCommandBackgroundTasks (unix-manager.c:430)
   by 0x913C6D: UnixManager (unix-manager.c:980)
   by 0x9072F3: TmThreadsManagement (tm-threads.c:602)
   by 0x68DE283: start_thread (pthread_create.c:333)
   by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so)
9 years ago
Eric Leblond 55a8f3ce1d output-stats: fix memleak
This fixes:

16 bytes in 2 blocks are definitely lost in loss record 69 of 319
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x85955D: OutputStatsLogThreadInit (output-stats.c:118)
   by 0x4CAE13: StatsMgmtThread (counters.c:352)
   by 0x68DE283: start_thread (pthread_create.c:333)
   by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so)
9 years ago
Eric Leblond c2e2174942 tmqh-flow: fix memleak in TmqhFlowCtx cleaning
This fixes:

96 bytes in 4 blocks are definitely lost in loss record 178 of 320
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x8FF88C: TmqhOutputFlowSetupCtx (tmqh-flow.c:163)
   by 0x908D5F: TmThreadCreate (tm-threads.c:1097)
   by 0x909A62: TmThreadCreatePacketHandler (tm-threads.c:1156)
   by 0x8790CF: RunModeFilePcapAutoFp (runmode-pcap-file.c:188)
   by 0x8837CB: RunModeDispatch (runmodes.c:372)
   by 0x87F2A5: UnixSocketPcapFilesCheck (runmode-unix-socket.c:393)
   by 0x910460: UnixCommandBackgroundTasks (unix-manager.c:430)
   by 0x91420D: UnixManager (unix-manager.c:980)
   by 0x907853: TmThreadsManagement (tm-threads.c:602)
   by 0x68DE283: start_thread (pthread_create.c:333)
   by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so)
9 years ago
Eric Leblond 41e540f2f1 tm-threads: fix memleak
Fix cleaning of threads where mutex and condition where not freed.

This fixes:

352 (192 direct, 160 indirect) bytes in 4 blocks are definitely lost in loss record 301 of 327
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x909404: TmThreadInitMC (tm-threads.c:1764)
   by 0x908DE7: TmThreadCreate (tm-threads.c:1120)
   by 0x90A326: TmThreadCreateMgmtThread (tm-threads.c:1183)
   by 0x4CA0AD: StatsSpawnThreads (counters.c:856)
   by 0x87F254: UnixSocketPcapFilesCheck (runmode-unix-socket.c:396)
   by 0x910330: UnixCommandBackgroundTasks (unix-manager.c:430)
   by 0x9140DD: UnixManager (unix-manager.c:980)
   by 0x9077F3: TmThreadsManagement (tm-threads.c:600)
   by 0x68DE283: start_thread (pthread_create.c:333)
   by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so)
9 years ago
Eric Leblond de6a37f17b tm-queue: unify queue name handling
Queue name was sometimes allocated and sometimes not. This
patch updates the behavior of creation function so it is
always allocated. This way we can free it at exit and fix
memory leak.

This fixes:

900 bytes in 110 blocks are definitely lost in loss record 322 of 329
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x803E0A9: strdup (in /lib/x86_64-linux-gnu/libc-2.21.so)
   by 0x90090E: StoreQueueId (tmqh-flow.c:112)
   by 0x8FFEA8: TmqhOutputFlowSetupCtx (tmqh-flow.c:180)
   by 0x908C7F: TmThreadCreate (tm-threads.c:1095)
   by 0x909982: TmThreadCreatePacketHandler (tm-threads.c:1154)
   by 0x87906F: RunModeFilePcapAutoFp (runmode-pcap-file.c:188)
   by 0x88376B: RunModeDispatch (runmodes.c:372)
   by 0x87F245: UnixSocketPcapFilesCheck (runmode-unix-socket.c:393)
   by 0x9102B0: UnixCommandBackgroundTasks (unix-manager.c:430)
   by 0x91405D: UnixManager (unix-manager.c:980)
   by 0x907773: TmThreadsManagement (tm-threads.c:600)

tm-queue: fix logic WIP
9 years ago
Eric Leblond f34fe85cfe unix-manager: fix memleak at exit
Buffer allocated for UnixClient was not correctly freed.
9 years ago
Eric Leblond f1f2f0d478 util-host-info: fix memleaks
This fixes pcre related memory leak in SCKernelVersionIsAtLeast
function.
9 years ago
Eric Leblond 606ac17c57 util: get rid of json_array_append
This function is causing a memleak because it is necessary to clean
up after usage.

This fixes at least:

37 (32 direct, 5 indirect) bytes in 1 blocks are definitely lost in loss record 104 of 394
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x66D0C7B: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.7.0)
   by 0x943584: LiveDeviceIfaceList (util-device.c:264)
   by 0x910889: UnixCommandExecute (unix-manager.c:486)
   by 0x910D7E: UnixCommandRun (unix-manager.c:545)
   by 0x911193: UnixMain (unix-manager.c:593)
   by 0x913CC7: UnixManager (unix-manager.c:961)
   by 0x907753: TmThreadsManagement (tm-threads.c:600)
   by 0x68DE283: start_thread (pthread_create.c:333)
   by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so)
9 years ago
Eric Leblond cc942b4fb8 runmodes: fix memleak
active_runmode value was leaking in unix socket mode.
9 years ago
Eric Leblond b1f907a58f unix-manager: fix memleak
This fixes:

2,595 (1,824 direct, 771 indirect) bytes in 57 blocks are definitely lost in loss record 328 of 332
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x66D0C7B: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.7.0)
   by 0x911A27: UnixManagerListCommand (unix-manager.c:766)
   by 0x9108A9: UnixCommandExecute (unix-manager.c:486)
   by 0x910D9E: UnixCommandRun (unix-manager.c:545)
   by 0x9111B3: UnixMain (unix-manager.c:593)
   by 0x913D27: UnixManager (unix-manager.c:961)
   by 0x907773: TmThreadsManagement (tm-threads.c:600)
   by 0x68DE283: start_thread (pthread_create.c:333)
   by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so)
9 years ago
Eric Leblond 2c755b5fc7 output-tx: fix memleak
This fixes:

Direct leak of 31752 byte(s) in 3969 object(s) allocated from:
    #0 0x4c396b in malloc (/opt/suricata-asan/bin/suricata+0x4c396b)
    #1 0xe385b9 in OutputTxLogThreadInit /home/pmanev/sandnet-qa/stage/oisf/src/output-tx.c:193:34
    #2 0x106c255 in TmThreadsSlotPktAcqLoop /home/pmanev/sandnet-qa/stage/oisf/src/tm-threads.c:295:17
    #3 0x7fbc9fcb3181 in start_thread /build/eglibc-3GlaMS/eglibc-2.19/nptl/pthread_create.c:312
9 years ago
Eric Leblond 2866f87c6d output-filedata: fix memleak
This fixes:

Direct leak of 31792 byte(s) in 3974 object(s) allocated from:
    #0 0x4c396b in malloc (/opt/suricata-asan/bin/suricata+0x4c396b)
    #1 0xd86ce2 in OutputFiledataLogThreadInit /home/pmanev/sandnet-qa/stage/oisf/src/output-filedata.c:308:34
    #2 0x106c255 in TmThreadsSlotPktAcqLoop /home/pmanev/sandnet-qa/stage/oisf/src/tm-threads.c:295:17
    #3 0x7fbc9fcb3181 in start_thread /build/eglibc-3GlaMS/eglibc-2.19/nptl/pthread_create.c:312
9 years ago
Eric Leblond d0ebe04c8b output-packet: fix memleak
This fixes:

Direct leak of 31832 byte(s) in 3979 object(s) allocated from:
    #0 0x4c396b in malloc (/opt/suricata-asan/bin/suricata+0x4c396b)
    #1 0xe22129 in OutputPacketLogThreadInit /home/pmanev/sandnet-qa/stage/oisf/src/output-packet.c:123:34
    #2 0x106c255 in TmThreadsSlotPktAcqLoop /home/pmanev/sandnet-qa/stage/oisf/src/tm-threads.c:295:17
    #3 0x7fbc9fcb3181 in start_thread /build/eglibc-3GlaMS/eglibc-2.19/nptl/pthread_create.c:312
9 years ago
Eric Leblond 24e4edd118 output-file: fix memleak
This fixes:

Direct leak of 31856 byte(s) in 3982 object(s) allocated from:
    #0 0x4c396b in malloc (/opt/suricata-asan/bin/suricata+0x4c396b)
    #1 0xd7ff39 in OutputFileLogThreadInit /home/pmanev/sandnet-qa/stage/oisf/src/output-file.c:182:34
    #2 0x106c255 in TmThreadsSlotPktAcqLoop /home/pmanev/sandnet-qa/stage/oisf/src/tm-threads.c:295:17
    #3 0x7fbc9fcb3181 in start_thread /build/eglibc-3GlaMS/eglibc-2.19/nptl/pthread_create.c:312
9 years ago
Eric Leblond c49145a79a log-filestore: suppress unused code
Code was unused and was leaking memory.

This fixes:

Direct leak of 614240 byte(s) in 3839 object(s) allocated from:
    #0 0x4c396b in malloc (/opt/suricata-asan/bin/suricata+0x4c396b)
    #1 0x11bc12e in LogFileNewCtx /home/pmanev/sandnet-qa/stage/oisf/src/util-logopenfile.c:474:27
    #2 0xcf7ef2 in LogFilestoreLogInitCtx /home/pmanev/sandnet-qa/stage/oisf/src/log-filestore.c:430:31
    #3 0xec3275 in RunModeInitializeOutputs /home/pmanev/sandnet-qa/stage/oisf/src/runmodes.c:763:26
    #4 0xeae17f in UnixSocketPcapFilesCheck /home/pmanev/sandnet-qa/stage/oisf/src/runmode-unix-socket.c:391:9
    #5 0x109bc37 in UnixCommandBackgroundTasks /home/pmanev/sandnet-qa/stage/oisf/src/unix-manager.c:430:20
    #6 0x10a9be2 in UnixManager /home/pmanev/sandnet-qa/stage/oisf/src/unix-manager.c:977:9
    #7 0x1075643 in TmThreadsManagement /home/pmanev/sandnet-qa/stage/oisf/src/tm-threads.c:600:9
    #8 0x7fbc9fcb3181 in start_thread /build/eglibc-3GlaMS/eglibc-2.19/nptl/pthread_create.c:312
9 years ago
Eric Leblond ab3aed7d25 decode: update icmpv6 message handling
This patch adds two new events relative to icmpv6. One for packets
using unassigned icmpv6 type. The second one for packets using
private experimentation type.

Icmpv6 type table taken from http://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-2
9 years ago
Victor Julien 27b02402e7 gre: support transparent ethernet bridge decoding 9 years ago
Victor Julien 219762b7d9 pfring: small cleanup 9 years ago
cardigliano 57e0bd39e9 pkt acq: introduce break loop API
This patch adds a new callback PktAcqBreakLoop() in TmModule to let
packet acquisition modules define "break-loop" functions to terminate
the capture loop. This is useful in case of blocking functions that
need special actions to take place in order to stop the execution.

Implement this for PF_RING
9 years ago
Andreas Herz 5d34ac071d rule-parsing: remove unnecessary code
Those lines were included former to prevent possible null pointer
dereference but that won't happen anymore with the rest of the rework
done in the code. The code even results in a control flow issue reported
by coverity scan, so just remove it.
9 years ago
Alexander Gozman 69785f186c BUG #1689: fix stack overflow when parsing variables
Suricata crashed when variable (either address or port)
referred to itself or if one created a looped chain of
variables. For instance:

HOME_NET:     "!$EXTERNAL_NET"
EXTERNAL_NET: "!$HOME_NET"

Or:

Var1: "$Var2"
Var2: "$Var3"
Var3: "$Var1"
9 years ago
Victor Julien 53704ea468 output-json: constify API 9 years ago
Jason Ish 1601222056 alert-debuglog: trigger rotation on non-decoder events as well
The write handling was missed for non-decoder events that
would trigger rotation after a HUP.
9 years ago
Victor Julien 75cd1f0bf5 gccprotect: fix SECLDFLAGS not getting used 9 years ago
Eric Leblond 5dbedbfa5b app-layer-smtp: fix memory leak
This patch fixes the following leak:

Direct leak of 9982880 byte(s) in 2902 object(s) allocated from:
    #0 0x4c253b in malloc ??:?
    #1 0x10c39ac in MimeDecInitParser /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/util-decode-mime.c:2379
    #2 0x6a0f91 in SMTPProcessRequest /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/app-layer-smtp.c:1085
    #3 0x697658 in SMTPParse /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/app-layer-smtp.c:1185
    #4 0x68fa7a in SMTPParseClientRecord /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/app-layer-smtp.c:1208
    #5 0x6561c5 in AppLayerParserParse /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/app-layer-parser.c:908
    #6 0x53dc2e in AppLayerHandleTCPData /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/app-layer.c:444
    #7 0xf8e0af in DoReassemble /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/stream-tcp-reassemble.c:2635
    #8 0xf8c3f8 in StreamTcpReassembleAppLayer /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/stream-tcp-reassemble.c:3028
    #9 0xf94267 in StreamTcpReassembleHandleSegmentUpdateACK /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/stream-tcp-reassemble.c:3404
    #10 0xf9643d in StreamTcpReassembleHandleSegment /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/stream-tcp-reassemble.c:3432
    #11 0xf578b4 in HandleEstablishedPacketToClient /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/stream-tcp.c:2245
    #12 0xeea3c7 in StreamTcpPacketStateEstablished /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/stream-tcp.c:2489
    #13 0xec1d38 in StreamTcpPacket /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/stream-tcp.c:4568
    #14 0xeb0e16 in StreamTcp /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/stream-tcp.c:5064
    #15 0xff52a4 in TmThreadsSlotVarRun /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/tm-threads.c:130
    #16 0xffdad1 in TmThreadsSlotVar /home/victor/qa/buildbot/donkey/z600fuzz/Private/src/tm-threads.c:474
    #17 0x7f7cd678d181 in start_thread /build/buildd/eglibc-2.19/nptl/pthread_create.c:312 (discriminator 2)

We come to this case when a SMTP session contains at least 2 mails
and then the ending of the first is not correctly detected. In that
case, switching to a new tx seems a good solution. This way we still
have partial logging.
9 years ago
Eric Leblond 10e2e2a8b6 app-layer-smtp: fix mem leak and add new alert
If SMTP session is weird then we may reach a state where a field
like MAIL FROM is seen as duplicated.

Valgrind output is:

30 bytes in 1 blocks are definitely lost in loss record 96 of 399
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4A5803: SMTPParseCommandWithParam (app-layer-smtp.c:996)
   by 0x4A4DCE: SMTPParseCommandMAILFROM (app-layer-smtp.c:1016)
   by 0x4A3F55: SMTPProcessRequest (app-layer-smtp.c:1127)
   by 0x4A1F8C: SMTPParse (app-layer-smtp.c:1191)
   by 0x493AD7: SMTPParseClientRecord (app-layer-smtp.c:1214)
   by 0x4878A6: AppLayerParserParse (app-layer-parser.c:908)
   by 0x42384E: AppLayerHandleTCPData (app-layer.c:444)
   by 0x8D7EAD: DoReassemble (stream-tcp-reassemble.c:2635)
   by 0x8D795F: StreamTcpReassembleAppLayer (stream-tcp-reassemble.c:3028)
   by 0x8D8BE0: StreamTcpReassembleHandleSegmentUpdateACK (stream-tcp-reassemble.c:3404)
   by 0x8D8F6E: StreamTcpReassembleHandleSegment (stream-tcp-reassemble.c:3432)
9 years ago
Eric Leblond 50ad1ce307 build: install app-layer-events.rules 9 years ago
Victor Julien a2ceb98064 file: fix flags type in API 9 years ago
Victor Julien 83f400dd60 http: remove unused param from HtpBodyAppendChunk 9 years ago
Victor Julien 6e3514a444 spm: constify search args 9 years ago
Victor Julien 914f7fa733 file: shrink data structure 9 years ago
Victor Julien 6b942b6734 htp file: constify name/data args 9 years ago
Victor Julien e3703ee126 file: constify data/name args 9 years ago
Victor Julien 8631b73852 http body: use HTPCalloc 9 years ago
Victor Julien 77f67062de htp: add HTPCalloc wrapper 9 years ago
Victor Julien a1a0acf8a8 magic: make data arg const 9 years ago
Jason Ish dddd2d06f6 dcerpc: cleanup list handling 9 years ago
Jason Ish 1efcaf2179 dcerpc: fix memory leak when called from smb
When DCERPC was wrapped in SMB it wasn't being initialized or
cleaned up properly. To fix, expose DCERPC initialization and
cleanup functions for use by the SMB application layer.

Redmine ticket:
https://redmine.openinfosecfoundation.org/issues/1708
9 years ago
Andreas Herz 27f6620874 rule-parsing: quick fix for rules with wrong double quotes
The stripping of leading and trailing "s has issues with rules like the
ones described in issue 1638 thus resulted in crashing the rule parser.
So for now this is a quick fix which approaches this issue directly by
stripping those "s correctly and handling error cases. It also adds the
skip for leading spaces at the msg keyword and worksaround a possible
null pointer dereference (that should never occur though).
A more general approach should be done in the future.
9 years ago
Victor Julien 881fc5500d lua output: clean up memory at shutdown
Lua module and submodules we're completely freed at exit, and nor
was the lua_State.

This patch does all the cleanup.
9 years ago
Victor Julien ecb79391a0 pcre: use pcre_free_study to free the study data 9 years ago
Victor Julien 066c4b0b24 detect ports: fix memory leak
Fix mem leak on rules that contained ports like "![21,25,119]".
9 years ago
Victor Julien 573284b5ed vlan: fix bad checks in unittests 9 years ago
Andreas Herz e1468107e5 nfqueue: fix wrong return value check in error cases
The check for the return value was wrong, we have 0 for success and 1
(and 2) for the error cases like TM_ECODE_FAILED, so we should quit
unless TM_ECODE_OK (0) is returned for NFQInitThread. This fixes #1870
9 years ago
DIALLO David 3a3cc43f6a modbus: fix compiler uninitialized warnings with -Wmaybe-uninitialized
All variables are initialized thanks to ModbusExtractUint8 or ModbusExtractUint16
function that extracts 8bits or 16bits data from pointer the received input data.
In case of extracting error (because of length), ModbusExtractUint8 or
ModbusExtractUint16 returns an error that is managed by the caller function.

All variables are now initialized to zero when they are declared. It does not
change anything functionnally but it removes Modbus warnings.
9 years ago
Victor Julien 3a6b7a1cd6 make install-rules: update URL to https and 3.0 9 years ago
Victor Julien fde7a2f656 cuda: fix compilation 9 years ago
Victor Julien c12044c6c5 cuda: update build system for modern versions
Remove support for compute capabilities below 2.0.

Add capabilities until 5.3.
9 years ago