From: Florian Westphal <fw@strlen.de>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Florian Westphal <fw@strlen.de>, Netdev <netdev@vger.kernel.org>,
David Miller <davem@davemloft.net>
Subject: Re: [PATCH v2 net 1/5] icmp: introduce helper for NAT'd source address in network device context
Date: Mon, 10 Feb 2020 23:26:14 +0100 [thread overview]
Message-ID: <20200210222614.GJ2991@breakpoint.cc> (raw)
In-Reply-To: <CAHmME9qQ=E1L0XVe=i714AMdpMJQs3zPz=XVKW9Ck6TvGu_Hew@mail.gmail.com>
Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> Hi Florian,
>
> On Mon, Feb 10, 2020 at 10:33 PM Florian Westphal <fw@strlen.de> wrote:
> >
> > Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> > > On Mon, Feb 10, 2020 at 3:15 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> > > > + ip_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.ip;
> > > > + }
> > > > + icmp_send(skb_in, type, code, info);
> > >
> > > According to the comments in icmp_send, access to
> > > ip_hdr(skb_in)->saddr requires first checking for `if
> > > (skb_network_header(skb_in) < skb_in->head ||
> > > (skb_network_header(skb_in) + sizeof(struct iphdr)) >
> > > skb_tail_pointer(skb_in))` first to be safe.
> >
> > You will probably also need skb_ensure_writable() to handle cloned skbs.
> >
> > I also suggest to check "ct->status & IPS_NAT_MASK", nat is only done if
> > those bits are set.
>
> Thanks for the suggestions. I've made these changes and they're queued
> up for a v3, currently staged in wireguard-linux.git's stable branch:
> https://git.zx2c4.com/wireguard-linux/log/?h=stable
I think this is a bit too conservative, f.e. i don't see how
ndo-called skbs could be shared (tx path needs to be able to change skb
list pointers)?
If its needed it looks ok.
Otherwise, I would suggest something like this:
void icmp_ndo_send(struct sk_buff *skb_in, int type, int code, __be32 info)
{
enum ip_conntrack_info ctinfo;
struct nf_conn *ct;
__be32 orig_ip;
ct = nf_ct_get(skb_in, &ctinfo);
if (!ct || ((ct->status & IPS_NAT_MASK) == 0) {
icmp_send(skb_in, type, code, info);
return;
}
/* avoid reallocations */
if (skb_network_header(skb_in) < skb_in->head ||
(skb_network_header(skb_in) + sizeof(struct iphdr)) >
skb_tail_pointer(skb_in))
return;
/* handle clones. NB: if reallocations are to be avoided, then
* if (skb_cloned(skb_in) &&
* !skb_clone_writable(skb_in, skb_network_offset(skb_in) + iphlen))
*
* ... should be placed here instead:
*/
if (unlikely(skb_ensure_writable(skb_in,
skb_network_offset(skb_in) + sizeof(struct iphdr))))
return;
orig_ip = ip_hdr(skb_in)->saddr;
ip_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.ip;
icmp_send(skb_in, type, code, info);
ip_hdr(skb_in)->saddr = orig_ip;
}
next prev parent reply other threads:[~2020-02-10 22:26 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-10 14:14 [PATCH v2 net 0/5] icmp: account for NAT when sending icmps from ndo layer Jason A. Donenfeld
2020-02-10 14:14 ` [PATCH v2 net 1/5] icmp: introduce helper for NAT'd source address in network device context Jason A. Donenfeld
2020-02-10 19:48 ` Jason A. Donenfeld
2020-02-10 21:32 ` Florian Westphal
2020-02-10 21:59 ` Jason A. Donenfeld
2020-02-10 22:26 ` Florian Westphal [this message]
2020-02-11 9:59 ` Jason A. Donenfeld
2020-02-11 12:25 ` Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 0/9] icmp: account for NAT when sending icmps from ndo layer Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 1/9] icmp: introduce helper for nat'd source address in network device context Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 2/9] gtp: use icmp_ndo_send helper Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 3/9] sunvnet: " Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 4/9] xfrm: interface: " Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 5/9] wireguard: device: use icmp_ndo_send helper and remove skb_share_check Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 6/9] firewire: remove skb_share_check from xmit path Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 7/9] ipvlan: " Jason A. Donenfeld
2020-02-11 17:39 ` Eric Dumazet
2020-02-11 17:44 ` Jason A. Donenfeld
2020-02-11 18:50 ` Eric Dumazet
2020-02-11 18:54 ` Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 8/9] fm10k: " Jason A. Donenfeld
2020-02-11 15:00 ` [PATCH v3 net 9/9] benet: " Jason A. Donenfeld
2020-02-10 14:14 ` [PATCH v2 net 2/5] gtp: use icmp_ndo_send helper Jason A. Donenfeld
2020-02-10 14:14 ` [PATCH v2 net 3/5] sunvnet: " Jason A. Donenfeld
2020-02-10 14:14 ` [PATCH v2 net 4/5] wireguard: " Jason A. Donenfeld
2020-02-10 14:14 ` [PATCH v2 net 5/5] xfrm: interface: " Jason A. Donenfeld
2020-02-10 19:30 ` [PATCH v2 net 6/5] wireguard: selftests: ensure that icmp src address is correct with NAT Jason A. Donenfeld
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=20200210222614.GJ2991@breakpoint.cc \
--to=fw@strlen.de \
--cc=Jason@zx2c4.com \
--cc=davem@davemloft.net \
--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).