From nobody Thu Nov 07 09:47:20 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XkcgF0kJXz5cdMS; Thu, 07 Nov 2024 09:47:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XkcgD6QMBz4Hs1; Thu, 7 Nov 2024 09:47:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730972840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oHSA/43WMjQLx4v6XaInbW9q7TpcGOoFQYY0SPWpkPM=; b=fk6nW+SASpanvrNT0DFcXX6nkIC5IlYxHqK3egVM8ZalZo1URHoZf++TFez2s/2W3xUyZN as0vuktYxu3R2YXJ1MO9M1FNqhmiKDsZRTE0jLWHl0oxdA5a2CEPNyJ/2baQIAE9KbzdQn PLhr3H/W4o5zQlloTXYn3FfyaZTTQZMltQCOVNQ/XfwO3zSu2+VnuytqiHXqI08r0gc+eC N6Bsv5RJ9eIF/2Q49oC4q7yaCw/LNX5/LPWsIBnPB2SHo8yYF8AeSMQH3d8XtCPjLYGUQB CeNI8YY7F2KjHbTiNY0jiDRmJ81THRSrILfN6k6y51OWXrV3sov11E1DBUbS1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730972840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oHSA/43WMjQLx4v6XaInbW9q7TpcGOoFQYY0SPWpkPM=; b=lhK9SBpFWM8mZHTw3u82eJAiv00FraaFOaAWvTz493+CS1ErFJD9/wp/BmJ/CgXQHpKD27 1X0lL286Rq+V3Yw1iaL49u/FnvEY45WnTPnMggoPCaq3pMJZdRWuoyosD6531pz3gEjU1h evkDsGC1C3L0dyU1lhqs0hGpcRmKQyJlrsnvuGgY41zCj0r0gFDhFyFnnXqW6OmfPRDlA0 49AEIvWXrk236MNniyaQI1sau+2uXSerhOHcoVdjBfdfN6r8N2L4qOgECA8p1phOZbRCQr rJlIZakCvUL8+Uwf0QpKc9tqTC4GPimCWVDidRRsU6urKpze7MSnweLpLtGb1A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730972840; a=rsa-sha256; cv=none; b=wE4gbRTupbq2DxC/bo0+KX/R6kk4fH2bwCRnHP3dKU0v9zwTjj/cvczEqEGLO3cqBkLOhu duWhmL496Ma06Tl6k8bglcs29JB2drlq3a68MkLguIMZHB2D7V1hjRAHOcDK9rrgeQVNPF jhMuTh2nL2zXaUzS0+LFo29b+m8n/eaxWrRRReGll5bzCdtPdOx1qU9ORe1wyEcChv4wUB nmR/HocsbN7HHy7IshxkSLg0uVT9wZdiVBOdr8FzF54ugrN9eXMLZuSzD2HuJxqH6kcaRz ojX77hU9F/PPAfum0WdrzKTBYgLyV17tJ4JXpDVcdOPur5EnRPVe27sPtVTL+w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XkcgD61Wlzgk1; Thu, 7 Nov 2024 09:47:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A79lKUG010232; Thu, 7 Nov 2024 09:47:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A79lKqY010229; Thu, 7 Nov 2024 09:47:20 GMT (envelope-from git) Date: Thu, 7 Nov 2024 09:47:20 GMT Message-Id: <202411070947.4A79lKqY010229@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: a0bc4ec08bef - releng/14.2 - sctp: improve handling of address changes List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.2 X-Git-Reftype: branch X-Git-Commit: a0bc4ec08bef381dc5005338d77caf301e585bf3 Auto-Submitted: auto-generated The branch releng/14.2 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=a0bc4ec08bef381dc5005338d77caf301e585bf3 commit a0bc4ec08bef381dc5005338d77caf301e585bf3 Author: Michael Tuexen AuthorDate: 2024-11-03 09:20:08 +0000 Commit: Michael Tuexen CommitDate: 2024-11-07 00:02:52 +0000 sctp: improve handling of address changes Identify interfaces consistenly by the pair of the ifn pointer and the index. This avoids a use after free when the ifn and or index was reused. Reported by: bz, pho, and others (cherry picked from commit 523913c94371ab50a8129cbab820394d25f7a269) (cherry picked from commit 331db93815afb49b01f269aeff0fe899acd47455) Approved by: re (cperviva) --- sys/netinet/sctp_bsd_addr.c | 1 + sys/netinet/sctp_pcb.c | 23 +++++++++++++---------- sys/netinet/sctp_pcb.h | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sys/netinet/sctp_bsd_addr.c b/sys/netinet/sctp_bsd_addr.c index 3c6952ab6f3c..a10fbcc5ca40 100644 --- a/sys/netinet/sctp_bsd_addr.c +++ b/sys/netinet/sctp_bsd_addr.c @@ -338,6 +338,7 @@ sctp_addr_change(struct ifaddr *ifa, int cmd) (void *)ifa, ifa->ifa_addr, ifa_flags, 1); } else { sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, ifa->ifa_addr, + (void *)ifa->ifa_ifp, ifa->ifa_ifp->if_index); /* diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c index 5f21b2b3d0e4..ab120fc951b1 100644 --- a/sys/netinet/sctp_pcb.c +++ b/sys/netinet/sctp_pcb.c @@ -193,12 +193,11 @@ sctp_find_ifn(void *ifn, uint32_t ifn_index) struct sctp_ifnlist *hash_ifn_head; SCTP_IPI_ADDR_LOCK_ASSERT(); + KASSERT(ifn != NULL, ("sctp_find_ifn(NULL, %u) called", ifn_index)); hash_ifn_head = &SCTP_BASE_INFO(vrf_ifn_hash)[(ifn_index & SCTP_BASE_INFO(vrf_ifn_hashmark))]; LIST_FOREACH(sctp_ifnp, hash_ifn_head, next_bucket) { - if (sctp_ifnp->ifn_index == ifn_index) { - break; - } - if (ifn != NULL && sctp_ifnp->ifn_p == ifn) { + if (sctp_ifnp->ifn_index == ifn_index && + sctp_ifnp->ifn_p == ifn) { break; } } @@ -439,7 +438,8 @@ sctp_add_addr_to_vrf(uint32_t vrf_id, void *ifn, uint32_t ifn_index, if (sctp_ifap != NULL) { /* The address being added is already or still known. */ if (sctp_ifap->ifn_p != NULL) { - if (sctp_ifap->ifn_p->ifn_index == ifn_index) { + if (sctp_ifap->ifn_p->ifn_index == ifn_index && + sctp_ifap->ifn_p->ifn_p == ifn) { SCTPDBG(SCTP_DEBUG_PCB4, "Using existing ifn %s (0x%x) for ifa %p\n", sctp_ifap->ifn_p->ifn_name, ifn_index, @@ -578,7 +578,7 @@ sctp_add_addr_to_vrf(uint32_t vrf_id, void *ifn, uint32_t ifn_index, */ SCTPDBG(SCTP_DEBUG_PCB4, "Lost an address change?\n"); /* Opps, must decrement the count */ - sctp_del_addr_from_vrf(vrf_id, addr, ifn_index); + sctp_del_addr_from_vrf(vrf_id, addr, ifn, ifn_index); return (NULL); } SCTP_INCR_LADDR_COUNT(); @@ -603,7 +603,7 @@ sctp_add_addr_to_vrf(uint32_t vrf_id, void *ifn, uint32_t ifn_index, void sctp_del_addr_from_vrf(uint32_t vrf_id, struct sockaddr *addr, - uint32_t ifn_index) + void *ifn, uint32_t ifn_index) { struct sctp_vrf *vrf; struct sctp_ifa *sctp_ifap; @@ -624,9 +624,12 @@ sctp_del_addr_from_vrf(uint32_t vrf_id, struct sockaddr *addr, if (sctp_ifap != NULL) { /* Validate the delete */ if (sctp_ifap->ifn_p) { - if (ifn_index != sctp_ifap->ifn_p->ifn_index) { - SCTPDBG(SCTP_DEBUG_PCB4, "ifn:%d ifname:%s - ignoring delete\n", - sctp_ifap->ifn_p->ifn_index, sctp_ifap->ifn_p->ifn_name); + if (ifn_index != sctp_ifap->ifn_p->ifn_index || + ifn != sctp_ifap->ifn_p->ifn_p) { + SCTPDBG(SCTP_DEBUG_PCB4, "ifn:%d (p) ifname:%s - ignoring delete\n", + sctp_ifap->ifn_p->ifn_index, + sctp_ifap->ifn_p->ifn_p, + sctp_ifap->ifn_p->ifn_name); SCTP_IPI_ADDR_WUNLOCK(); return; } diff --git a/sys/netinet/sctp_pcb.h b/sys/netinet/sctp_pcb.h index 736972c007d8..2bec2bc32d4e 100644 --- a/sys/netinet/sctp_pcb.h +++ b/sys/netinet/sctp_pcb.h @@ -498,7 +498,7 @@ void sctp_free_ifa(struct sctp_ifa *sctp_ifap); void sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr, - uint32_t ifn_index); + void *ifn, uint32_t ifn_index); struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);