Commit Graph

162 Commits (dbc2f9d1db7cecab3cbbd9fb9fbc9fca9835b272)

Author SHA1 Message Date
Philippe Antoine 85f2f597f1 defrag: remove unnecessary NULL check
CID: 727861
7 months ago
Jason Ish 22b77b0c56 conf: prefix conf API with SC 8 months ago
Philippe Antoine 9203656496 defrag: fix off by one
Ticket: 7067

This off by one could lead to an empty fragment being inserted
in the rb tree, which led to integer underflow
1 year ago
Philippe Antoine ce2c087e92 defrag: fix -Wshorten-64-to-32 warnings
Ticket: #6186
1 year ago
Victor Julien 1190e426f9 defrag: remove trackers on lookup
When looking up a tracker, remove any timed out / completed trackers.
1 year ago
Victor Julien 83dc703d1f defrag: add various counters 1 year ago
Victor Julien dcaeed7b95 defrag: remove tracker on frag pool issues
If a frag wasn't inserted due to pool empty or alloc failure, clear and

invalidate the tracker.
1 year ago
Victor Julien 383892463c defrag: fix test passing NULL pointers 1 year ago
Victor Julien fc93a3875e defrag: turn queue into stack
Only used by the spare tracker logic, which works better as a stack.
1 year ago
Victor Julien a40d6f5c4f decode/ipv6: prep for turning ip4h/ip6h into union
Store IPv6 decoder vars in a new Packet::l3 section in the packet.

Use inline functions instead of the often multi-layer macro's for
various IPv6 header getters.

Ticket: #6938.
2 years ago
Victor Julien 2d5c381c3b decode/ipv4: prep for turning ip4h/ip6h into union
Store IPv4 decoder vars in a new Packet::l3 section in the packet.

Use inline functions instead of the often multi-layer macro's for
various IPv4 header getters.

Ticket: #6938.
2 years ago
Victor Julien 0e99e8a7fa defrag: track ip hdr offset in tracker
In preparation of future Packet structure changes.

Ticket: #6938.
2 years ago
Victor Julien eb3ca643c1 decode: reduce PKT_IS_IPV4/PKT_IS_IPV6 use
Replace it with inline functions. Adds inline functions to
wrap PKT_IS_IPV4/PKT_IS_IPV6.

This is in preparation of removing the macro's, and cleaning up the
header pointers.

Ticket: #5517.
2 years ago
Jason Ish d226d0a3fc defrag: fix check for complete packet
The list of fragments may still contain overlaps, so adding up the
fragment lengths is flawed. Instead track the largest size of
contiguous data that can be re-assembled.

Bug: #6675
2 years ago
Jason Ish f1709ea551 defrag: fix subsequent overlap of start of original (bsd)
Fix the BSD policy case where a subsequent fragment starts before an
original fragment and overlaps the beginning of the original
fragment. In this case the overlapping data from the new fragment is
preferred.

Suricata was preferring the data from the original fragment, but it
should only do that when the original fragment has an offset <= to the
new fragment.

- Adds tests for this case.

Bug: #6669
2 years ago
Jason Ish d0fd078250 defrag: check next fragment for overlap before stopping re-assembly
Instead of breaking the loop when the current fragment does not have
any more fragments, set a flag and continue to the next fragment as
the next fragment may have data that occurs before this fragment, but
overlaps it.

Then break if the next fragment does not overlap the previous.

Bug: #6668
2 years ago
Jason Ish bdd17de73d defrag: use uint8_t in unit tests 2 years ago
Jason Ish 2f00b5870a defrag: consistent unit test naming
Use a more consistent naming scheme between ipv4 and ipv6.
2 years ago
Jason Ish 6339deadce defrag: make tests more readable
Make tests more readable for comparing to the paper "Target-Based
Fragmentation Reassembly".
2 years ago
Jason Ish 276d3d6541 defrag: minor cleanups
- typo in comment
- remove debug function that is not used and no longer valid
2 years ago
Victor Julien 49c67b2bb1 defrag: fix wrong datalink being logged
Eve's packet_info.linktype should correctly indicated what the `packet`
field contains. Until now it was using DLT_RAW even if Ethernet or other
L2+ headers were present.

This commit records the datalink of the packet creating the first
fragment, which can include the L2+ header data.

Bug: #6887.
2 years ago
Juliana Fajardini 485c0e1d9a defrag: add exception policy memcap stats counters
Add defrag memcap stats counter.

Task #5816
2 years ago
Victor Julien d3a429d919 defrag: test cleanups and fixes
Pass tv and dtv to make sure reassembled packet is decoded.
2 years ago
Victor Julien 6066c4d6e7 decode/tunnel: improve tunnel handling
Give each packet explicit tunnel type `ttype`: none, root, child.

Assigning happens when a (tunnel) packet is set up and is thread
safe.
2 years ago
Victor Julien af97316f42 defrag: match up v4 and v6 packet setup
v4 was doing redundant recursion level setup.

v6 was missing PKT_REBUILT_FRAGMENT flag.
2 years ago
Juliana Fajardini a37a88dcd5 defrag: clean up existing stats counters
7a044a99ee removed the lines that incremented these defrag
counters, but kept the entities themselves. This commit removes counters
that we judge too complex to maintain, given the current state of the
code, and re-adds incrementing max_hit (memcap related).

Related to
Task #5816
2 years ago
Jeff Lucovsky 0d2268ddfc decode/vlan: Decode upto 3 layers of VLAN
Issue: 2816

This commit increase the number of VLAN layers supported by Suricata
from 2 to 3. 3-layers are dubbed "Q-in-Q-in-Q".

Note that 3 layers are not compliant with any existing standard but are
often seen in larger deployments.
2 years ago
Victor Julien ca3c144ec8 defrag: spelling 3 years ago
Jeff Lucovsky 9fbe683642 time: Rework SCTime_t into a struct
Issue: 5718

This commit changes SCTime_t to a struct with members setup as
bitfields.
3 years ago
Jeff Lucovsky 31793aface time: Replace struct timeval with scalar value
Issue: 5718

This commit switches the majority of time handling to a new type --
SCTime_t -- which is a 64 bit container for time:
- 44 bits -- seconds
- 20 bits -- useconds
3 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 3 years ago
Philippe Antoine ad713246a9 src: remove double includes
Keep the unconditional include to be sure it works

git grep '#include "' src/*.c | sort | uniq -c | awk '$1 > 1'
3 years ago
Philippe Antoine 1f066cbbe8 unittest: fix unneeded includes as per cppclean
Especially because there is conditional inclusion from a header
3 years ago
Philippe Antoine e85f3916e3 src: fix integer warnings
and adds defrag debug validations
3 years ago
Victor Julien 256f0f2c5c defrag: no error logging in packet path 3 years ago
Victor Julien 39cf5b151a src: includes cleanup
Work towards making `suricata-common.h` only introduce system headers
and other things that are independent of complex internal Suricata
data structures.

Update files to compile after this.

Remove special DPDK handling for strlcpy and strlcat, as this caused
many compilation failures w/o including DPDK headers for all files.

Remove packet macros from decode.h and move them into their own file,
turn them into functions and rename them to match our function naming
policy.
3 years ago
Philippe Antoine e87c53bb55 defrag: use util function for timeout
To fix timestamp overflow as found by oss-fuzz
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44608

fixu
3 years ago
Philippe Antoine 9d6e5558f1 defrag: do not cast pkt len to u16
as it can overflow
4 years ago
Victor Julien 8580499ded exceptions: initial exception-policy implementation
Adds a framework for setting exception policies. These would be called
when the engine reaches some kind of exception condition, like hitting
a memcap or some traffic processing error.

The policy gives control over what should happen next: drop the packet,
drop the packet and flow, bypass, etc.

Implements the policy for:

    stream: If stream session or reassembly memcaps are hit call the
    memcap policy on the packet and flow.

    flow: Apply policy when memcap is reached and no flow could be
    freed up.

    defrag: Apply policy when no tracker could be picked up.

    app-layer: Apply ppolicy if a parser reaches an error state.

All options default to 'ignore', which means the default behavior
is unchanged.

Adds commandline options: add simulation options for exceptions. These
are only exposed if compiled with `--enable-debug`.

Ticket: #5214.
Ticket: #5215.
Ticket: #5216.
Ticket: #5218.
Ticket: #5194.
4 years ago
Philippe Antoine 717e51b7cf defrag: fix integer warnings
Ticket: #4516
4 years ago
Philippe Antoine 3a230c2208 ipv6: simpler generic overlap condition
This also changes the behavior, as the condition is checked in
every case cf ipv6-malformed-fragments-8
4 years ago
Jeff Lucovsky 1eeb96696b general: Cleanup bool usage 5 years ago
Victor Julien 36a93380a5 defrag: fix pthread warning on OpenBSD 5 years ago
Shivani Bhardwaj 6f7d8e50c8 src: use FatalError whenever possible
Replaces all patterns of SCLogError() followed by exit() with
FatalError(). Cocci script to do this:

@@
constant C;
constant char[] msg;
@@

- SCLogError(C,
+ FatalError(SC_ERR_FATAL,
  msg);
- exit(EXIT_FAILURE);

Closes redmine ticket 3188.
5 years ago
Victor Julien f8aed4ce2d threading: change local packet queue logic
Previously each 'TmSlot' had it's own packet queue that was passed
to the registered SlotFunc as an argument. This was used mostly for
tunnel packets by the decoders and by defrag.

This patch removes that in favor of a single queue in the ThreadVars:
decode_pq. This is the non-locked version of the queue as this is
only a temporary store for handling packets within a thread.

This patch removes the PacketQueue pointer argument from the API.
The new queue can be accessed directly through the ThreadVars
pointer.
6 years ago
Jason Ish c8b49aee56 defrag: check minimum size of reassembled packet
Before re-assembling, check that the first fragment is large
enough to contain the IPv4 or IPv6 header to prevent
an out of bounds read (IPv4) or write (IPv6).

Reported-by: Sirko Höer -- Code Intelligence for DCSO.

Bug #3171.
6 years ago
Jason Ish 9b86c7c5c0 defrag: break out of loop in linux profile when able to 7 years ago
Jason Ish aa98678662 defrag: remove fragments that have complete overlap
Instead of just marking fragments that have been completely
overlapped and won't be part of the assembled packet, remove
them from the fragment tree when detected.
7 years ago
Jason Ish fe6e96a8c1 defrag: use rb tree to store fragments 7 years ago
Victor Julien ab1200fbd7 compiler: more strict compiler warnings
Set flags by default:

    -Wmissing-prototypes
    -Wmissing-declarations
    -Wstrict-prototypes
    -Wwrite-strings
    -Wcast-align
    -Wbad-function-cast
    -Wformat-security
    -Wno-format-nonliteral
    -Wmissing-format-attribute
    -funsigned-char

Fix minor compiler warnings for these new flags on gcc and clang.
9 years ago