From nobody Wed Nov 06 10:13:44 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 4Xk1J91jkTz5cPLL; Wed, 06 Nov 2024 10:13:45 +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 4Xk1J90jpNz4d1h; Wed, 6 Nov 2024 10:13:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730888025; 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=G3t7bTQrKyHuiUy38dFsdRJ8+HdME4u78mDiAm+kDvQ=; b=iQXVJHIntlLUYMFMNiZPeW97wvNye/LbaV0pOXQPCxbelu7Q99u6thV7/v3cUp2WWjQ9nT hutQ6dRox+w5HVrS+mEq68JOfxbqt8eQlICF5iOHEKoDaqevMnyV5KWFC8m0qgxJIsXtzd //4VrKztovd3TpUoahj/jpKCzfZMxJNncV63Afp5PVQmMMKR7BWZviNJiIs2X+Nm3OJu/n gv9nCT0XS9Dr4RHeoeRy/LuaHGkNnbbFFyfEmPzUWFWFfX2sm0c+6TdQPrivGrgHO2ERVg eqdeIwsBk2UuJS7xTRd+KoJMNCcId2mT/qZUbP93547WO9IjyW4MXZM+Kf1aEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730888025; 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=G3t7bTQrKyHuiUy38dFsdRJ8+HdME4u78mDiAm+kDvQ=; b=TTonnWzNCcBpssotm1sHkIRLpQxOyIeBUbOtq9TUFXtq4rIeYJ4wB2sbIiY/B1wiAndcjw o748I9oOThuoXi+YykeqkhJUa1wO8NLdE9TvHPUIKVeq+KZnyArFn2BvNyRRXF/FgGdBTC AuhfAU/yV2yNotuVqPKQXIt1k1t8BR11rs8C3Q+tuGQep2j83BMma3fQbRFKUbCsARQRPM V3JHbdrlrRMDHtpqf7CttLilUSV7QqnVGVdjOHC9ZOHlmMXJi+DHQ/EhTf9GmySLY929lj KS6N5EmpMYoW1FUjgv3qOR4F4A8ZS/+Z8kgGD9q1SrbtRNnTvFIYYpY9jm0LlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730888025; a=rsa-sha256; cv=none; b=OBNL/a0Ab/O8Wzf3a7B30bf1+kgmeHDPOwXPXCr7fNmvvEl6B0XPUrDM1jakCKC+8lmPXw NveBFF+EhUiDg2r1X9ghiovStkbNTYxP3wuze+potAuHYQytxXgdZnGa5RVl7qqjOn8pJh WgzVTpPaAVcim1diDurGn51XoHGwHsssunSlLaTInuJl3/ddlMi+p26E7espPvjoNUPtRS F5BVgojxC4B/qnK1Y3WFQDhxXRbcKwmzHbFgF/N/r7H1nQX268bAuLQcg1mKGRKmG7xbg9 g07tDRj23+N+JepWIW7ZLsU5y/2XnlSwpcI6kX8ligYLnwY+vuRtb92EH6ywyQ== 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 4Xk1J90KGJzwwh; Wed, 6 Nov 2024 10:13:45 +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 4A6ADiou083199; Wed, 6 Nov 2024 10:13:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A6ADiNi083196; Wed, 6 Nov 2024 10:13:44 GMT (envelope-from git) Date: Wed, 6 Nov 2024 10:13:44 GMT Message-Id: <202411061013.4A6ADiNi083196@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: 5616189419f8 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 5616189419f82067dcd350675cbc7d27a2299580 Auto-Submitted: auto-generated The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=5616189419f82067dcd350675cbc7d27a2299580 commit 5616189419f82067dcd350675cbc7d27a2299580 Author: Michael Tuexen AuthorDate: 2024-11-03 09:20:08 +0000 Commit: Michael Tuexen CommitDate: 2024-11-06 09:12:28 +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) --- 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 *);