]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: check if signature uses too many buffers
authorPhilippe Antoine <pantoine@oisf.net>
Wed, 27 Sep 2023 12:15:18 +0000 (14:15 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 3 Oct 2023 07:29:30 +0000 (09:29 +0200)
Ticket: #6104

The approach in master branch is to change the prototype of
SigMatchAppendSMToList so that it allocates itself the new SigMatch
This approach requires to change all the 100-ish calls to
SigMatchAppendSMToList and is thus quite a big change.

For branch 7, we still wanted to avoid the buffer overflow, but
did not want such an intrusive change, and still wanted to make
the signature invalid. Instead of changing the prototype of the
function, we make it return early, and set a flag in the signature
which can be later checked by SigValidate

src/detect-parse.c
src/detect.h

index 33d739300dd8ee9a0d5d0be4518b3746a74ce055..2e798d7b1cbf9556b62bbb67588cfdb8b5b2e7b1 100644 (file)
@@ -473,7 +473,8 @@ void SigMatchAppendSMToList(Signature *s, SigMatch *new, const int list)
                 s->init_data->curbuf == NULL) {
             if (SignatureInitDataBufferCheckExpand(s) < 0) {
                 SCLogError("failed to expand rule buffer array");
-                // return -1; TODO error handle
+                s->init_data->init_flags |= SIG_FLAG_INIT_OVERFLOW;
+                return;
             }
 
             /* initialize new buffer */
@@ -1904,6 +1905,11 @@ static int SigValidate(DetectEngineCtx *de_ctx, Signature *s)
         SCReturnInt(0);
     }
 
+    if (s->init_data->init_flags & SIG_FLAG_INIT_OVERFLOW) {
+        SCLogError("rule %u tries to use too many buffers", s->id);
+        SCReturnInt(0);
+    }
+
     bool has_frame = false;
     bool has_app = false;
     bool has_pkt = false;
index fd299c5047b2ca6fd886e0946c31c473c3e8b002..69a5524e583c6bba3ce1e6a9a6e4434b799bc6f6 100644 (file)
@@ -283,6 +283,7 @@ typedef struct DetectPort_ {
     BIT_U32(8) /**< priority is explicitly set by the priority keyword */
 #define SIG_FLAG_INIT_FILEDATA              BIT_U32(9)  /**< signature has filedata keyword */
 #define SIG_FLAG_INIT_JA3                   BIT_U32(10) /**< signature has ja3 keyword */
+#define SIG_FLAG_INIT_OVERFLOW              BIT_U32(11) /**< signature has overflown buffers */
 
 /* signature mask flags */
 /** \note: additions should be added to the rule analyzer as well */