CVE-2017-13040 (Other, published 2017-09-14T06:29Z)
Description: value: The MPTCP parser in tcpdump before 4.9.2 has a buffer over-read in print-mptcp.c, several functions.
Severity: HIGH (CVSS v3 base score: 9.8)
Weakness: CWE-125 \u2014 Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
Repository: https://github.com/the-tcpdump-group/tcpdump
Files changed:
print-mptcp.c
tests/TESTLIST
tests/mptcp-dss-oobr.out
Commit message: CVE-2017-13040/MPTCP: Clean up printing DSS suboption.

Do the length checking inline; that means we print stuff up to the point
at which we run out of option data.

First check to make sure we have at least 4 bytes of option, so we have
flags to check.

This fixes a buffer over-read discovered by Kim Gwan Yeong.

Add a test using the capture file supplied by the reporter(s).


Vulnerable code:
        if (!(opt_len == 12 && flags & TH_SYN) &&
        if (!(opt_len == 12 && flags & TH_SYN) &&
            !(opt_len == 24 && flags & TH_ACK))
static u_int mp_dss_len(const  struct mp_dss *m, int csum)
{
        u_int len;

        len = 4;
        if (m->flags & MP_DSS_A) {
                /* Ack present - 4 or 8 octets */
                len += (m->flags & MP_DSS_a) ? 8 : 4;
        }
        if (m->flags & MP_DSS_M) {
                /*
                 * Data Sequence Number (DSN), Subflow Sequence Number (SSN),
                 * Data-Level Length present, and Checksum possibly present.
                 * All but the Checksum are 10 bytes if the m flag is
                 * clear (4-byte DSN) and 14 bytes if the m flag is set
                 * (8-byte DSN).
                 */
                len += (m->flags & MP_DSS_m) ? 14 : 10;

                /*
                 * The Checksum is present only if negotiated.
                 */
                if (csum)
                        len += 2;
	}
	return len;
}

        if ((opt_len != mp_dss_len(mdss, 1) &&
             opt_len != mp_dss_len(mdss, 0)) || flags & TH_SYN)
                if (opt_len == mp_dss_len(mdss, 1))

Fixed code:
        if (!(opt_len == 12 && (flags & TH_SYN)) &&
        if (!(opt_len == 12 && (flags & TH_SYN)) &&
            !(opt_len == 24 && (flags & TH_ACK)))
        /* We need the flags, at a minimum. */
        if (opt_len < 4)
                return 0;

        if (flags & TH_SYN)
        opt_len -= 4;
                /* Ack present */
                /*
                 * If the a flag is set, we have an 8-byte ack; if it's
                 * clear, we have a 4-byte ack.
                 */
                        if (opt_len < 8)
                                return 0;
                        opt_len -= 8;
                        if (opt_len < 4)
                                return 0;
                        opt_len -= 4;
                /*
                 * Data Sequence Number (DSN), Subflow Sequence Number (SSN),
                 * Data-Level Length present, and Checksum possibly present.
                 */
		/*
                 * If the m flag is set, we have an 8-byte NDS; if it's clear,
                 * we have a 4-byte DSN.
                 */
                        if (opt_len < 8)
                                return 0;
                        opt_len -= 8;
                        if (opt_len < 4)
                                return 0;
                        opt_len -= 4;
                if (opt_len < 4)
                        return 0;
                opt_len -= 4;
                if (opt_len < 2)
                        return 0;
                opt_len -= 2;
                /*
                 * The Checksum is present only if negotiated.
                 * If there are at least 2 bytes left, process the next 2
                 * bytes as the Checksum.
                 */
                if (opt_len >= 2) {
                        opt_len -= 2;
                }
        if (opt_len != 0)
                return 0;
# bad packets from Kim Gwan Yeong
mptcp-dss-oobr		mptcp-dss-oobr.pcap		mptcp-dss-oobr.out	-v

IP (tos 0x10, ttl 64, id 39991, offset 0, flags [DF], proto TCP (6), length 60)
    127.0.0.1.57370 > 127.0.0.1.23: Flags [S], seq 1736820995, win 32792, options [mss 16396,sackOK,TS val 597120308 ecr 0,mptcp dss[bad opt]>