centos 7
integer weakness #3

2

Weakness Breakdown


Definition:

An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.

Warning code(s):

Unless checked, the resulting number can exceed the expected range.

File Name:

iptstate-2.2.5/iptstate.cc

Context:

The highlighted line of code below is the trigger point of this particular Centos 7 integer weakness.

   } else if (entry.family == AF_INET6) {
    nfct_set_attr(ct, ATTR_ORIG_IPV6_SRC, (void *)&entry.src.s6_addr);
    nfct_set_attr(ct, ATTR_ORIG_IPV6_DST, (void *)&entry.dst.s6_addr);
  }

  // undo our space optimization so the kernel can find the state.
  protoent *pn;
  if (entry.proto == "icmp6")
    pn = getprotobyname("ipv6-icmp");
  else
    pn = getprotobyname(entry.proto.c_str());

  nfct_set_attr_u8(ct, ATTR_ORIG_L4PROTO, pn->p_proto);

  if (entry.proto == "tcp" || entry.proto == "udp") {
    nfct_set_attr_u16(ct, ATTR_ORIG_PORT_SRC, htons(entry.srcpt));
    nfct_set_attr_u16(ct, ATTR_ORIG_PORT_DST, htons(entry.dstpt));
  } else if (entry.proto == "icmp" || entry.proto == "icmp6") {
    string type, code, id, tmp;
    split('/', entry.state, type, tmp);
    split(' ', tmp, code, tmp);
    split('(', tmp, tmp, id);
    split(')', id, id, tmp);

    nfct_set_attr_u8(ct, ATTR_ICMP_TYPE, atoi(type.c_str()));
    nfct_set_attr_u8(ct, ATTR_ICMP_CODE, atoi(code.c_str()));
    nfct_set_attr_u16(ct, ATTR_ICMP_ID, atoi(id.c_str()));
  }

  ret = nfct_query(cth, NFCT_Q_DESTROY, ct);
  if (ret < 0) {
    string msg = "Failed to delete state: ";
    msg += strerror(errno);
    c_warn(win, msg.c_str(), flags);
  }

}


/*
 * CORE FUNCTIONS
 */

/*
 * Callback for conntrack
 */
int conntrack_hook(enum nf_conntrack_msg_type nf_type, struct nf_conntrack *ct,
                   void *tmp)
{
 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.