Skip to content

Commit f5ddcbb

Browse files
edumazetdavem330
authored andcommitted
net-tcp: fastopen: fix high order allocations
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 <[email protected]> Cc: Yuchung Cheng <[email protected]> Acked-by: Yuchung Cheng <[email protected]> Tested-by: Yuchung Cheng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 68ad785 commit f5ddcbb

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

include/net/tcp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,8 @@ struct tcp_fastopen_request {
13031303
/* Fast Open cookie. Size 0 means a cookie request */
13041304
struct tcp_fastopen_cookie cookie;
13051305
struct msghdr *data; /* data in MSG_FASTOPEN */
1306-
u16 copied; /* queued in tcp_connect() */
1306+
size_t size;
1307+
int copied; /* queued in tcp_connect() */
13071308
};
13081309
void tcp_free_fastopen_req(struct tcp_sock *tp);
13091310

net/ipv4/tcp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@ void tcp_free_fastopen_req(struct tcp_sock *tp)
10441044
}
10451045
}
10461046

1047-
static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *size)
1047+
static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
1048+
int *copied, size_t size)
10481049
{
10491050
struct tcp_sock *tp = tcp_sk(sk);
10501051
int err, flags;
@@ -1059,11 +1060,12 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *size)
10591060
if (unlikely(tp->fastopen_req == NULL))
10601061
return -ENOBUFS;
10611062
tp->fastopen_req->data = msg;
1063+
tp->fastopen_req->size = size;
10621064

10631065
flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0;
10641066
err = __inet_stream_connect(sk->sk_socket, msg->msg_name,
10651067
msg->msg_namelen, flags);
1066-
*size = tp->fastopen_req->copied;
1068+
*copied = tp->fastopen_req->copied;
10671069
tcp_free_fastopen_req(tp);
10681070
return err;
10691071
}
@@ -1083,7 +1085,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
10831085

10841086
flags = msg->msg_flags;
10851087
if (flags & MSG_FASTOPEN) {
1086-
err = tcp_sendmsg_fastopen(sk, msg, &copied_syn);
1088+
err = tcp_sendmsg_fastopen(sk, msg, &copied_syn, size);
10871089
if (err == -EINPROGRESS && copied_syn > 0)
10881090
goto out;
10891091
else if (err)

net/ipv4/tcp_output.c

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

2911-
syn_data = skb_copy_expand(syn, skb_headroom(syn), space,
2911+
space = min_t(size_t, space, fo->size);
2912+
2913+
/* limit to order-0 allocations */
2914+
space = min_t(size_t, space, SKB_MAX_HEAD(MAX_TCP_HEADER));
2915+
2916+
syn_data = skb_copy_expand(syn, MAX_TCP_HEADER, space,
29122917
sk->sk_allocation);
29132918
if (syn_data == NULL)
29142919
goto fallback;

0 commit comments

Comments
 (0)