Blob Blame History Raw
From 87ea58433208d17295e200d56be5e2a4fe4ce7d6 Mon Sep 17 00:00:00 2001
From: Eric Biggers <ebiggers@google.com>
Date: Tue, 17 Jul 2018 10:36:04 -0700
Subject: [PATCH] security: check for kstrdup() failure in lsm_append()
Git-commit: 87ea58433208d17295e200d56be5e2a4fe4ce7d6
Patch-mainline: v4.19-rc1
References: bsc#1051510

lsm_append() should return -ENOMEM if memory allocation failed.

Fixes: d69dece5f5b6 ("LSM: Add /sys/kernel/security/lsm")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: James Morris <james.morris@microsoft.com>
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 security/security.c |    2 ++
 1 file changed, 2 insertions(+)

--- a/security/security.c
+++ b/security/security.c
@@ -95,6 +95,8 @@ static int lsm_append(char *new, char **
 
 	if (*result == NULL) {
 		*result = kstrdup(new, GFP_KERNEL);
+		if (*result == NULL)
+			return -ENOMEM;
 	} else {
 		cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new);
 		if (cp == NULL)