Skip to content

Commit 07f3355

Browse files
arndbjgunthorpe
authored andcommitted
infiniband: i40iw, nes: don't use wall time for TCP sequence numbers
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. i40iw uses a variant of the same code, so I do that same thing there for ipv4. Unlike nes, i40e also supports ipv6, which needs to call secure_tcpv6_seq instead. Acked-by: Shiraz Saleem <shiraz.saleem@intel.com> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 59b851d commit 07f3355

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

drivers/infiniband/hw/i40iw/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
config INFINIBAND_I40IW
22
tristate "Intel(R) Ethernet X722 iWARP Driver"
33
depends on INET && I40E
4+
depends on IPV6 || !IPV6
45
depends on PCI
56
select GENERIC_ALLOCATOR
67
---help---

drivers/infiniband/hw/i40iw/i40iw_cm.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <net/addrconf.h>
5858
#include <net/ip6_route.h>
5959
#include <net/ip_fib.h>
60+
#include <net/secure_seq.h>
6061
#include <net/tcp.h>
6162
#include <asm/checksum.h>
6263

@@ -2164,7 +2165,6 @@ static struct i40iw_cm_node *i40iw_make_cm_node(
21642165
struct i40iw_cm_listener *listener)
21652166
{
21662167
struct i40iw_cm_node *cm_node;
2167-
struct timespec ts;
21682168
int oldarpindex;
21692169
int arpindex;
21702170
struct net_device *netdev = iwdev->netdev;
@@ -2214,10 +2214,26 @@ static struct i40iw_cm_node *i40iw_make_cm_node(
22142214
cm_node->tcp_cntxt.rcv_wscale = I40IW_CM_DEFAULT_RCV_WND_SCALE;
22152215
cm_node->tcp_cntxt.rcv_wnd =
22162216
I40IW_CM_DEFAULT_RCV_WND_SCALED >> I40IW_CM_DEFAULT_RCV_WND_SCALE;
2217-
ts = current_kernel_time();
2218-
cm_node->tcp_cntxt.loc_seq_num = ts.tv_nsec;
2219-
cm_node->tcp_cntxt.mss = (cm_node->ipv4) ? (iwdev->vsi.mtu - I40IW_MTU_TO_MSS_IPV4) :
2220-
(iwdev->vsi.mtu - I40IW_MTU_TO_MSS_IPV6);
2217+
if (cm_node->ipv4) {
2218+
cm_node->tcp_cntxt.loc_seq_num = secure_tcp_seq(htonl(cm_node->loc_addr[0]),
2219+
htonl(cm_node->rem_addr[0]),
2220+
htons(cm_node->loc_port),
2221+
htons(cm_node->rem_port));
2222+
cm_node->tcp_cntxt.mss = iwdev->vsi.mtu - I40IW_MTU_TO_MSS_IPV4;
2223+
} else if (IS_ENABLED(CONFIG_IPV6)) {
2224+
__be32 loc[4] = {
2225+
htonl(cm_node->loc_addr[0]), htonl(cm_node->loc_addr[1]),
2226+
htonl(cm_node->loc_addr[2]), htonl(cm_node->loc_addr[3])
2227+
};
2228+
__be32 rem[4] = {
2229+
htonl(cm_node->rem_addr[0]), htonl(cm_node->rem_addr[1]),
2230+
htonl(cm_node->rem_addr[2]), htonl(cm_node->rem_addr[3])
2231+
};
2232+
cm_node->tcp_cntxt.loc_seq_num = secure_tcpv6_seq(loc, rem,
2233+
htons(cm_node->loc_port),
2234+
htons(cm_node->rem_port));
2235+
cm_node->tcp_cntxt.mss = iwdev->vsi.mtu - I40IW_MTU_TO_MSS_IPV6;
2236+
}
22212237

22222238
cm_node->iwdev = iwdev;
22232239
cm_node->dev = &iwdev->sc_dev;

drivers/infiniband/hw/nes/nes_cm.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <net/neighbour.h>
5959
#include <net/route.h>
6060
#include <net/ip_fib.h>
61+
#include <net/secure_seq.h>
6162
#include <net/tcp.h>
6263
#include <linux/fcntl.h>
6364

@@ -1445,7 +1446,6 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
14451446
struct nes_cm_listener *listener)
14461447
{
14471448
struct nes_cm_node *cm_node;
1448-
struct timespec ts;
14491449
int oldarpindex = 0;
14501450
int arpindex = 0;
14511451
struct nes_device *nesdev;
@@ -1496,8 +1496,10 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
14961496
cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
14971497
cm_node->tcp_cntxt.rcv_wnd = NES_CM_DEFAULT_RCV_WND_SCALED >>
14981498
NES_CM_DEFAULT_RCV_WND_SCALE;
1499-
ts = current_kernel_time();
1500-
cm_node->tcp_cntxt.loc_seq_num = htonl(ts.tv_nsec);
1499+
cm_node->tcp_cntxt.loc_seq_num = secure_tcp_seq(htonl(cm_node->loc_addr),
1500+
htonl(cm_node->rem_addr),
1501+
htons(cm_node->loc_port),
1502+
htons(cm_node->rem_port));
15011503
cm_node->tcp_cntxt.mss = nesvnic->max_frame_size - sizeof(struct iphdr) -
15021504
sizeof(struct tcphdr) - ETH_HLEN - VLAN_HLEN;
15031505
cm_node->tcp_cntxt.rcv_nxt = 0;

net/core/secure_seq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ u32 secure_tcp_seq(__be32 saddr, __be32 daddr,
140140
&net_secret);
141141
return seq_scale(hash);
142142
}
143+
EXPORT_SYMBOL_GPL(secure_tcp_seq);
143144

144145
u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport)
145146
{

0 commit comments

Comments
 (0)