Skip to content

Commit

Permalink
bgpd: fix insecure data write with ip addresses
Browse files Browse the repository at this point in the history
Fix issues where an attacker may inject a tainted length value to
corrupt the memory.

> CID 1568378 (#1-6 of 6): Untrusted value as argument (TAINTED_SCALAR)
> 16. tainted_data: Passing tainted expression length to bgp_linkstate_tlv_attribute_value_display, which uses it as an offset. [show details]

Fixes: 7e0d9ff ("bgpd: display link-state prefixes detail")
Signed-off-by: Louis Scalbert <[email protected]>
  • Loading branch information
louis-6wind committed Sep 28, 2023
1 parent 25408c8 commit b4a24b5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bgpd/bgp_linkstate_tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,8 @@ static bool bgp_linkstate_nlri_value_display(char *buf, size_t size,
break;
case BGP_LS_TLV_IP_REACHABILITY_INFORMATION:
mask_length = pnt_decode8(&pnt);
if (nlri_type == BGP_LINKSTATE_PREFIX4) {
if (nlri_type == BGP_LINKSTATE_PREFIX4 &&
((length - sizeof(mask_length)) <= sizeof(ipv4.s_addr))) {
memcpy(&ipv4.s_addr, pnt, length - sizeof(mask_length));
if (json)
json_object_string_addf(json, "ipReachability",
Expand All @@ -587,7 +588,8 @@ static bool bgp_linkstate_nlri_value_display(char *buf, size_t size,
snprintfrr(buf, size, "%sIPv4:%pI4/%u",
first ? "" : " ", &ipv4,
mask_length);
} else if (nlri_type == BGP_LINKSTATE_PREFIX6) {
} else if (nlri_type == BGP_LINKSTATE_PREFIX6 &&
((length - sizeof(mask_length)) <= sizeof(ipv6))) {
memcpy(&ipv6, pnt, length - sizeof(mask_length));
if (json)
json_object_string_addf(json, "ipReachability",
Expand Down

0 comments on commit b4a24b5

Please sign in to comment.