Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ipv6: 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.

Signed-off-by: MichelleJin <shjy180909@gmail.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

MichelleJin and committed by
David S. Miller
f04ed7d2 d7cade51

+12 -6
+5 -1
net/ipv6/ila/ila_xlat.c
··· 610 610 if (err) 611 611 return err; 612 612 613 - rhashtable_init(&ilan->xlat.rhash_table, &rht_params); 613 + err = rhashtable_init(&ilan->xlat.rhash_table, &rht_params); 614 + if (err) { 615 + free_bucket_spinlocks(ilan->xlat.locks); 616 + return err; 617 + } 614 618 615 619 return 0; 616 620 }
+6 -2
net/ipv6/seg6.c
··· 374 374 net->ipv6.seg6_data = sdata; 375 375 376 376 #ifdef CONFIG_IPV6_SEG6_HMAC 377 - seg6_hmac_net_init(net); 377 + if (seg6_hmac_net_init(net)) { 378 + kfree(sdata); 379 + kfree(rcu_dereference_raw(sdata->tun_src)); 380 + return -ENOMEM; 381 + }; 378 382 #endif 379 383 380 384 return 0; ··· 392 388 seg6_hmac_net_exit(net); 393 389 #endif 394 390 395 - kfree(sdata->tun_src); 391 + kfree(rcu_dereference_raw(sdata->tun_src)); 396 392 kfree(sdata); 397 393 } 398 394
+1 -3
net/ipv6/seg6_hmac.c
··· 405 405 { 406 406 struct seg6_pernet_data *sdata = seg6_pernet(net); 407 407 408 - rhashtable_init(&sdata->hmac_infos, &rht_params); 409 - 410 - return 0; 408 + return rhashtable_init(&sdata->hmac_infos, &rht_params); 411 409 } 412 410 EXPORT_SYMBOL(seg6_hmac_net_init); 413 411