1
0
Fork 0
alistair23-linux/net/netfilter/ipvs
Jason A. Donenfeld 56907fa27b netfilter: use actual socket sk rather than skb sk when routing harder
[ Upstream commit 46d6c5ae95 ]

If netfilter changes the packet mark when mangling, the packet is
rerouted using the route_me_harder set of functions. Prior to this
commit, there's one big difference between route_me_harder and the
ordinary initial routing functions, described in the comment above
__ip_queue_xmit():

   /* Note: skb->sk can be different from sk, in case of tunnels */
   int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,

That function goes on to correctly make use of sk->sk_bound_dev_if,
rather than skb->sk->sk_bound_dev_if. And indeed the comment is true: a
tunnel will receive a packet in ndo_start_xmit with an initial skb->sk.
It will make some transformations to that packet, and then it will send
the encapsulated packet out of a *new* socket. That new socket will
basically always have a different sk_bound_dev_if (otherwise there'd be
a routing loop). So for the purposes of routing the encapsulated packet,
the routing information as it pertains to the socket should come from
that socket's sk, rather than the packet's original skb->sk. For that
reason __ip_queue_xmit() and related functions all do the right thing.

One might argue that all tunnels should just call skb_orphan(skb) before
transmitting the encapsulated packet into the new socket. But tunnels do
*not* do this -- and this is wisely avoided in skb_scrub_packet() too --
because features like TSQ rely on skb->destructor() being called when
that buffer space is truely available again. Calling skb_orphan(skb) too
early would result in buffers filling up unnecessarily and accounting
info being all wrong. Instead, additional routing must take into account
the new sk, just as __ip_queue_xmit() notes.

So, this commit addresses the problem by fishing the correct sk out of
state->sk -- it's already set properly in the call to nf_hook() in
__ip_local_out(), which receives the sk as part of its normal
functionality. So we make sure to plumb state->sk through the various
route_me_harder functions, and then make correct use of it following the
example of __ip_queue_xmit().

Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-11-18 19:20:17 +01:00
..
Kconfig net: Fix Kconfig indentation 2019-09-26 08:56:17 +02:00
Makefile netfilter: ipvs: Add configurations of Maglev hashing 2018-04-09 10:11:18 +03:00
ip_vs_app.c ipvs: don't ignore errors in case refcounting ip_vs module fails 2019-10-24 11:53:19 +02:00
ip_vs_conn.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_core.c netfilter: use actual socket sk rather than skb sk when routing harder 2020-11-18 19:20:17 +01:00
ip_vs_ctl.c ipvs: Fix uninit-value in do_ip_vs_set_ctl() 2020-10-29 09:58:08 +01:00
ip_vs_dh.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_est.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_fo.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_ftp.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-06-07 11:00:14 -07:00
ip_vs_lblc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_lblcr.c net: delete "register" keyword 2019-08-08 18:03:42 -07:00
ip_vs_lc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_mh.c netfilter: remove unnecessary spaces 2019-08-13 12:08:48 +02:00
ip_vs_nfct.c netfilter: nf_conntrack_sip: fix expectation clash 2019-07-16 13:16:59 +02:00
ip_vs_nq.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_ovf.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_pe.c ipvs: don't ignore errors in case refcounting ip_vs module fails 2019-10-24 11:53:19 +02:00
ip_vs_pe_sip.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
ip_vs_proto.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_proto_ah_esp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ip_vs_proto_sctp.c netfilter: ipvs: prefer skb_ensure_writable 2019-05-31 18:02:44 +02:00
ip_vs_proto_tcp.c netfilter: remove unnecessary spaces 2019-08-13 12:08:48 +02:00
ip_vs_proto_udp.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-06-07 11:00:14 -07:00
ip_vs_rr.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_sched.c ipvs: don't ignore errors in case refcounting ip_vs module fails 2019-10-24 11:53:19 +02:00
ip_vs_sed.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_sh.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_sync.c ipvs: fix the connection sync failed in some cases 2020-07-29 10:18:34 +02:00
ip_vs_wlc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_wrr.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ip_vs_xmit.c ipvs: clear skb->tstamp in forwarding path 2020-10-29 09:57:45 +01:00