Commit Graph

12549 Commits (809aebfee183c680ae14e4d58316e477fad0dca0)
 

Author SHA1 Message Date
Victor Julien 73ccd0de1d stream: fix TFO overlap detection with ECN/CWR flags
(cherry picked from commit 5fe2fba184)
4 years ago
Victor Julien 85fc446c55 stream: turn session flags into u32
Due to gaps/padding the size of the struct won't change.

(cherry picked from commit aa7d58b0c7)
4 years ago
Juliana Fajardini 7bfe59f936 flow/manager: apply clang formatting changes 4 years ago
Juliana Fajardini 2832b4a2ae flow/manager: fix coverity divide_by_zero warning
Updated all cases where flow_config.prealloc was used in a division.

*** CID 1524506:  Integer handling issues  (DIVIDE_BY_ZERO)
/src/flow-manager.c: 858 in FlowManager()
852                                "flow_spare_q status: %" PRIu32 "%% flows at the queue",
853                             spare_pool_len, flow_config.prealloc,
854                             spare_pool_len * 100 / flow_config.prealloc);
855
856                     /* only if we have pruned this "emergency_recovery" percentage
857                      * of flows, we will unset the emergency bit */
>>>     CID 1524506:  Integer handling issues  (DIVIDE_BY_ZERO)
>>>     In expression "spare_pool_len * 100U / flow_config.prealloc", division by expression "flow_config.prealloc" which may be zero has undefined behavior.
858                     if (spare_pool_len * 100 / flow_config.prealloc > flow_config.emergency_recovery) {
859                         emerg_over_cnt++;
860                     } else {
861                         emerg_over_cnt = 0;
862                     }

Related to
Bug #5919

(cherry picked from commit 754d2803dd)
4 years ago
Juliana Fajardini f2e863bfe8 flow/manager: fix prealloc unhandled division by 0
If flow.prealloc was set to zero in our yaml config, this led to
a floating point exception in the flow manager.

Bug: #5919.
(cherry picked from commit 5baa6c0024)
4 years ago
Jason Ish 2b02abfa75 rfb: remove duplicate logging of depth
The "depth" field in the "pixel_format" object was being logged twice.

Issue: 5813

(cherry picked from commit f15f092a69)
4 years ago
Jason Ish 0e0ce39190 smb: remove duplicate tree_id logging
Remove the second occurrence of tree_id logging which appears to
always be a duplicate of the first tree_id logged, even though they
come from different data structures.

Issue: 5811

(cherry picked from commit 67baab573b)
4 years ago
Philippe Antoine 70a4587a9b dns: remove unused events field from state
found overflowing by oss-fuzz

(cherry picked from commit 26dc70648c)
4 years ago
Shivani Bhardwaj 2e2483d27a util/mime: use uint8_t for cnt
cnt should not exceed B64_BLOCK which is 4, so, it is unnecessary to use
uint32_t for the variable.
4 years ago
Shivani Bhardwaj 082c7033ad util/mime: use uint32_t for consumed bytes
In a case of the line buffer being over 255 bytes, the consumed bytes
would reset to 0 as it was uint8_t. Fix this integer overflow by setting
the type to uint32_t.

Redmine ticket: 5883

(cherry picked from commit c089bbb7d7)
4 years ago
Philippe Antoine 95009e4411 smb: handles records with trailing nbss data
If a file (read/write) SMB record has padding/trailing data
after the buffer being read or written, and that Suricata falls
in one case where it skips the data, it should skip until
the very end of the NBSS record, meaning it should also skip the
padding/trailing data.

Otherwise, an attacker may smuggle some NBSS/SMB record in this
trailing data, that will be interpreted by Suricata, but not
by the SMB client/server, leading to evasions.

Ticket: #5786
(cherry picked from commit 233ab11148)
4 years ago
Philippe Antoine 0bf3ab9e6d smb: checks against nbss records length
When Suricata handles files over SMB, it does not wait for the
NBSS record to be complete, and can stream the payload to the
file... But it did not check the consistency of the SMB record
length being read or written against the NBSS record length.

This could lead to an evasion where an attacker crafts a SMB
write with a too big Length field, and then sends its evil
payload, even if the server returned an error for the write request.

Ticket: #5770
(cherry picked from commit c1b7befb18)
4 years ago
Jeff Lucovsky 6a66157e34 netmap/config: New API display during debug
This PR changes the log level associated with the message indicating
if the new Netmap API (v14+) is in use during module registration.

Issue: 5879
4 years ago
Bill Meeks 4835befec5 netmap: packet stall
- Fix packet processing stall under high load when using netmap in IPS mode.
- Detect and generate Fatal Error exit for rare case when hardware NIC exposes
unmatched RX/TX queue counts. This is rare, but would result in some traffic
bypassing Suricata since it assumes NIC queue counts are symmetrical.
- Fix instance of missing unlock call for netmap device list when exiting due
to an error condition.
- Clean up existing code comments and add additional ones to better document
the new netmap v14 API code.
4 years ago
Jason Ish 289e996a39 config: put version in configuration as a proper value
Adds a new field, "suricata-version" to the configuration file with
the major and minor version of the Suricata that generated the
configuration file.

This may be useful in the future for presenting warnings about
important changes, or even providing different defaults based on what
the user might expect.

Ticket: 5822

(cherry picked from commit c6c781ef67)
4 years ago
Victor Julien 517132b6ad eve/drop: don't log drops unless packet is dropped
In pass/drop combinations where the pass rule took precendence over
the drop, a "drop" false positive could still be logged due to the
storing of the drop record in the packet drop alert store.

Bug: #5867.
(cherry picked from commit 09348564f0)
4 years ago
Victor Julien 7838fc8b82 detect/urilen: fix applying urilen as depth
If urilen induced depth was set, later DetectContentPropagateLimits()
would apply a wrong depth setting, leading to a false negative in
some cases.

Bug: #5929.
(cherry picked from commit ba7db2583b)
4 years ago
Victor Julien a48e0229ae stream: SYN queue support
Support case where there are multiple SYN retransmits, where
each has a new timestamp.

Before this patch, Suricata would only accept a SYN/ACK that
matches the last timestamp. However, observed behavior is that
the server may choose to only respond to the first. In IPS mode
this could lead to a connection timing out as Suricata drops
the SYN/ACK it considers wrong, and the server continues to
retransmit it.

This patch reuses the SYN/ACK queuing logic to keep a list
of SYN packets and their window, timestamp, wscale and sackok
settings. Then when the SYN/ACK arrives, it is first evaluated
against the normal session state. But if it fails due to a
timestamp mismatch, it will look for queued SYN's and see if
any of them match the timestamp. If one does, the ssn is updated
to use that SYN and the SYN/ACK is accepted.

Bug: #5856.
(cherry picked from commit 7bfee147ef)
4 years ago
Victor Julien 66ddbc3a8b stream: move state queue code into util func
(cherry picked from commit 288086af3f)
4 years ago
Victor Julien 7ccec8f143 debug: add bool string print helper macro
(cherry picked from commit 0ec136621d)
4 years ago
Victor Julien 1ed8066d4e stream: support SYN/ACK with TFO only ack'ing ISN
Not ack'ing the data.

(cherry picked from commit 7ef57cc7cb)
4 years ago
Victor Julien 7f4a800156 stream: add liberal timetamps option
Linux is slightly more permissive wrt timestamps than many
other OS'. To avoid many events/issues with linux hosts, add an
option to allow for this slightly more permissive behavior.

Ideally the host-os config would be used, but in practice this
setting is rarely set up correctly, if at all.

This option is enabled by default.

(cherry picked from commit 01b7ccc224)
4 years ago
Victor Julien fee655bae6 stream: D-SACK detection and logging
RFC 2883 specifies a special use of SACKs to indicate a host has
received a segment it considers a spurious retransmission.

(cherry picked from commit d79a926085)
4 years ago
Victor Julien dcefc00b17 stream: fix next_seq updates after temporary gap
On every accepted packet in established state, update next_seq if
packet seq+len is larger than existing next_seq. This allows it to
catch up after large gaps that are filled again a bit later.

Bug: #5877.
(cherry picked from commit 76225bf9ac)
4 years ago
Victor Julien 006911fd5a stream: improve first FIN next_seq update
For accepted FIN packets, always update next_seq. This helps track the
FIN sequence.

Bug: #5877.
(cherry picked from commit 551fb80150)
4 years ago
Victor Julien a8cff36467 stream: improve FIN next_seq handling
Update next_seq to SEQ + payload_len + 1, so retransmission checks
work better.

Bug: #5877.
(cherry picked from commit 80a012a787)
4 years ago
Victor Julien f1904398a7 stream: set next_seq before last_ack
next_seq sometimes depends on last_ack in cases of packet loss
catch up, so first update it.

Bug: #5877.
(cherry picked from commit 20df715e64)
4 years ago
Eric Leblond 984698f8c5 stream/tcp: update ack handling logic
Only update the ack value of a session for regular packets when
the ACK bit is set.

(cherry picked from commit 0d81173d6e)
4 years ago
Victor Julien 237e06a991 stream/tcp: fix wrong ACK trigger FIN1 to FIN2
An ACK that ACK'd older data while still being in-window could
lead to FIN_WAIT1 to FIN_WAIT2 state transition. Detect this
case and generally harden the check.

Bug: #5877.
(cherry picked from commit 67af94f2e0)
4 years ago
Victor Julien 2b18412509 stream: fix overlap detection
If a in-tree segment was partly before base_seq the overlap detection
miscalculated the data offset. This lead to memcmp comparing the wrong
data.

Bug: #5881.

(cherry picked from commit cbcd70537a)
4 years ago
Victor Julien d0b1a04eb0 stream: set event on bad timestamp on syn_sent state
(cherry picked from commit fc376f8145)
4 years ago
Victor Julien 68bd193868 stream/tcp: allow tcp session reuse on null sessions
When a "stream starter" packet finds an existing TCP flow, the flow will be
evaluated for reuse.

The following scenario wasn't handled well:

1. Suricata starts after a tool has just stopped using lots of connections
   (e.g. ab stress testing a webserver)
2. even though the client is closed already, the server is still doing
   connection cleanup sending many FINs and later RSTs
3. Suricata creates flows for these packets, but no TCP sessions
4. client resumes testing, creating flows that have the same 5 tuple as the
   flows created for the FIN/RST packets
5. Suricata refuses to "reuse" the flows as the condition "tcp flow w/o session"
   is not considered valid for session reuse
6. new TCP connection is not properly tracked and evaluated in parsing and
   detection

There may be other vectors into this, like a flow w/o session because of
memcap issues.

Bug: #5843.
(cherry picked from commit 93c9594dd8)
4 years ago
Victor Julien d13bb7f5a7 flowworker: don't keep unnecessary flow reference
Flow stream/detect/log flush packets, don't hold on to the flow
beyond the flow worker module.

(cherry picked from commit a2dc9a40e7)
4 years ago
Victor Julien 2b998d23b4 version: start development towards 6.0.11 4 years ago
Shivani Bhardwaj 49713ebaa0 release: 6.0.10; update changelog 4 years ago
Jason Ish b57f6f3528 requirements: suricata-update 1.2.7 4 years ago
Victor Julien c08521cd52 threshold: suppress debug notice message 4 years ago
Victor Julien 777d88bd21 decode/events: add strict mode for udp.hlen_invalid; remove rule 4 years ago
Shivani Bhardwaj 9f4dcc4334 rules/decoder: add udp.len_invalid rule
(cherry picked from commit b5b05b8fce)
4 years ago
Shivani Bhardwaj eb26d1a64d decode/udp: fix payload_len calculation
Fix payload_len calculation post removal of the condition that returned
error code if the length to the decode fn did not match the length of
header from the UDP packet.

Bug 5379

(cherry picked from commit f941ceae2b)
4 years ago
Shivani Bhardwaj bbd53bcdf6 decode/events: add event type UDP_LEN_INVALID
(cherry picked from commit eebdfe9a3e)
4 years ago
Lukas Sismis f6fa16ce25 decode-udp: Allow shorter UDP packets than the remaining payload length
If the packet is shorter than IP payload length we no longer flag it as an
invalid UDP packet. UDP packet can be therefore shorter than IP payload.
Keyword "udp.hlen_invalid" became outdated as we no longer flag short UDP
packets as invalid. The keyword's evaluation remains the same.

Inspired by commit: d18e52ed93

Redmine ticket: #5793
4 years ago
Philippe Antoine fd358a5616 fuzz: checks pcap timestamp consistency
Inspired by commit e22b59b8c1

Master7 is now diverging with use of SCTime_t
4 years ago
Victor Julien 855e04ca79 app-layer: explicitly enable sip, rdp and mqtt
In the default config these were enabled implicitly, as their `enabled`
field was commented out. This lead to warnings in the default config.

Ticket: #5299.
4 years ago
Philippe Antoine 4b2a59a4d9 detect: config keyword transaction logic fix
When the keyword config:logging disable,type tx is used,
OutputTxLog checks a flag to skip the transaction without logging
it, but AppLayerParserTransactionsCleanup waits for the
transaction to be marked as logged to clean it.

So, OutputTxLog now marks the tx as logged, so that it can
get cleaned away.

Ticket: #5456
(cherry picked from commit 0c0fcc9411)
4 years ago
Victor Julien 6c7bdd7aca smb: set defaults for file transfer limits
Ticket: #5782.
(cherry picked from commit 37f13a4fc7)
4 years ago
Juliana Fajardini d47e8fffad stream/tcp: fix typos, update copyright year
Bug #5765
4 years ago
Juliana Fajardini 700b0a37a1 exceptions: ignore policy if stream.midstream=true
Set the engine to ignore the stream.midstream-policy if stream.midstream
is enabled.

If we had both stream.midstream AND stream.midstream_policy enabled,
this could lead to midstream flows being dropped (or bypassed, or...)
instead of being accepted by the engine, as it was probably meant when
the user enabled midstream flows.

Bug #5765

(cherry picked from commit 8e9905e0d8)
4 years ago
Philippe Antoine fa4dedc1d4 nfs2: improve READ parsing
Inspired by commit ddf14e51dc

But keeping old nom version
4 years ago
Philippe Antoine 7986919df0 fuzz: specify protocol with fuzz target name
cf https://redmine.openinfosecfoundation.org/issues/4125

This allows fuzz_applayerparser_parse to fuzz one specific
app-layer protocol based on the binary name, as is done
with the environment variable FUZZ_APPLAYER
That is if we rename/copy to fuzz_applayerparser_parse_smb,
it will fuzz only SMB protocol
This way, we can easily produce different fuzz targets for
each protocol in oss-fuzz

(cherry picked from commit e9b76a0e66)
4 years ago