Netdev List
 help / color / mirror / Atom feed
From: Henry Martin <bsdhenrymartin@gmail.com>
To: Xin Long <lucien.xin@gmail.com>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Eric Dumazet <edumazet@kernel.org>,
	Simon Horman <horms@kernel.org>
Cc: linux-sctp@vger.kernel.org, netdev@vger.kernel.org,
	Henry Martin <bsdhenrymartin@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH net v2] sctp: don't count pending-deleted addresses as survivors on bindx del
Date: Wed,  2 Dec 2026 18:13:55 +0800	[thread overview]
Message-ID: <20261202101355.540636-1-bsdhenrymartin@gmail.com> (raw)

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: stable@vger.kernel.org
Fixes: f57d96b2e92d ("[SCTP]: Change use_as_src into a full address state")
Link: https://lore.kernel.org/netdev/20261127065017.2922776-1-bsdhenrymartin@gmail.com/
Signed-off-by: Henry Martin <bsdhenrymartin@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


                 reply	other threads:[~2026-12-02 10:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202101355.540636-1-bsdhenrymartin@gmail.com \
    --to=bsdhenrymartin@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=lucien.xin@gmail.com \
    --cc=marcelo.leitner@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox