Re: [tcpm] RFC 5925 SNE algorithm concern

Joseph Touch <touch@strayalpha.com> Thu, 30 April 2020 14:31 UTC

Return-Path: <touch@strayalpha.com>
X-Original-To: tcpm@ietfa.amsl.com
Delivered-To: tcpm@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 3E4BB3A08FA for <tcpm@ietfa.amsl.com>; Thu, 30 Apr 2020 07:31:26 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.319
X-Spam-Level:
X-Spam-Status: No, score=-1.319 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, URIBL_BLOCKED=0.001] autolearn=no autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=strayalpha.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4z3Hyg5GQ4s8 for <tcpm@ietfa.amsl.com>; Thu, 30 Apr 2020 07:31:24 -0700 (PDT)
Received: from server217-3.web-hosting.com (server217-3.web-hosting.com [198.54.115.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 129753A08F8 for <tcpm@ietf.org>; Thu, 30 Apr 2020 07:31:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=strayalpha.com; s=default; h=To:References:Message-Id: Content-Transfer-Encoding:Cc:Date:In-Reply-To:From:Subject:Mime-Version: Content-Type:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KaBBnuWk7OtLSpzNtxbLTW20JsXqbQ/5wytAqJe3PrI=; b=k+Cb3FsKMGsYcP/3vOoPFOmIQ N13hhEQbdxEpqsFMzu4k29V1H2JGHoaYpb46LxF8cDx0L/bKOt0+RxGJ7llXeNE8k2Y2ug7fQSznh cZbIPVgL5Ugr9fSjXgN2EhCL0qGVoG/bmt5dWwhvAeVgZ29wFfRFafXBg0SwWmgbOC66TqUSw33AV /V9kmXtC7651kSMko7EmstIvkw7XA73XBChipMxOGEN1BWT4/xMp9r2E6rPBRDzTtiYwLOAwnGamn mHaJi2SzoZqbhBiupzZ9gcEG9CNM/9mo28dxz8sBAgY4Pz4NkFvkkGEDfMscTK/GnzAkruPrDPf31 q+er1VS2A==;
Received: from cpe-172-250-225-198.socal.res.rr.com ([172.250.225.198]:62288 helo=[192.168.1.14]) by server217.web-hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from <touch@strayalpha.com>) id 1jUADf-003nhl-76; Thu, 30 Apr 2020 10:31:23 -0400
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\))
From: Joseph Touch <touch@strayalpha.com>
In-Reply-To: <CACS3ZpBLAO2=O6Vf2Vx766qAGqmY2yD_yiLag-K7C3sYFjH9hw@mail.gmail.com>
Date: Thu, 30 Apr 2020 07:31:18 -0700
Cc: tcpm@ietf.org
Content-Transfer-Encoding: quoted-printable
Message-Id: <EAE578C4-4C60-429A-9826-821B3075DA08@strayalpha.com>
References: <CACS3ZpBLAO2=O6Vf2Vx766qAGqmY2yD_yiLag-K7C3sYFjH9hw@mail.gmail.com>
To: juhamatk@gmail.com
X-Mailer: Apple Mail (2.3608.60.0.2.5)
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - server217.web-hosting.com
X-AntiAbuse: Original Domain - ietf.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - strayalpha.com
X-Get-Message-Sender-Via: server217.web-hosting.com: authenticated_id: touch@strayalpha.com
X-Authenticated-Sender: server217.web-hosting.com: touch@strayalpha.com
X-Source:
X-Source-Args:
X-Source-Dir:
X-From-Rewrite: unmodified, already matched
Archived-At: <https://mailarchive.ietf.org/arch/msg/tcpm/nJBthGbsfiRY_b5j0t3h2K9ljl4>
Subject: Re: [tcpm] RFC 5925 SNE algorithm concern
X-BeenThere: tcpm@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: TCP Maintenance and Minor Extensions Working Group <tcpm.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/tcpm>, <mailto:tcpm-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/tcpm/>
List-Post: <mailto:tcpm@ietf.org>
List-Help: <mailto:tcpm-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/tcpm>, <mailto:tcpm-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 30 Apr 2020 14:31:28 -0000

Hi, Juhamatti,

See embedded below:

> On Apr 30, 2020, at 12:31 AM, juhamatk@gmail.com wrote:
> 
> Hello all,
> 
> While working with RFC 5925, I have been checking the details of
> example SNE algorithm. I have a slight concern with the example
> algorithm proposed by the RFC.
> 
> The idea of SNE is to simulate 64-bit sequence number with 32-bit
> sequences to prevent replay attacks. RFC 5925 proposes the following
> algorithm to implement 64-bit sequence numbering:
> 
> Original algorithm pseudo-code in the RFC 5925 + errata:
>     /* set the flag when the SEG.SEQ first rolls over */
>     if ((RCV.SNE_FLAG == 0)
>        && (RCV.PREV_SEQ > 0x7fffffff) && (SEG.SEQ < 0x7fffffff)) {
>           RCV.SNE = RCV.SNE + 1;
>           RCV.SNE_FLAG = 1;
>     }
>     /* decide which SNE to use after incremented */
>     if ((RCV.SNE_FLAG == 1) && (SEG.SEQ > 0x7fffffff)) {
>        SNE = RCV.SNE - 1; # use the pre-increment value
>     } else {
>        SNE = RCV.SNE; # use the current value
>     }
>     /* reset the flag in the *middle* of the window */
>     if ((RCV.PREV_SEQ < 0x7fffffff) && (SEG.SEQ > 0x7fffffff)) {
>        RCV.SNE_FLAG = 0;
>     }
>     /* save the current SEQ for the next time through the code */
>     RCV.PREV_SEQ = SEG.SEQ;
> 
> When looking into this in detail, to me it looks like there might be
> an issue when 32-bit sequence wraps back to the beginning and a
> retransmission occurs with the high sequence range.

Retransmission should always use the value cached with that segment, so there should not be an issue.

> Then SNE is
> increased unexpectedly and does not follow proper sequencing. A test
> case below:
> 
> State:
> PREV_SEQ = 0xffffffe
> RCV.SNE = 0
> RCV.SNE_FLAG = 0
> 
> New frame:
> SEG.SEQ = 0x0
> RCV.SNE => 1
> RCV.SNE_FLAG => 1
> PREV_SEQ => 0
> 
> Retransmit:
> SEG.SEQ = 0xfffffffd
> RCV.SNE_FLAG => 0 - incorrectly updated
> PREV_SEQ => 0xfffffffd - incorrectly updated

You’re using the pseudocode that creates new SNEs with a previously transmitted value. It’s acting like you’ve wrapped too quickly. 

> 
> New frame:
> SEG.SEQ = 0x2
> RCV.SNE => 2 - incorrect value, should be 1 based on sequencing
> RCV.SNE_FLAG => 1
> PREV_SEQ => 0x2
> 
> I could not figure out any reason why the above sequence would not be
> valid.

Because retransmission should be using the values cached when the original transmission occurred.

I don’t think the new code is needed - at least from this example.

Joe

> Even though it is mentioned in the RFC that the algorithm is
> just an example, the sequencing mismatch is unfortunate as mismatching
> SNEs on different sides will bring the authenticated TCP session down
> and cause data loss through timeout. Thus, for interoperability, it is
> crucial that correct sequencing is used on both ends.
> 
> If above is really a real problem, then perhaps an improved algorithm
> could be as follows:
> 
> Improved algorithm suggestion pseudo-code:
>     PRE = 0;
>     // set the flag when the SEG.SEQ first rolls over
>     if ((RCV.SNE_FLAG == 0)
>        && (RCV.PREV_SEQ > 0x7fffffff) && (SEG.SEQ < 0x7fffffff)) {
>          RCV.SNE = RCV.SNE + 1;
>          RCV.SNE_FLAG = 1;
>     }
>     // decide which SNE to use after incremented,
>     // pre-increment is used for retransmits
>     if ((RCV.SNE_FLAG == 1) && (SEG.SEQ > 0x7fffffff)) {
>        SNE = RCV.SNE - 1; # use the pre-increment value
>        PRE = 1;
>     } else {
>        SNE = RCV.SNE; # use the current value
>     }
>     // reset the flag in the *middle* of the window,
>     // include SEG.SEQ equals half so that we do not miss
>     // that edge case
>     if (PRE == 0) {
>        if(RCV.SNE_FLAG == 1 &&
>           RCV.PREV_SEQ < 0x7fffffff) && (SEG.SEQ >= 0x7fffffff)) {
>           RCV.SNE_FLAG = 0;
>        }
>        // save the current SEQ for the next time through the code,
>        // if we are not retransmitting
>        RCV.PREV_SEQ = SEG.SEQ;
>     }
> 
> This passes the problematic case (and bunch of others I have tested).
> This also includes a small additional fix in the middle window
> handling where SEG.SEQ was missing one edge value (SEG.SEQ >
> 0x7fffffff => SEG.SEQ >= 0x7fffffff). I hope I have not missed
> anything else, but it is certainly possible, so comments are welcome.
> 
> So, what do you think, is this a real concern? If it is a real issue,
> what would be the best way to handle this, perhaps an errata with an
> improved algorithm after throughout review of the new algorithm?
> 
> Thank you,
> --
> Juhamatti
> 
> _______________________________________________
> tcpm mailing list
> tcpm@ietf.org
> https://www.ietf.org/mailman/listinfo/tcpm