summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuho Choi <dbgh9129@gmail.com>2026-06-08 12:22:30 -0400
committerJakub Kicinski <kuba@kernel.org>2026-06-10 08:28:40 -0700
commitc8459ee2fef502d6ef6c063751c33d9ac7943eab (patch)
tree3d42d111e52a7963523cfdcff7ca283e469efad5
parent1225253dc50ce7154d3c0247c11f1e8b3ec92aeb (diff)
downloadlinux-next-c8459ee2fef502d6ef6c063751c33d9ac7943eab.tar.gz
linux-next-c8459ee2fef502d6ef6c063751c33d9ac7943eab.zip
sctp: Unwind address notifier registration on failure
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>
-rw-r--r--net/sctp/ipv6.c10
-rw-r--r--net/sctp/protocol.c10
2 files changed, 16 insertions, 4 deletions
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index cd15b695607e..ef26878f1282 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -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;
}
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 5c6fa8e8d34d..587b0017a67d 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -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;
}