Project

General

Profile

Actions

Documentation #8031

open

isdataat: document different semantics between absolute and relative modes

Added by Sven Cuyt 3 months ago. Updated 13 days ago.

Status:
In Review
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

Description

There seems to be an off by one error in isdataat's implementation. Below is the code that handles isdataat in detect-engine-content-inspection.c. Consider the following two scenarios:

1. isdataat is used absolutely with a value equal to the packet length. In that case, dataat < buffer_len would be false, thus it would not be a match.
2. isdataat is used relatively with a value equal to the packet length and the current offset is 0. In that case, det_ctx->buffer_offset + dataat > buffer_len is false, which results in a match.

However, I'd expect a relative isdataat from offset 0 to behave the same as an absolute isdataat.

        if (id->flags & ISDATAAT_RELATIVE) {
            if (det_ctx->buffer_offset + dataat > buffer_len) {
                SCLogDebug("det_ctx->buffer_offset + dataat %"PRIu32" > %"PRIu32, det_ctx->buffer_offset + dataat, buffer_len);
                if (id->flags & ISDATAAT_NEGATED)
                    goto match;
                if ((id->flags & ISDATAAT_OFFSET_VAR) == 0) {
                    goto no_match_discontinue;
                }
                goto no_match;
            } else {
                SCLogDebug("relative isdataat match");
                if (id->flags & ISDATAAT_NEGATED) {
                    goto no_match;
                }
                goto match;
            }
        } else {
            if (dataat < buffer_len) {
                SCLogDebug("absolute isdataat match");
                if (id->flags & ISDATAAT_NEGATED) {
                    if ((id->flags & ISDATAAT_OFFSET_VAR) == 0) {
                        goto no_match_discontinue;
                    }
                    goto no_match;
                }
                goto match;
            } else {
                SCLogDebug("absolute isdataat mismatch, id->isdataat %"PRIu32", buffer_len %"PRIu32"", dataat, buffer_len);
                if (id->flags & ISDATAAT_NEGATED)
                    goto match;
                if ((id->flags & ISDATAAT_OFFSET_VAR) == 0) {
                    goto no_match_discontinue;
                }
                goto no_match;
            }
        }
References:

Subtasks 2 (2 open0 closed)

Documentation #8240: isdataat: document different semantics between absolute and relative modes (8.0.x backport)AssignedVictor JulienActions
Documentation #8241: isdataat: document different semantics between absolute and relative modes (7.0.x backport)AssignedVictor JulienActions
Actions #1

Updated by Victor Julien 13 days ago

  • Subject changed from Different semantics between absolute and relative isdataat to isdataat: different semantics between absolute and relative modes
  • Status changed from New to Assigned
  • Assignee set to Victor Julien

I'll investigate.

Actions #2

Updated by Victor Julien 13 days ago · Edited

  • Tracker changed from Bug to Documentation
  • Subject changed from isdataat: different semantics between absolute and relative modes to isdataat: document different semantics between absolute and relative modes
  • Target version changed from TBD to 9.0.0-beta1

So this turns out to be a documented thing, but it's only documented here https://docs.suricata.io/en/suricata-8.0.2/rules/differences-from-snort.html#isdataat-keyword

It should be documented with the actual keyword doc too. It is not behavior we can change as it would risk of breaking many existing rules.

Actions #4

Updated by Victor Julien 13 days ago

  • Label Needs backport to 7.0, Needs backport to 8.0 added
Actions #5

Updated by OISF Ticketbot 13 days ago

  • Subtask #8240 added
Actions #6

Updated by OISF Ticketbot 13 days ago

  • Label deleted (Needs backport to 8.0)
Actions #7

Updated by OISF Ticketbot 13 days ago

  • Subtask #8241 added
Actions #8

Updated by OISF Ticketbot 13 days ago

  • Label deleted (Needs backport to 7.0)
Actions #9

Updated by Sven Cuyt 13 days ago

Victor Julien wrote in #note-2:

So this turns out to be a documented thing, but it's only documented here https://docs.suricata.io/en/suricata-8.0.2/rules/differences-from-snort.html#isdataat-keyword

It should be documented with the actual keyword doc too. It is not behavior we can change as it would risk of breaking many existing rules.

Being unable to change the existing behavior is unfortunate but understandable. As a result I'd love to see clear documentation explaining the difference between absolute and relative isdataat, e.g. by providing some examples.

Actions #10

Updated by Victor Julien 13 days ago · Edited

@Surikitty any feedback on https://github.com/OISF/suricata/pull/14664/changes#diff-7ffcd036dc5853dac864215faa64a0401e43ba8d38eeb35730aeaf42295d22aeR274 ?

(edit: spotted an error in the table, should be good now)

Actions #11

Updated by Sven Cuyt 13 days ago

Can you also add the link to https://docs.suricata.io/en/suricata-8.0.2/rules/differences-from-snort.html#isdataat-keyword

I also left some comments on the merge request you made.

Actions

Also available in: Atom PDF