From nobody Thu Oct 05 14:27:32 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 4S1Ymh63Ngz4wqvs; Thu, 5 Oct 2023 14:27:32 +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 4S1Ymh5YT9z4PWC; Thu, 5 Oct 2023 14:27:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696516052; 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=+kqDVDptzNnPHGpL5Ho8Z9w8wfZULQbLNe29sMOHgs4=; b=XB6z04IsACltt0U5n201rXgXCwwfpkKmoxa/wooVr89QGZBBUPKYBIjGKd4wGZ6jfg+SMR heMmHfTDj4OALX2XW9pt8PQnaLLki7NrPTrrq+p4PAlat5d3JElWfxFAbVUl/atA86P6ol iKCO2TRujOmrlj6/KHGARtYOlu00RmB+Wy9VqOouJJPk7dIOKtZRmfQFPwZJMbj6NW3Sz6 SPZYJuSRZuV9cOw99JR13vdHcvD5odcxca+XdVMuFavM7WeO3Zv5HfgzV6MjF4GZUYSIV9 6uZeMhYiJRYz15AhD0xJCrxUFirJU0WXxBhUwCFcVECPS1nhgXUvliftPxuT8w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696516052; a=rsa-sha256; cv=none; b=gKnD1AHAz5YTWwbwSTvHz//74Q86iVEFIH6g/4bb3RyVMllM701tgCQNXb13egyNfJQD+z uJDI7S/xSOU0xfzC9+5Sxyl+6n+MEBsox9OHzeWwIGmFD2hfQBBpxFGfcIO6+a6nnhiPbR IY54uq0M694NxYm01Ok0OVvfWgiYKqzqcX/8xaNI+6phkaCaz8K/59j3WVHMgz6LOZQobT ySsqEtMH4KWyxktFsQ8BqTF9q+GblxyOjLiF02ptVm852ay4M/baOGtJe/Nrj6WQ851qu/ 6xAhsiiGZn4hFmo02TtCvkwbZaWy6h8sYCJxBvwHAYFBzUaJWBNeP/y7o+LLWw== 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=1696516052; 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=+kqDVDptzNnPHGpL5Ho8Z9w8wfZULQbLNe29sMOHgs4=; b=NJfwmTo7QaPCk56O0b3D9Mcsy+SSRYoO1z/oWUPl2Xq3dU/TTVo9e9tNQp/VC97kn+u2q4 vUZSf/E1znrzeJzuEX5eDP7954upEKgbt8gK8wK6v0N0RMkNUT9oUQza1vjOqPuPCyBHFv tsXR4xNbxhoPVKWo5jBVldxPlWKqrxqt/OYEO4y52aZnQseBmdUcq4cbF14Cy+Ffwp3mgo s0i/GsoDESdeSNpps/eKK1+oNIppqW1PQCxqUtffH+9pbSolxEPEwBSgQvrgoq0g89r1t4 pzadMnxf1ATJfzI3vbHKJASoCNt+kDDy+yOkAWiRv98q1da9yw6EeKb/Wj0bTQ== 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 4S1Ymh4cxKz1MbW; Thu, 5 Oct 2023 14:27:32 +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 395ERWpB094858; Thu, 5 Oct 2023 14:27:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 395ERWd3094855; Thu, 5 Oct 2023 14:27:32 GMT (envelope-from git) Date: Thu, 5 Oct 2023 14:27:32 GMT Message-Id: <202310051427.395ERWd3094855@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 7d48224073ce - main - 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/main X-Git-Reftype: branch X-Git-Commit: 7d48224073ce14f0dd3db2d4e96876ac928b52f2 Auto-Submitted: auto-generated The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=7d48224073ce14f0dd3db2d4e96876ac928b52f2 commit 7d48224073ce14f0dd3db2d4e96876ac928b52f2 Author: Bjoern A. Zeeb AuthorDate: 2023-09-30 15:11:57 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-10-05 14:27:10 +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 MFC after: 3 days Reviewed by: jhibbits (earlier version), kp Differential Revision: https://reviews.freebsd.org/D42027 --- 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),