From nobody Sun Nov 03 10:23:28 2024 X-Original-To: dev-commits-src-main@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 4Xh9fm4zDhz5bnvy; Sun, 03 Nov 2024 10:23:28 +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 4Xh9fm4WZ5z4Yv7; Sun, 3 Nov 2024 10:23:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730629408; 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=labcbSzhWBwuJBrP7yYfdizt0EMs70FbnFBN4GR98Go=; b=weDlXi8GtFCOYQq34EE9wRmbOyOiXPZ5aJH2nPI0hh1aaORKZQDFW6rds/iNU2WcMnDpgX RBG0vFBiWDkeOJ2lFDKRcfkQ+PxxCL7K2mP75BklOKTqbX23wT53XDCRfQLq6n1jNWQ2d+ 6/0j8zdGBtr/EFcLie3aDa6jJRkYu6lIdWv08BijlNERDRANjZ27155+1+PkLvXtzK/kpp wThdbKf4AmOu50JjdHHS+7VJVmm4mAjH1KU4kFVToW9fCz4c9pwtfz8EzNqmFYUZYUwRe8 0PS6zshohjYALtMwvDnK7UoHIoit6QYm4W3bWOrswYV5aOGnMnQGBZi/13oOSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730629408; 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=labcbSzhWBwuJBrP7yYfdizt0EMs70FbnFBN4GR98Go=; b=g9gr3SEUBsnUZF2TU4i2OXc7Ow1I+04/grrOILPdUQdD9ebJ3dkQ9UsZf/V+7TuwOOsFYw qRTm6a4bjqUQxxlGMptMMNEql52yCViydZ2O5yQ7mNl3XglvmeVBveRCAezdSKR+f0Ur+Y V8f+ClpWziKdjyyM5Ef6vckHU48W7NDwyk9pEpW8eNzsJA1Ez6amnyEayWQ3D+P8Zssx09 ZYPUKIG04H5K9rW9HeO/Lx1LdwQr/6YEzLKfhmeLBnARl7fpjox3tqFB5i9QMuCg8xzjXH 1B7CDwIeGwFmQ0YlhDqj0QTAPTdST7fQW3H1Koo8RaZP8CuyvT1nt1rhDmldqw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730629408; a=rsa-sha256; cv=none; b=yC1i+QBYHI5Qy0s8jnyhoBTcmI9uOF/lVOXaaXyQPzYbIiXkY73WLu7O2Y4mAlv1IFxplU qoaNw6pJg62gAg/cETwDl3FMzzEPaGLajX4EPSKe06cxQG55rra8WzTMyChPa7JD7LEAAn LTg0R/xh1y7wRP4Q3EZRDiaeF7896noimDkfbpNLKnajI1SarHgU0NRyfLpzzQ/eDkZXEk 6MA86N483KN71SfjU4ISUXgZPyvTKmO8oL+0IO2B/CXoJB9d9YwKZXX25/RTeW97neiqgI b9mXpBVqz0rFt9ktApMblcgBd3vIB6bO62rk4KJSGuBgTPyyRXtITjs4GO+6HA== 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 4Xh9fm46qJzkj1; Sun, 3 Nov 2024 10:23:28 +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 4A3ANSWH083124; Sun, 3 Nov 2024 10:23:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A3ANSHq083121; Sun, 3 Nov 2024 10:23:28 GMT (envelope-from git) Date: Sun, 3 Nov 2024 10:23:28 GMT Message-Id: <202411031023.4A3ANSHq083121@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michael Tuexen Subject: git: 523913c94371 - main - sctp: improve handling of address changes List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 523913c94371ab50a8129cbab820394d25f7a269 Auto-Submitted: auto-generated The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=523913c94371ab50a8129cbab820394d25f7a269 commit 523913c94371ab50a8129cbab820394d25f7a269 Author: Michael Tuexen AuthorDate: 2024-11-03 09:20:08 +0000 Commit: Michael Tuexen CommitDate: 2024-11-03 09:20:08 +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 MFC after: 3 days --- 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 03f1d2e944f1..56d36dc9f34e 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 *);