From nobody Fri May 10 16:30:56 2024 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 4VbZBT01jJz5K1tt; Fri, 10 May 2024 16:30:57 +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 4VbZBS4sBhz43jv; Fri, 10 May 2024 16:30:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715358656; 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=bKaIrFnxqEE9SFOrWf0YRMq6JHTALeK0Fms3z2DgBgc=; b=XIHH8tmAiAoGtFt+54WH5lLexfCWrEqzjkdXlyha9dvCuwBemFJxRgssobYXo45vRJJO+R +CdFN1KlVknrM7co1e2XWrQ4YMZMSnvSAhMTBokzcwyEabBog9B6IfM0s/K8L30pobQHAY L8N81clue4WhjAPqKt4WayKc+0lUZS5PlHaJzUNXOfbpwqxR/fygDX4VZbiy4JdutPVCC8 KREX6050myx0YXtEcEt5UiUenS4RDoWhM7/0NzTGgYTIYQe6b6IhTizyVyqqSEiUBFjUYt gYwib14V9e5zwjzFnxf+yndN8jHfoxgrkd00QqDIQ2HcTHwScXvXbMiCLajbxA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715358656; a=rsa-sha256; cv=none; b=lS9KklzVa/GH6b/SGoMEgQyGzhaaY1EK4cGHVMQsyDNYhEmqU3ypv+0z04EmWGEuYxyiX/ guls0orXaKbKHdwjC6lH8eM+p1gm36bcVR48p0oyFlNe3pilA3pzamRbOnZ/tkVwNzyu7e raw93Bfmmkkaw+hay0hQQI3MRnYJacq0F1TJC+ObyKttpA/2e9N85jcxcMtEeHaCQwRNxw P4xd1idmUwoJjSAxQA4B0UuXaPWGCxpGrCzhyzbE8AMLkNJhO7mTA52V8lwxoq/lNZsXpA m0xysW0/O6EWlAdZtrg24Xu0QC/ft/tlGy6CPSsGs9Mh5Ci6a8CQHNXrC8rgqw== 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=1715358656; 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=bKaIrFnxqEE9SFOrWf0YRMq6JHTALeK0Fms3z2DgBgc=; b=hjQjxG5v3VUFeN7iZK4pu3/LNNm2w6UCgQqQvxQDiwru+jLHotH/p5+LfQ3r+zR+OrFNem 0neDCowuLeRUMlRk7rR2T1twaDPAtxuBInbzRc1JRGvdlJ/YYQPcL3YEeOIl3N6CO2nUnp xWP8ZJdhgJ3k4FqFAz4SY8JCZ8gmpRPDINcs+Jm6pl2YLNuIxjaWkHcdqYhygu/YP/Kog6 lVArOy/Rska9i9BsWlhxgVAPdQW8FnPCvux9FZKV3ZSup7KBqeuVb7bPdnBUm7EdPUEAGE nsnCzo5hPsI2xtktQodQzQw3xdCKpeIMrx6MxekzEmiMElIf0sZtQU6aR98epA== 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 4VbZBS4T11zkym; Fri, 10 May 2024 16:30:56 +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 44AGUuOu001850; Fri, 10 May 2024 16:30:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44AGUuO6001846; Fri, 10 May 2024 16:30:56 GMT (envelope-from git) Date: Fri, 10 May 2024 16:30:56 GMT Message-Id: <202405101630.44AGUuO6001846@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: ff99bfe3ef73 - stable/13 - inet6: protect address manipulation with a lock 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ff99bfe3ef739a026e0cf554295774c8bf02d326 Auto-Submitted: auto-generated The branch stable/13 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=ff99bfe3ef739a026e0cf554295774c8bf02d326 commit ff99bfe3ef739a026e0cf554295774c8bf02d326 Author: Mateusz Guzik AuthorDate: 2023-03-29 12:46:41 +0000 Commit: Zhenlei Huang CommitDate: 2024-05-10 16:27:07 +0000 inet6: protect address manipulation with a lock This is a total hack/bare minimum which follows inet4. Otherwise 2 threads removing the same address can easily crash. Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D39317 (cherry picked from commit f5a365e51feea75d1e5ebc86c53808d8cae7b6d7) --- sys/netinet6/in6.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 946a49030920..acf04e1e56bb 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -163,6 +163,9 @@ static int in6_broadcast_ifa(struct ifnet *, struct in6_aliasreq *, #define ifa2ia6(ifa) ((struct in6_ifaddr *)(ifa)) #define ia62ifa(ia6) (&((ia6)->ia_ifa)) +static struct sx in6_control_sx; +SX_SYSINIT(in6_control_sx, &in6_control_sx, "in6_control"); + void in6_newaddrmsg(struct in6_ifaddr *ia, int cmd) { @@ -251,6 +254,7 @@ in6_control(struct socket *so, u_long cmd, caddr_t data, int carp_attached = 0; int error; u_long ocmd = cmd; + bool control_locked = false; /* * Compat to make pre-10.x ifconfig(8) operable. @@ -406,6 +410,8 @@ in6_control(struct socket *so, u_long cmd, caddr_t data, if (td != NULL && (error = prison_check_ip6(td->td_ucred, &sa6->sin6_addr)) != 0) return (error); + sx_xlock(&in6_control_sx); + control_locked = true; ia = in6ifa_ifpwithaddr(ifp, &sa6->sin6_addr); } else ia = NULL; @@ -710,6 +716,9 @@ aifaddr_out: error = 0; out: + if (control_locked) + sx_xunlock(&in6_control_sx); + if (ia != NULL) ifa_free(&ia->ia_ifa); return (error);