check return value of rhashtable_init in mlx5e, ipv6, mac80211.
Subsystems (5)
v3 cover check return value of rhashtable_init in mlx5e, ipv6, mac80211.
When rhashtable_init() fails, it returns -EINVAL. However, since error return value of rhashtable_init is not checked, it can cause use of uninitialized pointers.
So, fix unhandled errors of rhashtable_init.
The three patches are essentially the same logic.
v1->v2:
- change commit message
- fix possible memory leaksv2->v3:
- split patch into mlx5e, ipv6, mac80211.
MichelleJin (3):
net/mlx5e: check return value of rhashtable_init
net: ipv6: check return value of rhashtable_init
net: mac80211: check return value of rhashtable_init
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 14 +++++++++++--- net/ipv6/ila/ila_xlat.c | 6 +++++- net/ipv6/seg6.c | 6 +++++- net/ipv6/seg6_hmac.c | 6 +++++- net/mac80211/mesh_pathtbl.c | 5 ++++- 5 files changed, 30 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/3 net/mlx5e: check return value of rhashtable_init
When rhashtable_init() fails, it returns -EINVAL. However, since error return value of rhashtable_init is not checked, it can cause use of uninitialized pointers.
So, fix unhandled errors of rhashtable_init.
---
v1->v2:
- change commit message
- fix unneeded destroying of htv2->v3:
- nothing changed
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +11 -3
@@ -2127,12 +2127,20 @@ mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains, ct_priv->post_act = post_act;mutex_init (&ct_priv->control_lock); -rhashtable_init (&ct_priv->zone_ht, &zone_params); -rhashtable_init (&ct_priv->ct_tuples_ht, &tuples_ht_params); -rhashtable_init (&ct_priv->ct_tuples_nat_ht, &tuples_nat_ht_params); +if (rhashtable_init (&ct_priv->zone_ht, &zone_params)) + goto err_ct_zone_ht; +if (rhashtable_init (&ct_priv->ct_tuples_ht, &tuples_ht_params)) + goto err_ct_tuples_ht; +if (rhashtable_init (&ct_priv->ct_tuples_nat_ht, &tuples_nat_ht_params)) + goto err_ct_tuples_nat_ht;return ct_priv; +err_ct_tuples_nat_ht: +rhashtable_destroy (&ct_priv->ct_tuples_ht); +err_ct_tuples_ht: +rhashtable_destroy (&ct_priv->zone_ht); +err_ct_zone_ht: err_ct_nat_tbl:mlx5_chains_destroy_global_table (chains, ct_priv->ct); err_ct_tbl:
Signature · 1 line
2.25.1
PATCH v3 2/3 net: ipv6: check return value of rhashtable_init
In reply to MichelleJinWhen rhashtable_init() fails, it returns -EINVAL. However, since error return value of rhashtable_init is not checked, it can cause use of uninitialized pointers.
So, fix unhandled errors of rhashtable_init.
---
v1->v2:
- change commit message
- fix possible memory leaksv2->v3:
- nothing changed
net/ipv6/ila/ila_xlat.c | 6 +++++- net/ipv6/seg6.c | 6 +++++- net/ipv6/seg6_hmac.c | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-)
net/ipv6/ila/ila_xlat.c +5 -1
@@ -610,7 +610,11 @@ int ila_xlat_init_net(struct net *net)if (err)return err; -rhashtable_init (&ilan->xlat.rhash_table, &rht_params); + err =rhashtable_init (&ilan->xlat.rhash_table, &rht_params); +if (err) { +free_bucket_spinlocks (ilan->xlat.locks); +return err; + }return 0 ; }
net/ipv6/seg6.c +5 -1
@@ -374,7 +374,11 @@ static int __net_init seg6_net_init(struct net *net) net->ipv6.seg6_data = sdata;#ifdef CONFIG_IPV6_SEG6_HMAC -seg6_hmac_net_init (net); +if (seg6_hmac_net_init (net)) { +kfree (sdata); +kfree (sdata->tun_src); +return -ENOMEM ; + };#endif return 0 ;
net/ipv6/seg6_hmac.c +5 -1
@@ -403,9 +403,13 @@ EXPORT_SYMBOL(seg6_hmac_init);int __net_init seg6_hmac_net_init (struct net *net) { +int err; +struct seg6_pernet_data *sdata =seg6_pernet (net); -rhashtable_init (&sdata->hmac_infos, &rht_params); + err =rhashtable_init (&sdata->hmac_infos, &rht_params); +if (err) +return err;return 0 ; }
Signature · 1 line
2.25.1
Re: [PATCH net-next v3 2/3] net: ipv6: check return value of rhashtable_init
Quoted 8 lines · MichelleJin
net/ipv6/seg6_hmac.c +0
-0@@ -403,9 +403,13 @@ EXPORT_SYMBOL(seg6_hmac_init);int __net_init seg6_hmac_net_init (struct net *net) {
net/ipv6/seg6_hmac.c EXPORT_SYMBOL(seg6_hmac_init); · line 414
Quoted 10 lines
net/ipv6/seg6_hmac.c +5
-1+int err; +struct seg6_pernet_data *sdata =seg6_pernet (net); -rhashtable_init (&sdata->hmac_infos, &rht_params); + err =rhashtable_init (&sdata->hmac_infos, &rht_params); +if (err) +return err;return 0 ;
Just:
return rhashtable_init(&sdata->hmac_infos, &rht_params);
PATCH v3 3/3 net: mac80211: check return value of rhashtable_init
In reply to MichelleJinWhen rhashtable_init() fails, it returns -EINVAL. However, since error return value of rhashtable_init is not checked, it can cause use of uninitialized pointers.
So, fix unhandled errors of rhashtable_init.
---
v1->v2:
- change commit message
- fix possible memory leaksv2->v3:
- nothing changed
net/mac80211/mesh_pathtbl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/mac80211/mesh_pathtbl.c +4 -1
@@ -60,7 +60,10 @@ static struct mesh_table *mesh_table_alloc(void)atomic_set (&newtbl->entries,0 );spin_lock_init (&newtbl->gates_lock);spin_lock_init (&newtbl->walk_lock); -rhashtable_init (&newtbl->rhead, &mesh_rht_params); +if (rhashtable_init (&newtbl->rhead, &mesh_rht_params)) { +kfree (newtbl); +return NULL ; + }return newtbl; }
Signature · 1 line
2.25.1
2021년 9월 25일 (토) 오후 3:10, MichelleJin <[email protected]>님이 작성:
Quoted 25 lines
When
rhashtable_init()fails, it returns-EINVAL. However, since error return value ofrhashtable_initis not checked, it can cause use of uninitialized pointers.
So, fix unhandled errors ofrhashtable_init.
The three patches are essentially the same logic.
v1->v2:
- change commit message
- fix possible memory leaksv2->v3:
- split patch into mlx5e, ipv6, mac80211.MichelleJin (3):
net/mlx5e: check return value ofrhashtable_init
net: ipv6: check return value ofrhashtable_init
net: mac80211: check return value ofrhashtable_initdrivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 14 +++++++++++--- net/ipv6/ila/ila_xlat.c | 6 +++++- net/ipv6/seg6.c | 6 +++++- net/ipv6/seg6_hmac.c | 6 +++++- net/mac80211/mesh_pathtbl.c | 5 ++++- 5 files changed, 30 insertions(+), 7 deletions(-)
Quoted 3 lines
--
2.25.1
There are new build warnings in net/ipv6/seg6.c.
I'll fix it and send v4 soon.
Thank you.