Skip to content

Commit 5f8873a

Browse files
edumazetpopcornmix
authored andcommitted
net-tcp: fastopen: fix high order allocations
[ Upstream commit f5ddcbb ] This patch fixes two bugs in fastopen : 1) The tcp_sendmsg(..., @SiZe) argument was ignored. Code was relying on user not fooling the kernel with iovec mismatches 2) When MTU is about 64KB, tcp_send_syn_data() attempts order-5 allocations, which are likely to fail when memory gets fragmented. Fixes: 783237e ("net-tcp: Fast Open client - sending SYN-data") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Yuchung Cheng <ycheng@google.com> Acked-by: Yuchung Cheng <ycheng@google.com> Tested-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7d26115 commit 5f8873a

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎include/net/tcp.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,8 @@ struct tcp_fastopen_request {
13081308
/* Fast Open cookie. Size 0 means a cookie request */
13091309
struct tcp_fastopen_cookie cookie;
13101310
struct msghdr *data; /* data in MSG_FASTOPEN */
1311-
u16 copied; /* queued in tcp_connect() */
1311+
size_t size;
1312+
int copied; /* queued in tcp_connect() */
13121313
};
13131314
void tcp_free_fastopen_req(struct tcp_sock *tp);
13141315

‎net/ipv4/tcp.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ void tcp_free_fastopen_req(struct tcp_sock *tp)
10011001
}
10021002
}
10031003

1004-
static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *size)
1004+
static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
1005+
int *copied, size_t size)
10051006
{
10061007
struct tcp_sock *tp = tcp_sk(sk);
10071008
int err, flags;
@@ -1016,11 +1017,12 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *size)
10161017
if (unlikely(tp->fastopen_req == NULL))
10171018
return -ENOBUFS;
10181019
tp->fastopen_req->data = msg;
1020+
tp->fastopen_req->size = size;
10191021

10201022
flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0;
10211023
err = __inet_stream_connect(sk->sk_socket, msg->msg_name,
10221024
msg->msg_namelen, flags);
1023-
*size = tp->fastopen_req->copied;
1025+
*copied = tp->fastopen_req->copied;
10241026
tcp_free_fastopen_req(tp);
10251027
return err;
10261028
}
@@ -1040,7 +1042,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
10401042

10411043
flags = msg->msg_flags;
10421044
if (flags & MSG_FASTOPEN) {
1043-
err = tcp_sendmsg_fastopen(sk, msg, &copied_syn);
1045+
err = tcp_sendmsg_fastopen(sk, msg, &copied_syn, size);
10441046
if (err == -EINPROGRESS && copied_syn > 0)
10451047
goto out;
10461048
else if (err)

‎net/ipv4/tcp_output.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,12 @@ static int tcp_send_syn_data(struct sock *sk, struct sk_buff *syn)
28922892
space = __tcp_mtu_to_mss(sk, inet_csk(sk)->icsk_pmtu_cookie) -
28932893
MAX_TCP_OPTION_SPACE;
28942894

2895-
syn_data = skb_copy_expand(syn, skb_headroom(syn), space,
2895+
space = min_t(size_t, space, fo->size);
2896+
2897+
/* limit to order-0 allocations */
2898+
space = min_t(size_t, space, SKB_MAX_HEAD(MAX_TCP_HEADER));
2899+
2900+
syn_data = skb_copy_expand(syn, MAX_TCP_HEADER, space,
28962901
sk->sk_allocation);
28972902
if (syn_data == NULL)
28982903
goto fallback;

0 commit comments

Comments
 (0)