From nobody Fri Mar 31 18:12:26 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 4Pp7g06c2zz434r0; Fri, 31 Mar 2023 18:12:28 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from glebi.us (glebi.us [162.251.186.162]) by mx1.freebsd.org (Postfix) with ESMTP id 4Pp7g016YTz4b5K; Fri, 31 Mar 2023 18:12:28 +0000 (UTC) (envelope-from glebius@freebsd.org) Authentication-Results: mx1.freebsd.org; dkim=none; spf=softfail (mx1.freebsd.org: 162.251.186.162 is neither permitted nor denied by domain of glebius@freebsd.org) smtp.mailfrom=glebius@freebsd.org; dmarc=none Received: by glebi.us (Postfix, from userid 1000) id 8091D6133E; Fri, 31 Mar 2023 11:12:26 -0700 (PDT) Date: Fri, 31 Mar 2023 11:12:26 -0700 From: Gleb Smirnoff To: Mateusz Guzik Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: f5a365e51fee - main - inet6: protect address manipulation with a lock Message-ID: References: <202303300847.32U8l1UM004219@gitrepo.freebsd.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <202303300847.32U8l1UM004219@gitrepo.freebsd.org> X-Spamd-Result: default: False [0.50 / 15.00]; VIOLATED_DIRECT_SPF(3.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org,dev-commits-src-main@freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:27348, ipnet:162.251.186.0/24, country:US]; ARC_NA(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; DMARC_NA(0.00)[freebsd.org]; FROM_HAS_DN(0.00)[]; FREEFALL_USER(0.00)[glebius]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_SOME(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Rspamd-Queue-Id: 4Pp7g016YTz4b5K X-Spamd-Bar: / X-ThisMailContainsUnwantedMimeParts: N Mateusz, On Thu, Mar 30, 2023 at 08:47:01AM +0000, Mateusz Guzik wrote: M> diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c M> index 27dc3550177c..3d967e9a40c7 100644 M> --- a/sys/netinet6/in6.c M> +++ b/sys/netinet6/in6.c M> @@ -168,6 +168,9 @@ static void in6_leave_proxy_ndp_mc(struct ifnet *, const struct in6_addr *); M> #define ifa2ia6(ifa) ((struct in6_ifaddr *)(ifa)) M> #define ia62ifa(ia6) (&((ia6)->ia_ifa)) M> M> +static struct sx in6_control_sx; M> +SX_SYSINIT(in6_control_sx, &in6_control_sx, "in6_control"); M> + M> void M> in6_newaddrmsg(struct in6_ifaddr *ia, int cmd) M> { M> @@ -254,6 +257,7 @@ in6_control(struct socket *so, u_long cmd, void *data, M> struct in6_aliasreq *ifra = (struct in6_aliasreq *)data; M> struct sockaddr_in6 *sa6; M> int error; M> + bool control_locked = false; M> M> /* M> * Compat to make pre-10.x ifconfig(8) operable. M> @@ -411,6 +415,8 @@ in6_control(struct socket *so, u_long cmd, void *data, M> if (td != NULL && (error = prison_check_ip6(td->td_ucred, M> &sa6->sin6_addr)) != 0) M> return (error); M> + sx_xlock(&in6_control_sx); M> + control_locked = true; M> ia = in6ifa_ifpwithaddr(ifp, &sa6->sin6_addr); M> } else M> ia = NULL; M> @@ -582,6 +588,9 @@ in6_control(struct socket *so, u_long cmd, void *data, M> M> error = 0; M> out: M> + if (control_locked) M> + sx_xunlock(&in6_control_sx); M> + M> if (ia != NULL) M> ifa_free(&ia->ia_ifa); M> return (error); Why do you prefer a bool over using sx_xlocked()? -- Gleb Smirnoff