Skip to content

Commit

Permalink
net: ipv6: check return value of rhashtable_init
Browse files Browse the repository at this point in the history
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.

Signed-off-by: MichelleJin <[email protected]>
Reviewed-by: David Ahern <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
MichelleJin12 authored and davem330 committed Sep 28, 2021
1 parent d7cade5 commit f04ed7d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion net/ipv6/ila/ila_xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions net/ipv6/seg6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(rcu_dereference_raw(sdata->tun_src));
return -ENOMEM;
};
#endif

return 0;
Expand All @@ -388,7 +392,7 @@ static void __net_exit seg6_net_exit(struct net *net)
seg6_hmac_net_exit(net);
#endif

kfree(sdata->tun_src);
kfree(rcu_dereference_raw(sdata->tun_src));
kfree(sdata);
}

Expand Down
4 changes: 1 addition & 3 deletions net/ipv6/seg6_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ int __net_init seg6_hmac_net_init(struct net *net)
{
struct seg6_pernet_data *sdata = seg6_pernet(net);

rhashtable_init(&sdata->hmac_infos, &rht_params);

return 0;
return rhashtable_init(&sdata->hmac_infos, &rht_params);
}
EXPORT_SYMBOL(seg6_hmac_net_init);

Expand Down

0 comments on commit f04ed7d

Please sign in to comment.