<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="rfc7991bis.rnc"?> 

<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc
  xmlns:xi="http://www.w3.org/2001/XInclude"
  category="std"
  docName="draft-ietf-tcpm-tcp-ghost-acks-10"
  ipr="trust200902"
  obsoletes=""
  updates=""
  submissionType="IETF"
  xml:lang="en"
  version="3">

  <front>
    <title abbrev="Ghost ACKs Mitigation">Improve TCP Handling of Out-of-Window Packets to Mitigate Ghost ACKs</title>
    <seriesInfo name="Internet-Draft" value="draft-ietf-tcpm-tcp-ghost-acks-10"/> 
    <author fullname="Yepeng Pan" initials="Y." surname="Pan"> 
      <organization abbrev='CISPA'>CISPA Helmholtz Center for Information Security</organization>
      <address>
      <email>yepeng.pan@cispa.de</email>
      </address>
    </author>
    <author fullname="Christian Rossow" initials="C." surname="Rossow">
      <organization abbrev='CISPA'>CISPA Helmholtz Center for Information Security</organization>
      <address>
      <email>rossow@cispa.de</email>
      </address>
    </author>
    <date/>
    <area>Transport</area>
    <workgroup>TCPM</workgroup>
    <keyword>TCP</keyword>
    <keyword>TCPM</keyword>
    <keyword>transport layer</keyword>
    <keyword>internet transport</keyword>
    <abstract pn="section-abstract">
      <t indent="0" pn="section-abstract-1">
        Historically, TCP as specified in RFC 793 was threatened 
        by the blind data injection attack because of the loose <tt>SEG.ACK</tt> value validation, where the <tt>SEG.ACK</tt> value of a
        TCP segment is considered valid in synchronized states as long as it does not acknowledge data ahead of what has been sent.
        RFC 5961 improved the input validation by
        shrinking the range of acceptable <tt>SEG.ACK</tt> values in a TCP segment. Later, RFC 9293
        incorporated the updates proposed by RFC 5961 as a TCP stack implementation option.<br></br>

        However, an endpoint that follows the RFC 9293 specifications can still accept in synchronized states a TCP segment containing
        an <tt>SEG.ACK</tt> value acknowledging data that the endpoint has never sent. This document specifies small modifications to the
        way TCP verifies incoming TCP segments' <tt>SEG.ACK</tt> value to prevent TCP from accepting such invalid <tt>SEG.ACK</tt> values.
      </t>
    </abstract>
  </front>

  <middle>
    <section>
      <name>Introduction</name>
      <t>
        TCP (as originally specified by  <xref target="RFC0793"/>) is widely deployed in today's Internet.
        Against the threat of the blind data injection attack, <xref section="5" sectionFormat="of" target="RFC5961"/> 
        proposed to improve the validation of the <tt>SEG.ACK</tt> field of incoming TCP segments handled in synchronized states.
        Currently, <xref target="RFC9293"/> is the latest main document for TCP, which obsoletes <xref target="RFC0793"/> and incorporates the <tt>SEG.ACK</tt> validation proposed by <xref target="RFC5961"/>
        as an optional implementation choice.

        The <tt>SEG.ACK</tt> validation introduced in <xref target="RFC9293"/> (with or without the <xref target="RFC5961"/> implementation choice)
        accepts in synchronized states a certain range of <tt>SEG.ACK</tt> values before <tt>SND.UNA</tt> as duplicate/old ACK values.
        This also applies to connections without data (or with little data) transferred previously.
        Consequently, current <tt>SEG.ACK</tt> validation in synchronized states accepts segments with invalid <tt>SEG.ACK</tt> values that acknowledge data that an endpoint has never sent as duplicate/old <tt>SEG.ACK</tt> values (ghost ACKs).
        <br></br>


        This document improves the <tt>SEG.ACK</tt> value validation in <xref target="RFC9293"/>,
        such that TCP endpoints in synchronized states would only accept duplicate/old <tt>SEG.ACK</tt> values acknowledging data already sent by the endpoint, eliminating the security risks imposed by ghost ACKs.
      </t>
      
      <section anchor="Terminology">
      <!-- anchor is an optional attribute -->
        <name>Terminology</name>
        <t>The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
        "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>",
        "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>",
        "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
        "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to
        be interpreted as described in
        BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when,
        they appear in all capitals, as shown here.</t>
        <t>TCP terminology is expected to be interpreted as described in <xref target="RFC9293"/>. 
        </t>
      </section>
      <!-- The 'Requirements Language' section is optional -->
    </section>
    
<section>
<name>Ghost ACKs</name>
<t>As described in <xref target="RFC9293"/>, when receiving a segment,
the endpoint performs checks on the <tt>SEG.ACK</tt> field of the
incoming segment.
Suppose the TCP stack has implemented the mitigation for blind data
injection attack proposed by <xref section="5" sectionFormat="of" target="RFC5961"/>,
an incoming segment whose <tt>SEG.ACK</tt> value satisfies the condition
<tt>SND.UNA - MAX.SND.WND =&lt; SEG.ACK =&lt; SND.NXT</tt> is considered
acceptable in a synchronized state, and the segment is further processed.
If the <xref target="RFC5961"/> mitigation is not implemented, an
incoming segment with <tt>SEG.ACK =&lt; SND.NXT</tt> is accepted in a
synchronized state and further processed.</t>
<t>However, there are cases where the number of bytes sent by the
endpoint is less than <tt>MAX.SND.WND</tt> or 2<sup>31</sup> - 1, and
this can result in accepting in a synchronized state a segment with an
<tt>SEG.ACK</tt> value acknowledging bytes the endpoint has never sent.
As a concrete example, consider a newly established TCP connection
without data transferred during the handshake.
There is <tt>SND.UNA == SND.NXT == ISS + 1</tt>.
In this case, any segments with <tt>SEG.ACK &lt; SND.UNA</tt>
acknowledges bytes that the endpoint has never sent, but they are still
considered acceptable since they satisfy the above <tt>SEG.ACK</tt>
validation condition.</t>
<t>Ghost ACKs therefore reduce the effectiveness of ACK validation
against blind data injection attacks, particularly for newly
established TCP connections.</t>
</section>

<section>
<name>Mitigation</name>
<t>TCP endpoints implementing this specification <bcp14>MUST</bcp14> add
in all synchronized states an input check for acknowledgements that
<tt>SEG.ACK</tt> is the next sequence number of a sequence number
occupied by one of the segments, which have been sent before.
All incoming segments whose <tt>SEG.ACK</tt> value doesn't satisfy this
condition <bcp14>MUST</bcp14> be discarded and a challenge ACK sent
back.</t>
<t><xref target="bsdcode"/> and <xref target="linuxcode"/> provide
pseudo code examples showing how to implement this mitigation under the
assumption that the TCP stack supports <xref target="RFC5961"/>.</t>
</section>

<section>
<name>Security Considerations</name>
<t>This document defines ghost ACKs and provides two alternative mitigations
against ghost ACK based attacks.
The security considerations in <xref target="RFC5961"/> and
<xref target="RFC9293"/> still apply to implementations handling ghost ACKs as
described in this document.</t>
<t>TCP implementation supporting <xref target="RFC5961"/> might be subject
to side channel attacks based on challenge ACKs.
When the ghost ACK mitigations are implemented, such attacks might be used to
disclose the <tt>ISS</tt> as long as less than <tt>MAX.SND.WND</tt> bytes of
data have been cumulatively acknowledged or the fact that more than
<tt>MAX.SND.WND</tt> bytes have been cumulatively acknowledged.</t>
</section>

<section>
<name>IANA Considerations</name>
<t>This document does not require any actions from IANA.</t>
</section>

</middle>

<back>

<references>
<name>References</name>
<references>
<name>Normative References</name>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.0793.xml"/>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.5961.xml"/>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.7323.xml"/>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9293.xml"/>
</references>
<references>
<name>Informative References</name>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.4898.xml"/>
</references>
</references>

<section anchor="bsdcode">
<name>Pseudo Code Example 1</name>

<t>This pseudo code example requires that the TCP stack supports
<xref target="RFC5961"/>.
It adds an additional boolean state variable <tt>NO.ISS.CHECK</tt> for
each endpoint in a synchronized state.
This variable is initialized to false.
Whenever <tt>SND.UNA</tt> is incremented, it is determined if the
<tt>ISS</tt>-based check is still needed:</t>
<sourcecode>
if (!NO.ISS.CHECK &amp;&amp; SND.UNA > ISS + (65535 &lt;&lt; Snd.Wind.Shift)) {
    /* Checking SEG.ACK against ISS is definitely redundant. */
    NO.ISS.CHECK = true;
}
</sourcecode>
<t><tt>Snd.Wind.Shift</tt> is defined in <xref target="RFC7323"/>.
For TCP stacks that do not implement <xref target="RFC7323"/>,
<tt>Snd.Wind.Shift</tt> is treated as 0.</t>
<t>At the beginning of the <tt>SEG.ACK</tt> validation in a synchronized
state, a local variable <tt>ACK.MIN</tt> is computed.
It is used to perform the <tt>SEG.ACK</tt> validation, which is stricter.</t>
<sourcecode>
if (NO.ISS.CHECK) {
    /* Check for too old ACKs (RFC 5961, Section 5.2). */
    ACK.MIN = SND.UNA - MAX.SND.WND;
} else {
    if (ISS + 1 > SND.UNA - MAX.SND.WND) {
        /* Checking for ghost ACKs is stricter. */
        ACK.MIN = ISS + 1;
    } else {
        /*
         * Checking for too old ACKs (RFC 5961, Section 5.2)
         * is stricter.
         */
        ACK.MIN = SND.UNA - MAX.SND.WND;
    }
}
</sourcecode>
<t>Finally the validation of <tt>SEG.ACK</tt> in a synchronized state as
specified in <xref section="5.2" sectionFormat="of" target="RFC5961"/>
is changed to:</t>
<sourcecode>
if (SEG.ACK &lt; ACK.MIN || SEG.ACK > SND.NXT) {
    send_challenge_ack();
    return;
}
</sourcecode>
</section>

<section anchor="linuxcode">
<name>Pseudo Code Example 2</name>
<t>This pseudo code example requires that the TCP stack supports
<xref target="RFC5961"/>.
It adds an additional counter <tt>CNT.CUM.ACKED.BYTES</tt> for
each endpoint in a synchronized state, which tracks the number of bytes
that are cumulatively acknowledged by the peer.
The size of this counter has to be chosen large enough to cover values
larger than <tt>MAX.SND.WND</tt> and to ensure that it does not wrap around.
During the initial phase of a TCP endpoint in the ESTABLISHED state,
<tt>CNT.CUM.ACKED.BYTES == SND.UNA - ISS - 1</tt> holds.</t>

<t>A local variable <tt>ACK.MIN</tt> is computed, which is used to
validate the <tt>SEG.ACK</tt> in a synchronized state.</t>
<sourcecode>
if (CNT.CUM.ACKED.BYTES &lt; MAX.SND.WND) {
    ACK.MIN = SND.UNA - CNT.CUM.ACKED.BYTES;
} else {
    ACK.MIN = SND.UNA - MAX.SND.WND;
}
</sourcecode>
<t>Finally the validation of <tt>SEG.ACK</tt> in a synchronized state as
specified in <xref section="5.2" sectionFormat="of" target="RFC5961"/>
is changed to:</t>
<sourcecode>
if (SEG.ACK &lt; ACK.MIN || SEG.ACK > SND.NXT) {
    send_challenge_ack();
    return;
}
</sourcecode>
<t>If the TCP stack supports the counter
<tt>tcpEStatsAppHCThruOctetsAcked</tt> specified in
<xref target="RFC4898"/>, a corresponding check can be implemented using
it instead of adding the counter <tt>CNT.CUM.ACKED.BYTES</tt>.</t>
</section>

<section anchor="Acknowledgements" numbered="false">
<!-- an Acknowledgements section is optional -->
<name>Acknowledgements</name>
<t>We thank Eric Dumazet for proposing the second mitigation option
using <tt>tcpEStatsAppHCThruOctetsAcked</tt>.</t>
</section>
    <!-- <section anchor="Contributors" numbered="false">
      
      <name>Contributors</name>
      <t>Thanks to all of the contributors.</t>
      <contact fullname="Jane Doe" initials="J" surname="Doe">
        
        <organization>Acme</organization>
        <address>
          <email>jdoe@example.com</email>
        </address>
      </contact>
    </section> -->

</back>
</rfc>
