From nobody Fri Mar 31 18:20:58 2023 X-Original-To: dev-commits-src-main@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 4Pp7rs0lGcz435KG; Fri, 31 Mar 2023 18:21:01 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pp7rr5rbsz4kt8; Fri, 31 Mar 2023 18:21:00 +0000 (UTC) (envelope-from mjguzik@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-17fcc07d6c4so10017006fac.8; Fri, 31 Mar 2023 11:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680286859; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=CXLcKmoTdO0bXzSSxbL2ng1QfUvCQYKnBCa9f2mPwHk=; b=FthCxPlN+sLoacOSDqEowsIhtsEYfaytseFeTdGX02LnL/rkarpUFj/USoQrE1a25L cpDMKqi3KUnZ1wN2MwH7J3k+Q99y+i9fz7gGTvr8RT/76qboJk2aCAW3CWcIyat4aZHw sU3EeRHRd8n+gavJxDib6h+ZmulUm9n8hLE91qN66qBZZwoLnF5/Aj40nGbzVv3y21jw mgxnGpn4d96qonwhamJJDA5aw9WRpegg5NQrFg+CZYdKzyHRn8V4dkS5IOfIXahP1NzT h2IvtLDE4wD+i5Iq8bXH1ugy2wEmAYfdZ+CtUPAe6sIcjNn7BAieu4Hab3BANfu5AyHF anJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680286859; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CXLcKmoTdO0bXzSSxbL2ng1QfUvCQYKnBCa9f2mPwHk=; b=Bk64iw9oaTLoK4T7eEfBlT8AV0uLs9KW3GJgAk8pLRdxOqasUhB3f1uhfIG0NxHs1G 7ThqmyC0EG2JsDn+VPJcmyZGmePnhNtZKg8EU1zOalPzg/7GacpkXdgcEPOYlHnRcV+V XD+pmaCpsjOOl/mD/6hZknUZNle1fSGv/lBLcnLDMGPug0jPNSGs8axo/0JcwzgsP39x zf1psk5Of1DMR2CKgn0DJTAKitpPwfeyuS2MZMcyu1uyQ4dm98rJI+H4rBQ2rvWxrmVW CwyZqB5ToA5BFnoeoXpgP0eS1usf299OAEybAMwIBeOhGiB81o9ct2r7rwBI6+8TYJJ0 4YvQ== X-Gm-Message-State: AAQBX9d8qM4z+Lh1WtszWrsIo91JnyIPhlFbNB/rRZA67ISvEp2L0wEl wFTtx6l0v3Ncj40+JwXJqjEip8krqo5wUbffANWdkuWW X-Google-Smtp-Source: AKy350YYvq/xljiouuYG8ljwN45M8iF3I3T8aP2Z8eM1s7hrpeq+vhVElQpWN2AlRDIrbvSmM8dGDGLWbnqubOjFLEQ= X-Received: by 2002:a05:6870:55:b0:177:c436:feb8 with SMTP id 21-20020a056870005500b00177c436feb8mr10795011oaz.4.1680286859148; Fri, 31 Mar 2023 11:20:59 -0700 (PDT) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Received: by 2002:ac9:7598:0:b0:49c:b071:b1e3 with HTTP; Fri, 31 Mar 2023 11:20:58 -0700 (PDT) In-Reply-To: References: <202303300847.32U8l1UM004219@gitrepo.freebsd.org> From: Mateusz Guzik Date: Fri, 31 Mar 2023 20:20:58 +0200 Message-ID: Subject: Re: git: f5a365e51fee - main - inet6: protect address manipulation with a lock To: Gleb Smirnoff Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4Pp7rr5rbsz4kt8 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2001:4860:4864::/48, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 3/31/23, Gleb Smirnoff wrote: > 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()? > It does not read from the lock but now that you mention it, perhaps i should assert it is not taken in the else clause -- Mateusz Guzik