Skip to contentSkip to conversation

LSM: add NULL check for kcalloc()

PATCH New Austin Kim 1 participant 1 message Jul 14, 2021 Security (LSM)

lore
Share & tools
lore

Austin Kim

author
#0 lore raw

PATCH v2 1/1 LSM: add NULL check for kcalloc()

From: Austin Kim <[email protected]>

kcalloc() may return NULL when memory allocation fails.
So it is necessary to add NULL check after the call to kcalloc() is made.

---
 security/security.c | 2 ++
 1 file changed, 2 insertions(+)
security/security.c +2 -0
index 09533cbb7221..f885c9e9bc35 100644
@@ -321,6 +321,8 @@ static void __init ordered_lsm_init(void)
 
 	ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms),
 				GFP_KERNEL);
+	if (!ordered_lsms)
+		return;
 
 	if (chosen_lsm_order) {
 		if (chosen_major_lsm) {
Signature · 1 line
2.20.1