Received: by 10.213.65.68 with SMTP id h4csp2119455imn; Sun, 8 Apr 2018 20:11:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/gJOkPWnUDZ0eztQTQSitOSyXoVDlA3AblWCMNJgBpU9zoH91fyHEjDKCNy3rKDzSuqdqX X-Received: by 2002:a17:902:566:: with SMTP id 93-v6mr35844847plf.327.1523243467487; Sun, 08 Apr 2018 20:11:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243467; cv=none; d=google.com; s=arc-20160816; b=PufS4kCVReg3N0w4nhCZzmOGGUGvAvMLVzrInk5YflyJQ/CQRaLCPuj/ru2V9EHX8+ J/IBIkArW4X6IanTCcwZP+ZLUy+H0cIYnXPFDalYbzKaePYe6RXr2jF1XaHxOblEJAoP x2aWKGErCV71p504qilpnth7sFVqYsfewyi7fmavudghqGZYD5a3CHVuK8VIbeBoNRiE vm6alMZpR3gK8flsa0j8HnmOXnUlGqLeT/7tVSTUwWwku+DruPErNanlqH/6lVKbcg7E 2PQustaqG++6DTHXv0nzK2CxvY6+9yR7e5Nf0Qvvn9Uh65QLV+kNIed8cLptmStmXBmL mowA== 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=uTsHEYP8Or4RxMO6Uw4IBY5YjNNMzCTziwm2aofW7Ro=; b=fh4m3v8nCmXVna+m65mV2blsqnxLMKZ7zUTHW0YtUw9GKLsddXTZPkEaazdpYd5Rr6 jPlb7m6WJ8ndHckekCe3dP2uUMY8Dl80QVnGG8or0iVpdixgPyDrhBzEpEApr1X/nHeK rwlYbUlLJ/0sjknHNsNpER68k6o//ivl1mO7ruEngSs1N7fxtdGSQGcIU3s348gYTxv6 EwVDwcW9mxb4A4VJo9zgR+pDeDrq8atT/bGtnZX5YZ98jjwJ+VHuqpZDVQm2kqFRfg4b lhDLgOQRMWMmMu8Kh2V6GCDtAmmXGqLwOCmQrDySzf3rprvHJCFbjNtjeW+31iNQHBFT syPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=D1xxBDHe; 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 f34-v6si13935240ple.622.2018.04.08.20.10.31; Sun, 08 Apr 2018 20:11:07 -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=D1xxBDHe; 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 S1757581AbeDIC14 (ORCPT + 98 others); Sun, 8 Apr 2018 22:27:56 -0400 Received: from mail-bn3nam01on0096.outbound.protection.outlook.com ([104.47.33.96]:38912 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755896AbeDIA2m (ORCPT ); Sun, 8 Apr 2018 20:28:42 -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=uTsHEYP8Or4RxMO6Uw4IBY5YjNNMzCTziwm2aofW7Ro=; b=D1xxBDHeeJV5dfYBQxDDdcVGOFSGNkr5QUbyfEis3CYxatmkA5RVNpi9xKWASGd9TvRHDv06Ecer84bCcVRfO8HbTqfZJ9s4qlzZmsbYt4z5nUway4LjyhkJ7HdTaIBz+22hZsEKX7gPSHUbdvy/4+AbgTtrC8aVvWJHfOo4oHM= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0807.namprd21.prod.outlook.com (10.167.110.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:28:35 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:28:35 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Sowmini Varadhan , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 087/293] rds: tcp: Set linger when rejecting an incoming conn in rds_tcp_accept_one Thread-Topic: [PATCH AUTOSEL for 4.9 087/293] rds: tcp: Set linger when rejecting an incoming conn in rds_tcp_accept_one Thread-Index: AQHTz5kPPJxfzy8YCUmDEMtHlXNu6g== Date: Mon, 9 Apr 2018 00:24:02 +0000 Message-ID: <20180409002239.163177-87-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB0807;7:9hEK1UrWDp6p+X/+cGfHTIX+MxUj/crLUi24jmIhfucgkoCmfky9GesilKSwDk4oE76hKZP2eNzcLZqHnxlTe/xa+MZLPHqeAbcGf/6PBdFcC8utFCDmbC8+JMN96V08qdtrhse6+773iR2pRgKLq1tYRs4LtUrVZJ17RToWK7QS4m5Tw13EUGl2chpJxnDWDEDJTf+8IuB/xaPw5MNUskyAfiryjXxDXkDFyR3nkEK2fUKGPlIZ1aWpJBOZv/ay;20:TBQj7yTRQhFZGPkYhl+SdVQ/o9KaGe0LETKzVsa3bk0ReV3qOLKCzUMMZDPXyN9U2BXB+V2t0YdPuRQr9Ogyb+Lr5H/ByiswiZkZiHLcW3tFEjuXKqot7uCffA3s93hCUBB9xfLR2QZst9FSscGcHsciLqLNrDXPmWupFj3uD5E= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 49f90bc0-0651-46db-29ab-08d59db0d4e8 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0807; x-ms-traffictypediagnostic: DM5PR2101MB0807: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231221)(944501327)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0807;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0807; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(396003)(366004)(376002)(346002)(199004)(189003)(14454004)(4326008)(54906003)(25786009)(53936002)(2900100001)(1076002)(3280700002)(6486002)(186003)(2616005)(68736007)(110136005)(11346002)(10090500001)(6116002)(107886003)(3846002)(36756003)(8676002)(72206003)(22452003)(66066001)(26005)(6512007)(478600001)(3660700001)(81156014)(86362001)(81166006)(86612001)(7736002)(305945005)(8936002)(10290500003)(6436002)(105586002)(6666003)(316002)(575784001)(59450400001)(76176011)(5660300001)(476003)(106356001)(2906002)(6506007)(446003)(2501003)(99286004)(5250100002)(486006)(102836004)(97736004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0807;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: P8krccJQiWzDaiXqKuS1A+6e218Cvhhk6n3KomZ0d7Hm8IsrdJaeC4o+wwG7ZKqjQV3rEILEa5E8vT2Ejuipmcf41NG01H+xU3cMxBGm3wmcCIWPx8U1mJKqeoPsCrbCCYEpKa2Lk6bS+iWfbP1Tfq5f1bFTmg8tiv/RmsUgvYBp3fyRr6Pbpvy3xlfqd3HxhkdYQQMwqlASfAtvGA+aMZrTNZ6XXqddx1g3RMjHHMO1snlEPPLO3ptSlSe2UiSJxkEY4DO8PmZzV1A01OaToezTB0DjBt/BlKxmEC4tqp5xwBeFnir435cqGxXfm1SeqZYD3mPsMS4xknO+0vlr25d0pgWcrCMXigPvk0Qq0sJ+FPaJxl4cjPODGpm4ZvO2AsztkfSnRMVg8K/oFlfLAT6j9lw5Fi9yJvWZQBfMw54= 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: 49f90bc0-0651-46db-29ab-08d59db0d4e8 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:02.5656 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0807 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sowmini Varadhan [ Upstream commit 10beea7d7408d0b1c9208757f445c5c710239e0e ] Each time we get an incoming SYN to the RDS_TCP_PORT, the TCP layer accepts the connection and then the rds_tcp_accept_one() callback is invoked to process the incoming connection. rds_tcp_accept_one() may reject the incoming syn for a number of reasons, e.g., commit 1a0e100fb2c9 ("RDS: TCP: Force every connection to be initiated by numerically smaller IP address"), or because we are getting spammed by a malicious node that is triggering a flood of connection attempts to RDS_TCP_PORT. If the incoming syn is rejected, no data would have been sent on the TCP socket, and we do not need to be in TIME_WAIT state, so we set linger on the TCP socket before closing, thereby closing the socket efficiently with a RST. Signed-off-by: Sowmini Varadhan Tested-by: Imanti Mendez Acked-by: Santosh Shilimkar Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/rds/tcp_listen.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c index 185a56b1e29c..1bdf1932c8bf 100644 --- a/net/rds/tcp_listen.c +++ b/net/rds/tcp_listen.c @@ -116,6 +116,17 @@ struct rds_tcp_connection *rds_tcp_accept_one_path(str= uct rds_connection *conn) return NULL; } =20 +static void rds_tcp_set_linger(struct socket *sock) +{ + struct linger no_linger =3D { + .l_onoff =3D 1, + .l_linger =3D 0, + }; + + kernel_setsockopt(sock, SOL_SOCKET, SO_LINGER, + (char *)&no_linger, sizeof(no_linger)); +} + int rds_tcp_accept_one(struct socket *sock) { struct socket *new_sock =3D NULL; @@ -198,7 +209,13 @@ int rds_tcp_accept_one(struct socket *sock) ret =3D 0; goto out; rst_nsk: - /* reset the newly returned accept sock and bail */ + /* reset the newly returned accept sock and bail. + * It is safe to set linger on new_sock because the RDS connection + * has not been brought up on new_sock, so no RDS-level data could + * be pending on it. By setting linger, we achieve the side-effect + * of avoiding TIME_WAIT state on new_sock. + */ + rds_tcp_set_linger(new_sock); kernel_sock_shutdown(new_sock, SHUT_RDWR); ret =3D 0; out: --=20 2.15.1