Skip to content

Commit 4a7ca91

Browse files
edumazetgregkh
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 4d9c46a commit 4a7ca91

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
@@ -1312,7 +1312,8 @@ struct tcp_fastopen_request {
13121312
/* Fast Open cookie. Size 0 means a cookie request */
13131313
struct tcp_fastopen_cookie cookie;
13141314
struct msghdr *data; /* data in MSG_FASTOPEN */
1315-
u16 copied; /* queued in tcp_connect() */
1315+
size_t size;
1316+
int copied; /* queued in tcp_connect() */
13161317
};
13171318
void tcp_free_fastopen_req(struct tcp_sock *tp);
13181319

‎net/ipv4/tcp.c‎

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

1005-
static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *size)
1005+
static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
1006+
int *copied, size_t size)
10061007
{
10071008
struct tcp_sock *tp = tcp_sk(sk);
10081009
int err, flags;
@@ -1017,11 +1018,12 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *size)
10171018
if (unlikely(tp->fastopen_req == NULL))
10181019
return -ENOBUFS;
10191020
tp->fastopen_req->data = msg;
1021+
tp->fastopen_req->size = size;
10201022

10211023
flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0;
10221024
err = __inet_stream_connect(sk->sk_socket, msg->msg_name,
10231025
msg->msg_namelen, flags);
1024-
*size = tp->fastopen_req->copied;
1026+
*copied = tp->fastopen_req->copied;
10251027
tcp_free_fastopen_req(tp);
10261028
return err;
10271029
}
@@ -1041,7 +1043,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
10411043

10421044
flags = msg->msg_flags;
10431045
if (flags & MSG_FASTOPEN) {
1044-
err = tcp_sendmsg_fastopen(sk, msg, &copied_syn);
1046+
err = tcp_sendmsg_fastopen(sk, msg, &copied_syn, size);
10451047
if (err == -EINPROGRESS && copied_syn > 0)
10461048
goto out;
10471049
else if (err)

‎net/ipv4/tcp_output.c‎

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

2890-
syn_data = skb_copy_expand(syn, skb_headroom(syn), space,
2890+
space = min_t(size_t, space, fo->size);
2891+
2892+
/* limit to order-0 allocations */
2893+
space = min_t(size_t, space, SKB_MAX_HEAD(MAX_TCP_HEADER));
2894+
2895+
syn_data = skb_copy_expand(syn, MAX_TCP_HEADER, space,
28912896
sk->sk_allocation);
28922897
if (syn_data == NULL)
28932898
goto fallback;

0 commit comments

Comments
 (0)