Skip to content

Commit

Permalink
ipv6: decoder event on invalid length
Browse files Browse the repository at this point in the history
From RFC 2460, section 4.5,
each fragment, except the last one, must have a length
which is a multiple of 8
  • Loading branch information
catenacyber authored and victorjulien committed Sep 3, 2021
1 parent 596a4a9 commit ca760e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rules/decoder-events.rules
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ alert pkthdr any any -> any any (msg:"SURICATA FRAG IPv4 Packet size too large";
alert pkthdr any any -> any any (msg:"SURICATA FRAG IPv4 Fragmentation overlap"; decode-event:ipv4.frag_overlap; classtype:protocol-command-decode; sid:2200070; rev:2;)
alert pkthdr any any -> any any (msg:"SURICATA FRAG IPv6 Packet size too large"; decode-event:ipv6.frag_pkt_too_large; classtype:protocol-command-decode; sid:2200071; rev:3;)
alert pkthdr any any -> any any (msg:"SURICATA FRAG IPv6 Fragmentation overlap"; decode-event:ipv6.frag_overlap; classtype:protocol-command-decode; sid:2200072; rev:2;)
alert pkthdr any any -> any any (msg:"SURICATA FRAG IPv6 Fragment invalid length"; decode-event:ipv6.frag_invalid_length; classtype:protocol-command-decode; sid:2200119; rev:1;)

# checksum rules
alert ip any any -> any any (msg:"SURICATA IPv4 invalid checksum"; ipv4-csum:invalid; classtype:protocol-command-decode; sid:2200073; rev:2;)
Expand Down Expand Up @@ -149,5 +150,5 @@ alert pkthdr any any -> any any (msg:"SURICATA CHDLC packet too small"; decode-e

alert pkthdr any any -> any any (msg:"SURICATA packet with too many layers"; decode-event:too_many_layers; classtype:protocol-command-decode; sid:2200116; rev:1;)

# next sid is 2200119
# next sid is 2200120

4 changes: 4 additions & 0 deletions src/decode-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ const struct DecodeEvents_ DEvents[] = {
"decoder.ipv6.frag_overlap",
IPV6_FRAG_OVERLAP,
},
{
"decoder.ipv6.frag_invalid_length",
IPV6_FRAG_INVALID_LENGTH,
},
/* Fragment ignored due to internal error */
{
"decoder.ipv4.frag_ignored",
Expand Down
1 change: 1 addition & 0 deletions src/decode-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ enum {
IPV6_FRAG_PKT_TOO_LARGE,
IPV4_FRAG_OVERLAP,
IPV6_FRAG_OVERLAP,
IPV6_FRAG_INVALID_LENGTH,

/* Fragment ignored due to internal error */
IPV4_FRAG_IGNORED,
Expand Down
6 changes: 6 additions & 0 deletions src/decode-ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
plen -= hdrextlen;
break;
}
if (p->ip6eh.fh_more_frags_set != 0 && plen % 8 != 0) {
// cf https://datatracker.ietf.org/doc/html/rfc2460#section-4.5
// each, except possibly the last ("rightmost") one,
// being an integer multiple of 8 octets long.
ENGINE_SET_EVENT(p, IPV6_FRAG_INVALID_LENGTH);
}

/* the rest is parsed upon reassembly */
p->flags |= PKT_IS_FRAGMENT;
Expand Down

0 comments on commit ca760e3

Please sign in to comment.