Commit Graph

10911 Commits (eb2665960c6c88ddf323d70e685126e9a356fa40)
 

Author SHA1 Message Date
Philippe Antoine eb2665960c smb: midstream probing checks for netbios message type
If it is available

Bug: #4620.
(cherry picked from commit f37240a3e2)
4 years ago
Philippe Antoine 4713ce44c2 tcp: rejects FIN+SYN packets as invalid
Ticket: #4569

If a FIN+SYN packet is sent, the destination may keep the
connection alive instead of starting to close it.
In this case, a later SYN packet will be ignored by the
destination.

Previously, Suricata considered this a session reuse, and thus
used the sequence number of the last SYN packet, instead of
using the one of the live connection, leading to evasion.

This commit errors on FIN+SYN so that they do not get
processed as regular FIN packets.

(cherry picked from commit 6cb6225b28)
4 years ago
Victor Julien f0dda61732 stream/tcp: handle RST with MD5 or AO header
Special handling for RST packets if they have an TCP MD5 or AO header option.
The options hash can't be validated. The end host might be able to validate
it, as it can have a key/password that was communicated out of band.

The sender could use this to move the TCP state to 'CLOSED', leading to
a desync of the TCP session.

This patch builds on top of
843d0b7a10 ("stream: support RST getting lost/ignored")

It flags the receiver as having received an RST and moves the TCP state
into the CLOSED state. It then reverts this if the sender continues to
send traffic. In this case it sets the following event:

    stream-event:suspected_rst_inject;

Bug: #4710.
(cherry picked from commit 50e2b973ee)
4 years ago
Philippe Antoine e52c850762 swf: right input length for decompression
Also when compress_depth reaches buffer_len

Bug: #4536.
(cherry picked from commit f211a330dd)
4 years ago
Philippe Antoine ad5b39a52a snmp: fixes leak of de_state
Bug: #4752.
(cherry picked from commit 28a3181a2d)
4 years ago
Philippe Antoine 1e860fe662 ntp: fixes leak of de_state
Bug: #4752.
(cherry picked from commit 3212fa7d2b)
4 years ago
Philippe Antoine ad1ac6619c smtp: completes RSET transaction on last multiline
Ticket: #4561
(cherry picked from commit f44bbbb9ad)
4 years ago
Philippe Antoine cb3b80ef4e rust: right condition for both uint to be zero
Theay can overflow leading to their addition to be zero

If a NFS read reply indicates a count of 0xFFFFFFFF

Bug: #4680.
(cherry picked from commit 8f8823b6f2)
4 years ago
Philippe Antoine e6171519ab loopback: decodes IPv6 from all OSes
As does wireshark

(cherry picked from commit 27b4f165b1)
5 years ago
Victor Julien 5f7f050213 af-packet: avoid flag colision with kernel
Avoid colision of TP_STATUS_USER_BUSY with TP_STATUS_TS_RAW_HARDWARE,
both were using bit 31.

Bug: #4800.
(cherry picked from commit ad862fff37)
5 years ago
Victor Julien 84d8390082 af-packet: fix soft lockup issues
The Suricata AF_PACKET code opens a socket per thread, then after some minor
setup enters a loop where the socket is poll()'d with a timeout. When the
poll() call returns a non zero positive value, the AF_PACKET ring will be
processed.

The ringbuffer processing logic has a pointer into the ring where we last
checked the ring. From this position we will inspect each frame until we
find a frame with tp_status == TP_STATUS_KERNEL (so essentially 0). This
means the frame is currently owned by the kernel.

There is a special case handling for starting the ring processing but
finding a TP_STATUS_KERNEL immediately. This logic then skip to the next
frame, rerun the check, etc until it either finds an initialized frame or
the last frame of the ringbuffer.

The problem was, however, that the initial uninitialized frame was possibly
(likely?) still being initialized by the kernel. A data race between the
notification through the socket (the poll()) and the updating of the
`tp_status` field in the frame could lead to a valid frame getting skipped.

Of note is that for example libpcap does not do frame scanning. Instead it
simply exits it ring processing loop. Also interesting is that libpcap uses
atomic loads and stores on the tp_status field.

This skipping of frames had 2 bad side effects:

1. in most cases, the buffer would be full enough that the frame would
   be processed in the next pass of the ring, but now the frame would
   out of order. This might have lead to packets belong to the same
   flow getting processed in the wrong order.

2. more severe is the soft lockup case. The skipped frame sits at ring
   buffer index 0. The rest of the ring has been cleared, after the
   initial frame was skipped. As our pass of the ring stops at the end
   of the ring (ptv->frame_offset + 1 == ptv->req.v2.tp_frame_nr) the code
   exits the ring processing loop at goes back to poll(). However, poll()
   will not indicate that there is more data, as the stale frame in the
   ring blocks the kernel from populating more frames beyond it. This
   is now a dead lock, as the kernel waits for Suricata and Suricata
   never touches the ring until it hears from the kernel.

   The scan logic will scan the whole ring at most once, so it won't
   reconsider the stale frame either.

This patch addresses the issues in several ways:

1. the startup "discard" logic was fixed to not skip over kernel
   frames. Doing so would get us in a bad state at start up.

2. Instead of scanning the ring, we now enter a busy wait loop
   when encountering a kernel frame where we didn't expect one. This
   means that if we got a > 0 poll() result, we'll busy wait until
   we get at least one frame.

3. Error handling is unified and cleaned up. Any frame error now
   returns the frame to the kernel and progresses the frame pointer.

4. If we find a frame that is owned by us (TP_STATUS_USER_BUSY) we
   yield to poll() immediately, as the next expected status of that
   frame is TP_STATUS_KERNEL.

5. the ring is no longer processed until the "end" of the ring (so
   highest index), but instead we process at most one full ring size
   per run.

6. Work with a copy of `tp_status` instead of accessing original touched
   also by the kernel.

Bug: #4785.
(cherry picked from commit a022648b9e)
5 years ago
Victor Julien 898dd11d8f sources: fix pipeline failure handling
When TmThreadsSlotProcessPkt fails it will return the packet that was
passed to it to the packetpool.

Some of the packet sources were doing this manually as well. This patch
fixes those sources.

(cherry picked from commit 7c83cb585e)
5 years ago
Victor Julien 7d194e09b0 capture: optimize checksum handling
Don't use a flag in the livedev, but overwrite the config setting after
'auto' mode has determined checksums should be disabled.

(cherry picked from commit 3957750731)
5 years ago
Victor Julien 4b977a4dc9 af-packet: define all current TP_STATUS_* flags
(cherry picked from commit 8b08b0343d)
5 years ago
Victor Julien b0a709e92a af-packet: fix warnings by undefined sanitizer
(cherry picked from commit d8c82d4f39)
5 years ago
Victor Julien 2a1c85a122 flow/manager: fix emergency timed wait handling
In emergency mode the time set to wait could be in the past.

Bug: #4816.
5 years ago
Victor Julien 57abc1dbf5 time: add timeradd implementation
timeradd isn't available on MinGW.
5 years ago
Todd Mortimer b1ef47dbbf time: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.
Make it easy to compare 'struct timeval's and get their difference.

(cherry picked from commit 9fafc1031c)
5 years ago
Philippe Antoine fc9779334b style: remove latest warnings
about unused variables

(cherry picked from commit cb30772372)
5 years ago
Philippe Antoine c0df143a80 flowint: same analysis warnings as flowbits
(cherry picked from commit f6ba3699bb)
5 years ago
Shivani Bhardwaj 97e57d686a datasets: better err msg if type not defined 5 years ago
Jason Ish 22a4993042 github-ci: pin macos build to 10.15
There is currently a build failure with macos-latest (recently updated)
to 11 in the libhtp test suite code. Not sure if there are other
build issues in libhtp or Suricata at this time.

(cherry picked from commit 8b9721b265)
5 years ago
Philippe Antoine e693375015 protodetect: handle all gaps, even when depth is reached
(cherry picked from commit 527415dba0)
5 years ago
Victor Julien c97819a4b1 detect: suppress error message for pcre only rules
(cherry picked from commit 9dd1444f44)
5 years ago
Philippe Antoine 7d3c7ab4a7 ipv6: simpler generic overlap condition
This also changes the behavior, as the condition is checked in
every case cf ipv6-malformed-fragments-8

(cherry picked from commit 3a230c2208)
5 years ago
Victor Julien 1a4288ff2b detect: fix FNs in case of too many prefilter engines
Fix FNs in case of too many prefilter engines. A transaction was tracking
which engines have run using a u64 bit array. The engines 'local_id' was
used to set and check this bit. However the bit checking code didn't
handle int types correctly, leading to an incorrect left shift result of
a u32 to a u64 bit value.

This commit addresses that by fixing the int handling.

This is only a partial fix however. It's not hard to craft a ruleset that
exceeds the 63-bit space available. A more complete fix is in:

932cf0b6a6 ("detect: track prefilter by progress, not engine")

However this seems like a too high risk change for a backport into
5.0.

This patch does issue a warning if the condition is detected at start
up, and `-T` does error out on it.

Bug: #4688.
5 years ago
Victor Julien 81c6969455 detect: unify alert handling; fix bugs
Unify handling of signature matches between various rule types and
between noalert and regular rules.

"noalert" sigs are added to the alert queue initially, but removed
from it after handling their actions. This way all actions are applied
from a single place.

Make sure flow drop and pass are mutually exclusive.

The above addresses issue with pass and drops not getting applied
correctly in various cases.

Bug: #4663
Bug: #4670

(cherry picked from commit aa93984b7e)
5 years ago
Victor Julien 1aa4fc13cb detect: remove dead code
(cherry picked from commit ae89874b06)
5 years ago
Juliana Fajardini 6b5b54ce46 util/lua-common: use lua_pushnumber for SCFileInfo
(cherry picked from commit b3f447a0df)
5 years ago
Juliana Fajardini 9440cc3c47 util/lua-common: use pushinteger w/ byte & pkt cnt
LuaCallbackStatsPushToStackFromFlow tuple is composed of integer values
not all of them had been converted to lua_pushinteger yet.

(cherry picked from commit 8b53468d32)
5 years ago
Juliana Fajardini f5a6da3ab6 util/lua-common: update copyright year
(cherry picked from commit 82cd125c62)
5 years ago
Juliana Fajardini be9967b1b6 util-lua-common: use lua_pushinteger w/ int values
replace lua_pushnumber with lua_pushinteger for SCFlowStats and
SCRuleIds.

(cherry picked from commit 9b6ce27487)
5 years ago
Juliana Fajardini 83e10306e5 lua/output: fix typo
(cherry picked from commit 00d7a152eb)
5 years ago
Juliana Fajardini d47ec1634f lua: use pushinteger for int in flow/packet tuples
(cherry picked from commit 7592a9be43)
5 years ago
Juliana Fajardini ee8e829ad0 doc/lua-functions: add sha items to SCFileInfo doc
(cherry picked from commit 751906b71d)
5 years ago
Jeff Lucovsky c19161cda3 detect: fix multi-inspect buffer issue
Fix multi-inspect buffer issue caused by setting up for multi but not
using it for inspection.
5 years ago
Juliana Fajardini ced0937e71 util/lua-common: fix SCFileInfo bug & doc comment
The callback for FileInfo was returning the wrong value, resulting
in loss of some tuple values for one calling SCFileInfo in a script.

The documentation comment wasn't mentioning the sha items that are
pushed.

(cherry picked from commit 1315cb793b)
5 years ago
Philippe Antoine 0d9cc0af4f ci: rebase specified s-v pr
So that CI does not fail, if suricata PR got upgraded in a new
version, but S-V PR did not get upgraded, and S-V changed
in master

(cherry picked from commit 3e81d20a71)
5 years ago
Philippe Antoine e39a8fcacd ci: dummy git configuration for rebase
(cherry picked from commit 7fa3e8df61)
5 years ago
Philippe Antoine ac80c6b012 app-layer/pd: review bailout conditions
To take TCP window into account
And to actually bail out if we received too much data
where the limit is configured by stream.reassembly.depth

(cherry picked from commit f77b027ada)
5 years ago
Victor Julien 30d6e14304 app-layer/pd: only consider actual available data
For size limit checks consider only available data at the stream start
and before any GAPS.

The old check would consider too much data if there were temporary gaps,
like when a data packet was in-window but (far) ahead of the expected
segment.

(cherry picked from commit 7a114e506a)
5 years ago
Victor Julien 1d85d1b8df streaming/buffer: account sbb data size
When tracking data track the size of the blocks so that in case
of gaps we can still know how much data we hold.

(cherry picked from commit be1baa8cab)
5 years ago
Philippe Antoine cbab065063 dnp3: regenerate object decoding code
Ticket: #4558
So as to avoid intra-structure overflow

(cherry picked from commit 44bd3169eb)
5 years ago
Philippe Antoine 05eb7a053d dnp3: adds bounds check for prefix chararray
Ticket: #4558
Avoids intra structure overflow

(cherry picked from commit 126a7dcb4f)
5 years ago
Philippe Antoine ef0085af80 dnp3: use base64 macro in gen script
As is done already in C
cf commit ea0936199d

(cherry picked from commit 5ec9688f03)
5 years ago
Shivani Bhardwaj 3166437fda counters: only print alerts if stats are enabled
(cherry picked from commit a17da8374a)
5 years ago
Victor Julien aeb0850441 threading: respect SC_MAX_CPUS envvar 5 years ago
Jason Ish b5bcdcf2ba github-ci: run suricata-verify in quiet mode
Makes it easier to pick out the failing tests.
5 years ago
Jason Ish 8d516380f4 github-ci: prepare cbindgen in its own job
We already do this in master. For 5.0.x it should clear up any
issues where our MSRV isn't suitable to build cbindgen.
5 years ago
Philippe Antoine 87001775bb ipv6: decoder event on invalid length
From RFC 2460, section 4.5,
each fragment, except the last one, must have a length
which is a multiple of 8

(cherry picked from commit ca760e305c)
5 years ago