Skip to content

Commit 67bf533

Browse files
author
Xin Long
committed
dccp: Call inet6_destroy_sock() via sk->sk_destruct().
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2160516 Tested: compile only commit 1651951 Author: Kuniyuki Iwashima <kuniyu@amazon.com> Date: Wed Oct 19 15:36:00 2022 -0700 dccp: Call inet6_destroy_sock() via sk->sk_destruct(). After commit d38afee ("tcp/udp: Call inet6_destroy_sock() in IPv6 sk->sk_destruct()."), we call inet6_destroy_sock() in sk->sk_destruct() by setting inet6_sock_destruct() to it to make sure we do not leak inet6-specific resources. DCCP sets its own sk->sk_destruct() in the dccp_init_sock(), and DCCPv6 socket shares it by calling the same init function via dccp_v6_init_sock(). To call inet6_sock_destruct() from DCCPv6 sk->sk_destruct(), we export it and set dccp_v6_sk_destruct() in the init function. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Xin Long <lxin@redhat.com>
1 parent af4a12d commit 67bf533

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

net/dccp/dccp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
283283
int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
284284
const struct dccp_hdr *dh, const unsigned int len);
285285

286+
void dccp_destruct_common(struct sock *sk);
286287
int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized);
287288
void dccp_destroy_sock(struct sock *sk);
288289

net/dccp/ipv6.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,12 @@ static const struct inet_connection_sock_af_ops dccp_ipv6_mapped = {
10031003
.sockaddr_len = sizeof(struct sockaddr_in6),
10041004
};
10051005

1006+
static void dccp_v6_sk_destruct(struct sock *sk)
1007+
{
1008+
dccp_destruct_common(sk);
1009+
inet6_sock_destruct(sk);
1010+
}
1011+
10061012
/* NOTE: A lot of things set to zero explicitly by call to
10071013
* sk_alloc() so need not be done here.
10081014
*/
@@ -1015,17 +1021,12 @@ static int dccp_v6_init_sock(struct sock *sk)
10151021
if (unlikely(!dccp_v6_ctl_sock_initialized))
10161022
dccp_v6_ctl_sock_initialized = 1;
10171023
inet_csk(sk)->icsk_af_ops = &dccp_ipv6_af_ops;
1024+
sk->sk_destruct = dccp_v6_sk_destruct;
10181025
}
10191026

10201027
return err;
10211028
}
10221029

1023-
static void dccp_v6_destroy_sock(struct sock *sk)
1024-
{
1025-
dccp_destroy_sock(sk);
1026-
inet6_destroy_sock(sk);
1027-
}
1028-
10291030
static struct timewait_sock_ops dccp6_timewait_sock_ops = {
10301031
.twsk_obj_size = sizeof(struct dccp6_timewait_sock),
10311032
};
@@ -1048,7 +1049,7 @@ static struct proto dccp_v6_prot = {
10481049
.accept = inet_csk_accept,
10491050
.get_port = inet_csk_get_port,
10501051
.shutdown = dccp_shutdown,
1051-
.destroy = dccp_v6_destroy_sock,
1052+
.destroy = dccp_destroy_sock,
10521053
.orphan_count = &dccp_orphan_count,
10531054
.max_header = MAX_DCCP_HEADER,
10541055
.obj_size = sizeof(struct dccp6_sock),

net/dccp/proto.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,18 @@ const char *dccp_packet_name(const int type)
171171

172172
EXPORT_SYMBOL_GPL(dccp_packet_name);
173173

174-
static void dccp_sk_destruct(struct sock *sk)
174+
void dccp_destruct_common(struct sock *sk)
175175
{
176176
struct dccp_sock *dp = dccp_sk(sk);
177177

178178
ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
179179
dp->dccps_hc_tx_ccid = NULL;
180+
}
181+
EXPORT_SYMBOL_GPL(dccp_destruct_common);
182+
183+
static void dccp_sk_destruct(struct sock *sk)
184+
{
185+
dccp_destruct_common(sk);
180186
inet_sock_destruct(sk);
181187
}
182188

net/ipv6/af_inet6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void inet6_sock_destruct(struct sock *sk)
113113
inet6_cleanup_sock(sk);
114114
inet_sock_destruct(sk);
115115
}
116+
EXPORT_SYMBOL_GPL(inet6_sock_destruct);
116117

117118
static int inet6_create(struct net *net, struct socket *sock, int protocol,
118119
int kern)

0 commit comments

Comments
 (0)