Skip to content

Commit 298fbb8

Browse files
author
Xin Long
committed
sctp: Call inet6_destroy_sock() via sk->sk_destruct().
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2160516 Tested: compile only commit 6431b0f Author: Kuniyuki Iwashima <kuniyu@amazon.com> Date: Wed Oct 19 15:36:01 2022 -0700 sctp: 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. 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. 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 67bf533 commit 298fbb8

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

net/sctp/socket.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5099,13 +5099,17 @@ static void sctp_destroy_sock(struct sock *sk)
50995099
}
51005100

51015101
/* Triggered when there are no references on the socket anymore */
5102-
static void sctp_destruct_sock(struct sock *sk)
5102+
static void sctp_destruct_common(struct sock *sk)
51035103
{
51045104
struct sctp_sock *sp = sctp_sk(sk);
51055105

51065106
/* Free up the HMAC transform. */
51075107
crypto_free_shash(sp->hmac);
5108+
}
51085109

5110+
static void sctp_destruct_sock(struct sock *sk)
5111+
{
5112+
sctp_destruct_common(sk);
51095113
inet_sock_destruct(sk);
51105114
}
51115115

@@ -9429,7 +9433,7 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
94299433
sctp_sk(newsk)->reuse = sp->reuse;
94309434

94319435
newsk->sk_shutdown = sk->sk_shutdown;
9432-
newsk->sk_destruct = sctp_destruct_sock;
9436+
newsk->sk_destruct = sk->sk_destruct;
94339437
newsk->sk_family = sk->sk_family;
94349438
newsk->sk_protocol = IPPROTO_SCTP;
94359439
newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
@@ -9664,11 +9668,20 @@ struct proto sctp_prot = {
96649668

96659669
#if IS_ENABLED(CONFIG_IPV6)
96669670

9667-
#include <net/transp_v6.h>
9668-
static void sctp_v6_destroy_sock(struct sock *sk)
9671+
static void sctp_v6_destruct_sock(struct sock *sk)
9672+
{
9673+
sctp_destruct_common(sk);
9674+
inet6_sock_destruct(sk);
9675+
}
9676+
9677+
static int sctp_v6_init_sock(struct sock *sk)
96699678
{
9670-
sctp_destroy_sock(sk);
9671-
inet6_destroy_sock(sk);
9679+
int ret = sctp_init_sock(sk);
9680+
9681+
if (!ret)
9682+
sk->sk_destruct = sctp_v6_destruct_sock;
9683+
9684+
return ret;
96729685
}
96739686

96749687
struct proto sctpv6_prot = {
@@ -9678,8 +9691,8 @@ struct proto sctpv6_prot = {
96789691
.disconnect = sctp_disconnect,
96799692
.accept = sctp_accept,
96809693
.ioctl = sctp_ioctl,
9681-
.init = sctp_init_sock,
9682-
.destroy = sctp_v6_destroy_sock,
9694+
.init = sctp_v6_init_sock,
9695+
.destroy = sctp_destroy_sock,
96839696
.shutdown = sctp_shutdown,
96849697
.setsockopt = sctp_setsockopt,
96859698
.getsockopt = sctp_getsockopt,

0 commit comments

Comments
 (0)