Re: Regarding keyed MD5/SHA1 authentication for BFD (RFC 5880)

Alan DeKok <aland@deployingradius.com> Wed, 27 April 2022 19:14 UTC

Return-Path: <aland@deployingradius.com>
X-Original-To: rtg-bfd@ietfa.amsl.com
Delivered-To: rtg-bfd@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 4021CC1594AB for <rtg-bfd@ietfa.amsl.com>; Wed, 27 Apr 2022 12:14:41 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.9
X-Spam-Level:
X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UbBd9FfSBR49 for <rtg-bfd@ietfa.amsl.com>; Wed, 27 Apr 2022 12:14:37 -0700 (PDT)
Received: from mail.networkradius.com (mail.networkradius.com [62.210.147.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id DD2A3C159494 for <rtg-bfd@ietf.org>; Wed, 27 Apr 2022 12:14:36 -0700 (PDT)
Received: from smtpclient.apple (24-52-251-6.cable.teksavvy.com [24.52.251.6]) by mail.networkradius.com (Postfix) with ESMTPSA id 61832216; Wed, 27 Apr 2022 19:14:33 +0000 (UTC)
Authentication-Results: NetworkRADIUS; dmarc=none (p=none dis=none) header.from=deployingradius.com
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.60.0.1.1\))
Subject: Re: Regarding keyed MD5/SHA1 authentication for BFD (RFC 5880)
From: Alan DeKok <aland@deployingradius.com>
In-Reply-To: <b4a3419f-b465-90fd-0f92-7385fa5595c4@mikrotik.com>
Date: Wed, 27 Apr 2022 15:14:31 -0400
Cc: rtg-bfd@ietf.org
Content-Transfer-Encoding: quoted-printable
Message-Id: <03DC02BB-FBC4-4820-83D3-AAC309E16117@deployingradius.com>
References: <b4a3419f-b465-90fd-0f92-7385fa5595c4@mikrotik.com>
To: Gļebs Ivanovskis <glebs@mikrotik.com>
X-Mailer: Apple Mail (2.3693.60.0.1.1)
Archived-At: <https://mailarchive.ietf.org/arch/msg/rtg-bfd/i_xs-GdP8b7AXM1_GzsEajjsa1Y>
X-BeenThere: rtg-bfd@ietf.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: "RTG Area: Bidirectional Forwarding Detection DT" <rtg-bfd.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/rtg-bfd>, <mailto:rtg-bfd-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/rtg-bfd/>
List-Post: <mailto:rtg-bfd@ietf.org>
List-Help: <mailto:rtg-bfd-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/rtg-bfd>, <mailto:rtg-bfd-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 27 Apr 2022 19:14:41 -0000

On Apr 25, 2022, at 6:23 AM, Gļebs Ivanovskis <glebs@mikrotik.com> wrote:
> I have a question regarding the order of operations during receipt of BFD control packet using keyed MD5/SHA1 authentication. Both Section 6.7.3. "Keyed MD5 and Meticulous Keyed MD5 Authentication" and Section 6.7.4. "Keyed SHA1 and Meticulous Keyed SHA1 Authentication" (in parts "Receipt Using Keyed MD5 and Meticulous Keyed MD5 Authentication" and "Receipt Using Keyed SHA1 and Meticulous Keyed SHA1 Authentication" respectively) suggest that Sequence Number field of incoming control packet is examined prior to calculating any digest/hash. I have discovered that the order was the other way round in early drafts, but then was changed between versions 8 and 9, presumably followed by this comment:
> 
> If we check the sequence number after doing a MD5 digest verification, even if we get replayed packets, we will be doing the costly hash operations, thus wasting a lot of CPU and exposing ourselves to simple CPU exhaustion attacks.

  From a security point of view, the usual process is to verify packets first, and then use the contents of the packets.  This can be expensive from a CPU point of view, but it's the cost of being secure.

> Unfortunately, I couldn't find any discussion following this suggestion. I understand the motivation of making a "cheaper" Sequence Number check before doing more "expensive" digest/hash calculation, but the reordering of stages does not seem to be thought through very well. The text of RFC 5880 mandates implementations to act on received Sequence Number before validating digest/hash:
> 
> Otherwise (bfd.AuthSeqKnown is 0), bfd.AuthSeqKnown MUST be set to 1, and bfd.RcvAuthSeq MUST be set to the value of the received Sequence Number field.
> 
> and
> 
> Otherwise (bfd.AuthSeqKnown is 0), bfd.AuthSeqKnown MUST be set to 1, bfd.RcvAuthSeq MUST be set to the value of the received Sequence Number field, and the received packet MUST be accepted.
> 
> This leaves the opportunity for unauthorized control packet to mess up session state variables, potentially leading to subsequent valid packets being dropped due to Sequence Number outside of expected range and BFD session being erroneously diagnosed as Down. Note that "and the received packet MUST be accepted" clause has been removed from MD5 part, but not from SHA1 part, requesting implementations to skip hash verification altogether if bfd.AuthSeqKnown is 0.

  It would be good to say that packets which fail authentication MUST NOT affect the BFD state.

> Is the sequence of operations described in Sections 6.7.3. and 6.7.4. correct?
> 
> In my opinion, as a minimum, the following changes need to be made:
> 
> 	• The "and the received packet MUST be accepted" clause needs to be removed from Section 6.7.4.
> 	• Sections 6.7.3. and 6.7.4. need to split examining incoming packet's Sequence Number (which can be done before digest/hash verification) and acting upon it (which has to happen after verification).

  That seems reasonable.

> Furthermore, I would like to suggest going back to original ordering with digest/hash verification being done before examining Sequence Number, because it simplifies the algorithm. I don't think that checking Sequence Number first provides much protection against CPU exhaustion attacks, because Sequence Numbers are transmitted in clear text and it wouldn't be that difficult for an attacker to come up with a valid Sequence Number to pass "cheap" check.

  Yes.

  The "secure sequence numbers" draft attempts to address these issues.

  Alan DeKok.