]> git.ipfire.org Git - thirdparty/suricata.git/commit
detect/threshold: fix offline time handling issue
authorVictor Julien <vjulien@oisf.net>
Tue, 7 Jun 2022 20:57:39 +0000 (22:57 +0200)
committerVictor Julien <vjulien@oisf.net>
Fri, 17 Jun 2022 15:41:31 +0000 (17:41 +0200)
commit72fad4a9f8be9dbc35a445fce572f8fe59e7ec27
treebe73472c89fe1a0f4f8617064e6cd685027e13cb
parent7f1a8b144ba0b726f25738264993b996441fd67b
detect/threshold: fix offline time handling issue

Due to the TIMEVAL_DIFF_SEC calculating the delta into an unsigned
integer, it would underflow to a high positive value leading to
and incorrect result if the packet timestamp was below the timestamp
for the threshold entry. In normal conditions this shouldn't happen,
but in offline mode each thread has its own concept of time which
might differ significantly based on the pcap. In this case the
overflow would be very common.

Changing it to a signed value calculation triggered fuzz undefined
behavior if the packet timeval was very high, so this patch takes a
new approach where it no longer calculates a diff but sets up the
"seconds" value we compare against as a timeval itself, and uses
that to compare.

Fixes: 9fafc1031c0c ("time: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.")
Fixes: 82dc61f4c3e3 ("detect/threshold: Refactor threshold calculation to handle by_rule and by_both.")
Uses add `timeradd` specific version where available.

Bug: #5386.
(cherry picked from commit df2e408d96d0e37a0599f885dc29fff4011f8899)
src/detect-engine-threshold.c
src/detect-threshold.h
src/util-time.h