Skip to content

Commit 95253dc

Browse files
committed
Merge branch 'tcp-better-memory-control-for-not-yet-accepted-sockets'
Eric Dumazet says: ==================== tcp: better memory control for not-yet-accepted sockets Address a possible OOM condition caused by a recent change. Add a new packetdrill test checking the expected behavior. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents ffdde7b + b939c07 commit 95253dc

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

net/ipv4/tcp_input.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5181,7 +5181,9 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)
51815181
skb_condense(skb);
51825182
skb_set_owner_r(skb, sk);
51835183
}
5184-
tcp_rcvbuf_grow(sk);
5184+
/* do not grow rcvbuf for not-yet-accepted or orphaned sockets. */
5185+
if (sk->sk_socket)
5186+
tcp_rcvbuf_grow(sk);
51855187
}
51865188

51875189
static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
--mss=1000
4+
5+
`./defaults.sh
6+
sysctl -q net.ipv4.tcp_rmem="4096 131072 $((32*1024*1024))"`
7+
8+
// Test that a not-yet-accepted socket does not change
9+
// its initial sk_rcvbuf (tcp_rmem[1]) when receiving ooo packets.
10+
11+
+0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
12+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
13+
+0 bind(3, ..., ...) = 0
14+
+0 listen(3, 1) = 0
15+
16+
+0 < S 0:0(0) win 65535 <mss 1000,nop,nop,sackOK,nop,wscale 7>
17+
+0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 10>
18+
+.1 < . 1:1(0) ack 1 win 257
19+
+0 < . 2001:41001(39000) ack 1 win 257
20+
+0 > . 1:1(0) ack 1 <nop,nop,sack 2001:41001>
21+
+0 < . 41001:101001(60000) ack 1 win 257
22+
+0 > . 1:1(0) ack 1 <nop,nop,sack 2001:101001>
23+
+0 < . 1:1001(1000) ack 1 win 257
24+
+0 > . 1:1(0) ack 1001 <nop,nop,sack 2001:101001>
25+
+0 < . 1001:2001(1000) ack 1 win 257
26+
+0 > . 1:1(0) ack 101001
27+
28+
+0 accept(3, ..., ...) = 4
29+
30+
+0 %{ assert SK_MEMINFO_RCVBUF == 131072, SK_MEMINFO_RCVBUF }%
31+
32+
+0 close(4) = 0
33+
+0 close(3) = 0
34+
35+
// Test that ooo packets for accepted sockets do increase sk_rcvbuf
36+
+0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
37+
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
38+
+0 bind(3, ..., ...) = 0
39+
+0 listen(3, 1) = 0
40+
41+
+0 < S 0:0(0) win 65535 <mss 1000,nop,nop,sackOK,nop,wscale 7>
42+
+0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 10>
43+
+.1 < . 1:1(0) ack 1 win 257
44+
45+
+0 accept(3, ..., ...) = 4
46+
47+
+0 < . 2001:41001(39000) ack 1 win 257
48+
+0 > . 1:1(0) ack 1 <nop,nop,sack 2001:41001>
49+
+0 < . 41001:101001(60000) ack 1 win 257
50+
+0 > . 1:1(0) ack 1 <nop,nop,sack 2001:101001>
51+
52+
+0 %{ assert SK_MEMINFO_RCVBUF > 131072, SK_MEMINFO_RCVBUF }%
53+

0 commit comments

Comments
 (0)