From nobody Tue Oct 10 14:34:20 2023 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 4S4dhD4Txtz4wqkJ; Tue, 10 Oct 2023 14:34:20 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S4dhD2Rqnz4Qx3; Tue, 10 Oct 2023 14:34:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696948460; 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=VkouFUE/Wv9nQt25kD9iP7iA2AXRspa40TbhVUUh+wk=; b=D6vrNxIcgoCDElqbOhaELxJaEz2yLgDzUVc187kUvOCWsLoLzQZDgUEC80S68hrq6Mtfyq xF6Q4UMsblvTf76/CT0Tp7b/G4m7UmihKgyjVeABzLV6e/AXTQJ7wKcWqSQrWx4ngzmy+E ZyY95mvCunVrS+yjGOwzobRIpfyT5vgTR0cFksNYGmawu6Sl1jN3Gr11WaLWYs10lueTXE kmBSeora0OQh+onhQXuWzmlNR/60rGr7cwyguPMn+JQdmNQRfiClNv29/GA5uE8/kIz55i RMGAQ5wd3U0eEOfvbyBJu96r/9mI8vDcuhkHU/MqhLr//nme4URx0GdPSRij5Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696948460; a=rsa-sha256; cv=none; b=KeEvM8IlNBkkg7xSmv3W1iz9WE0pCsyYIEO411gawtrZPextNqCSdRVLtMjwGfnJLEc0kq KR7VlrKt8+B7fLK1GXz44D8e41307UBciISdzN12xYEf2HHVE9sF0QkCEZVeOW7914vt+a 3SdC9E+6+r1rk+ZyxT00G4yC1yCbttwLdaV/lKxopdBgvWBPvw5WZ0YPlKfGfRuzdl3QL9 5aVT6EdMitINN+XUiHm38Dbub4hLgKnaIyFsi+yAqYjhmTZ3Wplr0uGLUVI05TpVuSUXTY qSadANkSllgNf8BlR6K9CX6DcyHydVnuSSSMlrF0nX9tiY7vFYy5CvGwUpECqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696948460; 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=VkouFUE/Wv9nQt25kD9iP7iA2AXRspa40TbhVUUh+wk=; b=IgFXgLMk64fHLqs3zj/+tlE5hhqz2RMtsK7yXJbrerfMKviJT2712aCAgxLmNeYrU7Fa8w sht1t+lUUMAf1pxFpGphXccoG8VWFWAV9OsEPBXxjDxC5gzP8xIT0oyNiQ17gXQTfU407Q jmEEy2/3WU4kjgBfKQoHVWmR/Gi5ni2OPtQhMh9TlyfDIgjWEtpFnEXWxW5lyYQiFTuLUF tTg0HAEFmVsaonsDVqUCdJSmmGgVWhAkYWMwboPZ1YkqFtxPDXElEB/BIlkODUKkwKFn9p s2EvjkLzsG8+196SpIKi0pbeaxZMYGAU9K+ti9fJfBTyYDNDrpAlywC67kuHzA== 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 4S4dhD1XKlzj5w; Tue, 10 Oct 2023 14:34:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39AEYKSZ005061; Tue, 10 Oct 2023 14:34:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39AEYKZ2005058; Tue, 10 Oct 2023 14:34:20 GMT (envelope-from git) Date: Tue, 10 Oct 2023 14:34:20 GMT Message-Id: <202310101434.39AEYKZ2005058@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 41023d85b3bc - releng/14.0 - netlink: fix accessing freed memory 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 41023d85b3bc43cb421f46bb35cf75201542c528 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=41023d85b3bc43cb421f46bb35cf75201542c528 commit 41023d85b3bc43cb421f46bb35cf75201542c528 Author: Bjoern A. Zeeb AuthorDate: 2023-09-30 15:11:57 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-10-10 14:33:37 +0000 netlink: fix accessing freed memory The check for if_addrlen in dump_iface() is not sufficient to determine if we still have a valid if_addr. Rather than directly accessing if_addr check the STAILQ (for the first entry). This avoids panics when destroying cloned interfaces as experienced with net80211 wlan ones. Sponsored by: The FreeBSD Foundation Approved by: re (gjb) Reviewed by: jhibbits (earlier version), kp Differential Revision: https://reviews.freebsd.org/D42027 (cherry picked from commit 7d48224073ce14f0dd3db2d4e96876ac928b52f2) (cherry picked from commit 8bda9f9c56a997d851e8fc2c20b5e37f072ecb4a) --- sys/netlink/route/iface.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c index e1939c7681de..b6e120933f83 100644 --- a/sys/netlink/route/iface.c +++ b/sys/netlink/route/iface.c @@ -292,6 +292,7 @@ static bool dump_iface(struct nl_writer *nw, if_t ifp, const struct nlmsghdr *hdr, int if_flags_mask) { + struct epoch_tracker et; struct ifinfomsg *ifinfo; NL_LOG(LOG_DEBUG3, "dumping interface %s data", if_name(ifp)); @@ -321,11 +322,15 @@ dump_iface(struct nl_writer *nw, if_t ifp, const struct nlmsghdr *hdr, nlattr_add_u8(nw, IFLA_PROTO_DOWN, val); nlattr_add_u8(nw, IFLA_LINKMODE, val); */ - if (if_getaddrlen(ifp) != 0) { - struct ifaddr *ifa = if_getifaddr(ifp); + if (if_getaddrlen(ifp) != 0) { + struct ifaddr *ifa; - dump_sa(nw, IFLA_ADDRESS, ifa->ifa_addr); - } + NET_EPOCH_ENTER(et); + ifa = CK_STAILQ_FIRST(&ifp->if_addrhead); + if (ifa != NULL) + dump_sa(nw, IFLA_ADDRESS, ifa->ifa_addr); + NET_EPOCH_EXIT(et); + } if ((if_getbroadcastaddr(ifp) != NULL)) { nlattr_add(nw, IFLA_BROADCAST, if_getaddrlen(ifp),