All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next V1 0/6] bpf: New approach for BPF MTU handling and enforcement
@ 2020-10-06 16:02 Jesper Dangaard Brouer
  2020-10-06 16:02 ` [PATCH bpf-next V1 1/6] bpf: Remove MTU check in __bpf_skb_max_len Jesper Dangaard Brouer
                   ` (5 more replies)
  0 siblings, 6 replies; 22+ messages in thread
From: Jesper Dangaard Brouer @ 2020-10-06 16:02 UTC (permalink / raw)
  To: bpf
  Cc: Jesper Dangaard Brouer, netdev, Daniel Borkmann,
	Alexei Starovoitov, maze, lmb, shaun, Lorenzo Bianconi, marek,
	John Fastabend, Jakub Kicinski

This patchset drops all the MTU checks in TC BPF-helpers that limits
growing the packet size. This is done because these BPF-helpers doesn't
take redirect into account, which can result in their MTU check being done
against the wrong netdev.

The new approach is to give BPF-programs knowledge about the MTU on a
netdev (via ifindex) and fib route lookup level. Meaning some BPF-helpers
are added and extended to make it possible to do MTU checks in the
BPF-code. If BPF-prog doesn't comply with the MTU this is enforced on the
kernel side.

Realizing MTU should only apply to transmitted packets, the MTU
enforcement is now done after the TC egress hook. This gives TC-BPF
programs most flexibility and allows to shrink packet size again in egress
hook prior to transmit.

This patchset is primarily focused on TC-BPF, but I've made sure that the
MTU BPF-helpers also works for XDP BPF-programs.

---

Jesper Dangaard Brouer (6):
      bpf: Remove MTU check in __bpf_skb_max_len
      bpf: bpf_fib_lookup return MTU value as output when looked up
      bpf: add BPF-helper for reading MTU from net_device via ifindex
      bpf: make it possible to identify BPF redirected SKBs
      bpf: Add MTU check for TC-BPF packets after egress hook
      bpf: drop MTU check when doing TC-BPF redirect to ingress


 include/linux/netdevice.h |    5 ++-
 include/uapi/linux/bpf.h  |   24 +++++++++++-
 net/core/dev.c            |   24 +++++++++++-
 net/core/filter.c         |   88 ++++++++++++++++++++++++++++++++++++++++-----
 net/sched/Kconfig         |    1 +
 5 files changed, 126 insertions(+), 16 deletions(-)

--


^ permalink raw reply	[flat|nested] 22+ messages in thread
* Re: [PATCH bpf-next V1 2/6] bpf: bpf_fib_lookup return MTU value as output when looked up
@ 2020-10-06 21:20 kernel test robot
  0 siblings, 0 replies; 22+ messages in thread
From: kernel test robot @ 2020-10-06 21:20 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 11230 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <160200017655.719143.17344942455389603664.stgit@firesoul>
References: <160200017655.719143.17344942455389603664.stgit@firesoul>
TO: Jesper Dangaard Brouer <brouer@redhat.com>
TO: bpf(a)vger.kernel.org
CC: Jesper Dangaard Brouer <brouer@redhat.com>
CC: netdev(a)vger.kernel.org
CC: Daniel Borkmann <borkmann@iogearbox.net>
CC: Alexei Starovoitov <alexei.starovoitov@gmail.com>
CC: maze(a)google.com
CC: lmb(a)cloudflare.com
CC: shaun(a)tigera.io
CC: Lorenzo Bianconi <lorenzo@kernel.org>
CC: marek(a)cloudflare.com

Hi Jesper,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Jesper-Dangaard-Brouer/bpf-New-approach-for-BPF-MTU-handling-and-enforcement/20201007-000903
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 5 hours ago
:::::: commit date: 5 hours ago
config: s390-randconfig-m031-20201002 (attached as .config)
compiler: s390-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
net/core/filter.c:5315 bpf_ipv4_fib_lookup() error: uninitialized symbol 'mtu'.

vim +/mtu +5315 net/core/filter.c

87f5fc7e48dd31 David Ahern            2018-05-09  5200  
87f5fc7e48dd31 David Ahern            2018-05-09  5201  #if IS_ENABLED(CONFIG_INET)
87f5fc7e48dd31 David Ahern            2018-05-09  5202  static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
4f74fede40df8d David Ahern            2018-05-21  5203  			       u32 flags, bool check_mtu)
87f5fc7e48dd31 David Ahern            2018-05-09  5204  {
eba618abacade7 David Ahern            2019-04-02  5205  	struct fib_nh_common *nhc;
87f5fc7e48dd31 David Ahern            2018-05-09  5206  	struct in_device *in_dev;
87f5fc7e48dd31 David Ahern            2018-05-09  5207  	struct neighbour *neigh;
87f5fc7e48dd31 David Ahern            2018-05-09  5208  	struct net_device *dev;
87f5fc7e48dd31 David Ahern            2018-05-09  5209  	struct fib_result res;
87f5fc7e48dd31 David Ahern            2018-05-09  5210  	struct flowi4 fl4;
87f5fc7e48dd31 David Ahern            2018-05-09  5211  	int err;
4f74fede40df8d David Ahern            2018-05-21  5212  	u32 mtu;
87f5fc7e48dd31 David Ahern            2018-05-09  5213  
87f5fc7e48dd31 David Ahern            2018-05-09  5214  	dev = dev_get_by_index_rcu(net, params->ifindex);
87f5fc7e48dd31 David Ahern            2018-05-09  5215  	if (unlikely(!dev))
87f5fc7e48dd31 David Ahern            2018-05-09  5216  		return -ENODEV;
87f5fc7e48dd31 David Ahern            2018-05-09  5217  
87f5fc7e48dd31 David Ahern            2018-05-09  5218  	/* verify forwarding is enabled on this interface */
87f5fc7e48dd31 David Ahern            2018-05-09  5219  	in_dev = __in_dev_get_rcu(dev);
87f5fc7e48dd31 David Ahern            2018-05-09  5220  	if (unlikely(!in_dev || !IN_DEV_FORWARD(in_dev)))
4c79579b44b187 David Ahern            2018-06-26  5221  		return BPF_FIB_LKUP_RET_FWD_DISABLED;
87f5fc7e48dd31 David Ahern            2018-05-09  5222  
87f5fc7e48dd31 David Ahern            2018-05-09  5223  	if (flags & BPF_FIB_LOOKUP_OUTPUT) {
87f5fc7e48dd31 David Ahern            2018-05-09  5224  		fl4.flowi4_iif = 1;
87f5fc7e48dd31 David Ahern            2018-05-09  5225  		fl4.flowi4_oif = params->ifindex;
87f5fc7e48dd31 David Ahern            2018-05-09  5226  	} else {
87f5fc7e48dd31 David Ahern            2018-05-09  5227  		fl4.flowi4_iif = params->ifindex;
87f5fc7e48dd31 David Ahern            2018-05-09  5228  		fl4.flowi4_oif = 0;
87f5fc7e48dd31 David Ahern            2018-05-09  5229  	}
87f5fc7e48dd31 David Ahern            2018-05-09  5230  	fl4.flowi4_tos = params->tos & IPTOS_RT_MASK;
87f5fc7e48dd31 David Ahern            2018-05-09  5231  	fl4.flowi4_scope = RT_SCOPE_UNIVERSE;
87f5fc7e48dd31 David Ahern            2018-05-09  5232  	fl4.flowi4_flags = 0;
87f5fc7e48dd31 David Ahern            2018-05-09  5233  
87f5fc7e48dd31 David Ahern            2018-05-09  5234  	fl4.flowi4_proto = params->l4_protocol;
87f5fc7e48dd31 David Ahern            2018-05-09  5235  	fl4.daddr = params->ipv4_dst;
87f5fc7e48dd31 David Ahern            2018-05-09  5236  	fl4.saddr = params->ipv4_src;
87f5fc7e48dd31 David Ahern            2018-05-09  5237  	fl4.fl4_sport = params->sport;
87f5fc7e48dd31 David Ahern            2018-05-09  5238  	fl4.fl4_dport = params->dport;
1869e226a7b3ef David Ahern            2020-09-13  5239  	fl4.flowi4_multipath_hash = 0;
87f5fc7e48dd31 David Ahern            2018-05-09  5240  
87f5fc7e48dd31 David Ahern            2018-05-09  5241  	if (flags & BPF_FIB_LOOKUP_DIRECT) {
87f5fc7e48dd31 David Ahern            2018-05-09  5242  		u32 tbid = l3mdev_fib_table_rcu(dev) ? : RT_TABLE_MAIN;
87f5fc7e48dd31 David Ahern            2018-05-09  5243  		struct fib_table *tb;
87f5fc7e48dd31 David Ahern            2018-05-09  5244  
87f5fc7e48dd31 David Ahern            2018-05-09  5245  		tb = fib_get_table(net, tbid);
87f5fc7e48dd31 David Ahern            2018-05-09  5246  		if (unlikely(!tb))
4c79579b44b187 David Ahern            2018-06-26  5247  			return BPF_FIB_LKUP_RET_NOT_FWDED;
87f5fc7e48dd31 David Ahern            2018-05-09  5248  
87f5fc7e48dd31 David Ahern            2018-05-09  5249  		err = fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF);
87f5fc7e48dd31 David Ahern            2018-05-09  5250  	} else {
87f5fc7e48dd31 David Ahern            2018-05-09  5251  		fl4.flowi4_mark = 0;
87f5fc7e48dd31 David Ahern            2018-05-09  5252  		fl4.flowi4_secid = 0;
87f5fc7e48dd31 David Ahern            2018-05-09  5253  		fl4.flowi4_tun_key.tun_id = 0;
87f5fc7e48dd31 David Ahern            2018-05-09  5254  		fl4.flowi4_uid = sock_net_uid(net, NULL);
87f5fc7e48dd31 David Ahern            2018-05-09  5255  
87f5fc7e48dd31 David Ahern            2018-05-09  5256  		err = fib_lookup(net, &fl4, &res, FIB_LOOKUP_NOREF);
87f5fc7e48dd31 David Ahern            2018-05-09  5257  	}
87f5fc7e48dd31 David Ahern            2018-05-09  5258  
4c79579b44b187 David Ahern            2018-06-26  5259  	if (err) {
4c79579b44b187 David Ahern            2018-06-26  5260  		/* map fib lookup errors to RTN_ type */
4c79579b44b187 David Ahern            2018-06-26  5261  		if (err == -EINVAL)
4c79579b44b187 David Ahern            2018-06-26  5262  			return BPF_FIB_LKUP_RET_BLACKHOLE;
4c79579b44b187 David Ahern            2018-06-26  5263  		if (err == -EHOSTUNREACH)
4c79579b44b187 David Ahern            2018-06-26  5264  			return BPF_FIB_LKUP_RET_UNREACHABLE;
4c79579b44b187 David Ahern            2018-06-26  5265  		if (err == -EACCES)
4c79579b44b187 David Ahern            2018-06-26  5266  			return BPF_FIB_LKUP_RET_PROHIBIT;
4c79579b44b187 David Ahern            2018-06-26  5267  
4c79579b44b187 David Ahern            2018-06-26  5268  		return BPF_FIB_LKUP_RET_NOT_FWDED;
4c79579b44b187 David Ahern            2018-06-26  5269  	}
4c79579b44b187 David Ahern            2018-06-26  5270  
4c79579b44b187 David Ahern            2018-06-26  5271  	if (res.type != RTN_UNICAST)
4c79579b44b187 David Ahern            2018-06-26  5272  		return BPF_FIB_LKUP_RET_NOT_FWDED;
87f5fc7e48dd31 David Ahern            2018-05-09  5273  
5481d73f81549e David Ahern            2019-06-03  5274  	if (fib_info_num_path(res.fi) > 1)
87f5fc7e48dd31 David Ahern            2018-05-09  5275  		fib_select_path(net, &res, &fl4, NULL);
87f5fc7e48dd31 David Ahern            2018-05-09  5276  
4f74fede40df8d David Ahern            2018-05-21  5277  	if (check_mtu) {
4f74fede40df8d David Ahern            2018-05-21  5278  		mtu = ip_mtu_from_fib_result(&res, params->ipv4_dst);
ab61fc7ee5c482 Jesper Dangaard Brouer 2020-10-06  5279  		if (params->tot_len > mtu) {
ab61fc7ee5c482 Jesper Dangaard Brouer 2020-10-06  5280  			params->mtu = mtu; /* union with tot_len */
4c79579b44b187 David Ahern            2018-06-26  5281  			return BPF_FIB_LKUP_RET_FRAG_NEEDED;
4f74fede40df8d David Ahern            2018-05-21  5282  		}
ab61fc7ee5c482 Jesper Dangaard Brouer 2020-10-06  5283  	}
4f74fede40df8d David Ahern            2018-05-21  5284  
eba618abacade7 David Ahern            2019-04-02  5285  	nhc = res.nhc;
87f5fc7e48dd31 David Ahern            2018-05-09  5286  
87f5fc7e48dd31 David Ahern            2018-05-09  5287  	/* do not handle lwt encaps right now */
eba618abacade7 David Ahern            2019-04-02  5288  	if (nhc->nhc_lwtstate)
4c79579b44b187 David Ahern            2018-06-26  5289  		return BPF_FIB_LKUP_RET_UNSUPP_LWT;
87f5fc7e48dd31 David Ahern            2018-05-09  5290  
eba618abacade7 David Ahern            2019-04-02  5291  	dev = nhc->nhc_dev;
87f5fc7e48dd31 David Ahern            2018-05-09  5292  
87f5fc7e48dd31 David Ahern            2018-05-09  5293  	params->rt_metric = res.fi->fib_priority;
87f5fc7e48dd31 David Ahern            2018-05-09  5294  
87f5fc7e48dd31 David Ahern            2018-05-09  5295  	/* xdp and cls_bpf programs are run in RCU-bh so
87f5fc7e48dd31 David Ahern            2018-05-09  5296  	 * rcu_read_lock_bh is not needed here
87f5fc7e48dd31 David Ahern            2018-05-09  5297  	 */
6f5f68d05ec0f6 David Ahern            2019-04-05  5298  	if (likely(nhc->nhc_gw_family != AF_INET6)) {
6f5f68d05ec0f6 David Ahern            2019-04-05  5299  		if (nhc->nhc_gw_family)
6f5f68d05ec0f6 David Ahern            2019-04-05  5300  			params->ipv4_dst = nhc->nhc_gw.ipv4;
6f5f68d05ec0f6 David Ahern            2019-04-05  5301  
6f5f68d05ec0f6 David Ahern            2019-04-05  5302  		neigh = __ipv4_neigh_lookup_noref(dev,
6f5f68d05ec0f6 David Ahern            2019-04-05  5303  						 (__force u32)params->ipv4_dst);
6f5f68d05ec0f6 David Ahern            2019-04-05  5304  	} else {
6f5f68d05ec0f6 David Ahern            2019-04-05  5305  		struct in6_addr *dst = (struct in6_addr *)params->ipv6_dst;
6f5f68d05ec0f6 David Ahern            2019-04-05  5306  
6f5f68d05ec0f6 David Ahern            2019-04-05  5307  		params->family = AF_INET6;
6f5f68d05ec0f6 David Ahern            2019-04-05  5308  		*dst = nhc->nhc_gw.ipv6;
6f5f68d05ec0f6 David Ahern            2019-04-05  5309  		neigh = __ipv6_neigh_lookup_noref_stub(dev, dst);
6f5f68d05ec0f6 David Ahern            2019-04-05  5310  	}
6f5f68d05ec0f6 David Ahern            2019-04-05  5311  
4c79579b44b187 David Ahern            2018-06-26  5312  	if (!neigh)
4c79579b44b187 David Ahern            2018-06-26  5313  		return BPF_FIB_LKUP_RET_NO_NEIGH;
87f5fc7e48dd31 David Ahern            2018-05-09  5314  
ab61fc7ee5c482 Jesper Dangaard Brouer 2020-10-06 @5315  	return bpf_fib_set_fwd_params(params, neigh, dev, mtu);
87f5fc7e48dd31 David Ahern            2018-05-09  5316  }
87f5fc7e48dd31 David Ahern            2018-05-09  5317  #endif
87f5fc7e48dd31 David Ahern            2018-05-09  5318  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 20726 bytes --]

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

end of thread, other threads:[~2020-10-07 17:44 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06 16:02 [PATCH bpf-next V1 0/6] bpf: New approach for BPF MTU handling and enforcement Jesper Dangaard Brouer
2020-10-06 16:02 ` [PATCH bpf-next V1 1/6] bpf: Remove MTU check in __bpf_skb_max_len Jesper Dangaard Brouer
2020-10-06 16:02 ` [PATCH bpf-next V1 2/6] bpf: bpf_fib_lookup return MTU value as output when looked up Jesper Dangaard Brouer
2020-10-07  1:34   ` Maciej Żenczykowski
2020-10-07  7:42     ` Jesper Dangaard Brouer
2020-10-07 16:38       ` David Ahern
2020-10-07  7:28   ` kernel test robot
2020-10-06 16:03 ` [PATCH bpf-next V1 3/6] bpf: add BPF-helper for reading MTU from net_device via ifindex Jesper Dangaard Brouer
2020-10-06 16:33   ` Jesper Dangaard Brouer
2020-10-07  1:18     ` Jakub Kicinski
2020-10-07  1:24       ` Maciej Żenczykowski
2020-10-07  7:53         ` Jesper Dangaard Brouer
2020-10-07 16:35         ` David Ahern
2020-10-07 17:44           ` Maciej Żenczykowski
2020-10-06 16:03 ` [PATCH bpf-next V1 4/6] bpf: make it possible to identify BPF redirected SKBs Jesper Dangaard Brouer
2020-10-06 16:03 ` [PATCH bpf-next V1 5/6] bpf: Add MTU check for TC-BPF packets after egress hook Jesper Dangaard Brouer
2020-10-06 20:09   ` kernel test robot
2020-10-06 20:09     ` kernel test robot
2020-10-07  0:26   ` kernel test robot
2020-10-07  0:26     ` kernel test robot
2020-10-06 16:03 ` [PATCH bpf-next V1 6/6] bpf: drop MTU check when doing TC-BPF redirect to ingress Jesper Dangaard Brouer
2020-10-06 21:20 [PATCH bpf-next V1 2/6] bpf: bpf_fib_lookup return MTU value as output when looked up kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.