Skip to content

Commit ae2dd71

Browse files
Florian Westphaldavem330
authored andcommitted
mptcp: handle tcp fallback when using syn cookies
We can't deal with syncookie mode yet, the syncookie rx path will create tcp reqsk, i.e. we get OOB access because we treat tcp reqsk as mptcp reqsk one: TCP: SYN flooding on port 20002. Sending cookies. BUG: KASAN: slab-out-of-bounds in subflow_syn_recv_sock+0x451/0x4d0 net/mptcp/subflow.c:191 Read of size 1 at addr ffff8881167bc148 by task syz-executor099/2120 subflow_syn_recv_sock+0x451/0x4d0 net/mptcp/subflow.c:191 tcp_get_cookie_sock+0xcf/0x520 net/ipv4/syncookies.c:209 cookie_v6_check+0x15a5/0x1e90 net/ipv6/syncookies.c:252 tcp_v6_cookie_check net/ipv6/tcp_ipv6.c:1123 [inline] [..] Bug can be reproduced via "sysctl net.ipv4.tcp_syncookies=2". Note that MPTCP should work with syncookies (4th ack would carry needed state), but it appears better to sort that out in -next so do tcp fallback for now. I removed the MPTCP ifdef for tcp_rsk "is_mptcp" member because if (IS_ENABLED()) is easier to read than "#ifdef IS_ENABLED()/#endif" pair. Cc: Eric Dumazet <[email protected]> Fixes: cec37a6 ("mptcp: Handle MP_CAPABLE options for outgoing connections") Reported-by: Christoph Paasch <[email protected]> Tested-by: Christoph Paasch <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b2c5b61 commit ae2dd71

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

include/linux/tcp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ struct tcp_request_sock {
148148
const struct tcp_request_sock_ops *af_specific;
149149
u64 snt_synack; /* first SYNACK sent time */
150150
bool tfo_listener;
151-
#if IS_ENABLED(CONFIG_MPTCP)
152151
bool is_mptcp;
153-
#endif
154152
u32 txhash;
155153
u32 rcv_isn;
156154
u32 snt_isn;

net/ipv4/syncookies.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
349349
req->ts_recent = tcp_opt.saw_tstamp ? tcp_opt.rcv_tsval : 0;
350350
treq->snt_synack = 0;
351351
treq->tfo_listener = false;
352+
353+
if (IS_ENABLED(CONFIG_MPTCP))
354+
treq->is_mptcp = 0;
355+
352356
if (IS_ENABLED(CONFIG_SMC))
353357
ireq->smc_ok = 0;
354358

net/ipv4/tcp_input.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6637,6 +6637,9 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
66376637

66386638
af_ops->init_req(req, sk, skb);
66396639

6640+
if (IS_ENABLED(CONFIG_MPTCP) && want_cookie)
6641+
tcp_rsk(req)->is_mptcp = 0;
6642+
66406643
if (security_inet_conn_request(sk, skb, req))
66416644
goto drop_and_free;
66426645

net/ipv6/syncookies.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
178178
treq = tcp_rsk(req);
179179
treq->tfo_listener = false;
180180

181+
if (IS_ENABLED(CONFIG_MPTCP))
182+
treq->is_mptcp = 0;
183+
181184
if (security_inet_conn_request(sk, skb, req))
182185
goto out_free;
183186

net/mptcp/subflow.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
186186

187187
pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
188188

189+
if (tcp_rsk(req)->is_mptcp == 0)
190+
goto create_child;
191+
189192
/* if the sk is MP_CAPABLE, we try to fetch the client key */
190193
subflow_req = mptcp_subflow_rsk(req);
191194
if (subflow_req->mp_capable) {
@@ -769,7 +772,7 @@ static void subflow_ulp_clone(const struct request_sock *req,
769772
struct mptcp_subflow_context *old_ctx = mptcp_subflow_ctx(newsk);
770773
struct mptcp_subflow_context *new_ctx;
771774

772-
if (!subflow_req->mp_capable) {
775+
if (!tcp_rsk(req)->is_mptcp || !subflow_req->mp_capable) {
773776
subflow_ulp_fallback(newsk, old_ctx);
774777
return;
775778
}

0 commit comments

Comments
 (0)