From nobody Fri Oct 06 14:25:03 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 4S29gN0DxJz4wghG; Fri, 6 Oct 2023 14:25:04 +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 4S29gM6qgTz3QVQ; Fri, 6 Oct 2023 14:25:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696602304; 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=xSWChhgW8dk0YKKiJfaLFA0ifSPsEtbFij/sUsEUeUQ=; b=qr0Uv00+rFVzfWhjnr3aFRulW9Syozm7QGfY41K/iY18r12rGwZelA06DOwIvXZaQVIk/E rTTGVGMwzFs0/7uJI8ptFVDAD7E93Puyx4slMmditXLHQKsMcvLn99KKlIGeA1n4lIPPZQ 4svU9WEyurTct6ADc58KdUDO7Eu/d9nAPPC8h9rLIy8Wt2aZDO7DTyA2hCf/LVMhcVgDWj Som1W2XnfARv+HbHAKPKrGbgkid+a4yx7/1/IC2Gn72+r6W5hT/Wnh+pNl7+2/BLRn9ipt RnxRjoI9BvrTVeYXkX1R6loiWFhXJBGeqY6vLSycRqRNYnOifT9CbDUSi3rOMg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696602304; a=rsa-sha256; cv=none; b=ZHj22s6SuNaqFwAcSxr4SNPK9rlbsWDBTPyZqU4aqLLygAEQ13VkinK6pUmny0RZ0Vt0Wk uzPJVtRvjQem7GZ3aq9fnd8P1sHXFjaunqkXsTFfyxHE5JfwFHKDNlt0XzFKUHIwy/w/B8 qR0QAhMdCmaDQWW/90XzUfo4kxF4NdhVlq+5kzV3kiiEO2IKqngfFclybPIXyGFmgYDKtx BPdMh7o9s73THn9SnmQx2wTpDOv5DhfVz/dCltXxSE823sU3B0HeChCKQxncPRkQVx/fl6 JUBj6P/HN+/CDUikDWm+kA3kBvBwV3IF8UQbBBExcn6IrrdnRqm2TA/cATlHEg== 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=1696602304; 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=xSWChhgW8dk0YKKiJfaLFA0ifSPsEtbFij/sUsEUeUQ=; b=FWlOmUR4q1z93ogfqbcysIq5vHj6X7nrFOjKU2HuWH/ehdp2Tp4jEtMMIaEpQ7zaKq21pY zRLFMhhtf+q1S7We4QQODL5oanfT7T8SGpKdOKIskeizaqIF7ZzkSffb4YTK6+Ojsr5jDO 84idj9sefQa3OuJvvmBnrGkl1KMIbjsCDT4aoDMCqA3ZG2WY3de3M0XnxCnImtrX9wlX9Z RQleY9T9UNUyzZg5s52cCAKcMJMH9CdykbHpsl7kP1KdeTwq3ODgUCk5rLlnr7UlooNdeR m4xiaMGWlN9kWi7JtuTrDJ+5zGbTy1Y4KP8UMhazTl2Q6vGDODGbib6d220QOg== 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 4S29gM5GzQzrXG; Fri, 6 Oct 2023 14:25:03 +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 396EP3cj092955; Fri, 6 Oct 2023 14:25:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 396EP3Fj092952; Fri, 6 Oct 2023 14:25:03 GMT (envelope-from git) Date: Fri, 6 Oct 2023 14:25:03 GMT Message-Id: <202310061425.396EP3Fj092952@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: 8bda9f9c56a9 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 8bda9f9c56a997d851e8fc2c20b5e37f072ecb4a Auto-Submitted: auto-generated The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=8bda9f9c56a997d851e8fc2c20b5e37f072ecb4a commit 8bda9f9c56a997d851e8fc2c20b5e37f072ecb4a Author: Bjoern A. Zeeb AuthorDate: 2023-09-30 15:11:57 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-10-06 12:47:39 +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 Reviewed by: jhibbits (earlier version), kp Differential Revision: https://reviews.freebsd.org/D42027 (cherry picked from commit 7d48224073ce14f0dd3db2d4e96876ac928b52f2) --- 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),