Netfilter/IPVS fixes for net
Subsystems (5)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS fixes for net
Hi David,
The following patchset contains Netfilter/IPVS fixes for your net tree:
1) Fix crash when dumping rules after conversion to RCU, from Florian Westphal.
2) Fix incorrect hook reinjection from nf_queue in case NF_REPEAT, from Jagdish Motwani.
3) Fix check for route existence in fib extension, from Phil Sutter.
4) Fix use after free in ip_vs_in() hook, from YueHaibing.
5) Check for veth existence from netfilter selftests, from Jeffrin Jose T.
6) Checksum corruption in UDP NAT helpers due to typo, from Florian Westphal.
7) Pass up packets to classic forwarding path regardless of IPv4 DF bit, patch for the flowtable infrastructure from Florian.
8) Set liberal TCP tracking for flows that are placed in the flowtable, in case they need to go back to classic forwarding path, also from Florian.
9) Don't add flow with sequence adjustment to flowtable, from Florian.
10) Skip IPv4 options from IPv6 datapath in flowtable, from Florian.
11) Add selftest for the flowtable infrastructure, from Florian.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks.
----------------------------------------------------------------
The following changes since commit ee8a2b95b737d5989efeb477d5a1ef5e6955b830:
Merge branch 'mlxsw-Two-port-module-fixes' (2019-05-18 13:13:40 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD
for you to fetch changes up to 2de03b45236f3af1800755614fd434d347adf046:
selftests: netfilter: add flowtable test script (2019-05-22 10:56:11 +0200)
----------------------------------------------------------------
Florian Westphal (7):
netfilter: nf_tables: fix oops during rule dump
netfilter: nat: fix udp checksum corruption
netfilter: nf_flow_table: ignore DF bit setting
netfilter: nft_flow_offload: set liberal tracking mode for tcp
netfilter: nft_flow_offload: don't offload when sequence numbers need adjustment
netfilter: nft_flow_offload: IPCB is only valid for ipv4 family
selftests: netfilter: add flowtable test script
Jagdish Motwani (1):
netfilter: nf_queue: fix reinject verdict handling
Jeffrin Jose T (1):
selftests: netfilter: missing error check when setting up veth interface
Phil Sutter (1):
netfilter: nft_fib: Fix existence check support
YueHaibing (1):
ipvs: Fix use-after-free in ip_vs_in
include/net/netfilter/nft_fib.h | 2 +- net/ipv4/netfilter/nft_fib_ipv4.c | 23 +- net/ipv6/netfilter/nft_fib_ipv6.c | 16 +- net/netfilter/ipvs/ip_vs_core.c | 2 +- net/netfilter/nf_flow_table_ip.c | 3 +- net/netfilter/nf_nat_helper.c | 2 +- net/netfilter/nf_queue.c | 1 + net/netfilter/nf_tables_api.c | 20 +- net/netfilter/nft_fib.c | 6 +- net/netfilter/nft_flow_offload.c | 31 +- tools/testing/selftests/netfilter/Makefile | 2 +- tools/testing/selftests/netfilter/nft_flowtable.sh | 324 +++++++++++++++++++++ tools/testing/selftests/netfilter/nft_nat.sh | 6 +- 13 files changed, 375 insertions(+), 63 deletions(-) create mode 100755 tools/testing/selftests/netfilter/nft_flowtable.sh
Pablo Neira Ayuso
maintainerPATCH 1/11 netfilter: nf_tables: fix oops during rule dump
From: Florian Westphal <[email protected]>
We can oops in nf_tables_fill_rule_info().
Its not possible to fetch previous element in rcu-protected lists when deletions are not prevented somehow: list_del_rcu poisons the ->prev pointer value.
Before rcu-conversion this was safe as dump operations did hold nfnetlink mutex.
Pass previous rule as argument, obtained by keeping a pointer to the previous rule during traversal.
--- net/netfilter/nf_tables_api.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
net/netfilter/nf_tables_api.c +11 -9
@@ -2270,13 +2270,13 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net, u32 flags, int family, const struct nft_table *table, const struct nft_chain *chain, - const struct nft_rule *rule) + const struct nft_rule *rule, + const struct nft_rule *prule) { struct nlmsghdr *nlh;struct nfgenmsg *nfmsg;const struct nft_expr *expr, *next;struct nlattr *list; -const struct nft_rule *prule;u16 type =nfnl_msg_type (NFNL_SUBSYS_NFTABLES , event); nlh =nlmsg_put (skb, portid, seq, type,sizeof (struct nfgenmsg ), flags);
@@ -2296,8 +2296,7 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net, NFTA_RULE_PAD)) goto nla_put_failure; -if ((event !=NFT_MSG_DELRULE ) && (rule->list.prev != &chain->rules)) { - prule =list_prev_entry (rule, list); +if (event !=NFT_MSG_DELRULE && prule) {if (nla_put_be64 (skb,NFTA_RULE_POSITION ,cpu_to_be64 (prule->handle),NFTA_RULE_PAD ))
@@ -2344,7 +2343,7 @@ static void nf_tables_rule_notify(const struct nft_ctx *ctx, err =nf_tables_fill_rule_info (skb, ctx->net, ctx->portid, ctx->seq, event,0 , ctx->family, ctx->table, - ctx->chain, rule); + ctx->chain, rule,NULL );if (err <0 ) {kfree_skb (skb); goto err;
@@ -2369,12 +2368,13 @@ static int __nf_tables_dump_rules(struct sk_buff *skb, const struct nft_chain *chain) {struct net *net =sock_net (skb->sk); +const struct nft_rule *rule, *prule;unsigned int s_idx = cb->args[0 ]; -const struct nft_rule *rule; + prule =NULL ;list_for_each_entry_rcu (rule, &chain->rules, list) {if (!nft_is_active (net, rule)) - goto cont; + goto cont_skip;if (*idx < s_idx) goto cont;if (*idx > s_idx) {
@@ -2386,11 +2386,13 @@ static int __nf_tables_dump_rules(struct sk_buff *skb,NFT_MSG_NEWRULE ,NLM_F_MULTI |NLM_F_APPEND , table->family, - table, chain, rule) < 0) + table, chain, rule, prule) < 0) return 1;nl_dump_check_consistent (cb,nlmsg_hdr (skb)); cont: + prule = rule; +cont_skip: (*idx)++; }return 0 ;
@@ -2546,7 +2548,7 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk, err =nf_tables_fill_rule_info (skb2, net,NETLINK_CB (skb).portid, nlh->nlmsg_seq,NFT_MSG_NEWRULE ,0 , - family, table, chain, rule); + family, table, chain, rule,NULL );if (err <0 ) goto err;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/11 netfilter: nf_queue: fix reinject verdict handling
In reply to Pablo Neira AyusoFrom: Jagdish Motwani <[email protected]>
This patch fixes netfilter hook traversal when there are more than 1 hooks returning NF_QUEUE verdict. When the first queue reinjects the packet, 'nf_reinject' starts traversing hooks with a proper hook_index. However, if it again receives a NF_QUEUE verdict (by some other netfilter hook), it queues the packet with a wrong hook_index. So, when the second queue reinjects the packet, it re-executes hooks in between.
--- net/netfilter/nf_queue.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nf_queue.c +1 -0
@@ -255,6 +255,7 @@ static unsigned int nf_iterate(struct sk_buff *skb, repeat: verdict =nf_hook_entry_hookfn (hook, skb, state);if (verdict !=NF_ACCEPT ) { + *index = i;if (verdict !=NF_REPEAT )return verdict; goto repeat;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/11 netfilter: nft_fib: Fix existence check support
In reply to Pablo Neira AyusoFrom: Phil Sutter <[email protected]>
NFTA_FIB_F_PRESENT flag was not always honored since eval functions did not call nft_fib_store_result in all cases.
Given that in all callsites there is a struct net_device pointer available which holds the interface data to be stored in destination register, simplify nft_fib_store_result() to just accept that pointer instead of the nft_pktinfo pointer and interface index. This also allows to drop the index to interface lookup previously needed to get the name associated with given index.
--- include/net/netfilter/nft_fib.h | 2 +- net/ipv4/netfilter/nft_fib_ipv4.c | 23 +++-------------------- net/ipv6/netfilter/nft_fib_ipv6.c | 16 ++-------------- net/netfilter/nft_fib.c | 6 +++--- 4 files changed, 9 insertions(+), 38 deletions(-)
include/net/netfilter/nft_fib.h +1 -1
@@ -34,5 +34,5 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt);void nft_fib_store_result (void *reg,const struct nft_fib *priv, -const struct nft_pktinfo *pkt,int index); +const struct net_device *dev);#endif
net/ipv4/netfilter/nft_fib_ipv4.c +3 -20
@@ -58,11 +58,6 @@ void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs, }EXPORT_SYMBOL_GPL (nft_fib4_eval_type); -static int get_ifindex (const struct net_device *dev) -{ -return dev ? dev->ifindex :0 ; -} -void nft_fib4_eval (const struct nft_expr *expr,struct nft_regs *regs,const struct nft_pktinfo *pkt) {
@@ -94,8 +89,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,if (nft_hook (pkt) ==NF_INET_PRE_ROUTING &&nft_fib_is_loopback (pkt->skb,nft_in (pkt))) { -nft_fib_store_result (dest, priv, pkt, -nft_in (pkt)->ifindex); +nft_fib_store_result (dest, priv,nft_in (pkt));return ; }
@@ -108,8 +102,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,if (ipv4_is_zeronet (iph->saddr)) {if (ipv4_is_lbcast (iph->daddr) ||ipv4_is_local_multicast (iph->daddr)) { -nft_fib_store_result (dest, priv, pkt, -get_ifindex (pkt->skb->dev)); +nft_fib_store_result (dest, priv, pkt->skb->dev);return ; } }
@@ -150,17 +143,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, found = oif; } -switch (priv->result) { -case NFT_FIB_RESULT_OIF : - *dest = found->ifindex; -break ; -case NFT_FIB_RESULT_OIFNAME : -strncpy ((char *)dest, found->name,IFNAMSIZ ); -break ; -default : -WARN_ON_ONCE (1 ); -break ; - } +nft_fib_store_result (dest, priv, found); }EXPORT_SYMBOL_GPL (nft_fib4_eval);
net/ipv6/netfilter/nft_fib_ipv6.c +2 -14
@@ -169,8 +169,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,if (nft_hook (pkt) ==NF_INET_PRE_ROUTING &&nft_fib_is_loopback (pkt->skb,nft_in (pkt))) { -nft_fib_store_result (dest, priv, pkt, -nft_in (pkt)->ifindex); +nft_fib_store_result (dest, priv,nft_in (pkt));return ; }
@@ -187,18 +186,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,if (oif && oif != rt->rt6i_idev->dev) goto put_rt_err; -switch (priv->result) { -case NFT_FIB_RESULT_OIF : - *dest = rt->rt6i_idev->dev->ifindex; -break ; -case NFT_FIB_RESULT_OIFNAME : -strncpy ((char *)dest, rt->rt6i_idev->dev->name,IFNAMSIZ ); -break ; -default : -WARN_ON_ONCE (1 ); -break ; - } - +nft_fib_store_result (dest, priv, rt->rt6i_idev->dev); put_rt_err:ip6_rt_put (rt); }
net/netfilter/nft_fib.c +3 -3
@@ -135,17 +135,17 @@ int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr)EXPORT_SYMBOL_GPL (nft_fib_dump);void nft_fib_store_result (void *reg,const struct nft_fib *priv, -const struct nft_pktinfo *pkt,int index) +const struct net_device *dev) { -struct net_device *dev;u32 *dreg = reg; +int index;switch (priv->result) {case NFT_FIB_RESULT_OIF : + index = dev ? dev->ifindex :0 ; *dreg = (priv->flags &NFTA_FIB_F_PRESENT ) ? !!index : index;break ;case NFT_FIB_RESULT_OIFNAME : - dev =dev_get_by_index_rcu (nft_net (pkt), index);if (priv->flags &NFTA_FIB_F_PRESENT ) *dreg = !!dev;else
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/11 ipvs: Fix use-after-free in ip_vs_in
In reply to Pablo Neira AyusoFrom: YueHaibing <[email protected]>
BUG: KASAN: use-after-free in ip_vs_in.part.29+0xe8/0xd20 [ip_vs] Read of size 4 at addr ffff8881e9b26e2c by task sshd/5603 CPU: 0 PID: 5603 Comm: sshd Not tainted 4.19.39+ #30 Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 Call Trace: dump_stack+0x71/0xab print_address_description+0x6a/0x270 kasan_report+0x179/0x2c0 ip_vs_in.part.29+0xe8/0xd20 [ip_vs] ip_vs_in+0xd8/0x170 [ip_vs] nf_hook_slow+0x5f/0xe0 __ip_local_out+0x1d5/0x250 ip_local_out+0x19/0x60 __tcp_transmit_skb+0xba1/0x14f0 tcp_write_xmit+0x41f/0x1ed0 ? _copy_from_iter_full+0xca/0x340 __tcp_push_pending_frames+0x52/0x140 tcp_sendmsg_locked+0x787/0x1600 ? tcp_sendpage+0x60/0x60 ? inet_sk_set_state+0xb0/0xb0 tcp_sendmsg+0x27/0x40 sock_sendmsg+0x6d/0x80 sock_write_iter+0x121/0x1c0 ? sock_sendmsg+0x80/0x80 __vfs_write+0x23e/0x370 vfs_write+0xe7/0x230 ksys_write+0xa1/0x120 ? __ia32_sys_read+0x50/0x50 ? __audit_syscall_exit+0x3ce/0x450 do_syscall_64+0x73/0x200 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7ff6f6147c60 Code: 73 01 c3 48 8b 0d 28 12 2d 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d 5d 73 2d 00 00 75 10 b8 01 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 RSP: 002b:00007ffd772ead18 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 0000000000000034 RCX: 00007ff6f6147c60 RDX: 0000000000000034 RSI: 000055df30a31270 RDI: 0000000000000003 RBP: 000055df30a31270 R08: 0000000000000000 R09: 0000000000000000 R10: 00007ffd772ead70 R11: 0000000000000246 R12: 00007ffd772ead74 R13: 00007ffd772eae20 R14: 00007ffd772eae24 R15: 000055df2f12ddc0 Allocated by task 6052: kasan_kmalloc+0xa0/0xd0 __kmalloc+0x10a/0x220 ops_init+0x97/0x190 register_pernet_operations+0x1ac/0x360 register_pernet_subsys+0x24/0x40 0xffffffffc0ea016d do_one_initcall+0x8b/0x253 do_init_module+0xe3/0x335 load_module+0x2fc0/0x3890 __do_sys_finit_module+0x192/0x1c0 do_syscall_64+0x73/0x200 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Freed by task 6067: __kasan_slab_free+0x130/0x180 kfree+0x90/0x1a0 ops_free_list.part.7+0xa6/0xc0 unregister_pernet_operations+0x18b/0x1f0 unregister_pernet_subsys+0x1d/0x30 ip_vs_cleanup+0x1d/0xd2f [ip_vs] __x64_sys_delete_module+0x20c/0x300 do_syscall_64+0x73/0x200 entry_SYSCALL_64_after_hwframe+0x44/0xa9 The buggy address belongs to the object at ffff8881e9b26600 which belongs to the cache kmalloc-4096 of size 4096 The buggy address is located 2092 bytes inside of 4096-byte region [ffff8881e9b26600, ffff8881e9b27600) The buggy address belongs to the page: page:ffffea0007a6c800 count:1 mapcount:0 mapping:ffff888107c0e600 index:0x0 compound_mapcount: 0 flags: 0x17ffffc0008100(slab|head) raw: 0017ffffc0008100 dead000000000100 dead000000000200 ffff888107c0e600 raw: 0000000000000000 0000000080070007 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected
while unregistering ipvs module, ops_free_list calls __ip_vs_cleanup, then nf_unregister_net_hooks be called to do remove nf hook entries. It need a RCU period to finish, however net->ipvs is set to NULL immediately, which will trigger NULL pointer dereference when a packet is hooked and handled by ip_vs_in where net->ipvs is dereferenced.
Another scene is ops_free_list call ops_free to free the net_generic directly while __ip_vs_cleanup finished, then calling ip_vs_in will triggers use-after-free.
This patch moves nf_unregister_net_hooks from __ip_vs_cleanup() to __ip_vs_dev_cleanup(), where rcu_barrier() is called by unregister_pernet_device -> unregister_pernet_operations, that will do the needed grace period.
--- net/netfilter/ipvs/ip_vs_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_core.c +1 -1
@@ -2312,7 +2312,6 @@ static void __net_exit __ip_vs_cleanup(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net); -nf_unregister_net_hooks (net, ip_vs_ops,ARRAY_SIZE (ip_vs_ops));ip_vs_service_net_cleanup (ipvs);/* ip_vs_flush() with locks */ ip_vs_conn_net_cleanup (ipvs);ip_vs_app_net_cleanup (ipvs);
@@ -2327,6 +2326,7 @@ static void __net_exit __ip_vs_dev_cleanup(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);EnterFunction (2 ); +nf_unregister_net_hooks (net, ip_vs_ops,ARRAY_SIZE (ip_vs_ops)); ipvs->enable =0 ;/* Disable packet reception */ smp_wmb ();ip_vs_sync_net_cleanup (ipvs);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/11 selftests: netfilter: missing error check when setting up veth interface
In reply to Pablo Neira AyusoFrom: Jeffrin Jose T <[email protected]>
A test for the basic NAT functionality uses ip command which needs veth device. There is a condition where the kernel support for veth is not compiled into the kernel and the test script breaks. This patch contains code for reasonable error display and correct code exit.
--- tools/testing/selftests/netfilter/nft_nat.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/testing/selftests/netfilter/nft_nat.sh +5 -1
@@ -24,7 +24,11 @@ ip netns add ns0 ip netns add ns1 ip netns add ns2 -ip link add veth0 netns ns0 type veth peer name eth0 netns ns1 +ip link add veth0 netns ns0 type veth peer name eth0 netns ns1 > /dev/null 2>&1 +if [ $? -ne 0 ];then + echo "SKIP: No virtual ethernet pair device support in kernel" + exit $ksft_skip +fi ip link add veth1 netns ns0 type veth peer name eth0 netns ns2 ip -net ns0 link set lo up
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/11 netfilter: nat: fix udp checksum corruption
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Due to copy&paste error nf_nat_mangle_udp_packet passes IPPROTO_TCP, resulting in incorrect udp checksum when payload had to be mangled.
--- net/netfilter/nf_nat_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_nat_helper.c +1 -1
@@ -170,7 +170,7 @@ nf_nat_mangle_udp_packet(struct sk_buff *skb,if (!udph->check && skb->ip_summed !=CHECKSUM_PARTIAL )return true; -nf_nat_csum_recalc (skb,nf_ct_l3num (ct),IPPROTO_TCP , +nf_nat_csum_recalc (skb,nf_ct_l3num (ct),IPPROTO_UDP , udph, &udph->check, datalen, oldlen);return true;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 7/11 netfilter: nf_flow_table: ignore DF bit setting
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Its irrelevant if the DF bit is set or not, we must pass packet to stack in either case.
If the DF bit is set, we must pass it to stack so the appropriate ICMP error can be generated.
If the DF is not set, we must pass it to stack for fragmentation.
--- net/netfilter/nf_flow_table_ip.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/netfilter/nf_flow_table_ip.c +1 -2
@@ -243,8 +243,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache; outdev = rt->dst.dev; -if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)) && - (ip_hdr (skb)->frag_off &htons (IP_DF )) !=0 ) +if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)))return NF_ACCEPT ;if (skb_try_make_writable (skb,sizeof (*iph)))
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/11 netfilter: nft_flow_offload: set liberal tracking mode for tcp
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Without it, whenever a packet has to be pushed up the stack (e.g. because of mtu mismatch), then conntrack will flag packets as invalid, which in turn breaks NAT.
--- net/netfilter/nft_flow_offload.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/netfilter/nft_flow_offload.c +8 -0
@@ -72,6 +72,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,struct nf_flow_route route;struct flow_offload *flow;enum ip_conntrack_dir dir; +bool is_tcp = false;struct nf_conn *ct;int ret;
@@ -84,6 +85,8 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,switch (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum) {case IPPROTO_TCP : + is_tcp = true; +break ;case IPPROTO_UDP :break ;default :
@@ -108,6 +111,11 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,if (!flow) goto err_flow_alloc; +if (is_tcp) { + ct->proto.tcp.seen[0 ].flags |=IP_CT_TCP_FLAG_BE_LIBERAL ; + ct->proto.tcp.seen[1 ].flags |=IP_CT_TCP_FLAG_BE_LIBERAL ; + } + ret =flow_offload_add (flowtable, flow);if (ret <0 ) goto err_flow_add;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/11 netfilter: nft_flow_offload: don't offload when sequence numbers need adjustment
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We can't deal with tcp sequence number rewrite in flow_offload. While at it, simplify helper check, we only need to know if the extension is present, we don't need the helper data.
--- net/netfilter/nft_flow_offload.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/netfilter/nft_flow_offload.c +2 -4
@@ -12,7 +12,6 @@#include <net/netfilter/nf_conntrack_core.h> #include <linux/netfilter/nf_conntrack_common.h> #include <net/netfilter/nf_flow_table.h> -#include <net/netfilter/nf_conntrack_helper.h> struct nft_flow_offload {struct nft_flowtable *flowtable;
@@ -67,7 +66,6 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, {struct nft_flow_offload *priv =nft_expr_priv (expr);struct nf_flowtable *flowtable = &priv->flowtable->data; -const struct nf_conn_help *help;enum ip_conntrack_info ctinfo;struct nf_flow_route route;struct flow_offload *flow;
@@ -93,8 +91,8 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, goto out; } - help =nfct_help (ct); -if (help) +if (nf_ct_ext_exist (ct,NF_CT_EXT_HELPER ) || + ct->status &IPS_SEQ_ADJUST ) goto out;if (!nf_ct_is_confirmed (ct))
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 10/11 netfilter: nft_flow_offload: IPCB is only valid for ipv4 family
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Guard this with a check vs. ipv4, IPCB isn't valid in ipv6 case.
--- net/netfilter/nft_flow_offload.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
net/netfilter/nft_flow_offload.c +11 -6
@@ -48,15 +48,20 @@ static int nft_flow_route(const struct nft_pktinfo *pkt,return 0 ; } -static bool nft_flow_offload_skip (struct sk_buff *skb) +static bool nft_flow_offload_skip (struct sk_buff *skb,int family) { -struct ip_options *opt = &(IPCB (skb)->opt); - -if (unlikely (opt->optlen)) -return true;if (skb_sec_path (skb))return true; +if (family ==NFPROTO_IPV4 ) { +const struct ip_options *opt; + + opt = &(IPCB (skb)->opt); + +if (unlikely (opt->optlen)) +return true; + } +return false; }
@@ -74,7 +79,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,struct nf_conn *ct;int ret; -if (nft_flow_offload_skip (pkt->skb)) +if (nft_flow_offload_skip (pkt->skb,nft_pf (pkt))) goto out; ct =nf_ct_get (pkt->skb, &ctinfo);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 11/11 selftests: netfilter: add flowtable test script
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Exercises 3 cases:
1. no pmtu discovery (need to frag)
2. no PMTUd + NAT (don't flag packets as invalid from conntrack)
3. PMTU + NAT (need to send icmp error)
The first two cases make sure we handle fragments correctly, i.e. pass them to classic forwarding path.
Third case checks we offload everything (in the test case, PMTUd will kick in so all packets should be within link mtu).
Nftables rules will filter packets that are supposed to be handled by the fast-path.
--- tools/testing/selftests/netfilter/Makefile | 2 +- tools/testing/selftests/netfilter/nft_flowtable.sh | 324 +++++++++++++++++++++ 2 files changed, 325 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/netfilter/nft_flowtable.sh
tools/testing/selftests/netfilter/Makefile +1 -1
@@ -2,6 +2,6 @@ # Makefile for netfilter selftests TEST_PROGS := nft_trans_stress.sh nft_nat.sh bridge_brouter.sh \ - conntrack_icmp_related.sh + conntrack_icmp_related.sh nft_flowtable.sh include ../lib.mk
tools/testing/selftests/netfilter/nft_flowtable.sh new file +324 -0
324 lines not on this page · raw message
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Thu, 23 May 2019 23:35:36 +0200
Quoted 1 line
The following patchset contains Netfilter/IPVS fixes for your net tree:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks.