linux/net/sctp
Xingyuan Mo 9802123cec sctp: reject forged cookie peer_addr with unknown address family
When cookie authentication is disabled, COOKIE-ECHO peer_addr is
attacker-controlled. An invalid sa_family made sctp_get_af_specific()
return NULL and crash in sctp_transport_init() on
af_specific->sockaddr_len. Validate it with af->addr_valid() in
sctp_unpack_cookie(), which also rejects a mismatched family, e.g.
an AF_INET6 peer_addr on an IPv4 socket that would later crash in
sctp_v6_get_dst() on inet6_sk(sk)->opt. Validate a copy of peer_addr,
since addr_valid() rewrites a v4-mapped v6 address in place and the
cookie still lives in the received skb, which is not guaranteed to
be unshared. Store the validated copy in the new association and
pass it to sctp_process_init() instead of the raw cookie, so a
v4-mapped v6 address is normalised to AF_INET before the association
and its primary transport are built from it.

For that, sctp_v6_addr_valid() has to return 0 for a non-v4-mapped
address when it is called with a socket that is not PF_INET6, so that
IPv6 addresses are never used on IPv4 sockets. The check is done after
the v4-mapped handling, so v4-mapped addresses passed to an IPv4
socket through the socket API keep being accepted. As addr_valid()
now also checks sk_family and ipv6_only_sock, simplify the address
handling in sctp_process_param() with it, as it additionally filters
out non-unicast addresses. As a side effect, a v4-mapped address in
an IPv6 address parameter is now normalised to AF_INET before the
transport is created, matching what the socket API paths already do.

Also add the missing !af check in sctp_process_init(), as
sctp_get_af_specific(AF_INET6) returns NULL on CONFIG_IPV6=n builds.

  BUG: KASAN: null-ptr-deref in sctp_transport_new+0xa7/0x350
  Read of size 4 at addr 00000000000000b4 by task poc/682
  Call Trace:
   <IRQ>
   sctp_transport_new+0xa7/0x350
   sctp_assoc_add_peer+0x153/0x850
   sctp_process_init+0xf9/0x1180
   sctp_sf_do_5_1D_ce+0x464/0xbc0
   sctp_do_sm+0x114/0x2990
   sctp_endpoint_bh_rcv+0x280/0x430
   sctp_inq_push+0xdd/0x100
   sctp_rcv+0x17f5/0x1ae0
   sctp4_rcv+0x2b/0x40
   ip_protocol_deliver_rcu+0x25b/0x270
   ip_local_deliver+0xd1/0xe0
   </IRQ>
  Kernel panic - not syncing: Fatal exception in interrupt

Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Xingyuan Mo <hdthky0@gmail.com>
Acked-by: Xin Long <lucien.xin@gmail.com>
Link: https://patch.msgid.link/20261019073747.178626-1-hdthky0@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-10-23 10:43:38 -07:00
..
associola.c sctp: avoid livelock while updating retransmit path 2026-09-18 17:24:10 -07:00
auth.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2026-08-13 11:00:14 -07:00
bind_addr.c sctp: validate embedded INIT chunk and address list lengths in cookie 2026-06-09 18:16:51 -07:00
chunk.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
debug.c
diag.c sctp: hold socket lock when dumping endpoints in sctp_diag 2026-06-17 16:41:34 -07:00
endpointola.c sctp: auth: discard auth_chunk when skb_clone fails 2026-07-29 16:36:20 -07:00
input.c sctp: hold asoc or transport before mod_timer() in timer handlers 2026-09-22 18:36:36 -07:00
inqueue.c sctp: validate chunk length in the inqueue parser 2026-08-30 14:17:53 -07:00
ipv6.c sctp: reject forged cookie peer_addr with unknown address family 2026-10-23 10:43:38 -07:00
Kconfig ipv6: convert CONFIG_IPV6 to built-in only and clean up Kconfigs 2026-03-29 11:21:22 -07:00
Makefile
objcnt.c
offload.c sctp: use skb_crc32c() instead of __skb_checksum() 2025-05-21 15:40:16 -07:00
output.c sctp: auth: propagate HMAC calculation errors to callers 2026-08-11 10:43:54 +02:00
outqueue.c sctp: keep chunk->transport in step with the list it is queued on 2026-08-03 14:23:05 -07:00
primitive.c
proc.c net: Replace %pK output with 0 2026-09-02 18:38:16 -07:00
protocol.c sctp: close UDP tunnel sockets during netns teardown 2026-07-21 14:03:32 -07:00
sm_make_chunk.c sctp: reject forged cookie peer_addr with unknown address family 2026-10-23 10:43:38 -07:00
sm_sideeffect.c sctp: hold asoc or transport before mod_timer() in timer handlers 2026-09-22 18:36:36 -07:00
sm_statefuns.c sctp: reject forged cookie peer_addr with unknown address family 2026-10-23 10:43:38 -07:00
sm_statetable.c
socket.c sctp: hold transport reference across connect wait 2026-10-15 18:54:04 -07:00
stream_interleave.c
stream_sched_fc.c sctp: Constify struct sctp_sched_ops 2025-10-28 17:50:55 -07:00
stream_sched_prio.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
stream_sched_rr.c sctp: Constify struct sctp_sched_ops 2025-10-28 17:50:55 -07:00
stream_sched.c sctp: Constify struct sctp_sched_ops 2025-10-28 17:50:55 -07:00
stream.c sctp: fix stream->outcnt underflow on duplicate RECONF responses 2026-08-25 13:33:08 +02:00
sysctl.c net: Const qualify ctl_tables that kmemdup unconditionally 2026-08-13 13:12:24 +02:00
transport.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
tsnmap.c
ulpevent.c
ulpqueue.c net: rename skb_unshare() to skb_unclone_full() 2026-10-20 11:28:49 -07:00