Thread (4 messages) 4 messages, 3 authors, 2021-08-06

Re: [PATCH] LSM: add NULL check for kcalloc()

flat view

From: James Morris <jmorris@namei.org>
Date: 2021-07-14 19:12:34
Also in: lkml

On Tue, 13 Jul 2021, Austin Kim wrote:
quoted hunk ↗ jump to hunk
From: Austin Kim <redacted>

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

Signed-off-by: Austin Kim <redacted>
---
 security/security.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/security/security.c b/security/security.c
index 09533cbb7221..f885c9e9bc35 100644
--- a/security/security.c
+++ b/security/security.c
@@ -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;
Your logic is reversed here.

Should this also be a kernel panic?
 
 	if (chosen_lsm_order) {
 		if (chosen_major_lsm) {
-- 
2.20.1
-- 
James Morris
[off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help