Skip to contentSkip to conversation

sctp: don't count pending-deleted addresses as survivors on bindx del

PATCH New Henry Martin 1 participant 1 message Nov 27

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sctp: don't count pending-deleted addresses as survivors on bindx del

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.

This issue was discovered by Tencent CodeBuddy Security.

Fixes f57d96b2e92d ("[SCTP]: Change use_as_src into a full address state")
---
 net/sctp/bind_addr.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/sctp/bind_addr.c +6 -0
index 31737f144c7f0..e20006b9f12e4 100644
@@ -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;
Signature · 1 line
2.39.5