selinux/stable-5.16 PR 20211123

-----BEGIN PGP SIGNATURE-----
 
 iQJIBAABCAAyFiEES0KozwfymdVUl37v6iDy2pc3iXMFAmGdTV8UHHBhdWxAcGF1
 bC1tb29yZS5jb20ACgkQ6iDy2pc3iXPN5Q/+O4ZtB40NcUOHOtJebrlXDdfTRpqJ
 xLkVlAdOLF1v9PuigJ85AW9zyBn8cbb6mQxHeiVJaFpRCUO6xcsi32cg9y+3oYfj
 rAGREsSD3JULvQTbist5e93BVbj+7J8+tgXwwUde38HqTViAAiZUQeWvZ32/Ussy
 9P+PNUeWHy5X9y76YEBNEdvhPcSVH63nFbq2CC4WPlfe5vlaU2231L3Hwia/LWEt
 oJsRDTUQ0iLBAfj0RH+UPZrci0L1F9HajP0MmaBazof4HBK/OnO0h18p7B8z1DdL
 wfCxNi5ovlAyMtU8hbmzuGAr1HtXJu7Lj+ee5E4mb/3KfiG4/rDG9gvDHTDsri/n
 S28eYKE1B0qpA4+KUvxu/7O9T8EBfb8jM4JQmcU5BOQvDyNbBHgOa6shG1fUBvva
 wdlO6JREXA4mFjph91PSLWOLFPmzFgS/FBRYKej1OAOX2VCPN2z+UwixE3jfPzxk
 YFUn34tz99/6xzgzWFMi4uPBU3TIOmXm7ZfeSjYoFKeWHjNkEihax96zgIHweSFY
 HyEJYjNtXyiY/0kJRD/EAV7ORqpIsG5eiL3b22rgeoyTncW1kUykroUozG/tzAnA
 xn9/6DIyofQdtdsgXThIPddJd+zEuJu9jweSPClzerHP45ILgdDcuG4pA91BG/vp
 Vbxmkjb8xdxZu5A=
 =3GqX
 -----END PGP SIGNATURE-----

Merge tag 'selinux-pr-20211123' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux

Pull SELinux fix from Paul Moore:
 "A fix to make sure things are handled correctly when an allocation
  fails"

* tag 'selinux-pr-20211123' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux:
  selinux: fix NULL-pointer dereference when hashtab allocation fails
This commit is contained in:
Linus Torvalds 2021-11-23 13:59:54 -08:00
commit 5d9f4cf367

View File

@ -31,13 +31,20 @@ static u32 hashtab_compute_size(u32 nel)
int hashtab_init(struct hashtab *h, u32 nel_hint)
{
h->size = hashtab_compute_size(nel_hint);
h->nel = 0;
if (!h->size)
return 0;
u32 size = hashtab_compute_size(nel_hint);
h->htable = kcalloc(h->size, sizeof(*h->htable), GFP_KERNEL);
return h->htable ? 0 : -ENOMEM;
/* should already be zeroed, but better be safe */
h->nel = 0;
h->size = 0;
h->htable = NULL;
if (size) {
h->htable = kcalloc(size, sizeof(*h->htable), GFP_KERNEL);
if (!h->htable)
return -ENOMEM;
h->size = size;
}
return 0;
}
int __hashtab_insert(struct hashtab *h, struct hashtab_node **dst,