From nobody Wed Nov 06 12:34:43 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 4Xk4Qr41jZz5cX2H; Wed, 06 Nov 2024 12:34:44 +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 4Xk4Qr0pQJz3xVZ; Wed, 6 Nov 2024 12:34:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730896484; 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=MY6GLMf/r0jFRRAXMsrp4Fcrqz3lWPb8S+mNhTakMNQ=; b=Pz5KNzSqqkt6D4P6C6znZ266/mxLG5wYy97OeCd5nHuzF6jnr02stnBlaSp9Dg5ZEhO6eM mevQHUquN6/yBDoe0nesj+bcUoRk/1MsA32oLk0SpHu/lLDzv4//MIYJ+/giDKr/EyLbyh rv//Fpwly8+vyuRdXx6Bnhwyl/EH9PpOjOcXD5WZIoOVYJjN6rFTeWzkNhfSOkoxnhkbSm 5hrKSZkW2QIMJ6FbZOQCtttiDpiRtIJEJfGiZGd3J+rUTO5lv6HAgKNOpLs8C/XA4u47n1 FQJaBNCxAW8TZ/N0bv4aQieJkPuuI15x7o336j8QUM7Rn4Ho07oebHOjP48Lvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730896484; 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=MY6GLMf/r0jFRRAXMsrp4Fcrqz3lWPb8S+mNhTakMNQ=; b=fP0YicE6I8vLFvE11+lzpUcKHBW0eV/jkDXyZHVJljAxicKB+vV1FY021j/2Zt/nP6l5bL NjlcVNI8bR7lRvx7HXz1eBicWPOOn/bqYYWfuvFxwmYUXCSYl+L5b4zB9KpEgoHJRNnh+7 Rqfq+mzrjK2wGsiHOfwLW0mn1CdmZYNgbsKaCmfZ5Gc1tB1m6/1FZwWLuOW0VnzwWhYVf+ KEKuaCNpSA3QF/nd7EjAEE46COGGe34gfgjqoUt8hv20hnl7SdCqY3dxdITt6qzhcq0Thg H7kmmNVqtJ2OUWNQM6/Lxb3fVjZVdNwfkuQUptS8GFzmn3Ncn+ex82jh1U745g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730896484; a=rsa-sha256; cv=none; b=gRX/MdIhPl/iLg+A/98rvjiWD8TR+4VuuBsuSBdvPHjcFNHyGyMhA9P3bA1cIVzpFrsMCC 7XfSzzoRvU/esTi97w5Xw0IyseQf5fbE9+OXjsHv/DVNw0w6RRiq3hf9CVP417Rq6GiOLD Y6SckOb2y24FYZ/oM7EAOX/GQK9iEEJ00K1QsbfkCKOjrvo03Dq1rtEo38Cf41DhSmG791 YJfGOR6HXpvbAVRNV/WEn0yuMVxXXKme/z4r7Os2fgbjqNSuYxQsgo4xF2eZMwNeYjnrD9 VQiHvAAYpa1z8T/V/hwKPM58ICspffV4E8CKrar/YAa1wPnx0enXAUIy0prHBQ== 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 4Xk4Qr0Mydz11X3; Wed, 6 Nov 2024 12:34:44 +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 4A6CYhql043496; Wed, 6 Nov 2024 12:34:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A6CYhXB043493; Wed, 6 Nov 2024 12:34:43 GMT (envelope-from git) Date: Wed, 6 Nov 2024 12:34:43 GMT Message-Id: <202411061234.4A6CYhXB043493@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: 331db93815af - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 331db93815afb49b01f269aeff0fe899acd47455 Auto-Submitted: auto-generated The branch stable/13 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=331db93815afb49b01f269aeff0fe899acd47455 commit 331db93815afb49b01f269aeff0fe899acd47455 Author: Michael Tuexen AuthorDate: 2024-11-03 09:20:08 +0000 Commit: Michael Tuexen CommitDate: 2024-11-06 12:33:58 +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 d190be1948ba..5381898ab0ef 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 469c401978ac..0ad898c6df69 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 7ef6feee9c01..ce38e7cede2d 100644 --- a/sys/netinet/sctp_pcb.h +++ b/sys/netinet/sctp_pcb.h @@ -497,7 +497,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 *);