]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sctp: Unwind address notifier registration on failure
authorYuho Choi <dbgh9129@gmail.com>
Mon, 8 Jun 2026 16:22:30 +0000 (12:22 -0400)
committerJakub Kicinski <kuba@kernel.org>
Wed, 10 Jun 2026 15:28:40 +0000 (08:28 -0700)
sctp_v4_add_protocol() and sctp_v6_add_protocol() register their
address notifiers before registering the SCTP protocol handlers. If
protocol registration fails, the functions return without unregistering
the notifiers.

Unregister the notifiers on the protocol registration failure paths.
Also propagate notifier registration failures instead of ignoring them.

Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
Link: https://patch.msgid.link/20260608162230.46644-1-dbgh9129@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/sctp/ipv6.c
net/sctp/protocol.c

index cd15b695607ebeee4bdaf8685e621b3e2275512d..ef26878f1282ae8c8b875229aa7c0e4fc42c7d19 100644 (file)
@@ -1176,11 +1176,17 @@ void sctp_v6_protosw_exit(void)
 /* Register with inet6 layer. */
 int sctp_v6_add_protocol(void)
 {
+       int ret;
+
        /* Register notifier for inet6 address additions/deletions. */
-       register_inet6addr_notifier(&sctp_inet6addr_notifier);
+       ret = register_inet6addr_notifier(&sctp_inet6addr_notifier);
+       if (ret)
+               return ret;
 
-       if (inet6_add_protocol(&sctpv6_protocol, IPPROTO_SCTP) < 0)
+       if (inet6_add_protocol(&sctpv6_protocol, IPPROTO_SCTP) < 0) {
+               unregister_inet6addr_notifier(&sctp_inet6addr_notifier);
                return -EAGAIN;
+       }
 
        return 0;
 }
index 5c6fa8e8d34d3304f26a4927f58227f2fc987964..587b0017a67d503e31a61e1133782094c6272743 100644 (file)
@@ -1263,12 +1263,18 @@ static void sctp_v4_protosw_exit(void)
 
 static int sctp_v4_add_protocol(void)
 {
+       int ret;
+
        /* Register notifier for inet address additions/deletions. */
-       register_inetaddr_notifier(&sctp_inetaddr_notifier);
+       ret = register_inetaddr_notifier(&sctp_inetaddr_notifier);
+       if (ret)
+               return ret;
 
        /* Register SCTP with inet layer.  */
-       if (inet_add_protocol(&sctp_protocol, IPPROTO_SCTP) < 0)
+       if (inet_add_protocol(&sctp_protocol, IPPROTO_SCTP) < 0) {
+               unregister_inetaddr_notifier(&sctp_inetaddr_notifier);
                return -EAGAIN;
+       }
 
        return 0;
 }