netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 net 0/5] icmp: account for NAT when sending icmps from ndo layer
@ 2020-02-10 14:14 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
                   ` (5 more replies)
  0 siblings, 6 replies; 27+ messages in thread
From: Jason A. Donenfeld @ 2020-02-10 14:14 UTC (permalink / raw)
  To: netdev, davem; +Cc: Jason A. Donenfeld, netfilter-devel

The ICMP routines use the source address for two reasons:

1. Rate-limiting ICMP transmissions based on source address, so
   that one source address cannot provoke a flood of replies. If
   the source address is wrong, the rate limiting will be
   incorrectly applied.

2. Choosing the interface and hence new source address of the
   generated ICMP packet. If the original packet source address
   is wrong, ICMP replies will be sent from the wrong source
   address, resulting in either a misdelivery, infoleak, or just
   general network admin confusion.

Most of the time, the icmp_send and icmpv6_send routines can just reach
down into the skb's IP header to determine the saddr. However, if
icmp_send or icmpv6_send is being called from a network device driver --
there are a few in the tree -- then it's possible that by the time
icmp_send or icmpv6_send looks at the packet, the packet's source
address has already been transformed by SNAT or MASQUERADE or some other
transformation that CONNTRACK knows about. In this case, the packet's
source address is most certainly the *wrong* source address to be used
for the purpose of ICMP replies.

Rather, the source address we want to use for ICMP replies is the
original one, from before the transformation occurred.

Fortunately, it's very easy to just ask CONNTRACK if it knows about this
packet, and if so, how to fix it up. The saddr is the only field in the
header we need to fix up, for the purposes of the subsequent processing
in the icmp_send and icmpv6_send functions, so we do the lookup very
early on, so that the rest of the ICMP machinery can progress as usual.

Changes v1->v2:
- icmpv6 takes subtly different types than icmpv4, like u32 instead of be32,
  u8 instead of int.
- Since we're technically writing to the skb, we need to make sure it's not
  a shared one [Dave, 2017].
- Restore the original skb data after icmp_send returns. All current users
  are freeing the packet right after, so it doesn't matter, but future users
  might not.
- Remove superfluous route lookup in sunvnet [Dave].
- Use NF_NAT instead of NF_CONNTRACK for condition [Florian].
- Include this cover letter [Dave].

Cc: netdev@vger.kernel.org
Cc: netfilter-devel@vger.kernel.org

Jason A. Donenfeld (5):
  icmp: introduce helper for NAT'd source address in network device
    context
  gtp: use icmp_ndo_send helper
  sunvnet: use icmp_ndo_send helper
  wireguard: use icmp_ndo_send helper
  xfrm: interface: use icmp_ndo_send helper

 drivers/net/ethernet/sun/sunvnet_common.c | 23 +++--------------
 drivers/net/gtp.c                         |  4 +--
 drivers/net/wireguard/device.c            |  4 +--
 include/linux/icmpv6.h                    |  6 +++++
 include/net/icmp.h                        |  6 +++++
 net/ipv4/icmp.c                           | 29 ++++++++++++++++++++++
 net/ipv6/ip6_icmp.c                       | 30 +++++++++++++++++++++++
 net/xfrm/xfrm_interface.c                 |  6 ++---
 8 files changed, 82 insertions(+), 26 deletions(-)

-- 
2.25.0


^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2020-02-11 18:54 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).