Received: by 10.213.65.68 with SMTP id h4csp1900166imn; Mon, 19 Mar 2018 16:55:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELuq9Qme6LJc1vH+tF9oNfaygNcCuAJQVzn0tC9KMFG6Ue0iZum/+QjsQPdp+XStsfkdWogS X-Received: by 2002:a17:902:7007:: with SMTP id y7-v6mr14313167plk.275.1521503752540; Mon, 19 Mar 2018 16:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521503752; cv=none; d=google.com; s=arc-20160816; b=jTSVwksJ2SANZLLwe7tbUdcpfdrWJcMkJM8HNqAQ5PZ4TsUsR0dD5kgJGcbGtb4AxV sbDRzkm05YwJ6F+L4NdESKIgAZFGbyXfcToaVhHu8p8yl5hVmaz5R92Bg7PeBY0ngSva 7wPFpQd6PT2i4IIFym6MnjIoGlptIAZsYfX0r0NxuVDoq1O4ajK0aeoBjd0aLG0/MU6g /4VV7OUh7BHDE7sgzxmso7yWoIfd2UBIgved7F8GSm963OoBcB1U/wMJDqghfaqtg9Bu pvClcU2ZUYexamWY3pgEGEN0t0eWCN8awzP1IFN3ZK5teykyQ8lcN0sYzw7zdM5bEh8v 8Z1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=NDEJwyTEql0/KnNwc4B7PNgG9aWD1HiGt14LpR1HLEU=; b=FVFmFTFWi6IXv+3IY34YYSAS6GitMWPP2ysQkfdqTMKoiDv0ekl6E05Tse6ouHaIDV zNEKeAy1BggCm2F+/GjP478hvIc9QhigwfVxIO9NmfFbMeX2bMbQ0qR3Zo770xOSRn7F lWvPibfFG8SGKjE0t0LvYlR30viVcEb8eU8fB96K/3LRlyH0BjVtbXkOavyr27kQGVE0 jn3gkg8H5Pe1arkjKxL23pHCJEz2czHDddxlr3t8GmH4XnGJIC06Xcc5xgcs6Fa7lE0W kaAyyqJpkyowG9OKdZ2x174+StBUTldKWK8hstANCBCgIGOicijsR1/VBnURjcJbK21o cHyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jHvKDNuk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4-v6si330252plr.598.2018.03.19.16.55.38; Mon, 19 Mar 2018 16:55:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jHvKDNuk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967919AbeCSRTf (ORCPT + 99 others); Mon, 19 Mar 2018 13:19:35 -0400 Received: from mail-by2nam01on0128.outbound.protection.outlook.com ([104.47.34.128]:46817 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966112AbeCSQJO (ORCPT ); Mon, 19 Mar 2018 12:09:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=NDEJwyTEql0/KnNwc4B7PNgG9aWD1HiGt14LpR1HLEU=; b=jHvKDNukf/lTAfqjiXHxTcpwfcBI6LmfjoB/+jL2egk5EFphUnSvcEYJKKUB91Oie0YYh06xQndgFtetetQg7lDmGmKt3/eECGPKRTfjVFwjKzouxHyD2+zYv1CWqzgK5MbjX+FlySGkUNkx7kWDfAxT3JynxRvxx03fsQhBp+w= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0965.namprd21.prod.outlook.com (52.132.133.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 16:09:02 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 16:09:02 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Eric Dumazet , Neal Cardwell , Yuchung Cheng , Soheil Hassas Yeganeh , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 076/167] tcp: better validation of received ack sequences Thread-Topic: [PATCH AUTOSEL for 4.4 076/167] tcp: better validation of received ack sequences Thread-Index: AQHTv5xO3KJ4Eu9U0kqS7FVgwFQQKQ== Date: Mon, 19 Mar 2018 16:06:57 +0000 Message-ID: <20180319160513.16384-76-alexander.levin@microsoft.com> References: <20180319160513.16384-1-alexander.levin@microsoft.com> In-Reply-To: <20180319160513.16384-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0965;7:+2AgIJ8ERNqCM+K77sCu5Y7JTKvRR4NAm3k/ZLyBses5vM2vXGgy/gbfIXpfzifHnQpp5Jdtnq0RVm1W3/pzOO6WgOPLcswExX5v3JsKAOeEl82LNzZTixSeqfOGSOzLEv0rOYU4XTD5WQbsVLuSSQCITo2J69U+EkzcHB4OEtY2A63+7hXSy78eeldVkhh2G6/D+hiyJ7/ap/CKsBuas7/IjOwBYLbSmufDmteTCzzCH+xJyG1XTDZg0ir/+h0E;20:tNSPE33p8p1zcv/rdFjfjWwkX5RKhOpK8oj3FV85VhiYms+/+qymQp5YD62xMNqD+GU1JgNzFryuPtOi5/ldcAmUB72ecdM0bmiP9/+hPipZ+5L6aryp+iF/cGBW9qXjoDOkdYcPnCzrMNWhzjhRqBiOGta++bWJXdzJ1TecX64= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 21c182a3-01c4-4627-922a-08d58db3bb24 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0965; x-ms-traffictypediagnostic: DM5PR2101MB0965: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(158342451672863)(89211679590171)(211936372134217)(153496737603132); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB0965;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0965; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(366004)(396003)(39860400002)(376002)(39380400002)(189003)(199004)(25786009)(7736002)(6506007)(86362001)(575784001)(86612001)(10090500001)(478600001)(53936002)(6666003)(6512007)(36756003)(2950100002)(8936002)(110136005)(54906003)(105586002)(14454004)(107886003)(72206003)(10290500003)(316002)(102836004)(2501003)(59450400001)(5250100002)(99286004)(22452003)(305945005)(6436002)(6486002)(1076002)(76176011)(26005)(4326008)(186003)(97736004)(106356001)(3660700001)(3846002)(6116002)(5660300001)(68736007)(2900100001)(8676002)(81166006)(81156014)(3280700002)(2906002)(66066001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0965;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: RIY1IyW3Fm4+AQYe1voA9hTw+j28mAjeYodFwIb230f7pWad4gE+6ph8vSvoH2AXopgSsCbaA/AgyqVIUpjYpFnSmvvJsU6I0ezvz40f6hqF1d+eGOHhUJ2DSu+bBZkjgqkhutu5n+dmsePXgce6XpYDoF8eZSbVylULQIlFZWSXGRvI6XnC1hNuv2IB/GmLJ09s0ug3sa8oPpt3H/NP21cSifDaktbseTqmUV6bfpXoqpbCDeZD8rX80Hov+svJuckyNJy8ENOERrbdovrk3O48+DlmP91pld1GiqkwmSOfgboJolftXHuV+ESRXVW5WhaOuvX0zb6oPi1GEqKrVw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21c182a3-01c4-4627-922a-08d58db3bb24 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 16:06:57.6459 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0965 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit d0e1a1b5a833b625c93d3d49847609350ebd79db ] Paul Fiterau Brostean reported : Linux TCP stack we analyze exhibits behavior that seems odd to me. The scenario is as follows (all packets have empty payloads, no window scaling, rcv/snd window size should not be a factor): TEST HARNESS (CLIENT) LINUX SERVER 1. - LISTEN (server listen, then accepts) 2. - --> --> SYN-RECEIVED 3. - <-- <-- SYN-RECEIVED 4. - --> --> ESTABLISHED 5. - <-- <-- FIN WAIT-1 (server opts to close the data connection calling "close" on the connection socket) 6. - --> --> CLOSING (client se= nds FIN,ACK with not yet sent acknowledgement number) 7. - <-- <-- CLOSING (ACK is 102 instead of 101, why?) ... (silence from CLIENT) 8. - <-- <-- CLOSING (retransmission, again ACK is 102) Now, note that packet 6 while having the expected sequence number, acknowledges something that wasn't sent by the server. So I would expect the packet to maybe prompt an ACK response from the server, and then be ignored. Yet it is not ignored and actually leads to an increase of the acknowledgement number in the server's retransmission of the FIN,ACK packet. The explanation I found is that the FIN in packet 6 was processed, despite the acknowledgement number being unacceptable. Further experiments indeed show that the server processes this FIN, transitioning to CLOSING, then on receiving an ACK for the FIN it had send in packet 5, the server (or better said connection) transitions from CLOSING to TIME_WAIT (as signaled by netstat). Indeed, tcp_rcv_state_process() calls tcp_ack() but does not exploit the @acceptable status but for TCP_SYN_RECV state. What we want here is to send a challenge ACK, if not in TCP_SYN_RECV state. TCP_FIN_WAIT1 state is not the only state we should fix. Add a FLAG_NO_CHALLENGE_ACK so that tcp_rcv_state_process() can choose to send a challenge ACK and discard the packet instead of wrongly change socket state. With help from Neal Cardwell. Signed-off-by: Eric Dumazet Reported-by: Paul Fiterau Brostean Cc: Neal Cardwell Cc: Yuchung Cheng Cc: Soheil Hassas Yeganeh Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/tcp_input.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 71290fb7d500..5720d8155225 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -117,6 +117,7 @@ int sysctl_tcp_invalid_ratelimit __read_mostly =3D HZ/2= ; #define FLAG_DSACKING_ACK 0x800 /* SACK blocks contained D-SACK info */ #define FLAG_SACK_RENEGING 0x2000 /* snd_una advanced to a sacked seq */ #define FLAG_UPDATE_TS_RECENT 0x4000 /* tcp_replace_ts_recent() */ +#define FLAG_NO_CHALLENGE_ACK 0x8000 /* do not call tcp_send_challenge_ack= () */ =20 #define FLAG_ACKED (FLAG_DATA_ACKED|FLAG_SYN_ACKED) #define FLAG_NOT_DUP (FLAG_DATA|FLAG_WIN_UPDATE|FLAG_ACKED) @@ -3543,7 +3544,8 @@ static int tcp_ack(struct sock *sk, const struct sk_b= uff *skb, int flag) if (before(ack, prior_snd_una)) { /* RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] */ if (before(ack, prior_snd_una - tp->max_window)) { - tcp_send_challenge_ack(sk, skb); + if (!(flag & FLAG_NO_CHALLENGE_ACK)) + tcp_send_challenge_ack(sk, skb); return -1; } goto old_ack; @@ -5830,13 +5832,17 @@ int tcp_rcv_state_process(struct sock *sk, struct s= k_buff *skb) =20 /* step 5: check the ACK field */ acceptable =3D tcp_ack(sk, skb, FLAG_SLOWPATH | - FLAG_UPDATE_TS_RECENT) > 0; + FLAG_UPDATE_TS_RECENT | + FLAG_NO_CHALLENGE_ACK) > 0; =20 + if (!acceptable) { + if (sk->sk_state =3D=3D TCP_SYN_RECV) + return 1; /* send one RST */ + tcp_send_challenge_ack(sk, skb); + goto discard; + } switch (sk->sk_state) { case TCP_SYN_RECV: - if (!acceptable) - return 1; - if (!tp->srtt_us) tcp_synack_rtt_meas(sk, req); =20 @@ -5905,14 +5911,6 @@ int tcp_rcv_state_process(struct sock *sk, struct sk= _buff *skb) * our SYNACK so stop the SYNACK timer. */ if (req) { - /* Return RST if ack_seq is invalid. - * Note that RFC793 only says to generate a - * DUPACK for it but for TCP Fast Open it seems - * better to treat this case like TCP_SYN_RECV - * above. - */ - if (!acceptable) - return 1; /* We no longer need the request sock. */ reqsk_fastopen_remove(sk, req, false); tcp_rearm_rto(sk); --=20 2.14.1