From patchwork Mon Jun 18 14:44:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 138982 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4038809lji; Mon, 18 Jun 2018 07:45:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJWmJVamT1OkXxgXqiFhlcWmf/PCphX83tfvKD0XL4AMOpmzpWEs+651u+JTpwN/mglDiJt X-Received: by 2002:a17:902:3124:: with SMTP id w33-v6mr14350653plb.235.1529333123340; Mon, 18 Jun 2018 07:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529333123; cv=none; d=google.com; s=arc-20160816; b=Wa0ywGRSG9JjM0i8V3XuPUtRBp21HCoYN5AQQkeIiYprwwV9aZLUC+o1KnlqHZm8+l TtrARRnipgmpotE/IzkeNB7dHTavR1C5d/y2lUI2h9UZKdmtnYNAlEgqY5tgvwhEvmcW 3/0M6jGxUiwbnd0BE/+LLBIGFkN3/bJX56Sczs0q2LsC1i2WJfFbVd+XOTLa7ZKMKSd4 5WbUfF6+iB397+hl0VZ6xGuGy3QWoK6iSHYcj1htQWuS333an4Gp1sGP2Fc0wtQm9t3+ 1vf92A8dZQAFKI5lLUd9seT5DCP92KPVGBxbAFPlyNnkIdwAn9KjDkJF4yzASxUe8Bl9 dANA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=+4BKE3RGpJ22G2lCOgaIudgk5gEaHs8lFpA5Kl6L70Y=; b=S45E7+V4y6ASFflIPh4rqiZiwQJLPuhSWR1OzMWYH6olaeGWIIkvczYOhWfw+g+PPt O0VY1NQS86riWuPspanXnKbE1bGeXlLArgqJuHO9g+RxG1xemi58BWUs/RglmTHaxWS0 VSsyp1DdL40YvjmfGVV7+3QMJ3vMt+nXg7xYG/OV9S0Oz23zDgNv3EVcXiwxsmb8uo/K q6m79xgfWfIMpHhmSwB5FXYokRuJHPPlGv8k238JN3qBbGxLeHX3kN8vLNMZPSkNpQMj DhfhNcwXSCRGMcXG3Oks8QdlMi5fA6MzkSlU5evfp+BW4UMijn5/8wMbCx3coDuGISLO Y07A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c32-v6si14736993plj.277.2018.06.18.07.45.23; Mon, 18 Jun 2018 07:45:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935310AbeFROpU (ORCPT + 30 others); Mon, 18 Jun 2018 10:45:20 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:40369 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935268AbeFROpR (ORCPT ); Mon, 18 Jun 2018 10:45:17 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0MNtFb-1faj5A1uod-007RBU; Mon, 18 Jun 2018 16:44:47 +0200 From: Arnd Bergmann To: Faisal Latif , Shiraz Saleem , Doug Ledford , Jason Gunthorpe , "David S. Miller" , Arnd Bergmann Cc: y2038@lists.linaro.org, netdev@vger.kernel.org, Henry Orosco , Tatyana Nikolova , Mustafa Ismail , Jia-Ju Bai , Yuval Shaia , Bart Van Assche , Kees Cook , "Reshetova, Elena" , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] infiniband: i40iw, nes: don't use wall time for TCP sequence numbers Date: Mon, 18 Jun 2018 16:44:17 +0200 Message-Id: <20180618144443.137068-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K1:bgpobGyGp8qz5YX86RA4EBUYoavY2o2XQMpH72mgwvsA+Vfz2Cy TzbR/SomELtSPL3zucYebeJ7fcK2u5+KbnpjInQt5aw4ZtHkji/vbI9XeKjQ/fRsbCpmKBJ hbshIPXuUr94XtWudMhe5+fWbV2kp8E5qCt6oagCDoK3q0CdVTLbhUaOQ+oHXR36Bzg/gq7 sUQMmV3AnQgI7Q1/cAcuQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:8JHttKDuCvE=:fVKsNN69bg30Bz+8rkr7WC 3szhA5v+0z2le/3nIs8OrITdv4NWJCfLdSwGfvLw3yfRQSuhhtcGyYfxwjGuruSEg6qrCFNPf uP9QmsOzm0ZnWsWFHxhARh7HcjE4AkzANzttyzRo+wCiv9QnXWhqg4I8dMg11czqDBn9vDRZ2 7d89waaq5RRLVlu+Vb5/n7CLVzdJQAGN3RH2ZQMyrKP9lnxOkKZGjIjeX46Jsa+dZlXyVPTqo 1k1rApmc4nIEZtcEY1Mfs0wqBAR/uWWh3f2QUtccJ1n9fLhenIj0e7F0HcLADgzoTC0HyGrG1 LVd1Jtcqg0OyzePiA73txPC8uljV6jRalSCrwRoeTK/5msDNUMNqIeGJo7xV6MYsbIBsRlm+2 +f1S/4JoHpvYW10sHKuOE8bleDcfxCk06eZp1Z39AH6sQuK561fZWwkdhtKYIM9cUiXYhoXTm KI6XZmwsDydCH6sxhNQ2LZWDzi4J2OkwBGn4teYckZOQjMkCueaA8hZa90tU8WMOkvU8j7Wb5 FoYeR2t/h4fYjQQzoA066sYAzBT7UmZuvliujScXtFOv0r646pkVnfl0XTHDoNLNZ53bZJTIt BgKw9gCVbQqzCW/fwOignD0OmK1IJDxjp+k1rdoBoqRGJaJaugcUyEuKQV3mvkKfA8ntaUdDD kE9C63YqK15BuTAxeP5NKgYkgQl2NVnLy6vm3tkv2FsylPMVcmQv8SFdplpALHXndkrA= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The nes infiniband driver uses current_kernel_time() to get a nanosecond granunarity timestamp to initialize its tcp sequence counters. This is one of only a few remaining users of that deprecated function, so we should try to get rid of it. Aside from using a deprecated API, there are several problems I see here: - Using a CLOCK_REALTIME based time source makes it predictable in case the time base is synchronized. - Using a coarse timestamp means it only gets updated once per jiffie, making it even more predictable in order to avoid having to access the hardware clock source - The upper 2 bits are always zero because the nanoseconds are at most 999999999. For the Linux TCP implementation, we use secure_tcp_seq(), which appears to be appropriate here as well, and solves all the above problems. I'm doing the same change in both versions of the nes driver, with i40iw being a later copy of the same code. Signed-off-by: Arnd Bergmann --- The above change is just a guess at what it should look like, please review carefully and Ack/Nak as appropriate. --- drivers/infiniband/hw/i40iw/i40iw_cm.c | 8 +++++--- drivers/infiniband/hw/nes/nes_cm.c | 8 +++++--- net/core/secure_seq.c | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) -- 2.9.0 diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c b/drivers/infiniband/hw/i40iw/i40iw_cm.c index 7b2655128b9f..da221d07f2dd 100644 --- a/drivers/infiniband/hw/i40iw/i40iw_cm.c +++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -2164,7 +2165,6 @@ static struct i40iw_cm_node *i40iw_make_cm_node( struct i40iw_cm_listener *listener) { struct i40iw_cm_node *cm_node; - struct timespec ts; int oldarpindex; int arpindex; struct net_device *netdev = iwdev->netdev; @@ -2214,8 +2214,10 @@ static struct i40iw_cm_node *i40iw_make_cm_node( cm_node->tcp_cntxt.rcv_wscale = I40IW_CM_DEFAULT_RCV_WND_SCALE; cm_node->tcp_cntxt.rcv_wnd = I40IW_CM_DEFAULT_RCV_WND_SCALED >> I40IW_CM_DEFAULT_RCV_WND_SCALE; - ts = current_kernel_time(); - cm_node->tcp_cntxt.loc_seq_num = ts.tv_nsec; + cm_node->tcp_cntxt.loc_seq_num = secure_tcp_seq(htonl(cm_node->loc_addr[0]), + htonl(cm_node->rem_addr[0]), + htons(cm_node->loc_port), + htons(cm_node->rem_port)); cm_node->tcp_cntxt.mss = (cm_node->ipv4) ? (iwdev->vsi.mtu - I40IW_MTU_TO_MSS_IPV4) : (iwdev->vsi.mtu - I40IW_MTU_TO_MSS_IPV6); diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c index 6cdfbf8c5674..2b67ace5b614 100644 --- a/drivers/infiniband/hw/nes/nes_cm.c +++ b/drivers/infiniband/hw/nes/nes_cm.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -1445,7 +1446,6 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core, struct nes_cm_listener *listener) { struct nes_cm_node *cm_node; - struct timespec ts; int oldarpindex = 0; int arpindex = 0; struct nes_device *nesdev; @@ -1496,8 +1496,10 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core, cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE; cm_node->tcp_cntxt.rcv_wnd = NES_CM_DEFAULT_RCV_WND_SCALED >> NES_CM_DEFAULT_RCV_WND_SCALE; - ts = current_kernel_time(); - cm_node->tcp_cntxt.loc_seq_num = htonl(ts.tv_nsec); + cm_node->tcp_cntxt.loc_seq_num = secure_tcp_seq(htonl(cm_node->loc_addr), + htonl(cm_node->rem_addr), + htons(cm_node->loc_port), + htons(cm_node->rem_port)); cm_node->tcp_cntxt.mss = nesvnic->max_frame_size - sizeof(struct iphdr) - sizeof(struct tcphdr) - ETH_HLEN - VLAN_HLEN; cm_node->tcp_cntxt.rcv_nxt = 0; diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c index 7232274de334..af6ad467ed61 100644 --- a/net/core/secure_seq.c +++ b/net/core/secure_seq.c @@ -140,6 +140,7 @@ u32 secure_tcp_seq(__be32 saddr, __be32 daddr, &net_secret); return seq_scale(hash); } +EXPORT_SYMBOL_GPL(secure_tcp_seq); u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport) {