sctp_send_asconf_del_ip() uses sctp_find_unmatch_addr() to make sure a bindx delete keeps at least one address in the association. The lookup counts entries that are already marked SCTP_ADDR_DEL by a previous delete request as survivors. With a peer that holds back the ASCONF acks, two sequential bindx deletes each pass the check while together marking every address for deletion. Once the peer acks both deletes, the association's address list is empty. An empty address list breaks its consumers. SCTP diag reads the list head as an address and returns 16 bytes of association memory in idiag_src. A following bindx add builds an ASCONF from a bogus address taken from the empty list head, whose address family matches no sctp_af, and dereferences a NULL af pointer. e.g. on mainline v7.4-rc4 (KASAN build): Oops: general protection fault (non-canonical 0xdffffc000000000b) KASAN: null-ptr-deref in range [0x0000000000000058-0x000000000000005f] CPU: 1 UID: 1000 PID: 81 Comm: poc-crash Not tainted 7.4.0-rc4 #1 RIP: 0010:sctp_make_asconf+0xd9/0x280 Call Trace: sctp_make_asconf_update_ip+0x243/0x540 sctp_send_asconf_add_ip+0x366/0xc90 sctp_setsockopt+0x1986/0x9410 do_sock_setsockopt+0xb2/0x160 __sys_setsockopt+0xdd/0x140 An address that is already being deleted cannot serve as the remaining address, so skip SCTP_ADDR_DEL entries in the survivor lookup. The existing keep-last handling then holds the final address back, same as it already does for a single-address delete. Two more places have to agree with that rule: - sctp_asconf_param_success() resets the address state to SCTP_ADDR_SRC on an ADD_IP ack, even when a delete for that address is still queued. That drops the SCTP_ADDR_DEL mark and lets the next delete count the address as a survivor again. Keep the mark for an address that is being deleted. - the keep-last path sets src_out_of_asoc_ok so that a later bindx add can use the new address as a source while no SCTP_ADDR_SRC address is left. sctp_process_asconf_ack() clears that flag on any error-free ack, even if asconf_addr_del_pending is still set, which leaves the association with no usable source address. Clear the flag only once the pending delete is gone. While there, update the comments that describe the survivor lookup. This issue was discovered by Tencent CodeBuddy Security. Cc: stab…@vger.kernel.org Fixes: f57d96b2e92d ("[SCTP]: Change use_as_src into a full address state") Link: https://lore.kernel.org/netdev/2026…@gmail.com/ Signed-off-by: Henry Martin <bsdh…@gmail.com> --- Changes in v2: - Skip SCTP_ADDR_DEL entries when an ADD_IP ack sets an address to SCTP_ADDR_SRC, so a queued delete is no longer cancelled by the ack. - Keep src_out_of_asoc_ok set while asconf_addr_del_pending is non-NULL, so a newly added address can still be used as the source. - Update the comments describing the survivor lookup. --- net/sctp/bind_addr.c | 8 +++++++- net/sctp/sm_make_chunk.c | 6 ++++-- net/sctp/socket.c | 6 +++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c index 31737f144c7f0..7a5890877ff0e 100644 --- a/net/sctp/bind_addr.c +++ b/net/sctp/bind_addr.c @@ -427,7 +427,7 @@ int sctp_bind_addr_state(const struct sctp_bind_addr *bp, } /* Find the first address in the bind address list that is not present in - * the addrs packed array. + * the addrs packed array and is not being deleted. */ union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp, const union sctp_addr *addrs, @@ -445,6 +445,12 @@ union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp, * can't change. */ list_for_each_entry(laddr, &bp->address_list, list) { + /* An address already being deleted cannot serve as the + * one remaining address. + */ + if (laddr->state == SCTP_ADDR_DEL) + continue; + addr_buf = (union sctp_addr *)addrs; for (i = 0; i < addrcnt; i++) { addr = addr_buf; diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index ba0474c2a0bc8..877c139c9ed62 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -3393,7 +3393,8 @@ static void sctp_asconf_param_success(struct sctp_association *asoc, */ local_bh_disable(); list_for_each_entry(saddr, &bp->address_list, list) { - if (sctp_cmp_addr_exact(&saddr->a, &addr)) + if (sctp_cmp_addr_exact(&saddr->a, &addr) && + saddr->state != SCTP_ADDR_DEL) saddr->state = SCTP_ADDR_SRC; } local_bh_enable(); @@ -3558,7 +3559,8 @@ int sctp_process_asconf_ack(struct sctp_association *asoc, asconf_len -= length; } - if (no_err && asoc->src_out_of_asoc_ok) { + if (no_err && asoc->src_out_of_asoc_ok && + !asoc->asconf_addr_del_pending) { asoc->src_out_of_asoc_ok = 0; sctp_transport_immediate_rtx(asoc->peer.primary_path); } diff --git a/net/sctp/socket.c b/net/sctp/socket.c index bc68af88e2710..173804240e166 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -855,9 +855,9 @@ static int sctp_send_asconf_del_ip(struct sock *sk, continue; /* Find one address in the association's bind address list - * that is not in the packed array of addresses. This is to - * make sure that we do not delete all the addresses in the - * association. + * that is not in the packed array of addresses and is not + * being deleted. This is to make sure that we do not delete + * all the addresses in the association. */ bp = &asoc->base.bind_addr; laddr = sctp_find_unmatch_addr(bp, (union sctp_addr *)addrs,
-- 2.53.0