From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 706A75A0265 for ; Mon, 7 Nov 2022 19:08:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667844536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Wteok9G1+s9xGfxL6cDtxu1KnDztU/ZQdFhN8a99aQ=; b=DlQVZwo8HPZ0eJm09aw0NHccASh+3lr9WIrl9SxK0pyrhb8LdmC7CGFSjZDBUeNeBBZQSJ KXyW5FbD4w7RDT5aWjL2q2glW/9KvOs8zksCoVxBwNCLtk0B8Oax0JUnNF4TARqs4ytFjw 9CSs5py++Afdwc71PgoXtMqKMSlkJjs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-187-Rh1hrcM1Oa2Hm5rA7A6G9w-1; Mon, 07 Nov 2022 13:08:53 -0500 X-MC-Unique: Rh1hrcM1Oa2Hm5rA7A6G9w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1F0B101AA45; Mon, 7 Nov 2022 18:08:52 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-9.brq.redhat.com [10.40.208.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC793492B05; Mon, 7 Nov 2022 18:08:52 +0000 (UTC) Date: Mon, 7 Nov 2022 19:08:46 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 10/10] tcp: Fix small error in tcp_seq_init() time handling Message-ID: <20221107190846.32ece8ac@elisabeth> In-Reply-To: <20221104084333.3761760-11-david@gibson.dropbear.id.au> References: <20221104084333.3761760-1-david@gibson.dropbear.id.au> <20221104084333.3761760-11-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: V4IQ5IXCMEWRV2LRF4MD5NV75WZ3EX6L X-Message-ID-Hash: V4IQ5IXCMEWRV2LRF4MD5NV75WZ3EX6L X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: <> Archived-At: List-Archive: <> List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri, 4 Nov 2022 19:43:33 +1100 David Gibson wrote: > It looks like tcp_seq_init() is supposed to advance the sequence number > by one every 32ns. However we only right shift the ns part of the timesp= ec > not the seconds part, meaning that we'll advance by an extra 32 steps on > each second. >=20 > I don't know if that's exploitable in any way, but it doesn't appear to b= e > the intent, nor what RFC 6528 suggests. Oh, oops, nice catch. Well, as long as the step, modulo 32 bits, is not 0, it's still arguably the 250 KHz / 4 =C2=B5s period clock from RFC 793, so there's no practical difference (other than the overflow period). See also the note in RFC 1948: More precisely, RFC 793 specifies that the 32-bit counter be incremented by 1 in the low-order position about every 4 microseconds. Instead, Berkeley-derived kernels increment it by a constant every second [...] I kind of wonder if adding a time non-linearity like the unintended one I added actually increases entropy. But indeed ~4 seconds overflow is also not intended, and we should just stick to RFC 6528. > Signed-off-by: David Gibson > --- > tcp.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/tcp.c b/tcp.c > index 59e03ff..941fafb 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -2027,8 +2027,8 @@ static void tcp_seq_init(const struct ctx *c, struc= t tcp_conn *conn, > =20 > =09seq =3D siphash_36b((uint8_t *)&in, c->tcp.hash_secret); > =20 > -=09ns =3D now->tv_sec * 1E9; > -=09ns +=3D now->tv_nsec >> 5; /* 32ns ticks, overflows 32 bits every 137= s */ > +=09/* 32ns ticks, overflows 32 bits every 137s */ > +=09ns =3D (now->tv_sec * 1E9 + now->tv_nsec) >> 5; > =20 > =09conn->seq_to_tap =3D seq + ns; > } --=20 Stefano