From: Zihan Xi <zihanx@nebusec.ai>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
edumazet@kernel.org, pabeni@redhat.com, horms@kernel.org,
vega@nebusec.ai, zihanx@nebusec.ai
Subject: [PATCH net 0/1] ipv6: mcast: fix default-interface source filter selection
Date: Thu, 12 Nov 2026 15:19:03 +0000 [thread overview]
Message-ID: <cover.1794492711.git.zihanx@nebusec.ai> (raw)
Hi Linux kernel maintainers,
We found an issue in net/ipv6/mcast.c. The bug is reachable by an
unprivileged process using the IPv6 multicast source-filter socket API.
The relevant details are provided below.
---- details below ----
An LLM was used to help create this patch.
This bug is tracked at: https://bugtracker.nebusec.ai/f/Z8p (Z8p)
Bug details:
When gsr_interface is zero, ip6_mc_source() resolves the multicast route
to a device but previously searched socket memberships with a wildcard
interface index. With the same group joined on multiple interfaces, the
socket filter could be updated on one interface while the aggregate
filter was updated on the route-selected interface. The patch uses the
resolved interface index for both membership lookup and last-source
membership removal.
Reproducer:
Build and run as an unprivileged user in a Linux guest where ff0e::1234
routes through eth0 and lo is available:
gcc -O2 -Wall -Wextra -o mini_poc mini_poc.c
ip -6 route get ff0e::1234
./mini_poc
The test used a 2 vCPU, 2 GiB x86 QEMU/KVM environment. On the baseline,
the source appeared in socket[lo] while socket[eth0] stayed empty. With
the patch, it appeared in socket[eth0] while socket[lo] stayed empty.
No kernel crash was observed.
------BEGIN PoC------
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#ifndef GROUP_FILTER_SIZE
#define GROUP_FILTER_SIZE(n) \
(sizeof(struct group_filter) - sizeof(struct sockaddr_storage) + \
(n) * sizeof(struct sockaddr_storage))
#endif
static void set_group(struct sockaddr_storage *ss, const char *addr)
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ss;
sin6->sin6_family = AF_INET6;
if (inet_pton(AF_INET6, addr, &sin6->sin6_addr) != 1) {
perror("inet_pton");
exit(EXIT_FAILURE);
}
}
static void show_filter(int fd, unsigned int ifindex, const char *ifname)
{
struct group_filter *gf = calloc(1, GROUP_FILTER_SIZE(1));
struct sockaddr_in6 *sin6;
socklen_t len = GROUP_FILTER_SIZE(1);
if (!gf) {
perror("calloc");
exit(EXIT_FAILURE);
}
gf->gf_interface = ifindex;
gf->gf_numsrc = 1;
set_group(&gf->gf_group, "ff0e::1234");
if (getsockopt(fd, SOL_IPV6, MCAST_MSFILTER, gf, &len)) {
perror("getsockopt(MCAST_MSFILTER)");
exit(EXIT_FAILURE);
}
printf("%s: mode=%s sources=%u", ifname,
gf->gf_fmode == MCAST_INCLUDE ? "INCLUDE" : "EXCLUDE",
gf->gf_numsrc);
if (gf->gf_numsrc) {
char source[INET6_ADDRSTRLEN];
sin6 = (struct sockaddr_in6 *)&gf->gf_slist[0];
inet_ntop(AF_INET6, &sin6->sin6_addr, source, sizeof(source));
printf(" first-source=%s", source);
}
putchar('\n');
free(gf);
}
int main(void)
{
const char *group = "ff0e::1234";
const char *source = "2001:db8::1";
unsigned int route_if = if_nametoindex("eth0");
unsigned int shadow_if = if_nametoindex("lo");
struct ipv6_mreq mreq = { 0 };
struct group_source_req gsr = { 0 };
int fd;
if (!route_if || !shadow_if) {
fprintf(stderr, "eth0 or lo is unavailable\n");
return EXIT_FAILURE;
}
fd = socket(AF_INET6, SOCK_DGRAM, 0);
if (fd < 0) {
perror("socket");
return EXIT_FAILURE;
}
if (inet_pton(AF_INET6, group, &mreq.ipv6mr_multiaddr) != 1) {
perror("inet_pton(group)");
return EXIT_FAILURE;
}
mreq.ipv6mr_interface = route_if;
if (setsockopt(fd, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq))) {
perror("IPV6_ADD_MEMBERSHIP(eth0)");
return EXIT_FAILURE;
}
mreq.ipv6mr_interface = shadow_if;
if (setsockopt(fd, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq))) {
perror("IPV6_ADD_MEMBERSHIP(lo)");
return EXIT_FAILURE;
}
gsr.gsr_interface = 0;
set_group(&gsr.gsr_group, group);
set_group(&gsr.gsr_source, source);
show_filter(fd, route_if, "eth0 before");
show_filter(fd, shadow_if, "lo before");
if (setsockopt(fd, SOL_IPV6, MCAST_BLOCK_SOURCE, &gsr, sizeof(gsr))) {
perror("setsockopt(MCAST_BLOCK_SOURCE)");
return EXIT_FAILURE;
}
show_filter(fd, route_if, "eth0 after");
show_filter(fd, shadow_if, "lo after");
close(fd);
return 0;
}
------END PoC--------
Best regards,
Zihan Xi
Zihan Xi (1):
ipv6: mcast: use resolved interface for source filters
net/ipv6/mcast.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--
2.43.0
next reply other threads:[~2026-11-12 15:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 15:19 Zihan Xi [this message]
2026-11-12 15:19 ` [PATCH net 1/1] ipv6: mcast: use resolved interface for source filters Zihan Xi
2026-11-19 8:39 ` Paolo Abeni
2026-11-19 8:43 ` Paolo Abeni
2026-11-19 10:42 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1794492711.git.zihanx@nebusec.ai \
--to=zihanx@nebusec.ai \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vega@nebusec.ai \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox