From nobody Fri Feb 25 19:55:28 2022 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 C0F2619E0525; Fri, 25 Feb 2022 19:55: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4K50r051zzz3NvR; Fri, 25 Feb 2022 19:55:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645818928; 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=4dl2AuiNgH8IA9NEaKc6CMsLTne8tmGouQzvVWGXo7Y=; b=DI7R/ek2FL2W+NdeABWEmeMuzHu+T0Idmq+3K2IoAChHcMT1FUriIQat2wCcp8NX0/icAa M7xWK1IShFG/wPSVErVdSpHg4fIcflco2zgPooMUNF1mol9hqD5qnMWIiQEGjaRnnxzm4E v0iSili7MZXLyNn6IbOiI+WxbcCoK5f3eURd7FwXAOj1Do89hFPmSpi6pRTjbLwgtxUrMU DBBC4aeKhFA4wII47N0fgZ3hrRKAMgK7K6bsnGVjBJq9u6n+aacMAvj9R7LUXzvWIzxZLA KT9HuvYRG+fVEZmsTmFNUPfNo7RhjuqDcAQFWFRy5JIn7tJTLiKXKnoJH/F+rQ== 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 883C925A43; Fri, 25 Feb 2022 19:55:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21PJtS01027731; Fri, 25 Feb 2022 19:55:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21PJtSJ1027730; Fri, 25 Feb 2022 19:55:28 GMT (envelope-from git) Date: Fri, 25 Feb 2022 19:55:28 GMT Message-Id: <202202251955.21PJtSJ1027730@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ryan Stone Subject: git: bbce80f3efcb - stable/13 - MFC 2290dfb40fce: 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: rstone X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: bbce80f3efcb1333ef661ade6b78ecd190fa32df Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645818928; 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=4dl2AuiNgH8IA9NEaKc6CMsLTne8tmGouQzvVWGXo7Y=; b=P7Ponugeipd/T4myM+y70cqF5zyF81qzeitdJz4fMbMr2uQs7NQl5H23ABadhwSzXMft6P RT+QoxCTQ28YFdjJgIUeD1DJKE7Bp0nvvK88F8gapG6Ok0OU0iyaZDZqtJGbFJ7i+v7Vsq O011fNzhbQ7IJxvRSFaMULlrKfT3uW37gfjdHSACxgiUscvFCSKaQxZMRlgmEGH3yPr7Bf yLpbtz9QMbV60dy3c+/uQhf4IAHrVk4Onju2x2eXIlSKqP/4wO7h4eRtr6a31kh8ou5oT8 ZESNGEmIyshQWKNkqqP4IFa9nCmuNhXbfAsTCP8VYULSxKTBz6iQNJibDUBJFQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645818928; a=rsa-sha256; cv=none; b=w54ZPdMY8W/zUWGpCGPJd3Dc60+zSdWCvN2WHG1iLnUZjPKEtyfutIpDW6IvyM5JG+LnHK oRIiHjcyriXAhdXNqfhpDtaXwQOmBR2GAIk3s946ksYAlaQxuQs3mKEctxK/MJRm+zSJGq WfSJPe/tgNFcUBuepYaPeZcp7me0t20VMLBnJ8E8tUFOu3P35sRUZ6j85y6egWbli+YTHR gxy3djis5TD6Lb/9wvlR9w7+7k8sqMh16c9jo71C3ekdnmfOJIw41+BgbB2Q2w7u6sIbFA U1lSiIy654OFTndRjDPX+1fMolziBT2G2xb/CWxSzaQvDwrXRVLgqAKY8hYhGA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by rstone: URL: https://cgit.FreeBSD.org/src/commit/?id=bbce80f3efcb1333ef661ade6b78ecd190fa32df commit bbce80f3efcb1333ef661ade6b78ecd190fa32df Author: Ryan Stone AuthorDate: 2021-05-19 19:10:03 +0000 Commit: Ryan Stone CommitDate: 2022-02-25 19:49:33 +0000 MFC 2290dfb40fce: Enter the net epoch before calling ip6_setpktopts ip6_setpktopts() can look up ifnets via ifnet_by_index(), which is only safe in the net epoch. Ensure that callers are in the net epoch before calling this function. Sponsored by: Dell EMC Isilon MFC after: 4 weeks Reviewed by: donner, kp Differential Revision: https://reviews.freebsd.org/D30630 (cherry picked from commit 2290dfb40fce0ab46d91244282014173c7316e42) --- sys/netinet6/ip6_output.c | 10 ++++++++++ sys/netinet6/raw_ip6.c | 8 ++++++-- sys/netinet6/udp6_usrreq.c | 9 ++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 877d9db508c7..3c8811ca1af9 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -2488,6 +2488,7 @@ ip6_pcbopts(struct ip6_pktopts **pktopt, struct mbuf *m, struct ip6_pktopts *opt = *pktopt; int error = 0; struct thread *td = sopt->sopt_td; + struct epoch_tracker et; /* turn off any old options. */ if (opt) { @@ -2515,12 +2516,15 @@ ip6_pcbopts(struct ip6_pktopts **pktopt, struct mbuf *m, } /* set options specified by user. */ + NET_EPOCH_ENTER(et); if ((error = ip6_setpktopts(m, opt, NULL, (td != NULL) ? td->td_ucred : NULL, so->so_proto->pr_protocol)) != 0) { ip6_clearpktopts(opt, -1); /* XXX: discard all options */ free(opt, M_IP6OPT); + NET_EPOCH_EXIT(et); return (error); } + NET_EPOCH_EXIT(et); *pktopt = opt; return (0); } @@ -2816,6 +2820,12 @@ ip6_setpktopts(struct mbuf *control, struct ip6_pktopts *opt, if (control == NULL || opt == NULL) return (EINVAL); + /* + * ip6_setpktopt can call ifnet_by_index(), so it's imperative that we are + * in the net epoch here. + */ + NET_EPOCH_ASSERT(); + ip6_initpktopts(opt); if (stickyopt) { int error; diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 3e3df65a0e12..aaba91c6d5e7 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -419,9 +419,13 @@ rip6_output(struct mbuf *m, struct socket *so, ...) INP_WLOCK(inp); if (control != NULL) { - if ((error = ip6_setpktopts(control, &opt, + NET_EPOCH_ENTER(et); + error = ip6_setpktopts(control, &opt, inp->in6p_outputopts, so->so_cred, - so->so_proto->pr_protocol)) != 0) { + so->so_proto->pr_protocol); + NET_EPOCH_EXIT(et); + + if (error != 0) { goto bad; } optp = &opt; diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 816e3bdd2850..6ee2abc4ea1b 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -810,21 +810,16 @@ udp6_output(struct socket *so, int flags_arg, struct mbuf *m, return (EINVAL); } + NET_EPOCH_ENTER(et); if (control) { if ((error = ip6_setpktopts(control, &opt, inp->in6p_outputopts, td->td_ucred, nxt)) != 0) { - INP_UNLOCK(inp); - ip6_clearpktopts(&opt, -1); - if (control) - m_freem(control); - m_freem(m); - return (error); + goto release; } optp = &opt; } else optp = inp->in6p_outputopts; - NET_EPOCH_ENTER(et); if (sin6) { /* * Since we saw no essential reason for calling in_pcbconnect,