Backport complete patchset for call inet6_destroy_sock() in IPv6 sk->sk_destruct()
Subsystems (3)
cover Backport complete patchset for call inet6_destroy_sock() in IPv6 sk->sk_destruct()
5.10 LTS has backported commit ca43ccf41224 ("dccp/tcp: Avoid negative sk_forward_alloc by ipv6_pinfo.pktoptions.") and commit 62ec33b44e0f ("net:
Remove WARN_ON_ONCE(sk->sk_forward_alloc) from sk_stream_kill_queues()."), but these are incomplete. There are some patches that have not been backported including key commit d38afeec26ed ("tcp/udp: Call inet6_destroy_sock() in IPv6 sk->sk_destruct().") and commit b5fc29233d28 ("inet6: Remove inet6_destroy_sock() in sk->sk_prot->destroy()."). Without them, there will be some memory leak bugs.
Backport complete patchset for call inet6_destroy_sock() in IPv6 sk->sk_destruct().
Kuniyuki Iwashima (5):
udp: Call inet6_destroy_sock() in setsockopt(IPV6_ADDRFORM). tcp/udp: Call inet6_destroy_sock() in IPv6 sk->sk_destruct().
inet6: Remove inet6_destroy_sock() in sk->sk_prot->destroy().
dccp: Call inet6_destroy_sock() via sk->sk_destruct().
sctp: Call inet6_destroy_sock() via sk->sk_destruct().
include/net/ipv6.h | 2 ++ include/net/udp.h | 2 +- include/net/udplite.h | 8 -------- net/dccp/dccp.h | 1 + net/dccp/ipv6.c | 15 ++++++++------- net/dccp/proto.c | 8 +++++++- net/ipv4/udp.c | 9 ++++++--- net/ipv4/udplite.c | 8 ++++++++ net/ipv6/af_inet6.c | 15 ++++++++++++++- net/ipv6/ipv6_sockglue.c | 20 ++++++++------------ net/ipv6/ping.c | 6 ------ net/ipv6/raw.c | 2 -- net/ipv6/tcp_ipv6.c | 8 +------- net/ipv6/udp.c | 17 ++++++++++++++--- net/ipv6/udp_impl.h | 1 + net/ipv6/udplite.c | 9 ++++++++- net/l2tp/l2tp_ip6.c | 2 -- net/mptcp/protocol.c | 7 ------- net/sctp/socket.c | 29 +++++++++++++++++++++-------- 19 files changed, 100 insertions(+), 69 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/5 udp: Call inet6_destroy_sock() in setsockopt(IPV6_ADDRFORM).
From: Kuniyuki Iwashima <[email protected]>
commit 21985f43376cee092702d6cb963ff97a9d2ede68 upstream.
Commit 4b340ae20d0e ("IPv6: Complete IPV6_DONTFRAG support") forgot to add a change to free inet6_sk(sk)->rxpmtu while converting an IPv6 socket into IPv4 with IPV6_ADDRFORM. After conversion, sk_prot is changed to udp_prot and ->destroy() never cleans it up, resulting in a memory leak.
This is due to the discrepancy between inet6_destroy_sock() and IPV6_ADDRFORM, so let's call inet6_destroy_sock() from IPV6_ADDRFORM to remove the difference.
However, this is not enough for now because rxpmtu can be changed without lock_sock() after commit 03485f2adcde ("udpv6: Add lockless sendmsg() support"). We will fix this case in the following patch.
Note we will rename inet6_destroy_sock() to inet6_cleanup_sock() and remove unnecessary inet6_destroy_sock() calls in sk_prot->destroy() in the future.
--- include/net/ipv6.h | 1 + net/ipv6/af_inet6.c | 6 ++++++ net/ipv6/ipv6_sockglue.c | 20 ++++++++------------ 3 files changed, 15 insertions(+), 12 deletions(-)
include/net/ipv6.h +1 -0
@@ -1109,6 +1109,7 @@ void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,void ipv6_local_error (struct sock *sk,int err,struct flowi6 *fl6,u32 info);void ipv6_local_rxpmtu (struct sock *sk,struct flowi6 *fl6,u32 mtu); +void inet6_cleanup_sock (struct sock *sk);int inet6_release (struct socket *sock);int inet6_bind (struct socket *sock,struct sockaddr *uaddr,int addr_len); int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
net/ipv6/af_inet6.c +6 -0
@@ -503,6 +503,12 @@ void inet6_destroy_sock(struct sock *sk) }EXPORT_SYMBOL_GPL (inet6_destroy_sock); +void inet6_cleanup_sock (struct sock *sk) +{ +inet6_destroy_sock (sk); +} +EXPORT_SYMBOL_GPL (inet6_cleanup_sock); +/* * This does both peername and sockname. */
net/ipv6/ipv6_sockglue.c +8 -12
@@ -429,9 +429,6 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,if (optlen <sizeof (int )) goto e_inval;if (val ==PF_INET ) { -struct ipv6_txoptions *opt; -struct sk_buff *pktopt; -if (sk->sk_type ==SOCK_RAW )break ;
@@ -462,7 +459,6 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,break ; } -fl6_free_socklist (sk);__ipv6_sock_mc_close (sk);__ipv6_sock_ac_close (sk);
@@ -497,14 +493,14 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, sk->sk_socket->ops = &inet_dgram_ops; sk->sk_family =PF_INET ; } - opt =xchg ((__force struct ipv6_txoptions **)&np->opt, -NULL ); -if (opt) { -atomic_sub (opt->tot_len, &sk->sk_omem_alloc); -txopt_put (opt); - } - pktopt =xchg (&np->pktoptions,NULL ); -kfree_skb (pktopt); + +/* Disable all options not to allocate memory anymore, +* but there is still a race. See the lockless path +* in udpv6_sendmsg() and ipv6_local_rxpmtu(). +*/ + np->rxopt.all =0 ; + +inet6_cleanup_sock (sk);/* * ... and add it to the refcnt debug socks count
Signature · 1 line
2.25.1
Greg KH
maintainerRe: [PATCH 5.10 1/5] udp: Call inet6_destroy_sock() in setsockopt(IPV6_ADDRFORM).
Quoted 3 lines · Ziyang Xuan
From: Kuniyuki Iwashima <[email protected]>
commit
21985f43376cee092702d6cb963ff97a9d2ede68upstream.
Why is this only relevant for 5.10.y? What about 5.15.y?
For obvious reasons, we can not take patches only for older branches as that would cause people to have regressions when moving to newer kernel releases. So can you please fix this up by sending a 5.15.y series, and this 5.10.y series again, and we can queue them all up at the same time?
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH 5.10 1/5] udp: Call inet6_destroy_sock() in setsockopt(IPV6_ADDRFORM).
Quoted 11 lines · Greg KH
Quoted 3 lines · Ziyang Xuan
From: Kuniyuki Iwashima <[email protected]>
commit
21985f43376cee092702d6cb963ff97a9d2ede68upstream.Why is this only relevant for 5.10.y? What about 5.15.y?
For obvious reasons, we can not take patches only for older branches as that would cause people to have regressions when moving to newer kernel releases. So can you please fix this up by sending a 5.15.y series, and this 5.10.y series again, and we can queue them all up at the same time?
Also a 6.1.y series to be complete.
thanks,
greg k-h
Re: [PATCH 5.10 1/5] udp: Call inet6_destroy_sock() in setsockopt(IPV6_ADDRFORM).
Quoted 6 lines · Greg KH
Quoted 5 lines · Ziyang Xuan
Quoted 3 lines
From: Kuniyuki Iwashima <[email protected]>
commit
21985f43376cee092702d6cb963ff97a9d2ede68upstream.
Quoted 9 lines
Quoted 6 lines
Why is this only relevant for 5.10.y? What about 5.15.y?
For obvious reasons, we can not take patches only for older branches as that would cause people to have regressions when moving to newer kernel releases. So can you please fix this up by sending a 5.15.y series, and this 5.10.y series again, and we can queue them all up at the same time?
Also a 6.1.y series to be complete.
4.14.y, 4.19.y, 5.4.y, 5.10.y, 5.15.y and 6.1.y are all involved. Can I send series for them all together?
William Xuan
Quoted 5 lines
thanks,
greg k-h
.
Greg KH
maintainerRe: [PATCH 5.10 1/5] udp: Call inet6_destroy_sock() in setsockopt(IPV6_ADDRFORM).
Quoted 13 lines · Ziyang Xuan (William)
Quoted 13 lines · Greg KH
Quoted 11 lines · Ziyang Xuan
Quoted 3 lines
From: Kuniyuki Iwashima <[email protected]>
commit
21985f43376cee092702d6cb963ff97a9d2ede68upstream.Why is this only relevant for 5.10.y? What about 5.15.y?
For obvious reasons, we can not take patches only for older branches as that would cause people to have regressions when moving to newer kernel releases. So can you please fix this up by sending a 5.15.y series, and this 5.10.y series again, and we can queue them all up at the same time?
Quoted 4 lines
Quoted 2 lines
Also a 6.1.y series to be complete.
4.14.y, 4.19.y, 5.4.y, 5.10.y, 5.15.y and 6.1.y are all involved. Can I send series for them all together?
Yes please, as 5 different patch series.
thanks,
greg k-h
PATCH 2/5 tcp/udp: Call inet6_destroy_sock() in IPv6 sk->sk_destruct().
In reply to Ziyang XuanFrom: Kuniyuki Iwashima <[email protected]>
commit d38afeec26ed4739c640bf286c270559aab2ba5f upstream.
Originally, inet6_sk(sk)->XXX were changed under lock_sock(), so we were able to clean them up by calling inet6_destroy_sock() during the IPv6 -> IPv4 conversion by IPV6_ADDRFORM. However, commit 03485f2adcde ("udpv6:
Add lockless sendmsg() support") added a lockless memory allocation path, which could cause a memory leak:
setsockopt(IPV6_ADDRFORM) sendmsg() +-----------------------+ +-------+ - do_ipv6_setsockopt(sk, ...) - udpv6_sendmsg(sk, ...)
- sockopt_lock_sock(sk) ^._ called via udpv6_prot
- lock_sock(sk) before WRITE_ONCE()
- WRITE_ONCE(sk->sk_prot, &tcp_prot)
- inet6_destroy_sock() - if (!corkreq)
- sockopt_release_sock(sk) - ip6_make_skb(sk, ...)
- release_sock(sk) ^._ lockless fast path for
the non-corking case
- __ip6_append_data(sk, ...)
- ipv6_local_rxpmtu(sk, ...)
- xchg(&np->rxpmtu, skb) ^._ rxpmtu is never freed.
- goto out_no_dst;
- lock_sock(sk)
For now, rxpmtu is only the case, but not to miss the future change and a similar bug fixed in commit e27326009a3d ("net: ping6: Fix memleak in ipv6_renew_options()."), let's set a new function to IPv6 sk->sk_destruct() and call inet6_cleanup_sock() there. Since the conversion does not change sk->sk_destruct(), we can guarantee that we can clean up IPv6 resources finally.
We can now remove all inet6_destroy_sock() calls from IPv6 protocol specific ->destroy() functions, but such changes are invasive to backport. So they can be posted as a follow-up later for net-next.
--- include/net/ipv6.h | 1 + include/net/udp.h | 2 +- include/net/udplite.h | 8 -------- net/ipv4/udp.c | 9 ++++++--- net/ipv4/udplite.c | 8 ++++++++ net/ipv6/af_inet6.c | 8 +++++++- net/ipv6/udp.c | 15 ++++++++++++++- net/ipv6/udp_impl.h | 1 + net/ipv6/udplite.c | 9 ++++++++- 9 files changed, 46 insertions(+), 15 deletions(-)
include/net/ipv6.h +1 -0
@@ -1110,6 +1110,7 @@ void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info);void ipv6_local_rxpmtu (struct sock *sk,struct flowi6 *fl6,u32 mtu);void inet6_cleanup_sock (struct sock *sk); +void inet6_sock_destruct (struct sock *sk);int inet6_release (struct socket *sock);int inet6_bind (struct socket *sock,struct sockaddr *uaddr,int addr_len); int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
include/net/udp.h +1 -1
@@ -268,7 +268,7 @@ static inline bool udp_sk_bound_dev_eq(struct net *net, int bound_dev_if, }/* net/ipv4/udp.c */ -void udp_destruct_sock (struct sock *sk); +void udp_destruct_common (struct sock *sk);void skb_consume_udp (struct sock *sk,struct sk_buff *skb,int len);int __udp_enqueue_schedule_skb (struct sock *sk,struct sk_buff *skb);void udp_skb_destructor (struct sock *sk,struct sk_buff *skb);
include/net/udplite.h +0 -8
@@ -24,14 +24,6 @@ static __inline__ int udplite_getfrag(void *from, char *to, int offset,return copy_from_iter_full (to, len, &msg->msg_iter) ?0 : -EFAULT ; } -/* Designate sk as UDP-Lite socket */ -static inline int udplite_sk_init (struct sock *sk) -{ -udp_init_sock (sk); -udp_sk (sk)->pcflag =UDPLITE_BIT ; -return 0 ; -} -/* * Checksumming routines */
net/ipv4/udp.c +6 -3
@@ -1582,7 +1582,7 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb) }EXPORT_SYMBOL_GPL (__udp_enqueue_schedule_skb); -void udp_destruct_sock (struct sock *sk) +void udp_destruct_common (struct sock *sk) {/* reclaim completely the forward allocated memory */ struct udp_sock *up =udp_sk (sk);
@@ -1595,10 +1595,14 @@ void udp_destruct_sock(struct sock *sk)kfree_skb (skb); }udp_rmem_release (sk, total,0 , true); +} +EXPORT_SYMBOL_GPL (udp_destruct_common); +static void udp_destruct_sock (struct sock *sk) +{ +udp_destruct_common (sk);inet_sock_destruct (sk); } -EXPORT_SYMBOL_GPL (udp_destruct_sock);int udp_init_sock (struct sock *sk) {
@@ -1606,7 +1610,6 @@ int udp_init_sock(struct sock *sk) sk->sk_destruct = udp_destruct_sock;return 0 ; } -EXPORT_SYMBOL_GPL (udp_init_sock);void skb_consume_udp (struct sock *sk,struct sk_buff *skb,int len) {
net/ipv4/udplite.c +8 -0
@@ -17,6 +17,14 @@struct udp_table udplite_table__read_mostly ;EXPORT_SYMBOL (udplite_table); +/* Designate sk as UDP-Lite socket */ +static int udplite_sk_init (struct sock *sk) +{ +udp_init_sock (sk); +udp_sk (sk)->pcflag =UDPLITE_BIT ; +return 0 ; +} +static int udplite_rcv (struct sk_buff *skb) {return __udp4_lib_rcv (skb, &udplite_table,IPPROTO_UDPLITE );
net/ipv6/af_inet6.c +7 -1
@@ -107,6 +107,12 @@ static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)return (struct ipv6_pinfo *)(((u8 *)sk) + offset); } +void inet6_sock_destruct (struct sock *sk) +{ +inet6_cleanup_sock (sk); +inet_sock_destruct (sk); +} +static int inet6_create (struct net *net,struct socket *sock,int protocol,int kern) {
@@ -199,7 +205,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol, inet->hdrincl =1 ; } - sk->sk_destruct = inet_sock_destruct; + sk->sk_destruct = inet6_sock_destruct; sk->sk_family =PF_INET6 ; sk->sk_protocol = protocol;
net/ipv6/udp.c +14 -1
@@ -54,6 +54,19 @@#include <trace/events/skb.h> #include "udp_impl.h" +static void udpv6_destruct_sock (struct sock *sk) +{ +udp_destruct_common (sk); +inet6_sock_destruct (sk); +} + +int udpv6_init_sock (struct sock *sk) +{ +skb_queue_head_init (&udp_sk (sk)->reader_queue); + sk->sk_destruct = udpv6_destruct_sock; +return 0 ; +} + static u32 udp6_ehashfn(const struct net *net, const struct in6_addr *laddr, const u16 lport,
@@ -1700,7 +1713,7 @@ struct proto udpv6_prot = { .connect = ip6_datagram_connect, .disconnect = udp_disconnect, .ioctl = udp_ioctl, - .init = udp_init_sock, + .init = udpv6_init_sock, .destroy = udpv6_destroy_sock, .setsockopt = udpv6_setsockopt, .getsockopt = udpv6_getsockopt,
net/ipv6/udp_impl.h +1 -0
@@ -12,6 +12,7 @@ int __udp6_lib_rcv(struct sk_buff *, struct udp_table *, int);int __udp6_lib_err (struct sk_buff *,struct inet6_skb_parm *,u8 ,u8 ,int ,__be32 ,struct udp_table *); +int udpv6_init_sock (struct sock *sk);int udp_v6_get_port (struct sock *sk,unsigned short snum);void udp_v6_rehash (struct sock *sk);
net/ipv6/udplite.c +8 -1
@@ -12,6 +12,13 @@#include <linux/proc_fs.h> #include "udp_impl.h" +static int udplitev6_sk_init (struct sock *sk) +{ +udpv6_init_sock (sk); +udp_sk (sk)->pcflag =UDPLITE_BIT ; +return 0 ; +} +static int udplitev6_rcv (struct sk_buff *skb) {return __udp6_lib_rcv (skb, &udplite_table,IPPROTO_UDPLITE );
@@ -38,7 +45,7 @@ struct proto udplitev6_prot = { .connect = ip6_datagram_connect, .disconnect = udp_disconnect, .ioctl = udp_ioctl, - .init = udplite_sk_init, + .init = udplitev6_sk_init, .destroy = udpv6_destroy_sock, .setsockopt = udpv6_setsockopt, .getsockopt = udpv6_getsockopt,
Signature · 1 line
2.25.1
PATCH 3/5 inet6: Remove inet6_destroy_sock() in sk->sk_prot->destroy().
In reply to Ziyang XuanFrom: Kuniyuki Iwashima <[email protected]>
commit b5fc29233d28be7a3322848ebe73ac327559cdb9 upstream.
After commit d38afeec26ed ("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.
Now we can remove unnecessary inet6_destroy_sock() calls in sk->sk_prot->destroy().
DCCP and SCTP have their own sk->sk_destruct() function, so we change them separately in the following patches.
--- net/ipv6/ping.c | 6 ------ net/ipv6/raw.c | 2 -- net/ipv6/tcp_ipv6.c | 8 +------- net/ipv6/udp.c | 2 -- net/l2tp/l2tp_ip6.c | 2 -- net/mptcp/protocol.c | 7 ------- 6 files changed, 1 insertion(+), 26 deletions(-)
net/ipv6/ping.c +0 -6
@@ -22,11 +22,6 @@#include <linux/proc_fs.h> #include <net/ping.h> -static void ping_v6_destroy (struct sock *sk) -{ -inet6_destroy_sock (sk); -} -/* Compatibility glue so we can support IPv6 when it's compiled as a module */ static int dummy_ipv6_recv_error (struct sock *sk,struct msghdr *msg,int len,int *addr_len)
@@ -171,7 +166,6 @@ struct proto pingv6_prot = { .owner = THIS_MODULE, .init = ping_init_sock, .close = ping_close, - .destroy = ping_v6_destroy, .connect = ip6_datagram_connect_v6_only, .disconnect = __udp_disconnect, .setsockopt = ipv6_setsockopt,
net/ipv6/raw.c +0 -2
@@ -1211,8 +1211,6 @@ static void raw6_destroy(struct sock *sk)lock_sock (sk);ip6_flush_pending_frames (sk);release_sock (sk); - -inet6_destroy_sock (sk); }static int rawv6_init_sk (struct sock *sk)
net/ipv6/tcp_ipv6.c +1 -7
@@ -1936,12 +1936,6 @@ static int tcp_v6_init_sock(struct sock *sk)return 0 ; } -static void tcp_v6_destroy_sock (struct sock *sk) -{ -tcp_v4_destroy_sock (sk); -inet6_destroy_sock (sk); -} -#ifdef CONFIG_PROC_FS /* Proc filesystem TCPv6 sock list dumping. */ static void get_openreq6(struct seq_file *seq,
@@ -2134,7 +2128,7 @@ struct proto tcpv6_prot = { .accept = inet_csk_accept, .ioctl = tcp_ioctl, .init = tcp_v6_init_sock, - .destroy = tcp_v6_destroy_sock, + .destroy = tcp_v4_destroy_sock, .shutdown = tcp_shutdown, .setsockopt = tcp_setsockopt, .getsockopt = tcp_getsockopt,
net/ipv6/udp.c +0 -2
@@ -1628,8 +1628,6 @@ void udpv6_destroy_sock(struct sock *sk)udp_encap_disable (); } } - -inet6_destroy_sock (sk); }/*
net/l2tp/l2tp_ip6.c +0 -2
@@ -255,8 +255,6 @@ static void l2tp_ip6_destroy_sock(struct sock *sk)if (tunnel)l2tp_tunnel_delete (tunnel); - -inet6_destroy_sock (sk); }static int l2tp_ip6_bind (struct sock *sk,struct sockaddr *uaddr,int addr_len)
net/mptcp/protocol.c +0 -7
@@ -2863,12 +2863,6 @@ static const struct proto_ops mptcp_v6_stream_ops = {static struct proto mptcp_v6_prot; -static void mptcp_v6_destroy (struct sock *sk) -{ -mptcp_destroy (sk); -inet6_destroy_sock (sk); -} -static struct inet_protosw mptcp_v6_protosw = { .type =SOCK_STREAM , .protocol =IPPROTO_MPTCP ,
@@ -2884,7 +2878,6 @@ int __init mptcp_proto_v6_init(void) mptcp_v6_prot = mptcp_prot;strcpy (mptcp_v6_prot.name,"MPTCPv6" ); mptcp_v6_prot.slab =NULL ; - mptcp_v6_prot.destroy = mptcp_v6_destroy; mptcp_v6_prot.obj_size =sizeof (struct mptcp6_sock ); err =proto_register (&mptcp_v6_prot,1 );
Signature · 1 line
2.25.1
PATCH 4/5 dccp: Call inet6_destroy_sock() via sk->sk_destruct().
In reply to Ziyang XuanFrom: Kuniyuki Iwashima <[email protected]>
commit 1651951ebea54970e0bda60c638fc2eee7a6218f upstream.
After commit d38afeec26ed ("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.
--- net/dccp/dccp.h | 1 + net/dccp/ipv6.c | 15 ++++++++------- net/dccp/proto.c | 8 +++++++- net/ipv6/af_inet6.c | 1 + 4 files changed, 17 insertions(+), 8 deletions(-)
net/dccp/dccp.h +1 -0
@@ -283,6 +283,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,int dccp_rcv_established (struct sock *sk,struct sk_buff *skb,const struct dccp_hdr *dh,const unsigned int len); +void dccp_destruct_common (struct sock *sk);int dccp_init_sock (struct sock *sk,const __u8 ctl_sock_initialized);void dccp_destroy_sock (struct sock *sk);
net/dccp/ipv6.c +8 -7
@@ -992,6 +992,12 @@ static const struct inet_connection_sock_af_ops dccp_ipv6_mapped = { .sockaddr_len = sizeof(struct sockaddr_in6), }; +static void dccp_v6_sk_destruct (struct sock *sk) +{ +dccp_destruct_common (sk); +inet6_sock_destruct (sk); +} +/* NOTE: A lot of things set to zero explicitly by call to * sk_alloc() so need not be done here. */
@@ -1004,17 +1010,12 @@ static int dccp_v6_init_sock(struct sock *sk)if (unlikely (!dccp_v6_ctl_sock_initialized)) dccp_v6_ctl_sock_initialized =1 ;inet_csk (sk)->icsk_af_ops = &dccp_ipv6_af_ops; + sk->sk_destruct = dccp_v6_sk_destruct; }return err; } -static void dccp_v6_destroy_sock (struct sock *sk) -{ -dccp_destroy_sock (sk); -inet6_destroy_sock (sk); -} -static struct timewait_sock_ops dccp6_timewait_sock_ops = { .twsk_obj_size =sizeof (struct dccp6_timewait_sock ), };
@@ -1037,7 +1038,7 @@ static struct proto dccp_v6_prot = { .accept = inet_csk_accept, .get_port = inet_csk_get_port, .shutdown = dccp_shutdown, - .destroy = dccp_v6_destroy_sock, + .destroy = dccp_destroy_sock, .orphan_count = &dccp_orphan_count, .max_header = MAX_DCCP_HEADER, .obj_size = sizeof(struct dccp6_sock),
net/dccp/proto.c +7 -1
@@ -171,12 +171,18 @@ const char *dccp_packet_name(const int type)EXPORT_SYMBOL_GPL (dccp_packet_name); -static void dccp_sk_destruct (struct sock *sk) +void dccp_destruct_common (struct sock *sk) {struct dccp_sock *dp =dccp_sk (sk);ccid_hc_tx_delete (dp->dccps_hc_tx_ccid, sk); dp->dccps_hc_tx_ccid =NULL ; +} +EXPORT_SYMBOL_GPL (dccp_destruct_common); + +static void dccp_sk_destruct (struct sock *sk) +{ +dccp_destruct_common (sk);inet_sock_destruct (sk); }
net/ipv6/af_inet6.c +1 -0
@@ -112,6 +112,7 @@ void inet6_sock_destruct(struct sock *sk)inet6_cleanup_sock (sk);inet_sock_destruct (sk); } +EXPORT_SYMBOL_GPL (inet6_sock_destruct);static int inet6_create (struct net *net,struct socket *sock,int protocol,int kern)
Signature · 1 line
2.25.1
PATCH 5/5 sctp: Call inet6_destroy_sock() via sk->sk_destruct().
In reply to Ziyang XuanFrom: Kuniyuki Iwashima <[email protected]>
commit 6431b0f6ff1633ae598667e4cdd93830074a03e8 upstream.
After commit d38afeec26ed ("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.
SCTP sets its own sk->sk_destruct() in the sctp_init_sock(), and SCTPv6 socket reuses it as the init function.
To call inet6_sock_destruct() from SCTPv6 sk->sk_destruct(), we set sctp_v6_destruct_sock() in a new init function.
--- net/sctp/socket.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
net/sctp/socket.c +21 -8
@@ -4991,13 +4991,17 @@ static void sctp_destroy_sock(struct sock *sk) }/* Triggered when there are no references on the socket anymore */ -static void sctp_destruct_sock (struct sock *sk) +static void sctp_destruct_common (struct sock *sk) {struct sctp_sock *sp =sctp_sk (sk);/* Free up the HMAC transform. */ crypto_free_shash (sp->hmac); +} +static void sctp_destruct_sock (struct sock *sk) +{ +sctp_destruct_common (sk);inet_sock_destruct (sk); }
@@ -9191,7 +9195,7 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,sctp_sk (newsk)->reuse = sp->reuse; newsk->sk_shutdown = sk->sk_shutdown; - newsk->sk_destruct = sctp_destruct_sock; + newsk->sk_destruct = sk->sk_destruct; newsk->sk_family = sk->sk_family; newsk->sk_protocol =IPPROTO_SCTP ; newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
@@ -9423,11 +9427,20 @@ struct proto sctp_prot = {#if IS_ENABLED (CONFIG_IPV6 ) -#include <net/transp_v6.h> -static void sctp_v6_destroy_sock (struct sock *sk) +static void sctp_v6_destruct_sock (struct sock *sk) +{ +sctp_destruct_common (sk); +inet6_sock_destruct (sk); +} + +static int sctp_v6_init_sock (struct sock *sk) { -sctp_destroy_sock (sk); -inet6_destroy_sock (sk); +int ret =sctp_init_sock (sk); + +if (!ret) + sk->sk_destruct = sctp_v6_destruct_sock; + +return ret; } struct proto sctpv6_prot = {
@@ -9437,8 +9450,8 @@ struct proto sctpv6_prot = { .disconnect = sctp_disconnect, .accept = sctp_accept, .ioctl = sctp_ioctl, - .init = sctp_init_sock, - .destroy = sctp_v6_destroy_sock, + .init = sctp_v6_init_sock, + .destroy = sctp_destroy_sock, .shutdown = sctp_shutdown, .setsockopt = sctp_setsockopt, .getsockopt = sctp_getsockopt,
Signature · 1 line
2.25.1