Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv4: Restore accept_local behaviour in fib_validate_source()

Commit 7a9bc9b81a5b ("ipv4: Elide fib_validate_source() completely when possible.")
introduced a short-circuit to avoid calling fib_validate_source when not
needed. That change took rp_filter into account, but not accept_local.
This resulted in a change of behaviour: with rp_filter and accept_local
off, incoming packets with a local address in the source field should be
dropped.

Here is how to reproduce the change pre/post 7a9bc9b81a5b commit:
-configure the same IPv4 address on hosts A and B.
-try to send an ARP request from B to A.
-The ARP request will be dropped before that commit, but accepted and answered
after that commit.

This adds a check for ACCEPT_LOCAL, to maintain full
fib validation in case it is 0. We also leave __fib_validate_source() earlier
when possible, based on the same check as fib_validate_source(), once the
accept_local stuff is verified.

Cc: Gregory Detal <gregory.detal@uclouvain.be>
Cc: Christoph Paasch <christoph.paasch@uclouvain.be>
Cc: Hannes Frederic Sowa <hannes@redhat.com>
Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Sébastien Barré <sebastien.barre@uclouvain.be>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Sébastien Barré and committed by
David S. Miller
1dced6a8 14462b6e

+8 -6
+8 -6
net/ipv4/fib_frontend.c
··· 243 243 u8 tos, int oif, struct net_device *dev, 244 244 int rpf, struct in_device *idev, u32 *itag) 245 245 { 246 - int ret, no_addr, accept_local; 246 + int ret, no_addr; 247 247 struct fib_result res; 248 248 struct flowi4 fl4; 249 249 struct net *net; ··· 258 258 259 259 no_addr = idev->ifa_list == NULL; 260 260 261 - accept_local = IN_DEV_ACCEPT_LOCAL(idev); 262 261 fl4.flowi4_mark = IN_DEV_SRC_VMARK(idev) ? skb->mark : 0; 263 262 264 263 net = dev_net(dev); 265 264 if (fib_lookup(net, &fl4, &res)) 266 265 goto last_resort; 267 - if (res.type != RTN_UNICAST) { 268 - if (res.type != RTN_LOCAL || !accept_local) 269 - goto e_inval; 270 - } 266 + if (res.type != RTN_UNICAST && 267 + (res.type != RTN_LOCAL || !IN_DEV_ACCEPT_LOCAL(idev))) 268 + goto e_inval; 269 + if (!rpf && !fib_num_tclassid_users(dev_net(dev)) && 270 + (dev->ifindex != oif || !IN_DEV_TX_REDIRECTS(idev))) 271 + goto last_resort; 271 272 fib_combine_itag(itag, &res); 272 273 dev_match = false; 273 274 ··· 322 321 int r = secpath_exists(skb) ? 0 : IN_DEV_RPFILTER(idev); 323 322 324 323 if (!r && !fib_num_tclassid_users(dev_net(dev)) && 324 + IN_DEV_ACCEPT_LOCAL(idev) && 325 325 (dev->ifindex != oif || !IN_DEV_TX_REDIRECTS(idev))) { 326 326 *itag = 0; 327 327 return 0;