Skip to content

Commit d3295fe

Browse files
matttbekuba-moo
authored andcommitted
mptcp: use proper req destructor for IPv6
Before, only the destructor from TCP request sock in IPv4 was called even if the subflow was IPv6. It is important to use the right destructor to avoid memory leaks with some advanced IPv6 features, e.g. when the request socks contain specific IPv6 options. Fixes: 79c0949 ("mptcp: Add key generation and token tree") Reviewed-by: Mat Martineau <[email protected]> Cc: [email protected] Signed-off-by: Matthieu Baerts <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 34b21d1 commit d3295fe

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

net/mptcp/subflow.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static void subflow_req_destructor(struct request_sock *req)
4545
sock_put((struct sock *)subflow_req->msk);
4646

4747
mptcp_token_destroy_request(req);
48-
tcp_request_sock_ops.destructor(req);
4948
}
5049

5150
static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
@@ -550,6 +549,12 @@ static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb)
550549
return 0;
551550
}
552551

552+
static void subflow_v4_req_destructor(struct request_sock *req)
553+
{
554+
subflow_req_destructor(req);
555+
tcp_request_sock_ops.destructor(req);
556+
}
557+
553558
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
554559
static struct request_sock_ops mptcp_subflow_v6_request_sock_ops __ro_after_init;
555560
static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops __ro_after_init;
@@ -581,6 +586,12 @@ static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb)
581586
tcp_listendrop(sk);
582587
return 0; /* don't send reset */
583588
}
589+
590+
static void subflow_v6_req_destructor(struct request_sock *req)
591+
{
592+
subflow_req_destructor(req);
593+
tcp6_request_sock_ops.destructor(req);
594+
}
584595
#endif
585596

586597
struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops,
@@ -1929,15 +1940,15 @@ static int subflow_ops_init(struct request_sock_ops *subflow_ops)
19291940
if (!subflow_ops->slab)
19301941
return -ENOMEM;
19311942

1932-
subflow_ops->destructor = subflow_req_destructor;
1933-
19341943
return 0;
19351944
}
19361945

19371946
void __init mptcp_subflow_init(void)
19381947
{
19391948
mptcp_subflow_v4_request_sock_ops = tcp_request_sock_ops;
19401949
mptcp_subflow_v4_request_sock_ops.slab_name = "request_sock_subflow_v4";
1950+
mptcp_subflow_v4_request_sock_ops.destructor = subflow_v4_req_destructor;
1951+
19411952
if (subflow_ops_init(&mptcp_subflow_v4_request_sock_ops) != 0)
19421953
panic("MPTCP: failed to init subflow v4 request sock ops\n");
19431954

@@ -1963,6 +1974,8 @@ void __init mptcp_subflow_init(void)
19631974

19641975
mptcp_subflow_v6_request_sock_ops = tcp6_request_sock_ops;
19651976
mptcp_subflow_v6_request_sock_ops.slab_name = "request_sock_subflow_v6";
1977+
mptcp_subflow_v6_request_sock_ops.destructor = subflow_v6_req_destructor;
1978+
19661979
if (subflow_ops_init(&mptcp_subflow_v6_request_sock_ops) != 0)
19671980
panic("MPTCP: failed to init subflow v6 request sock ops\n");
19681981

0 commit comments

Comments
 (0)