[secdir] Secdir review of draft-ietf-tsvwg-port-randomization-06.txt

Charlie Kaufman <charliek@microsoft.com> Sat, 27 February 2010 02:03 UTC

Return-Path: <charliek@microsoft.com>
X-Original-To: secdir@core3.amsl.com
Delivered-To: secdir@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id E64A128C217; Fri, 26 Feb 2010 18:03:41 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -10.599
X-Spam-Level:
X-Spam-Status: No, score=-10.599 tagged_above=-999 required=5 tests=[BAYES_00=-2.599, RCVD_IN_DNSWL_HI=-8]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CU+64hMMZsLN; Fri, 26 Feb 2010 18:03:40 -0800 (PST)
Received: from smtp.microsoft.com (mailb.microsoft.com [131.107.115.215]) by core3.amsl.com (Postfix) with ESMTP id C6C8C28C1FD; Fri, 26 Feb 2010 18:03:40 -0800 (PST)
Received: from TK5EX14CASC130.redmond.corp.microsoft.com (157.54.52.9) by TK5-EXGWY-E802.partners.extranet.microsoft.com (10.251.56.168) with Microsoft SMTP Server (TLS) id 8.2.176.0; Fri, 26 Feb 2010 18:05:57 -0800
Received: from TK5EX14MBXC115.redmond.corp.microsoft.com ([169.254.4.20]) by TK5EX14CASC130.redmond.corp.microsoft.com ([157.54.52.9]) with mapi; Fri, 26 Feb 2010 18:05:40 -0800
From: Charlie Kaufman <charliek@microsoft.com>
To: "secdir@ietf.org" <secdir@ietf.org>, "iesg@ietf.org" <iesg@ietf.org>, "micheal.larsen@tietoenator.com" <micheal.larsen@tietoenator.com>, "fernando@gont.com.ar" <fernando@gont.com.ar>, "jmpolk@cisco.com" <jmpolk@cisco.com>, "gorry@erg.abdn.ac.uk" <gorry@erg.abdn.ac.uk>, "lars.eggert@nokia.com" <lars.eggert@nokia.com>
Thread-Topic: Secdir review of draft-ietf-tsvwg-port-randomization-06.txt
Thread-Index: Acq3UVrFxdRHn0hzRWysE0Ue9YIZzA==
Date: Sat, 27 Feb 2010 02:05:37 +0000
Message-ID: <D80EDFF2AD83E648BD1164257B9B09120E1B46FD@TK5EX14MBXC115.redmond.corp.microsoft.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Subject: [secdir] Secdir review of draft-ietf-tsvwg-port-randomization-06.txt
X-BeenThere: secdir@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: Security Area Directorate <secdir.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/secdir>, <mailto:secdir-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/secdir>
List-Post: <mailto:secdir@ietf.org>
List-Help: <mailto:secdir-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/secdir>, <mailto:secdir-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Feb 2010 02:03:42 -0000

I am reviewing this document as part of the security directorate's ongoing effort to review all IETF documents being processed by the IESG.  These comments were written primarily for the benefit of the security area directors.  Document editors and WG chairs should treat these comments just like any other last call comments. Feel free to forward to any appropriate forum.

This document (targeting BCP status) describes an obscure but important practice regarding the selection of ephemeral port IDs when creating TCP connections. If an attacker can guess the ephemeral port used by a TCP connection between some pair of nodes, it greatly increases the chances he can corrupt the data being passed over that connection or cause the connection to break. To make such an attack harder, the originators of TCP connections should pick the ephemeral port number randomly (or at least unpredictably) from a large set of available ports.

For some arcane reasons, picking ports strictly randomly is not the best you can do, because some choices don't work out. If you pick a port number that has used for a recently closed TCP connection to the same IP address, the other end might become confused, think that the old connection is continuing, and generally mess things up. (Most applications will eventually sort themselves out after some timeouts and retries, but it is not guaranteed). Another possible problem is that if someone starts listening on the port you selected and the timing is "just wrong", you connection could become confused with one of his.

These problems can be almost certainly avoided by picking ports from a particular narrow range and picking them in sequence so that no port number is reused until all have been used once. Unfortunately, doing that increases the chance that an attacker can predict the port some new connection will choose.

This document describes how various implementations trade-off these two conflicting goals, and makes recommendations as to how a new implementation might pick an algorithm.

Unfortunately, this algorithm is a cryptographers dream with lots of opportunities to make micro-optimizations. I could not resist the temptation to do so myself when reading the document, but I *can* resist the temptation to tell anyone about the resulting algorithm. There are only 64K ports, so nothing anyone can do is going to make a cryptographically significant improvement over the proposals made here, and spending time debating whether my algorithm beats your algorithm is a waste of everyone's time.

Detailed security-relevant comments:

p13 para 2: says random must return integers in the range 0 - (2^n-1) where n>15. Larger values of n (e.g. n=31) are preferred, since otherwise distribution when reduced mod num_ephemeral will not be uniform.

p16 para 2: suggests use of MD5, which is fine from the point of view of documenting current practice, and in fact is cryptographically just fine in this context. Nevertheless, crypto weenies the world over will pounce on you if it looks like you're suggesting that people use it. It's probably better to just suggest "some cryptographic hash function", or if you have to suggest something specific, perhaps SHA-256. The appendix at the end should specify the hash algorithm used by existing implementations.

Your sample code in many cases, but in particular on page 17 figure 5 ignores the possibility of integer overflow when incrementing things (e.g. table[index]++). The results of modular arithmetic when one of the operands is negative is language dependent, and in ANSI C is not defined, so this code could corrupt memory (unless the values being incremented are unsigned).

p20 para 2: suggests use of a 32 bit key, which has exploitable security problems even though MD5 is fine. 64 bits is a bare minimum, and since bits are cheap someone should really use 128.

p20 last 2 lines: use of pseudo-random data is never harmful and might help, so "should not be done" seems a little strong.

p24 para 3: Since the local offset function is a cryptographic hash reduced to a small number of bits, there will be identical offsets for different inputs and they are generally harmless. If they occurred at greater frequency than would be expected by chance, the port-offset mechanism proposed in this document would have a reduced effect.

p24 para 4: Similarly, seeding the random number generator with a good  source of randomness will make an implementation more secure, but "must" is a bit strong.

Detailed non-security relevant comments:

The document is titled "Transport Protocol Port Randomization Recommendations", but it doesn't really make recommendations. It enumerates current practice and calls out the pros and cons, but it doesn't really recommend what an implementer should do. That's probably OK, but it seemed a bit odd.

p6 last para section 1: Given that this document never uses SHOULD, MUST, ... outside of this paragraph, does it really need this paragraph and the reference to RFC 2119?

p7 end of section 2.1 says ports in the range 49152-65535 are meant for the selection of ephemeral ports
p12 1st para says:  "ephemeral port selection algorithms should use the whole range 1024-49151". Is this saying you should use port numbers not intended for this use? Do you mean should use the whole range 1024-65535?

Typos:

p12 line 2: "is not affected is not affected" -> "is not affected"
p13 para 2 line 2: "interger" -> "integer"
p16 para 3: "chosen as random as possible" -> "chosen to be as random as possible"
p20 para 3: "reasonable" -> "reasonably"


	--Charlie