Article View: linux.kernel.netdev
Article #20022Re: [PATCH net v2 1/1] ipv6: mcast: pass resolved interface to source update
From: Jakub Kicinski
Date: Fri, 20 Nov 2026 23:56
Date: Fri, 20 Nov 2026 23:56
141 lines
13109 bytes
13109 bytes
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
ipv6: mcast: pass resolved interface to source update
This patch changes __ipv6_sock_mc_join() to resolve the device before the
duplicate membership check and to return the resolved ifindex to
do_ipv6_mcast_group_source(). ip6_mc_source() now matches memberships only
on the resolved interface and passes that ifindex to ipv6_sock_mc_drop().
The intent is for the membership lookup and the source update to share one
route selection, as in the IPv4 group-source path.
> When gsr_interface is zero, the SSM join helper resolves the default
> interface before checking for an existing membership. ip6_mc_source()
> then resolves the route again. A route change between these lookups can
> leave a membership on the first device while the source update fails on
> the second.
[Severity: Medium]
Is this an accurate description of the pre-patch behaviour? It looks like
no route change is needed, and the source update doesn't fail.
Before this patch, ip6_mc_source() took idev from the route when
gsr_interface was 0. Its membership loop, however, skipped the interface
check:
for_each_pmc_socklock(inet6, sk, pmc) {
if (pgsr->gsr_interface && pmc->ifindex != pgsr->gsr_interface)
continue;
The old __ipv6_sock_mc_join() also matched any interface for ifindex 0 and
returned -EADDRINUSE. do_ipv6_mcast_group_source() treats that as success.
Take a socket with a membership on device A, while the route for the group
points at B. A MCAST_BLOCK_SOURCE, MCAST_JOIN_SOURCE_GROUP or
MCAST_UNBLOCK_SOURCE call with gsr_interface 0 then updates the
sflist/sfmode of the A membership.
The ip6_mc_add_src()/ip6_mc_del_src() calls run on B's ifmcaddr6 instead.
This covers both the mode-switch pair and the per-source calls. The
syscall still returns 0.
If another socket has joined the group on B, B's per-source
sf_count[MCAST_EXCLUDE] goes up. ipv6_chk_mcast_addr() then drops that
source for every listener on B:
rv = READ_ONCE(psf->sf_count[MCAST_INCLUDE]) ||
READ_ONCE(psf->sf_count[MCAST_EXCLUDE]) !=
READ_ONCE(mc->mca_sfcount[MCAST_EXCLUDE]);
The mode-switch path can also lower B's mca_sfcount[MCAST_EXCLUDE] and flip
B's filter mode. Nothing undoes this later, because ip6_mc_leave_src() runs
against A, not B.
The ip6_mc_source() change in this patch does fix this.
Could the commit message say that an unprivileged socket can reliably
change another device's source filter state, affecting other sockets?
Right now it reads like a timing-dependent failure. The difference matters
for stable and security triage.
> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
> index ecef55f261890..3f2a431ea0c81 100644
> --- a/net/ipv6/mcast.c
> +++ b/net/ipv6/mcast.c
[ ... ]
> @@ -207,25 +208,30 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex,
> if (!ipv6_addr_is_multicast(addr))
> return -EINVAL;
>
> + dev = ip6_mc_find_dev(net, addr, ifindex);
> + if (!dev)
> + return -ENODEV;
> + ifindex = dev->ifindex;
> + if (resolved_ifindex)
> + *resolved_ifindex = ifindex;
> +
> for_each_pmc_socklock(np, sk, mc_lst) {
> - if ((ifindex == 0 || mc_lst->ifindex == ifindex) &&
> - ipv6_addr_equal(&mc_lst->addr, addr))
> + if (mc_lst->ifindex == ifindex &&
> + ipv6_addr_equal(&mc_lst->addr, addr)) {
> + dev_put(dev);
> return -EADDRINUSE;
> + }
> }
[Severity: Medium]
With this change, join treats ifindex 0 as the route-selected device.
ipv6_sock_mc_drop() is unchanged and still treats 0 as a wildcard:
net/ipv6/mcast.c:ipv6_sock_mc_drop() {
...
if ((ifindex == 0 || mc_lst->ifindex == ifindex) &&
ipv6_addr_equal(&mc_lst->addr, addr)) {
...
}
Is this asymmetry intended? Joins with ifindex 0 can now create several
memberships for the same group. A drop with ifindex 0 removes whichever
matching entry comes first in the list (the most recent join), on any
interface.
For example, using IPV6_ADD_MEMBERSHIP/IPV6_DROP_MEMBERSHIP or
MCAST_JOIN_GROUP/MCAST_LEAVE_GROUP through ipv6_mcast_join_leave():
join(G, 0) -> membership on A
route for G moves to B
join(G, 0) -> membership on B (previously -EADDRINUSE)
route for G moves back to A
drop(G, 0) -> removes the B membership, not A
Some of this ambiguity already existed when an explicit-ifindex join was
mixed with an ifindex 0 join. Now ifindex 0 joins alone can produce it.
An application written for the old -EADDRINUSE behaviour sends one leave.
It then keeps receiving G on the other interface until the socket is
closed.
The IPv4 path mentioned in the commit message resolves ifindex 0 on leave
too. ip_mc_leave_group() calls ip_mc_find_dev(), which fills in
imr->imr_ifindex, and then matches that exact interface:
ifindex = imr->imr_ifindex;
...
if (ifindex) {
if (iml->multi.imr_ifindex != ifindex)
continue;
The leavegroup path in ip6_mc_msfilter() also still passes the raw
gf_interface, which can be 0. ip6_mc_source() now passes the resolved
ifindex instead:
err = ipv6_sock_mc_drop(sk, gsf->gf_interface, group);
Should ipv6_sock_mc_drop() resolve ifindex 0 the same way? Then join,
source update and drop would all use one interface, as the commit message
describes.
Technical Details
Message-ID:
<20261120235637.868362-1-kuba@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368211-linux-kernel-netdev=dewy.ruReferences:
<43dfcc2e60579f68e436ade82bbd7ab7c727e250.1794738094.git.zihanx@nebusec.ai>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368211-linux-kernel-netdev=dewy.ru From: kuba@kernel.org (Jakub Kicinski) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2 1/1] ipv6: mcast: pass resolved interface to source update Date: Fri, 20 Nov 2026 15:56:37 -0800 Organization: Usenet Network Message-ID: <20261120235637.868362-1-kuba@kernel.org> References: <43dfcc2e60579f68e436ade82bbd7ab7c727e250.1794738094.git.zihanx@nebusec.ai> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3295468"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:xz13WE6eZC+/BVqRtdn8dGI1KsY= sha256:+KDHBRRc1n9fhpa/PD5StzCWhEcPKY/zoLe9ZvQVQT0= sha1:cS4b2k5tmGIoiaV7MvwC7ijGwso= sha256:PA1+dQqAWnW4kajbjNHnOLrh7F1OhTsiO6Va2JN9Sb4= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 58796115ADB; Sat, 21 Nov 2026 02:57:00 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hsPYn_xiHaB9; Sat, 21 Nov 2026 02:56:52 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-368211-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 94243115801; Sat, 21 Nov 2026 02:56:44 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 86F502D195; Fri, 20 Nov 2026 23:56:43 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795219002; b=HkUbMHWvONQD9Ktm83eSwQR1QSpd8jZn6+bLpMAXtCdvVjbO3EZ727juAt4h5JFCsAwl AxXKK1BSjrbpxy8zTS80gTK7n5Mr7P9rPsT/cq0AisZI7IRhARbbgvc4xWO97IKd6JD0J LtZaEzZiW7bheKWkHW+8OsaQuNpbb3G3jvPm2uwQ/fzA+lOaM/Wsr8qwXVDOHzm5EEuW8 O5Lio6yCmGVmZaCzYaPu34vG6RSCE8SkidKcYR+gKfGemuflcEu4wRPef+LYkobO7pVhg NxpEV8AjCqimj2cnpMD5cSzh3EPi+KlR5tme9ccX6SB1Mxjk/ZsCn598avaqNqqxzAA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795219002; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding; bh=cURjqbFZ9ajyWde9z4VPmL8uchIRR0mkeMbwrPQE50E=; b=o3UL2RRQa2SdwKv3TGDM9JmpqXxMW2ZW/f1iSu9lJby91odWKxql/FI5MRfRUxHu/h0g 1SyxSCI62OzqPMsAF3/aCXeWGrXsBBucisdrOddZjZaf4i5weOJwugnchU0BjY5WPuS+7 pAW0czdrDNoguoWy3lNVLBi1NSF4yL0xgF8I0sLVZuPro55XnXJYN/PnCE7creK0X0NFQ sjan6949rUmme/vJefbRfsimia0bgTLGmO7zmuTKROnnNkxVkKbAAK0Oj7CRPqxptv9fz bagfL3Deip1lMM5rd+TqoxNCvfpOXNkhBc/qtWCWlWtHeSqi49Osdu7tKUFAMbYPlZQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DokEm2vQ; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA61960A2601; Fri, 20 Nov 2026 23:56:42 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DokEm2vQ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795219002; b=krVYApjd2D0DVX/njrN+UGlZ9/bDCFIkOaBfTVVz7RDdz/ycuhRD33tOOsYFpT8n+pUm X41UskSYVqAoLTJBWdTwpwyWQo+26OzSSubcjsZtPd60ct7NlyezubbrhPTx1khUcAV6z KlnTcoN0nvY3H94aMPlUgcwtU8bKhGXAMC+j8osccDc8jwOFYDj4rNEKenmzeuhW0bimY Qg8juHQ1tbxA8vAarN/YVGuMwER+p89X/M8q7SiQLT8/uEXhlE9LIHn7bHZz2TdBonw7F XN3WH2RRXGWNjq/Qnvf/qcoNtsEpUstU39ckeTwJCCBGwPya9QMgeMYtiupyTApd4bA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795219002; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=cURjqbFZ9ajyWde9z4VPmL8uchIRR0mkeMbwrPQE50E=; b=dQDwKutF9gs17gTTseJemFxtOfhG91iQ8FQSTaHZaMHi8tsWLO9EbBsnFWVmfjYeitam +rUzHBEp2eDDrqixW6LGVt9G1i5wDcVGIKCabANWo9j32Z3Gh5R67Wk41CbQ0UUGHD4SA UiA9PiidC1abMysEszHZlgJbzh8a6p/bDCpyhO6yvCyN7BIG9mirKIX4ZKilxuz5okMrt MlaLQaZal/PMAyfYgtNFAUpfoJ/9KyUHDFTx8NM6ldiLEX0YyTuI8wMTNhwlKZCf9rMAT odMfPo1L7UqubJ0Kfxj/YaSkc6HH65Mgpd7anwYOi0BV0Qwu5c23FttxPYY0BduoOzw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DokEm2vQ; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02791606A6BC for <netdev@vger.kernel.org>; Fri, 20 Nov 2026 23:56:41 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA5091F000C4; Fri, 20 Nov 2026 23:56:40 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795219001; bh=cURjqbFZ9ajyWde9z4VPmL8uchIRR0mkeMbwrPQE50E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DokEm2vQ2ojWOaRyi+sFlbL8J3S+2KExtMDybRuky+5ojyGrEPFRAMI2XxA51kbby /tZ5B3lmZ3k8PkC2B4X+b/4CF3Ba4RwO/vUMR7MvnQHY7DcNX8roAiue/Z6QgH57X+ 6k0jr0hSVTQZtyXDeqfZi6jUYq0l3ala8wILX/XHPTRFpnk8oiKNmnKSXmgZt703Vn TtrjPdU1sBpYPhb5BsTNb9Spuq4S43S5fi/+OtjgohY1vuBQZEJfM87fxvbW4Imj0T G2CHkme5ljW/sqmCIGLmNmK488BLDbI9CpohBipuHDahFnFHgBtYor+GmM9KhNd1z0 7MhVDNI+cPykA== X-Cc: Jakub Kicinski <kuba@kernel.org>, netdev@vger.kernel.org, dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com, horms@kernel.org, vega@nebusec.ai X-Mailer: git-send-email 2.56.1 X-In-Reply-To: <43dfcc2e60579f68e436ade82bbd7ab7c727e250.1794738094.git.zihanx@nebusec.ai> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list