Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
1) Fix NAT IPv6 offload in the flowtable.
2) icmpv6 is printed as unknown in /proc/net/nf_conntrack.
3) Use div64_u64() in nft_limit, from Eric Dumazet.
4) Use pre_exit to unregister ebtables and arptables hooks, from Florian Westphal.
5) Fix out-of-bound memset in x_tables compat match/target, also from Florian.
6) Clone set elements expression to ensure proper initialization.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 9adc89af724f12a03b47099cd943ed54e877cd59:
net: let skb_orphan_partial wake-up waiters. (2021-03-30 13:57:28 -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 4d8f9065830e526c83199186c5f56a6514f457d2:
netfilter: nftables: clone set element expression template (2021-04-13 00:19:05 +0200)
----------------------------------------------------------------
Eric Dumazet (1):
netfilter: nft_limit: avoid possible divide error in nft_limit_init
Florian Westphal (3):
netfilter: bridge: add pre_exit hooks for ebtable unregistration
netfilter: arp_tables: add pre_exit hook for table unregister
netfilter: x_tables: fix compat match/target pad out-of-bound write
Pablo Neira Ayuso (3):
netfilter: flowtable: fix NAT IPv6 offload mangling
netfilter: conntrack: do not print icmpv6 as unknown via /proc
netfilter: nftables: clone set element expression template
include/linux/netfilter_arp/arp_tables.h | 5 ++-- include/linux/netfilter_bridge/ebtables.h | 5 ++-- net/bridge/netfilter/ebtable_broute.c | 8 +++++- net/bridge/netfilter/ebtable_filter.c | 8 +++++- net/bridge/netfilter/ebtable_nat.c | 8 +++++- net/bridge/netfilter/ebtables.c | 30 ++++++++++++++++++-- net/ipv4/netfilter/arp_tables.c | 11 ++++++-- net/ipv4/netfilter/arptable_filter.c | 10 ++++++- net/ipv4/netfilter/ip_tables.c | 2 ++ net/ipv6/netfilter/ip6_tables.c | 2 ++ net/netfilter/nf_conntrack_standalone.c | 1 + net/netfilter/nf_flow_table_offload.c | 6 ++-- net/netfilter/nf_tables_api.c | 46 +++++++++++++++++++++++-------- net/netfilter/nft_limit.c | 4 +-- net/netfilter/x_tables.c | 10 ++----- 15 files changed, 118 insertions(+), 38 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/7 netfilter: flowtable: fix NAT IPv6 offload mangling
Fix out-of-bound access in the address array.
--- net/netfilter/nf_flow_table_offload.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nf_flow_table_offload.c +3 -3
@@ -305,12 +305,12 @@ static void flow_offload_ipv6_mangle(struct nf_flow_rule *flow_rule, const __be32 *addr, const __be32 *mask) { struct flow_action_entry *entry; -int i; +int i, j; -for (i =0 ; i <sizeof (struct in6_addr ) /sizeof (u32); i +=sizeof (u32)) { +for (i =0 , j =0 ; i <sizeof (struct in6_addr ) /sizeof (u32); i +=sizeof (u32), j++) { entry =flow_action_entry_next (flow_rule);flow_offload_mangle (entry,FLOW_ACT_MANGLE_HDR_TYPE_IP6 , - offset + i, &addr[i], mask); + offset + i, &addr[j], mask); } }
Signature · 1 line
2.20.1
Re: [PATCH net 1/7] netfilter: flowtable: fix NAT IPv6 offload mangling
This series was applied to netdev/net.git (refs/heads/master):
Hello:
This series was applied to netdev/net.git (refs/heads/master):
Quoted 7 lines · On Tue, 13 Apr 2021 00:30:53 +0200 you wrote:
Fix out-of-bound access in the address array.
Fixes 5c27d8d76ce8 ("netfilter: nf_flow_table_offload: add IPv6 support")Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/netfilter/nf_flow_table_offload.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Here is the summary with links:
- [net,1/7] netfilter: flowtable: fix NAT IPv6 offload mangling
https://git.kernel.org/netdev/net/c/0e07e25b481a - [net,2/7] netfilter: conntrack: do not print icmpv6 as unknown via /proc https://git.kernel.org/netdev/net/c/fbea31808ca1 - [net,3/7] netfilter: nft_limit: avoid possible divide error in nft_limit_init https://git.kernel.org/netdev/net/c/b895bdf5d643 - [net,4/7] netfilter: bridge: add pre_exit hooks for ebtable unregistration https://git.kernel.org/netdev/net/c/7ee3c61dcd28 - [net,5/7] netfilter: arp_tables: add pre_exit hook for table unregister https://git.kernel.org/netdev/net/c/d163a925ebbc - [net,6/7] netfilter: x_tables: fix compat match/target pad out-of-bound write https://git.kernel.org/netdev/net/c/b29c457a6511 - [net,7/7] netfilter: nftables: clone set element expression template https://git.kernel.org/netdev/net/c/4d8f9065830e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH 2/7 netfilter: conntrack: do not print icmpv6 as unknown via /proc
In reply to Pablo Neira Ayuso/proc/net/nf_conntrack shows icmpv6 as unknown.
--- net/netfilter/nf_conntrack_standalone.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nf_conntrack_standalone.c +1 -0
@@ -266,6 +266,7 @@ static const char* l4proto_name(u16 proto)case IPPROTO_GRE :return "gre" ;case IPPROTO_SCTP :return "sctp" ;case IPPROTO_UDPLITE :return "udplite" ; +case IPPROTO_ICMPV6 :return "icmpv6" ; }return "unknown" ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 3/7 netfilter: nft_limit: avoid possible divide error in nft_limit_init
In reply to Pablo Neira AyusoFrom: Eric Dumazet <[email protected]>
div_u64() divides u64 by u32.
nft_limit_init() wants to divide u64 by u64, use the appropriate math function (div64_u64)
divide error: 0000 [#1] PREEMPT SMP KASAN
CPU: 1 PID: 8390 Comm: syz-executor188 Not tainted 5.12.0-rc4-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:div_u64_rem include/linux/math64.h:28 [inline] RIP: 0010:div_u64 include/linux/math64.h:127 [inline] RIP: 0010:nft_limit_init+0x2a2/0x5e0 net/netfilter/nft_limit.c:85 Code: ef 4c 01 eb 41 0f 92 c7 48 89 de e8 38 a5 22 fa 4d 85 ff 0f 85 97 02 00 00 e8 ea 9e 22 fa 4c 0f af f3 45 89 ed 31 d2 4c 89 f0 <49> f7 f5 49 89 c6 e8 d3 9e 22 fa 48 8d 7d 48 48 b8 00 00 00 00 00 RSP: 0018:ffffc90009447198 EFLAGS: 00010246 RAX: 0000000000000000 RBX: 0000200000000000 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffffff875152e6 RDI: 0000000000000003 RBP: ffff888020f80908 R08: 0000200000000000 R09: 0000000000000000 R10: ffffffff875152d8 R11: 0000000000000000 R12: ffffc90009447270 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 FS: 000000000097a300(0000) GS:ffff8880b9d00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000200001c4 CR3: 0000000026a52000 CR4: 00000000001506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: nf_tables_newexpr net/netfilter/nf_tables_api.c:2675 [inline] nft_expr_init+0x145/0x2d0 net/netfilter/nf_tables_api.c:2713 nft_set_elem_expr_alloc+0x27/0x280 net/netfilter/nf_tables_api.c:5160 nf_tables_newset+0x1997/0x3150 net/netfilter/nf_tables_api.c:4321 nfnetlink_rcv_batch+0x85a/0x21b0 net/netfilter/nfnetlink.c:456 nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:580 [inline] nfnetlink_rcv+0x3af/0x420 net/netfilter/nfnetlink.c:598 netlink_unicast_kernel net/netlink/af_netlink.c:1312 [inline] netlink_unicast+0x533/0x7d0 net/netlink/af_netlink.c:1338 netlink_sendmsg+0x856/0xd90 net/netlink/af_netlink.c:1927 sock_sendmsg_nosec net/socket.c:654 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:674 ____sys_sendmsg+0x6e8/0x810 net/socket.c:2350 ___sys_sendmsg+0xf3/0x170 net/socket.c:2404 __sys_sendmsg+0xe5/0x1b0 net/socket.c:2433 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x44/0xae
--- net/netfilter/nft_limit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_limit.c +2 -2
@@ -76,13 +76,13 @@ static int nft_limit_init(struct nft_limit *limit,return -EOVERFLOW ;if (pkts) { - tokens =div_u64 (limit->nsecs, limit->rate) * limit->burst; + tokens =div64_u64 (limit->nsecs, limit->rate) * limit->burst; }else {/* The token bucket size limits the number of tokens can be * accumulated. tokens_max specifies the bucket size. * tokens_max = unit * (rate + burst) / rate. */ - tokens =div_u64 (limit->nsecs * (limit->rate + limit->burst), + tokens =div64_u64 (limit->nsecs * (limit->rate + limit->burst), limit->rate); }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 4/7 netfilter: bridge: add pre_exit hooks for ebtable unregistration
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Just like ip/ip6/arptables, the hooks have to be removed, then synchronize_rcu() has to be called to make sure no more packets are being processed before the ruleset data is released.
Place the hook unregistration in the pre_exit hook, then call the new ebtables pre_exit function from there.
Years ago, when first netns support got added for netfilter+ebtables, this used an older (now removed) netfilter hook unregister API, that did a unconditional synchronize_rcu().
Now that all is done with call_rcu, ebtable_{filter,nat,broute} pernet exit handlers may free the ebtable ruleset while packets are still in flight.
This can only happens on module removal, not during netns exit.
The new function expects the table name, not the table struct.
This is because upcoming patch set (targeting -next) will remove all net->xt.{nat,filter,broute}_table instances, this makes it necessary to avoid external references to those member variables.
The existing APIs will be converted, so follow the upcoming scheme of passing name + hook type instead.
--- include/linux/netfilter_bridge/ebtables.h | 5 ++-- net/bridge/netfilter/ebtable_broute.c | 8 +++++- net/bridge/netfilter/ebtable_filter.c | 8 +++++- net/bridge/netfilter/ebtable_nat.c | 8 +++++- net/bridge/netfilter/ebtables.c | 30 ++++++++++++++++++++--- 5 files changed, 51 insertions(+), 8 deletions(-)
include/linux/netfilter_bridge/ebtables.h +3 -2
@@ -110,8 +110,9 @@ extern int ebt_register_table(struct net *net,const struct ebt_table *table, const struct nf_hook_ops *ops, struct ebt_table **res); -extern void ebt_unregister_table (struct net *net,struct ebt_table *table, -const struct nf_hook_ops *); +extern void ebt_unregister_table (struct net *net,struct ebt_table *table); +void ebt_unregister_table_pre_exit (struct net *net,const char *tablename, +const struct nf_hook_ops *ops);extern unsigned int ebt_do_table (struct sk_buff *skb,const struct nf_hook_state *state,struct ebt_table *table);
net/bridge/netfilter/ebtable_broute.c +7 -1
@@ -105,14 +105,20 @@ static int __net_init broute_net_init(struct net *net) &net->xt.broute_table); } +static void __net_exit broute_net_pre_exit(struct net *net) +{ +ebt_unregister_table_pre_exit (net,"broute" , &ebt_ops_broute); +} + static void __net_exit broute_net_exit(struct net *net) { -ebt_unregister_table (net, net->xt.broute_table, &ebt_ops_broute); +ebt_unregister_table (net, net->xt.broute_table); }static struct pernet_operations broute_net_ops = { .init = broute_net_init, .exit = broute_net_exit, + .pre_exit = broute_net_pre_exit, };static int __init ebtable_broute_init (void )
net/bridge/netfilter/ebtable_filter.c +7 -1
@@ -99,14 +99,20 @@ static int __net_init frame_filter_net_init(struct net *net) &net->xt.frame_filter); } +static void __net_exit frame_filter_net_pre_exit(struct net *net) +{ +ebt_unregister_table_pre_exit (net,"filter" , ebt_ops_filter); +} + static void __net_exit frame_filter_net_exit(struct net *net) { -ebt_unregister_table (net, net->xt.frame_filter, ebt_ops_filter); +ebt_unregister_table (net, net->xt.frame_filter); }static struct pernet_operations frame_filter_net_ops = { .init = frame_filter_net_init, .exit = frame_filter_net_exit, + .pre_exit = frame_filter_net_pre_exit, };static int __init ebtable_filter_init (void )
net/bridge/netfilter/ebtable_nat.c +7 -1
@@ -99,14 +99,20 @@ static int __net_init frame_nat_net_init(struct net *net) &net->xt.frame_nat); } +static void __net_exit frame_nat_net_pre_exit(struct net *net) +{ +ebt_unregister_table_pre_exit (net,"nat" , ebt_ops_nat); +} + static void __net_exit frame_nat_net_exit(struct net *net) { -ebt_unregister_table (net, net->xt.frame_nat, ebt_ops_nat); +ebt_unregister_table (net, net->xt.frame_nat); }static struct pernet_operations frame_nat_net_ops = { .init = frame_nat_net_init, .exit = frame_nat_net_exit, + .pre_exit = frame_nat_net_pre_exit, };static int __init ebtable_nat_init (void )
net/bridge/netfilter/ebtables.c +27 -3
@@ -1232,10 +1232,34 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,return ret; } -void ebt_unregister_table (struct net *net,struct ebt_table *table, -const struct nf_hook_ops *ops) +static struct ebt_table *__ebt_find_table (struct net *net,const char *name) +{ +struct ebt_table *t; + +mutex_lock (&ebt_mutex); + +list_for_each_entry (t, &net->xt.tables[NFPROTO_BRIDGE ], list) { +if (strcmp (t->name, name) ==0 ) { +mutex_unlock (&ebt_mutex); +return t; + } + } + +mutex_unlock (&ebt_mutex); +return NULL ; +} + +void ebt_unregister_table_pre_exit (struct net *net,const char *name,const struct nf_hook_ops *ops) +{ +struct ebt_table *table =__ebt_find_table (net, name); + +if (table) +nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); +} +EXPORT_SYMBOL (ebt_unregister_table_pre_exit); + +void ebt_unregister_table (struct net *net,struct ebt_table *table) { -nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks));__ebt_unregister_table (net, table); }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 5/7 netfilter: arp_tables: add pre_exit hook for table unregister
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Same problem that also existed in iptables/ip(6)tables, when arptable_filter is removed there is no longer a wait period before the table/ruleset is free'd.
Unregister the hook in pre_exit, then remove the table in the exit function.
This used to work correctly because the old nf_hook_unregister API did unconditional synchronize_net.
The per-net hook unregister function uses call_rcu instead.
--- include/linux/netfilter_arp/arp_tables.h | 5 +++-- net/ipv4/netfilter/arp_tables.c | 9 +++++++-- net/ipv4/netfilter/arptable_filter.c | 10 +++++++++- 3 files changed, 19 insertions(+), 5 deletions(-)
include/linux/netfilter_arp/arp_tables.h +3 -2
@@ -52,8 +52,9 @@ extern void *arpt_alloc_initial_table(const struct xt_table *);int arpt_register_table (struct net *net,const struct xt_table *table,const struct arpt_replace *repl,const struct nf_hook_ops *ops,struct xt_table **res); -void arpt_unregister_table (struct net *net,struct xt_table *table, -const struct nf_hook_ops *ops); +void arpt_unregister_table (struct net *net,struct xt_table *table); +void arpt_unregister_table_pre_exit (struct net *net,struct xt_table *table, +const struct nf_hook_ops *ops);extern unsigned int arpt_do_table (struct sk_buff *skb,const struct nf_hook_state *state,struct xt_table *table);
net/ipv4/netfilter/arp_tables.c +7 -2
@@ -1539,10 +1539,15 @@ int arpt_register_table(struct net *net,return ret; } -void arpt_unregister_table (struct net *net,struct xt_table *table, -const struct nf_hook_ops *ops) +void arpt_unregister_table_pre_exit (struct net *net,struct xt_table *table, +const struct nf_hook_ops *ops) {nf_unregister_net_hooks (net, ops,hweight32 (table->valid_hooks)); +} +EXPORT_SYMBOL (arpt_unregister_table_pre_exit); + +void arpt_unregister_table (struct net *net,struct xt_table *table) +{__arpt_unregister_table (net, table); }
net/ipv4/netfilter/arptable_filter.c +9 -1
@@ -56,16 +56,24 @@ static int __net_init arptable_filter_table_init(struct net *net)return err; } +static void __net_exit arptable_filter_net_pre_exit(struct net *net) +{ +if (net->ipv4.arptable_filter) +arpt_unregister_table_pre_exit (net, net->ipv4.arptable_filter, + arpfilter_ops); +} + static void __net_exit arptable_filter_net_exit(struct net *net) {if (!net->ipv4.arptable_filter)return ; -arpt_unregister_table (net, net->ipv4.arptable_filter, arpfilter_ops); +arpt_unregister_table (net, net->ipv4.arptable_filter); net->ipv4.arptable_filter =NULL ; }static struct pernet_operations arptable_filter_net_ops = { .exit = arptable_filter_net_exit, + .pre_exit = arptable_filter_net_pre_exit, };static int __init arptable_filter_init (void )
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 6/7 netfilter: x_tables: fix compat match/target pad out-of-bound write
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
xt_compat_match/target_from_user doesn't check that zeroing the area to start of next rule won't write past end of allocated ruleset blob.
Remove this code and zero the entire blob beforehand.
--- net/ipv4/netfilter/arp_tables.c | 2 ++ net/ipv4/netfilter/ip_tables.c | 2 ++ net/ipv6/netfilter/ip6_tables.c | 2 ++ net/netfilter/x_tables.c | 10 ++-------- 4 files changed, 8 insertions(+), 8 deletions(-)
net/ipv4/netfilter/arp_tables.c +2 -0
@@ -1193,6 +1193,8 @@ static int translate_compat_table(struct net *net,if (!newinfo) goto out_unlock; +memset (newinfo->entries,0 , size); + newinfo->number = compatr->num_entries;for (i =0 ; i <NF_ARP_NUMHOOKS ; i++) { newinfo->hook_entry[i] = compatr->hook_entry[i];
net/ipv4/netfilter/ip_tables.c +2 -0
@@ -1428,6 +1428,8 @@ translate_compat_table(struct net *net,if (!newinfo) goto out_unlock; +memset (newinfo->entries,0 , size); + newinfo->number = compatr->num_entries;for (i =0 ; i <NF_INET_NUMHOOKS ; i++) { newinfo->hook_entry[i] = compatr->hook_entry[i];
net/ipv6/netfilter/ip6_tables.c +2 -0
@@ -1443,6 +1443,8 @@ translate_compat_table(struct net *net,if (!newinfo) goto out_unlock; +memset (newinfo->entries,0 , size); + newinfo->number = compatr->num_entries;for (i =0 ; i <NF_INET_NUMHOOKS ; i++) { newinfo->hook_entry[i] = compatr->hook_entry[i];
net/netfilter/x_tables.c +2 -8
@@ -733,7 +733,7 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, {const struct xt_match *match = m->u.kernel.match;struct compat_xt_entry_match *cm = (struct compat_xt_entry_match *)m; -int pad, off =xt_compat_match_offset (match); +int off =xt_compat_match_offset (match);u_int16_t msize = cm->u.user.match_size;char name[sizeof (m->u.user.name)];
@@ -743,9 +743,6 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, match->compat_from_user (m->data, cm->data); else memcpy(m->data, cm->data, msize - sizeof(*cm)); - pad =XT_ALIGN (match->matchsize) - match->matchsize; -if (pad >0 ) -memset (m->data + match->matchsize,0 , pad); msize += off; m->u.user.match_size = msize;
@@ -1116,7 +1113,7 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr, {const struct xt_target *target = t->u.kernel.target;struct compat_xt_entry_target *ct = (struct compat_xt_entry_target *)t; -int pad, off =xt_compat_target_offset (target); +int off =xt_compat_target_offset (target);u_int16_t tsize = ct->u.user.target_size;char name[sizeof (t->u.user.name)];
@@ -1126,9 +1123,6 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr, target->compat_from_user (t->data, ct->data); else memcpy(t->data, ct->data, tsize - sizeof(*ct)); - pad =XT_ALIGN (target->targetsize) - target->targetsize; -if (pad >0 ) -memset (t->data + target->targetsize,0 , pad); tsize += off; t->u.user.target_size = tsize;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 7/7 netfilter: nftables: clone set element expression template
In reply to Pablo Neira Ayusomemcpy() breaks when using connlimit in set elements. Use nft_expr_clone() to initialize the connlimit expression list, otherwise connlimit garbage collector crashes when walking on the list head copy.
[ 493.064656] Workqueue: events_power_efficient nft_rhash_gc [nf_tables] [ 493.064685] RIP: 0010:find_or_evict+0x5a/0x90 [nf_conncount] [ 493.064694] Code: 2b 43 40 83 f8 01 77 0d 48 c7 c0 f5 ff ff ff 44 39 63 3c 75 df 83 6d 18 01 48 8b 43 08 48 89 de 48 8b 13 48 8b 3d ee 2f 00 00 <48> 89 42 08 48 89 10 48 b8 00 01 00 00 00 00 ad de 48 89 03 48 83 [ 493.064699] RSP: 0018:ffffc90000417dc0 EFLAGS: 00010297 [ 493.064704] RAX: 0000000000000000 RBX: ffff888134f38410 RCX: 0000000000000000 [ 493.064708] RDX: 0000000000000000 RSI: ffff888134f38410 RDI: ffff888100060cc0 [ 493.064711] RBP: ffff88812ce594a8 R08: ffff888134f38438 R09: 00000000ebb9025c [ 493.064714] R10: ffffffff8219f838 R11: 0000000000000017 R12: 0000000000000001 [ 493.064718] R13: ffffffff82146740 R14: ffff888134f38410 R15: 0000000000000000 [ 493.064721] FS: 0000000000000000(0000) GS:ffff88840e440000(0000) knlGS:0000000000000000 [ 493.064725] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 493.064729] CR2: 0000000000000008 CR3: 00000001330aa002 CR4: 00000000001706e0 [ 493.064733] Call Trace: [ 493.064737] nf_conncount_gc_list+0x8f/0x150 [nf_conncount] [ 493.064746] nft_rhash_gc+0x106/0x390 [nf_tables]
--- net/netfilter/nf_tables_api.c | 46 ++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-)
net/netfilter/nf_tables_api.c +34 -12
@@ -5295,16 +5295,35 @@ int nft_set_elem_expr_clone(const struct nft_ctx *ctx, struct nft_set *set,return -ENOMEM ; } -static void nft_set_elem_expr_setup (const struct nft_set_ext *ext,int i, -struct nft_expr *expr_array[]) +static int nft_set_elem_expr_setup (struct nft_ctx *ctx, +const struct nft_set_ext *ext, +struct nft_expr *expr_array[], +u32 num_exprs) {struct nft_set_elem_expr *elem_expr =nft_set_ext_expr (ext); -struct nft_expr *expr =nft_setelem_expr_at (elem_expr, elem_expr->size); +struct nft_expr *expr; +int i, err; + +for (i =0 ; i < num_exprs; i++) { + expr =nft_setelem_expr_at (elem_expr, elem_expr->size); + err =nft_expr_clone (expr, expr_array[i]); +if (err <0 ) + goto err_elem_expr_setup; + + elem_expr->size += expr_array[i]->ops->size; +nft_expr_destroy (ctx, expr_array[i]); + expr_array[i] =NULL ; + } + +return 0 ; + +err_elem_expr_setup: +for (; i < num_exprs; i++) { +nft_expr_destroy (ctx, expr_array[i]); + expr_array[i] =NULL ; + } -memcpy (expr, expr_array[i], expr_array[i]->ops->size); - elem_expr->size += expr_array[i]->ops->size; -kfree (expr_array[i]); - expr_array[i] =NULL ; +return -ENOMEM ; } static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
@@ -5556,12 +5575,15 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, *nft_set_ext_obj (ext) = obj; obj->use++; } -for (i =0 ; i < num_exprs; i++) -nft_set_elem_expr_setup (ext, i, expr_array); + err =nft_set_elem_expr_setup (ctx, ext, expr_array, num_exprs); +if (err <0 ) + goto err_elem_expr; trans =nft_trans_elem_alloc (ctx,NFT_MSG_NEWSETELEM , set); -if (trans ==NULL ) - goto err_trans; +if (trans ==NULL ) { + err = -ENOMEM ; + goto err_elem_expr; + } ext->genmask =nft_genmask_cur (ctx->net) |NFT_SET_ELEM_BUSY_MASK ; err = set->ops->insert (ctx->net, set, &elem, &ext2);
@@ -5605,7 +5627,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, set->ops->remove (ctx->net, set, &elem); err_element_clash:kfree (trans); -err_trans: +err_elem_expr:if (obj) obj->use--;
Signature · 1 line
2.20.1