From 8d84d690f6e30c4b4ef5cb3f04ab988a9069e3e1 Mon Sep 17 00:00:00 2001 From: Lv Ruyi Date: Tue, 29 Mar 2022 10:40:04 +0000 Subject: [PATCH] proc: bootconfig: Add null pointer check kzalloc is a memory allocation function which can return NULL when some internal memory errors happen. It is safer to add null pointer check. Link: https://lkml.kernel.org/r/20220329104004.2376879-1-lv.ruyi@zte.com.cn Cc: stable@vger.kernel.org Fixes: 9d52ced8893c ("proc: bootconfig: Add /proc/bootconfig to show boot config list") Acked-by: Masami Hiramatsu Reported-by: Zeal Robot Signed-off-by: Lv Ruyi Signed-off-by: Steven Rostedt (Google) --- fs/proc/bootconfig.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c index 6d8d4bf208377..2e244ada1f970 100644 --- a/fs/proc/bootconfig.c +++ b/fs/proc/bootconfig.c @@ -32,6 +32,8 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size) int ret = 0; key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL); + if (!key) + return -ENOMEM; xbc_for_each_key_value(leaf, val) { ret = xbc_node_compose_key(leaf, key, XBC_KEYLEN_MAX); -- 2.39.5