From: Florian Westphal <fw@strlen.de>
To: Austin Hendrix <namniart@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: Duplicate invocation of NF_INET_POST_ROUTING rule for outbound multicast?
Date: Thu, 31 Oct 2024 22:52:43 +0100 [thread overview]
Message-ID: <20241031215243.GA4460@breakpoint.cc> (raw)
In-Reply-To: <CAL5mK8wsgqQCVt0jG7YjJz4E6YoPPs3tq7rrhhbsr=BDeJMVMg@mail.gmail.com>
Austin Hendrix <namniart@gmail.com> wrote:
> I've been staring at the linux source code for a while, and I think
> this part of ip_mc_output explains it.
>
> if (sk_mc_loop(sk)
> #ifdef CONFIG_IP_MROUTE
> /* Small optimization: do not loopback not local frames,
> which returned after forwarding; they will be dropped
> by ip_mr_input in any case.
> Note, that local frames are looped back to be delivered
> to local recipients.
>
> This check is duplicated in ip_mr_input at the moment.
> */
> &&
> ((rt->rt_flags & RTCF_LOCAL) ||
> !(IPCB(skb)->flags & IPSKB_FORWARDED))
> #endif
> ) {
> struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
> if (newskb)
> NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING,
> net, sk, newskb, NULL, newskb->dev,
> ip_mc_finish_output);
> }
>
> It looks like ip_mc_output duplicates outgoing multicast, sends the
> copy through POSTROUTING first (remember how the first copy didn't
> have UID and GID?), and then loops that copy back for local multicast
> listeners.
>
> I haven't followed all of the details yet, but it looks like the copy
> that is looped back lacks the sk_buff attributes which identify the
> UID, GID and cgroup of the sender.
Yes, skb_clone'd skbs are not owned by any socket.
> Is my understanding of this correct? Is the netdev team willing to
> discuss possible solutions to this, or is this behavior "by design?"
Its for historic reasons, this is very old and predates cgroups.
You could try this (untested) patch, ipv6 would need similar treatment.
We'd probably also want to extend this to RTCF_BROADCAST, i.e. add
skb_clone_sk() or similar helper and then use that for these clones.
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -396,10 +396,16 @@ int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb)
#endif
) {
struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
- if (newskb)
+ if (newskb) {
+ struct sock *skb_sk = skb->sk;
+
+ if (skb_sk)
+ skb_set_owner_edemux(newskb, skb_sk);
+
NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING,
net, sk, newskb, NULL, newskb->dev,
ip_mc_finish_output);
+ }
}
/* Multicasts with ttl 0 must not go beyond the host */
next prev parent reply other threads:[~2024-10-31 21:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-31 7:23 Duplicate invocation of NF_INET_POST_ROUTING rule for outbound multicast? Austin Hendrix
2024-10-31 21:52 ` Florian Westphal [this message]
2024-11-01 1:59 ` namniart
2024-11-02 16:12 ` Florian Westphal
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=20241031215243.GA4460@breakpoint.cc \
--to=fw@strlen.de \
--cc=namniart@gmail.com \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).