@@ -2454,15 +2454,14 @@ static int nft_table_validate(struct net *net, const struct nft_table *table)
2454
2454
2455
2455
#define NFT_RULE_MAXEXPRS 128
2456
2456
2457
- static struct nft_expr_info * info ;
2458
-
2459
2457
static int nf_tables_newrule (struct net * net , struct sock * nlsk ,
2460
2458
struct sk_buff * skb , const struct nlmsghdr * nlh ,
2461
2459
const struct nlattr * const nla [],
2462
2460
struct netlink_ext_ack * extack )
2463
2461
{
2464
2462
const struct nfgenmsg * nfmsg = nlmsg_data (nlh );
2465
2463
u8 genmask = nft_genmask_next (net );
2464
+ struct nft_expr_info * info = NULL ;
2466
2465
int family = nfmsg -> nfgen_family ;
2467
2466
struct nft_table * table ;
2468
2467
struct nft_chain * chain ;
@@ -2533,6 +2532,12 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
2533
2532
n = 0 ;
2534
2533
size = 0 ;
2535
2534
if (nla [NFTA_RULE_EXPRESSIONS ]) {
2535
+ info = kvmalloc_array (NFT_RULE_MAXEXPRS ,
2536
+ sizeof (struct nft_expr_info ),
2537
+ GFP_KERNEL );
2538
+ if (!info )
2539
+ return - ENOMEM ;
2540
+
2536
2541
nla_for_each_nested (tmp , nla [NFTA_RULE_EXPRESSIONS ], rem ) {
2537
2542
err = - EINVAL ;
2538
2543
if (nla_type (tmp ) != NFTA_LIST_ELEM )
@@ -2625,6 +2630,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
2625
2630
list_add_rcu (& rule -> list , & chain -> rules );
2626
2631
}
2627
2632
}
2633
+ kvfree (info );
2628
2634
chain -> use ++ ;
2629
2635
2630
2636
if (net -> nft .validate_state == NFT_VALIDATE_DO )
@@ -2638,6 +2644,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
2638
2644
if (info [i ].ops != NULL )
2639
2645
module_put (info [i ].ops -> type -> owner );
2640
2646
}
2647
+ kvfree (info );
2641
2648
return err ;
2642
2649
}
2643
2650
@@ -7203,29 +7210,19 @@ static int __init nf_tables_module_init(void)
7203
7210
7204
7211
nft_chain_filter_init ();
7205
7212
7206
- info = kmalloc_array (NFT_RULE_MAXEXPRS , sizeof (struct nft_expr_info ),
7207
- GFP_KERNEL );
7208
- if (info == NULL ) {
7209
- err = - ENOMEM ;
7210
- goto err1 ;
7211
- }
7212
-
7213
7213
err = nf_tables_core_module_init ();
7214
7214
if (err < 0 )
7215
- goto err2 ;
7215
+ return err ;
7216
7216
7217
7217
err = nfnetlink_subsys_register (& nf_tables_subsys );
7218
7218
if (err < 0 )
7219
- goto err3 ;
7219
+ goto err ;
7220
7220
7221
7221
register_netdevice_notifier (& nf_tables_flowtable_notifier );
7222
7222
7223
7223
return register_pernet_subsys (& nf_tables_net_ops );
7224
- err3 :
7224
+ err :
7225
7225
nf_tables_core_module_exit ();
7226
- err2 :
7227
- kfree (info );
7228
- err1 :
7229
7226
return err ;
7230
7227
}
7231
7228
@@ -7237,7 +7234,6 @@ static void __exit nf_tables_module_exit(void)
7237
7234
unregister_pernet_subsys (& nf_tables_net_ops );
7238
7235
rcu_barrier ();
7239
7236
nf_tables_core_module_exit ();
7240
- kfree (info );
7241
7237
}
7242
7238
7243
7239
module_init (nf_tables_module_init );
0 commit comments