Commit Graph

12092 Commits (6e5b7199cfd04ffbbfce4fa1244b80ed1ef61e2a)
 

Author SHA1 Message Date
Jeff Lucovsky c9bed6e0b2 detect/file_data: Reject invalid protocols
Issue: #4895

This commit causes Suricata to reject signatures that combine TCP-based
alerts using file_data with NFS keywords.

file_data doesn't support the NFS protocol.

(cherry picked from commit 215335fdc6)
5 years ago
Victor Julien aae628b1bb stream: fix stream pruning being too aggressive
Pruning of StreamBufferBlocks could remove blocks that fell entirely
after the target offset due to a logic error. This could lead to data
being evicted that was still meant to be processed in theapp-layer
parsers.

Bug: #4953.
(cherry picked from commit 78f5e082f5)
5 years ago
Jeff Lucovsky fae78d438b suricatasc: Handle incomplete/empty recv values
Issue: 4947

Improve handling of values returned by recv. Sometimes, recv returns an
empty string if suricata terminates asynchronously.

(cherry picked from commit fc6fdef070)
5 years ago
Odin Jenseg 89f453f7e7 doc/eve-json-format/dns: Describing Z-bit
(cherry picked from commit 2a5d79e426)
5 years ago
Jason Ish a3b803d150 dns: add dns flag to dns request logging
Ticket #4515

(cherry picked from commit 0861b66e15)
5 years ago
Odin Jenseg 4318e9726f dns: Logging of Z-bit
[Edit by Jason Ish: fix flag bit value]

Ticket #4515

(cherry picked from commit dfb6f105e8)
5 years ago
Jason Ish 6a55c14c77 dns: create transaction even if z-bit was set
It appears that DNS servers will still process a DNS request even if the
z-bit is set, our parser will fail the transaction. So create the
transaction, but still set the event.

Ticket #4924

(cherry picked from commit fcbdc30426)
5 years ago
Victor Julien ecea31d8c4 flow/bypass: clear memory on bypass
Previously the flow would hold on to the app-layer and segment data
until the end of the flow, even though it would never be accessed again.

This patch clears app-layer and stream data, but not stream ssn as its
used in flow logging.

Bug: #4778.
(cherry picked from commit 536291054c)
5 years ago
Victor Julien 16bf8a6ee4 flow/bypass: add util func to check if flow is bypassed
To hide the ifdefs for capture offload.

(cherry picked from commit b19d1df69f)
5 years ago
Victor Julien 95f3a06c3a flow/worker: run housekeeping for bypassed packets
Run flow eviction and flow inject queues for bypassed packets as well,
to avoid a scenario where these won't get run at all if too much of the
traffic is bypassed.

Bug: #4779.
(cherry picked from commit ab8f289bb6)
5 years ago
Shivani Bhardwaj 0a51ff3999 detect/proto: Warn if proto not found in config
Ticket 4744
5 years ago
Victor Julien 9410264a0d flow: immediately evict tcp reused flows
Since we already know we're going to no longer use it, might as well
evict it right away.

Ticket 4978

(cherry picked from commit 286c510ece)
5 years ago
Shivani Bhardwaj e28796670d ci: remove eol Fedora 32 & 33 5 years ago
Corey Thomas eaeb99762f ci: add fedora 35 to builds
(cherry picked from commit 7be793f7b4)
5 years ago
Shivani Bhardwaj 4ad3533092 ci: add Fedora 34 to builds 5 years ago
Jason Ish 3a349bb035 datasets: initialize after dropping privileges
Move initialization of datasets to a point after privileges
have been dropped.

Ticket 4239

(cherry picked from commit 92eb14c5ad)
5 years ago
Eric Leblond 36659d16a8 util/streaming: improve error handling
It differentiates memory error than regular ones.

(cherry picked from commit 0e70958e67)
5 years ago
Philippe Antoine 2b6c57626e conf: avoid quadratic complexity
Ticket: 4812

When adding many sequence nodes

(cherry picked from commit 15649424a7)
5 years ago
Jason Ish a2f79b110a af-packet: use configured cluster-id when checking for fanout
When testing for fanout support a cluster-id of 1 was always being
used instead of the configured cluster-id. This limited fanout
support to only one Suricata instance.

Instead of hardcoding an ID of 1, use the configured cluster-id.

Also make cluster_id a uint16_t instead of an int in AFPThreadVars.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/3419

(cherry picked from commit df0ed6fda4)
5 years ago
Eric Leblond 033c4b6f44 profiling: fix profiling with sample rate
Rules profiling was returning invalid results when used with sample
rate. The problem was that the sample condition was run twice in the
packet flow. As a result, the second pass was not initializing the
variable storing the initial CPU ticks and the resulting performance
counters were reporting invalid values.

Bug: #4836.
(cherry picked from commit 6d5f59696d)
5 years ago
Jason Ish 6e9b21d0e6 smtp: log transaction even if no email present
The SMTP transaction logger was not writing the log if the email
portion of the logger failed, such as in the case of STARTTLS
where this is no email decoded.

Ticket #4817

(cherry picked from commit 52b9c12f41)
5 years ago
Shivani Bhardwaj 87f04475aa rust: bump MSRV to 1.41.1
Ticket: #4902.
5 years ago
Victor Julien 6a06e07eb3 mingw: add bcrypt to LDADD for rust compilation
(cherry picked from commit e93dc24383)
5 years ago
Philippe Antoine def83c8188 alert: fixes leak in ThresholdHandlePacketRule
ThresholdHandlePacketRule may take ownership of an allocated
DetectThresholdEntry, and places it in a position of the
array th_entry. But it never got released

(cherry picked from commit 6fadb97d5d)
5 years ago
Philippe Antoine 9d7630d142 mqtt: fix transaction completion
Ticket: 4862

A transaction to client is always considered
complete in the direction to server and vice versa.
Otherwise, transactions are never complete for
AppLayerParserTransactionsCleanup

(cherry picked from commit 1b10848d84)
5 years ago
Jason Ish 19d9a05549 dhcp: fix url in comment
rustdoc was complaining about the format of the URL in a comment
while trying to generate documentation. Convert the comment to a
non-rustdoc comment for now to satisfy rustdoc.

(cherry picked from commit eb6cc62937)
5 years ago
Jason Ish 1a54fde4ad ci: update Ubuntu 16.04 test to 20.04 with MSRV
Update the Ubuntu 16.04 test to Ubuntu 20.04 and make it clear
that it is also testing the minimum supported Rust version for 6.0.

Note: Ubuntu 16.04 is now EOL.
5 years ago
Victor Julien 055262dac9 version: start development towards 6.0.5 5 years ago
Victor Julien e9c8767b90 release: 6.0.4; update changelog; require htp 0.5.39 5 years ago
Philippe Antoine ff46cd66b7 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)
5 years ago
Victor Julien 7787290454 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)
5 years ago
Philippe Antoine f5049041be ntp: fixes leak of de_state
Bug: #4752.
(cherry picked from commit 3212fa7d2b)
5 years ago
Philippe Antoine 7e8247164c snmp: fixes leak of de_state
Bug: #4752.
(cherry picked from commit 28a3181a2d)
5 years ago
Philippe Antoine 5c95c28387 smb: midstream probing checks for netbios message type
If it is available

Bug: #4620.
(cherry picked from commit f37240a3e2)
5 years ago
Philippe Antoine 36e6d632df protodetect: opposing side cannot change protocol
Ticket: #4562

As the data which triggered the opposing side
was the same protocol and not another one,
that means the protocol change failed.

Prevents a memory leak in later call of AppLayerParserParse
which would allocate a new state and leak the old one

(cherry picked from commit be617a3c1b)
5 years ago
Philippe Antoine f6dd81ad7e smtp: completes RSET transaction on last multiline
Bug: #4561.
(cherry picked from commit f44bbbb9ad)
5 years ago
Philippe Antoine fb852c0906 swf: right input length for decompression
Also when compress_depth reaches buffer_len

Bug: #4536.
(cherry picked from commit f211a330dd)
5 years ago
Philippe Antoine 8b54e8fdf0 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)
5 years ago
Philippe Antoine 00cfb1ea74 inspect: debug validation to ensure correct argument
(cherry picked from commit 689ac97d72)
5 years ago
Philippe Antoine 087ec7c570 detect: fixes InspectionBuffer id with transforms
When InspectionBufferGet gets called with base_id
Later InspectionBufferSetup must also be called with base_id

In case there were transforms, we had base_id != list_id

Not calling InspectionBufferSetup with the right id
resulted in leaving a dangling pointer,
because it was not added to det_ctx->inspect.to_clear_queue

Bug: #4681.
(cherry picked from commit c3339c853e)
5 years ago
Philippe Antoine 3c0a155157 loopback: decodes IPv6 from all OSes
As does wireshark

(cherry picked from commit 27b4f165b1)
5 years ago
Victor Julien 38c19b9e8b flow/bypass: use_cnt desync'd on bypassed flows
Locally bypassed flows had unsafe updates to `Flow::use_cnt` leading to a race
issue. For a packet it would do the flow lookup, attach the flow to the packet,
increment the `use_cnt`. Then it would detect that the flow is in the bypass
state, and unlock it while holding a reference (so alos not decrementing the
`use_cnt`). When the packet was then returned to the packet pool, the flow would
be disconnected from the packet, which would decrement `use_cnt` without holding
the flow lock.

This patch addresses this issue by disconnecting the flow from the packet
immediately when the bypassed state is detected. This moves the `use_cnt`
decrement to within the lock.

Bug: #4766.
(cherry picked from commit ec7e0561e8)
5 years ago
Victor Julien a3f88cb6f2 packetpool: reset PacketRelease on return to pool
Reset PacketRelease callback to make sure its not set to a capture
specific callback.

As an example:

  0x000055e00af09d35 in AFPReleaseDataFromRing (p=0x7f1d884cb830) at source-af-packet.c:653
  0x000055e00af09dd0 in AFPReleasePacket (p=0x7f1d884cb830) at source-af-packet.c:678
  0x000055e00ab53d7e in TmqhOutputPacketpool (t=0x55e00fb79250, p=0x7f1d884cb830) at tmqh-packetpool.c:465
  0x000055e00af08dec in TmThreadsSlotProcessPkt (tv=0x55e00fb79250, s=0x55e012134790, p=0x7f1d884cb830) at tm-threads.h:201
  0x000055e00af08e70 in TmThreadsCaptureInjectPacket (tv=0x55e00fb79250, p=0x7f1d884cb830) at tm-threads.h:221
  0x000055e00af08f2e in TmThreadsCaptureHandleTimeout (tv=0x55e00fb79250, p=0x0) at tm-threads.h:245
  0x000055e00af0ba76 in ReceiveAFPLoop (tv=0x55e00fb79250, data=0x7f1d884ccb60, slot=0x55e01198e4b0) at source-af-packet.c:1321
  0x000055e00ab55257 in TmThreadsSlotPktAcqLoop (td=0x55e00fb79250) at tm-threads.c:312
  0x00007f1dca9d5609 in start_thread (arg=<optimized out>) at pthread_create.c:477
  0x00007f1dca7c6293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Here the packet was a pseudo packet to handle a timeout condition. But
the ReleasePacket callback was still set to AFPReleasePacket from a
previous use of the Packet.

Bug: #4807.
(cherry picked from commit 07ce871da4)
5 years ago
Victor Julien 22afa1c551 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 a3a428a95c 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 d106671ceb af-packet: define all current TP_STATUS_* flags
(cherry picked from commit 8b08b0343d)
5 years ago
Victor Julien 58ed89598f flow/manager: fix flows not evicted & freed in time
Flows have been shown to linger for a long time w/o giving up their
resources. This would lead to higher memory use and memcaps getting
reached.

Three main causes have been identified:

Slow passes hash passes. By default the flow manager will scan the
flow hash slowly. It is based on the flow timeout settings, and with
the default config it will take 4 minutes for a full scan to be
complete. This leaves a window for flows that are timed out to linger
for minutes longer than expected.

Flow Manager yields under pressure. The per row TryLock causes work
to be delayed more. The Flow manager will use trylock on a hash row
and will yield immediately if the row is busy. This means that it will
take a full pass before the row is revisited again. If the row holds
busy flows, this could happen many times in a row.

Flow Manager favors evicted flows over active flows. The Flow Manager
will only process the evicted flows if they are present. These flows
have been evicted by workers. The active flows on that hash row will
have to wait until the next hash pass. Of course by then there could
be more evicted flows.

Combined these factors could lead to flows not being considered for
freeing and logging for a very long time, potentially even indefinitly.

The patch addresses the latter two flow manager issues by no longer
using TryLock. It will now simply wait for the lock to be released and
then do its work on it. Additionally for each row both the evicted list
and the active flow list will be processed.

Bug: #4650.
(cherry picked from commit 244dd11c34)
5 years ago
Victor Julien 4d18e3cac7 flow/manager: remove obsolete code
(cherry picked from commit 41fee41722)
5 years ago
Philippe Antoine f992e2adb1 style: remove latest warnings
about unused variables

(cherry picked from commit cb30772372)
5 years ago
Philippe Antoine 5cdcb90019 flowint: same analysis warnings as flowbits
(cherry picked from commit f6ba3699bb)
5 years ago