Netfilter fixes for net
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
1) Patches to bump position index from sysctl seq_next, from Vasilin Averin.
2) Release flowtable hook from error path, from Florian Westphal.
3) Patches to add missing netlink attribute validation, from Jakub Kicinski.
4) Missing NFTA_CHAIN_FLAGS in nf_tables_fill_chain_info().
5) Infinite loop in module autoload if extension is not available, from Florian Westphal.
6) Missing module ownership in inet/nat chain type definition.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thank you.
----------------------------------------------------------------
The following changes since commit f8a0fea9518c5ff7c37679504bd9eeabeae8ee36:
docs: networking: net_failover: Fix a few typos (2020-03-03 16:07:02 -0800)
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 6a42cefb25d8bdc1b391f4a53c78c32164eea2dd:
netfilter: nft_chain_nat: inet family is missing module ownership (2020-03-06 18:00:43 +0100)
----------------------------------------------------------------
Florian Westphal (2):
netfilter: nf_tables: free flowtable hooks on hook register error
netfilter: nf_tables: fix infinite loop when expr is not available
Jakub Kicinski (3):
netfilter: cthelper: add missing attribute validation for cthelper
netfilter: nft_payload: add missing attribute validation for payload csum flags
netfilter: nft_tunnel: add missing attribute validation for tunnels
Pablo Neira Ayuso (2):
netfilter: nf_tables: dump NFTA_CHAIN_FLAGS attribute
netfilter: nft_chain_nat: inet family is missing module ownership
Vasily Averin (4):
netfilter: nf_conntrack: ct_cpu_seq_next should increase position index
netfilter: synproxy: synproxy_cpu_seq_next should increase position index
netfilter: xt_recent: recent_seq_next should increase position index
netfilter: x_tables: xt_mttg_seq_next should increase position index
net/netfilter/nf_conntrack_standalone.c | 2 +- net/netfilter/nf_synproxy_core.c | 2 +- net/netfilter/nf_tables_api.c | 22 ++++++++++++++-------- net/netfilter/nfnetlink_cthelper.c | 2 ++ net/netfilter/nft_chain_nat.c | 1 + net/netfilter/nft_payload.c | 1 + net/netfilter/nft_tunnel.c | 2 ++ net/netfilter/x_tables.c | 6 +++--- net/netfilter/xt_recent.c | 2 +- 9 files changed, 26 insertions(+), 14 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/11 netfilter: nf_conntrack: ct_cpu_seq_next should increase position index
From: Vasily Averin <[email protected]>
If .next function does not change position index, following .show function will repeat output related to current position index.
--- net/netfilter/nf_conntrack_standalone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_standalone.c +1 -1
@@ -411,7 +411,7 @@ static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos) *pos = cpu +1 ;return per_cpu_ptr (net->ct.stat, cpu); } - + (*pos)++;return NULL ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/11 netfilter: synproxy: synproxy_cpu_seq_next should increase position index
In reply to Pablo Neira AyusoFrom: Vasily Averin <[email protected]>
If .next function does not change position index, following .show function will repeat output related to current position index.
--- net/netfilter/nf_synproxy_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_synproxy_core.c +1 -1
@@ -267,7 +267,7 @@ static void *synproxy_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos) *pos = cpu +1 ;return per_cpu_ptr (snet->stats, cpu); } - + (*pos)++;return NULL ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/11 netfilter: xt_recent: recent_seq_next should increase position index
In reply to Pablo Neira AyusoFrom: Vasily Averin <[email protected]>
If .next function does not change position index, following .show function will repeat output related to current position index.
Without the patch:
# dd if=/proc/net/xt_recent/SSH # original file outpt src=127.0.0.4 ttl: 0 last_seen: 6275444819 oldest_pkt: 1 6275444819 src=127.0.0.2 ttl: 0 last_seen: 6275438906 oldest_pkt: 1 6275438906 src=127.0.0.3 ttl: 0 last_seen: 6275441953 oldest_pkt: 1 6275441953 0+1 records in 0+1 records out 204 bytes copied, 6.1332e-05 s, 3.3 MB/s
Read after lseek into middle of last line (offset 140 in example below) generates expected end of last line and then unexpected whole last line once again
# dd if=/proc/net/xt_recent/SSH bs=140 skip=1 dd: /proc/net/xt_recent/SSH: cannot skip to specified offset 127.0.0.3 ttl: 0 last_seen: 6275441953 oldest_pkt: 1 6275441953 src=127.0.0.3 ttl: 0 last_seen: 6275441953 oldest_pkt: 1 6275441953 0+1 records in 0+1 records out 132 bytes copied, 6.2487e-05 s, 2.1 MB/s
--- net/netfilter/xt_recent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_recent.c +1 -1
@@ -492,12 +492,12 @@ static void *recent_seq_next(struct seq_file *seq, void *v, loff_t *pos)const struct recent_entry *e = v;const struct list_head *head = e->list.next; + (*pos)++;while (head == &t->iphash[st->bucket]) {if (++st->bucket >= ip_list_hash_size)return NULL ; head = t->iphash[st->bucket].next; } - (*pos)++; return list_entry(head, struct recent_entry, list); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/11 netfilter: x_tables: xt_mttg_seq_next should increase position index
In reply to Pablo Neira AyusoFrom: Vasily Averin <[email protected]>
If .next function does not change position index, following .show function will repeat output related to current position index.
Without patch:
# dd if=/proc/net/ip_tables_matches # original file output conntrack conntrack conntrack recent recent icmp udplite udp tcp 0+1 records in 0+1 records out 65 bytes copied, 5.4074e-05 s, 1.2 MB/s
# dd if=/proc/net/ip_tables_matches bs=62 skip=1 dd: /proc/net/ip_tables_matches: cannot skip to specified offset cp <<< end of last line tcp <<< and then unexpected whole last line once again 0+1 records in 0+1 records out 7 bytes copied, 0.000102447 s, 68.3 kB/s
--- net/netfilter/x_tables.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/x_tables.c +3 -3
@@ -1551,6 +1551,9 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,uint8_t nfproto = (unsigned long )PDE_DATA (file_inode (seq->file));struct nf_mttg_trav *trav = seq->private; +if (ppos !=NULL ) + ++(*ppos); +switch (trav->class) {case MTTG_TRAV_INIT : trav->class =MTTG_TRAV_NFP_UNSPEC ;
@@ -1576,9 +1579,6 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,default :return NULL ; } - -if (ppos !=NULL ) - ++*ppos;return trav; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/11 netfilter: nf_tables: free flowtable hooks on hook register error
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
If hook registration fails, the hooks allocated via nft_netdev_hook_alloc need to be freed.
We can't change the goto label to 'goto 5' -- while it does fix the memleak it does cause a warning splat from the netfilter core (the hooks were not registered).
--- net/netfilter/nf_tables_api.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +6 -1
@@ -6300,8 +6300,13 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, goto err4; err =nft_register_flowtable_net_hooks (ctx.net, table, flowtable); -if (err <0 ) +if (err <0 ) { +list_for_each_entry_safe (hook, next, &flowtable->hook_list, list) { +list_del_rcu (&hook->list); +kfree_rcu (hook, rcu); + } goto err4; + } err =nft_trans_flowtable_add (&ctx,NFT_MSG_NEWFLOWTABLE , flowtable);if (err <0 )
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/11 netfilter: cthelper: add missing attribute validation for cthelper
In reply to Pablo Neira AyusoFrom: Jakub Kicinski <[email protected]>
Add missing attribute validation for cthelper
to the netlink policy.
--- net/netfilter/nfnetlink_cthelper.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nfnetlink_cthelper.c +2 -0
@@ -742,6 +742,8 @@ static const struct nla_policy nfnl_cthelper_policy[NFCTH_MAX+1] = { [NFCTH_NAME ] = { .type =NLA_NUL_STRING , .len = NF_CT_HELPER_NAME_LEN-1 }, [NFCTH_QUEUE_NUM] = { .type = NLA_U32, }, + [NFCTH_PRIV_DATA_LEN] = { .type = NLA_U32, }, + [NFCTH_STATUS] = { .type = NLA_U32, }, };static const struct nfnl_callback nfnl_cthelper_cb[NFNL_MSG_CTHELPER_MAX ] = {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 7/11 netfilter: nft_payload: add missing attribute validation for payload csum flags
In reply to Pablo Neira AyusoFrom: Jakub Kicinski <[email protected]>
Add missing attribute validation for NFTA_PAYLOAD_CSUM_FLAGS to the netlink policy.
--- net/netfilter/nft_payload.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nft_payload.c +1 -0
@@ -129,6 +129,7 @@ static const struct nla_policy nft_payload_policy[NFTA_PAYLOAD_MAX + 1] = { [NFTA_PAYLOAD_LEN] = { .type = NLA_U32 }, [NFTA_PAYLOAD_CSUM_TYPE] = { .type = NLA_U32 }, [NFTA_PAYLOAD_CSUM_OFFSET] = { .type = NLA_U32 }, + [NFTA_PAYLOAD_CSUM_FLAGS] = { .type = NLA_U32 }, }; static int nft_payload_init(const struct nft_ctx *ctx,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/11 netfilter: nft_tunnel: add missing attribute validation for tunnels
In reply to Pablo Neira AyusoFrom: Jakub Kicinski <[email protected]>
Add missing attribute validation for tunnel source and destination ports to the netlink policy.
--- net/netfilter/nft_tunnel.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nft_tunnel.c +2 -0
@@ -339,6 +339,8 @@ static const struct nla_policy nft_tunnel_key_policy[NFTA_TUNNEL_KEY_MAX + 1] = [NFTA_TUNNEL_KEY_FLAGS] = { .type = NLA_U32, }, [NFTA_TUNNEL_KEY_TOS] = { .type = NLA_U8, }, [NFTA_TUNNEL_KEY_TTL] = { .type = NLA_U8, }, + [NFTA_TUNNEL_KEY_SPORT] = { .type = NLA_U16, }, + [NFTA_TUNNEL_KEY_DPORT] = { .type = NLA_U16, }, [NFTA_TUNNEL_KEY_OPTS] = { .type = NLA_NESTED, }, };
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/11 netfilter: nf_tables: dump NFTA_CHAIN_FLAGS attribute
In reply to Pablo Neira AyusoMissing NFTA_CHAIN_FLAGS netlink attribute when dumping basechain definitions.
--- net/netfilter/nf_tables_api.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_tables_api.c +5 -0
@@ -1405,6 +1405,11 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net, lockdep_commit_lock_is_held(net));if (nft_dump_stats (skb, stats)) goto nla_put_failure; + +if ((chain->flags &NFT_CHAIN_HW_OFFLOAD ) && +nla_put_be32 (skb,NFTA_CHAIN_FLAGS , +htonl (NFT_CHAIN_HW_OFFLOAD ))) + goto nla_put_failure; }if (nla_put_be32 (skb,NFTA_CHAIN_USE ,htonl (chain->use)))
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 10/11 netfilter: nf_tables: fix infinite loop when expr is not available
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
nft will loop forever if the kernel doesn't support an expression:
1. nft_expr_type_get() appends the family specific name to the module list.
2. -EAGAIN is returned to nfnetlink, nfnetlink calls abort path.
3. abort path sets ->done to true and calls request_module for the expression.
4. nfnetlink replays the batch, we end up in nft_expr_type_get() again.
5. nft_expr_type_get attempts to append family-specific name. This one already exists on the list, so we continue
6. nft_expr_type_get adds the generic expression name to the module list. -EAGAIN is returned, nfnetlink calls abort path.
7. abort path encounters the family-specific expression which has 'done' set, so it gets removed.
8. abort path requests the generic expression name, sets done to true.
9. batch is replayed.
If the expression could not be loaded, then we will end up back at 1), because the family-specific name got removed and the cycle starts again.
Note that userspace can SIGKILL the nft process to stop the cycle, but the desired behaviour is to return an error after the generic expr name fails to load the expression.
--- net/netfilter/nf_tables_api.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
net/netfilter/nf_tables_api.c +3 -7
@@ -7388,13 +7388,8 @@ static void nf_tables_module_autoload(struct net *net)list_splice_init (&net->nft.module_list, &module_list);mutex_unlock (&net->nft.commit_mutex);list_for_each_entry_safe (req, next, &module_list, list) { -if (req->done) { -list_del (&req->list); -kfree (req); - }else { -request_module ("%s" , req->module); - req->done = true; - } +request_module ("%s" , req->module); + req->done = true; }mutex_lock (&net->nft.commit_mutex);list_splice (&module_list, &net->nft.module_list);
@@ -8177,6 +8172,7 @@ static void __net_exit nf_tables_exit_net(struct net *net)__nft_release_tables (net);mutex_unlock (&net->nft.commit_mutex);WARN_ON_ONCE (!list_empty (&net->nft.tables)); +WARN_ON_ONCE (!list_empty (&net->nft.module_list)); }static struct pernet_operations nf_tables_net_ops = {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 11/11 netfilter: nft_chain_nat: inet family is missing module ownership
In reply to Pablo Neira AyusoSet owner to THIS_MODULE, otherwise the nft_chain_nat module might be removed while there are still inet/nat chains in place.
[ 117.942096] BUG: unable to handle page fault for address: ffffffffa0d5e040 [ 117.942101] #PF: supervisor read access in kernel mode [ 117.942103] #PF: error_code(0x0000) - not-present page [ 117.942106] PGD 200c067 P4D 200c067 PUD 200d063 PMD 3dc909067 PTE 0 [ 117.942113] Oops: 0000 [#1] PREEMPT SMP PTI [ 117.942118] CPU: 3 PID: 27 Comm: kworker/3:0 Not tainted 5.6.0-rc3+ #348 [ 117.942133] Workqueue: events nf_tables_trans_destroy_work [nf_tables] [ 117.942145] RIP: 0010:nf_tables_chain_destroy.isra.0+0x94/0x15a [nf_tables] [ 117.942149] Code: f6 45 54 01 0f 84 d1 00 00 00 80 3b 05 74 44 48 8b 75 e8 48 c7 c7 72 be de a0 e8 56 e6 2d e0 48 8b 45 e8 48 c7 c7 7f be de a0 <48> 8b 30 e8 43 e6 2d e0 48 8b 45 e8 48 8b 40 10 48 85 c0 74 5b 8b [ 117.942152] RSP: 0018:ffffc9000015be10 EFLAGS: 00010292 [ 117.942155] RAX: ffffffffa0d5e040 RBX: ffff88840be87fc2 RCX: 0000000000000007 [ 117.942158] RDX: 0000000000000007 RSI: 0000000000000086 RDI: ffffffffa0debe7f [ 117.942160] RBP: ffff888403b54b50 R08: 0000000000001482 R09: 0000000000000004 [ 117.942162] R10: 0000000000000000 R11: 0000000000000001 R12: ffff8883eda7e540 [ 117.942164] R13: dead000000000122 R14: dead000000000100 R15: ffff888403b3db80 [ 117.942167] FS: 0000000000000000(0000) GS:ffff88840e4c0000(0000) knlGS:0000000000000000 [ 117.942169] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 117.942172] CR2: ffffffffa0d5e040 CR3: 00000003e4c52002 CR4: 00000000001606e0 [ 117.942174] Call Trace: [ 117.942188] nf_tables_trans_destroy_work.cold+0xd/0x12 [nf_tables] [ 117.942196] process_one_work+0x1d6/0x3b0 [ 117.942200] worker_thread+0x45/0x3c0 [ 117.942203] ? process_one_work+0x3b0/0x3b0 [ 117.942210] kthread+0x112/0x130 [ 117.942214] ? kthread_create_worker_on_cpu+0x40/0x40 [ 117.942221] ret_from_fork+0x35/0x40
nf_tables_chain_destroy() crashes on module_put() because the module is gone.
--- net/netfilter/nft_chain_nat.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nft_chain_nat.c +1 -0
@@ -89,6 +89,7 @@ static const struct nft_chain_type nft_chain_nat_inet = { .name = "nat", .type = NFT_CHAIN_T_NAT, .family = NFPROTO_INET, + .owner = THIS_MODULE, .hook_mask = (1 <<NF_INET_PRE_ROUTING ) | (1 <<NF_INET_LOCAL_IN ) | (1 << NF_INET_LOCAL_OUT) |
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 6 Mar 2020 19:15:02 +0100
Quoted 12 lines
The following patchset contains Netfilter fixes for net:
1) Patches to bump position index from sysctl
seq_next, from Vasilin Averin.2) Release flowtable hook from error path, from Florian Westphal.
3) Patches to add missing netlink attribute validation, from Jakub Kicinski.
4) Missing
NFTA_CHAIN_FLAGSinnf_tables_fill_chain_info().
Quoted 8 lines
5) Infinite loop in module autoload if extension is not available, from Florian Westphal.
6) Missing module ownership in inet/nat chain type definition.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.